/* PROTHERMO OS — charte thermo (orange chaud -> teal/bleu froid sur navy) */
:root {
  /* Charte PROTHERMO officielle (échantillonnée sur le logo) */
  --brand-orange: #e0873a;
  --brand-amber: #e8a03c;
  --brand-teal: #5aa0a8;
  --brand-cyan: #4fa3c7;
  --brand-blue: #2a5a72;
  --navy: #152430;
  --navy-2: #1c2f3e;
  --navy-3: #26404f;

  --ink: #1b2733;
  --muted: #5a6b7a;
  --line: #e2e8f0;
  --bg: #f4f7fb;
  --card: #ffffff;
  --danger: #d6455d;
  --ok: #2faf7d;

  --disp: 'Archivo', system-ui, sans-serif;
  --body: 'Public Sans', system-ui, sans-serif;
  --thermo: linear-gradient(135deg, var(--brand-teal), var(--brand-amber) 60%, var(--brand-orange));

  --radius: 12px;
  --shadow: 0 1px 3px rgba(6, 18, 26, .08), 0 8px 24px rgba(6, 18, 26, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--brand-cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Garde-fous anti-débordement horizontal (média et contenus larges) */
img, svg, video, canvas, iframe { max-width: 100%; }
canvas { height: auto; }

/* ---------------------------------------------------------------- LAYOUT */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px; flex-shrink: 0;
  background: var(--navy); color: #cdd8ea;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.brand-logo { height: 22px; width: auto; display: block; }
.brand-os {
  font-family: var(--disp); font-weight: 800; font-size: 11px; color: var(--brand-amber);
  letter-spacing: 1.5px; border: 1px solid rgba(232, 160, 60, .4); border-radius: 5px;
  padding: 1px 6px;
}

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav .group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.4px;
  color: #5d728c; padding: 14px 12px 6px; font-weight: 700;
}
.nav a.item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px; color: #c2d0e3;
  font-weight: 500; margin-bottom: 2px; position: relative;
}
.nav a.item:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.item.active { background: var(--navy-3); color: #fff; }
.nav a.item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 3px; background: var(--thermo);
}
.nav a.item .ic { width: 20px; text-align: center; font-size: 15px; }
.nav a.item .soon {
  margin-left: auto; font-size: 9px; background: rgba(232, 162, 60, .18);
  color: var(--brand-amber); padding: 2px 6px; border-radius: 20px;
  font-weight: 700; letter-spacing: .5px;
}

.userbox {
  border-top: 1px solid rgba(255, 255, 255, .07); padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.userbox .av {
  width: 32px; height: 32px; border-radius: 50%; background: var(--navy-3);
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px;
}
.userbox .who { font-size: 12.5px; line-height: 1.2; overflow: hidden; }
.userbox .who b { color: #fff; display: block; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width: 130px; }
.userbox .who span { color: #7e93ab; font-size: 11px; }
.userbox a.logout { margin-left: auto; color: #7e93ab; font-size: 16px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 24px; gap: 14px;
  position: sticky; top: 0; z-index: 5;
}
.topbar .title { font-family: var(--disp); font-weight: 700; font-size: 17px; }
.topbar .co { margin-left: auto; color: var(--muted); font-size: 13px; }
.content { padding: 24px; max-width: 1180px; width: 100%; }

/* ---------------------------------------------------------------- COMPONENTS */
.page-head { margin-bottom: 20px; }
.page-head h1 { font-family: var(--disp); font-size: 24px; margin: 0 0 4px; }
.page-head p { color: var(--muted); margin: 0; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card .card-body { padding: 20px; }
.card .card-head {
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  font-family: var(--disp); font-weight: 700; display: flex; align-items: center; gap: 10px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: block; color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 6px 20px rgba(6, 18, 26, .12); }
.tile .ic { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font-size: 22px; color: #fff; margin-bottom: 12px; }
.tile h3 { margin: 0 0 4px; font-family: var(--disp); font-size: 16px; }
.tile p { margin: 0; color: var(--muted); font-size: 13px; }
.tile .badge-soon { display: inline-block; margin-top: 10px; font-size: 10px; font-weight: 700; color: var(--brand-amber); background: rgba(232, 162, 60, .12); padding: 3px 9px; border-radius: 20px; letter-spacing: .5px; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
table.grid th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; }
table.grid tr:hover td { background: #fafcff; }

/* Conteneur de graphique : borne la hauteur, le canvas remplit (responsive) */
.chart-box { position: relative; width: 100%; height: 260px; }
.chart-box canvas { position: absolute; inset: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-family: var(--body); font-weight: 600; font-size: 14px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: #c7d2e0; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: #0e1a23; border-color: #0e1a23; }
.btn-danger { color: var(--danger); border-color: #f0c6cf; background: #fff; }
.btn-danger:hover { background: #fdecef; }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label.lbl { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: #33414f; }
input[type=text], input[type=email], input[type=password], input[type=tel], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-family: var(--body); font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-cyan); box-shadow: 0 0 0 3px rgba(79, 163, 199, .15); }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand-orange); }

.flash { padding: 11px 16px; border-radius: 9px; margin-bottom: 18px; font-weight: 600; font-size: 14px; }
.flash.ok { background: #e7f7f0; color: #1d7a56; border: 1px solid #b8e6d2; }
.flash.err { background: #fdecef; color: #b13049; border: 1px solid #f3c5d0; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.on { background: #e7f7f0; color: #1d7a56; }
.pill.off { background: #f0f2f5; color: #8a96a3; }
.pill.su { background: rgba(217, 110, 48, .12); color: var(--brand-orange); }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 16px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--brand-orange); border-bottom-color: var(--brand-orange); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* matrice de droits */
.matrix th, .matrix td { padding: 9px 12px; }
.matrix td.mod { font-weight: 600; }
.matrix td.center, .matrix th.center { text-align: center; width: 90px; }
.matrix .mod-ic { margin-right: 8px; }

/* ---------------------------------------------------------------- LOGIN */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 70% -10%, #103048, var(--navy)); }
.login-card { width: 380px; background: var(--card); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); overflow: hidden; }
.login-card .head { background: var(--thermo); height: 8px; }
.login-card .body { padding: 32px 30px; }
.login-card .logo-big { width: 52px; height: 52px; border-radius: 13px; background: var(--thermo); display: grid; place-items: center; font-family: var(--disp); font-weight: 900; font-size: 24px; color: var(--navy); margin-bottom: 16px; }
.login-card h1 { font-family: var(--disp); font-size: 22px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }

/* ---------------------------------------------------------------- CRM KANBAN */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol { flex: 0 0 270px; background: #eef2f8; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 200px); }
.kcol-head { padding: 12px 14px; font-family: var(--disp); font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; border-bottom: 2px solid; }
.kcol-head .count { font-size: 11px; background: rgba(6,18,26,.08); color: var(--muted); padding: 1px 8px; border-radius: 20px; font-family: var(--body); }
.kcol-head .sum { margin-left: auto; font-size: 12px; color: var(--brand-blue); font-family: var(--body); font-weight: 700; }
.kcol-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; box-shadow: 0 1px 2px rgba(6,18,26,.06); }
.kcard .ktitle { font-weight: 700; font-size: 14px; margin-bottom: 3px; display: block; color: var(--ink); }
.kcard .ktitle:hover { color: var(--brand-orange); text-decoration: none; }
.kcard .kmeta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kcard .krev { font-family: var(--disp); font-weight: 700; color: var(--brand-blue); font-size: 13px; }
.kcard .kfoot { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.kcard select { font-size: 11.5px; padding: 4px 6px; border-radius: 7px; }
.actbadge { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; display: inline-flex; align-items: center; gap: 4px; }
.actbadge.ok { background: #e7f7f0; color: #1d7a56; }
.actbadge.late { background: #fdecef; color: #b13049; }
.actbadge.none { background: #fff4e0; color: #b97a1a; }
.kcol.empty .kcol-body { color: var(--muted); font-size: 13px; text-align: center; padding: 18px; }

/* timeline activités */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .tk { width: 64px; flex-shrink: 0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--brand-cyan); padding-top: 2px; }
.timeline .tbody { flex: 1; }
.timeline .tbody .ts { font-weight: 600; }
.timeline .tbody .td { font-size: 12px; color: var(--muted); }
.timeline li.done .tbody .ts { text-decoration: line-through; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- AGENDA */
.cal-nav { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.cal-nav h2 { font-family: var(--disp); font-size: 20px; margin: 0; text-transform: capitalize; }
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal th { background: #f0f4fa; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); padding: 9px; border-bottom: 1px solid var(--line); }
.cal td { height: 108px; vertical-align: top; border: 1px solid var(--line); padding: 5px 6px; position: relative; }
.cal td.other { background: #fafbfd; }
.cal td.other .daynum { color: #c2ccd8; }
.cal td.today { background: #fff6ef; }
.cal .daynum { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.cal td.today .daynum { background: var(--brand-orange); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: inline-grid; place-items: center; }
.cal .addday { position: absolute; top: 5px; right: 6px; color: #c2ccd8; font-size: 15px; text-decoration: none; opacity: 0; }
.cal td:hover .addday { opacity: 1; }
.cal .ev { display: block; font-size: 11.5px; color: #fff; padding: 2px 6px; border-radius: 5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .ev:hover { text-decoration: none; filter: brightness(1.07); }

/* chips statut */
.chip { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.chip.gray { background: #eef1f5; color: #6a7682; }
.chip.green { background: #e7f7f0; color: #1d7a56; }
.chip.red { background: #fdecef; color: #b13049; }
.chip.amber { background: #fff4e0; color: #b97a1a; }
.chip.blue { background: #e6f1f8; color: #2a6f93; }

.kpi { display: flex; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.kpi .box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); min-width: 150px; }
.kpi .box .v { font-family: var(--disp); font-size: 24px; font-weight: 800; }
.kpi .box .l { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- ASSISTANT IA */
.ai-fab { position: fixed; right: 22px; bottom: 22px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--thermo); color: #06121a; border: none; cursor: pointer; font-size: 24px;
  box-shadow: 0 8px 24px rgba(6,18,26,.3); z-index: 50; display: grid; place-items: center; }
.ai-fab:hover { filter: brightness(1.05); }
.ai-panel { position: fixed; right: 22px; bottom: 88px; width: 380px; max-width: calc(100vw - 44px);
  height: 540px; max-height: calc(100vh - 130px); background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(6,18,26,.28); z-index: 50; display: none;
  flex-direction: column; overflow: hidden; }
.ai-panel.open { display: flex; }
.ai-head { background: var(--navy); color: #fff; padding: 12px 16px; font-family: var(--disp); font-weight: 700;
  display: flex; align-items: center; gap: 8px; }
.ai-head .x { margin-left: auto; cursor: pointer; opacity: .8; background: none; border: none; color: #fff; font-size: 18px; }
.ai-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.ai-msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.ai-msg.user { align-self: flex-end; background: var(--brand-orange); color: #fff; border-bottom-right-radius: 3px; }
.ai-msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.ai-msg.err { align-self: flex-start; background: #fdecef; color: #b13049; border: 1px solid #f3c5d0; }
.ai-foot { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; background: var(--card); }
.ai-foot textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 9px; padding: 9px; font-family: var(--body); font-size: 14px; height: 42px; }
.ai-foot button { border: none; background: var(--brand-orange); color: #fff; border-radius: 9px; padding: 0 14px; cursor: pointer; font-weight: 700; }
.ai-hint { color: var(--muted); font-size: 12px; text-align: center; padding: 4px; }

/* ================================================================ RESPONSIVE
   Refonte mobile & tablette « brique par brique ». Quatre paliers :
   ≤1024 (tablette), ≤900 (tiroir off-canvas), ≤600 (téléphone),
   ≤380 (très petits écrans). La sidebar devient un tiroir (hamburger),
   les tables scrollent proprement, le kanban défile colonne par colonne,
   les formulaires passent tactiles, l'assistant devient une feuille. */

/* Bouton hamburger (dans la topbar) — masqué tant qu'on est en large */
.nav-toggle {
  display: none; background: none; border: 0; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--ink); padding: 6px 10px;
  margin-left: -6px; border-radius: 9px;
}
.nav-toggle:hover { background: var(--bg); }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 18, 26, .45); backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}

/* La topbar peut rétrécir sans pousser ses voisins hors écran */
.topbar .title {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- Tablette : largeurs un peu plus souples ---- */
@media (max-width: 1024px) {
  .sidebar { width: 224px; }
  .content { padding: 20px; }
  .form-grid { gap: 14px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* ---- Bascule mobile / petite tablette : sidebar en tiroir ---- */
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; align-items: center; }

  /* La sidebar passe en overlay fixe, glissée hors écran par défaut.
     padding-left = encoche éventuelle (téléphone en paysage). */
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100%;
    width: 280px; max-width: 86vw; z-index: 70;
    padding-left: env(safe-area-inset-left);
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
  }
  .sidebar.open { transform: translateX(0); }
  body.nav-open .sidebar-overlay { display: block; }
  body.nav-open { overflow: hidden; }            /* fige le scroll derrière le tiroir */
  /* Cibles tactiles plus généreuses dans le menu */
  .nav a.item { padding: 11px 12px; }

  .main { width: 100%; min-width: 0; }
  .topbar {
    padding: 0 14px; gap: 10px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .topbar .title { font-size: 16px; }
  .topbar .co { font-size: 12px; max-width: 38vw; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 16px; }

  .page-head h1 { font-size: 21px; }

  /* Formulaires & colonnes : tout en une colonne (le !important bat les
     grid-template-columns posés en inline, ex. boîte mail, atelier devis,
     accès rapide du tableau de bord). */
  .form-grid { grid-template-columns: 1fr; }
  .two-col,
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  /* Les cartes plafonnées en dur (max-width:…px inline) deviennent fluides */
  .card[style*="max-width"], form[style*="max-width"], div[style*="max-width"] {
    max-width: 100% !important;
  }

  /* Tables de données : scroll horizontal propre, sans casser la page.
     display:block sur la table seule (PAS sur thead/tbody, sinon les colonnes
     en-tête / corps se désalignent) ; le contenu non sécable déborde et scrolle. */
  table.grid {
    display: block; width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  table.grid th, table.grid td { white-space: nowrap; }
  table.grid th, table.grid td { padding: 10px 12px; }
  /* fine barre de défilement discrète */
  table.grid::-webkit-scrollbar, .tabs::-webkit-scrollbar,
  .kanban::-webkit-scrollbar, .cal-wrap::-webkit-scrollbar { height: 6px; }
  table.grid::-webkit-scrollbar-thumb, .kanban::-webkit-scrollbar-thumb,
  .cal-wrap::-webkit-scrollbar-thumb { background: #cdd6e0; border-radius: 6px; }

  /* Calendrier : scroll horizontal via le wrapper, cellules réduites */
  .cal-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal { min-width: 680px; }
  .cal td { height: 84px; }
  .cal td[style*="height"] { height: 220px !important; }   /* vue semaine */

  /* Barres d'outils & onglets : retour à la ligne / scroll ; boutons tactiles */
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar form { display: inline-flex; }
  .cal-nav { flex-wrap: wrap; row-gap: 8px; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { height: 0; }
  .tabs a { white-space: nowrap; }

  /* Kanban : défilement « par colonne » (scroll-snap) pour le pouce */
  .kanban {
    scroll-snap-type: x proximity; gap: 12px;
    margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px;
  }
  .kcol { flex-basis: 84vw; max-width: 320px; scroll-snap-align: start;
    max-height: none; }

  /* KPI : cartes souples empilées */
  .kpi { gap: 12px; }
  .kpi .box { flex: 1 1 140px; min-width: 130px; }

  /* Carte de connexion fluide */
  .login-card { width: 100%; max-width: 400px; margin: 0 16px; }

  /* Assistant : bulle compacte, panneau quasi pleine largeur */
  .ai-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 54px; height: 54px; }
  .ai-panel { right: 12px; left: 12px; width: auto; max-width: none; bottom: 80px; }
}

/* ---- Téléphones ---- */
@media (max-width: 600px) {
  body { font-size: 14.5px; }
  .content { padding: 14px; padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right)); }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: 19px; }
  .topbar { height: 54px; }
  .topbar .co { display: none; }                 /* on masque la société pour la place */

  .tiles { grid-template-columns: 1fr; gap: 12px; }
  .form-grid { gap: 12px; }

  /* Anti-zoom iOS : 16px sur les champs ; cibles tactiles confortables */
  input[type=text], input[type=email], input[type=password], input[type=tel],
  input[type=search], input[type=number], input[type=date], textarea, select {
    font-size: 16px; padding: 11px 12px;
  }
  .btn { padding: 11px 16px; min-height: 42px; }
  .btn-sm { padding: 8px 12px; min-height: 38px; }

  /* Cartes & contenu : un peu plus de respiration verticale, moins de marges */
  .card .card-body { padding: 16px; }
  .card .card-head { padding: 12px 16px; }

  /* Titres de page / KPI plus compacts */
  .kpi .box { padding: 12px 14px; }
  .kpi .box .v { font-size: 21px; }

  /* Atelier devis : la conversation ne mange pas tout l'écran */
  .chat { height: 60vh !important; }

  /* Le panneau assistant occupe l'écran de bord à bord, comme une feuille */
  .ai-panel {
    right: 8px; left: 8px; width: auto;
    bottom: calc(8px + env(safe-area-inset-bottom));
    max-width: none; height: 78vh; max-height: none; border-radius: 18px;
  }
  .ai-msg { max-width: 90%; }

  /* Boutons d'action de formulaire : pleine largeur, empilés et tapables */
  .form-actions, .btn-row { flex-wrap: wrap; }

  /* ============================================================
     LISTES → CARTES. Plus aucune table plus large que l'écran :
     chaque ligne devient une carte « libellé : valeur » (les libellés
     sont recopiés du <thead> par un petit script dans base.html).
     On exclut la matrice de droits (.matrix) et le calendrier (.cal). */
  table.grid:not(.matrix) { display: block; width: 100%; overflow: visible; border: 0; }
  table.grid:not(.matrix) thead { position: absolute; left: -9999px; }   /* masqué mais accessible */
  table.grid:not(.matrix) tbody { display: block; }
  table.grid:not(.matrix) tr {
    display: block; background: #fff; border: 1px solid var(--line);
    border-radius: 11px; padding: 9px 13px; margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(6, 18, 26, .05);
  }
  table.grid:not(.matrix) tr:hover td { background: transparent; }
  table.grid:not(.matrix) td {
    display: flex; align-items: center; gap: 10px;
    width: auto !important; max-width: none !important;
    padding: 4px 0 !important; border: 0 !important;
    white-space: normal !important; text-align: left !important;
    overflow: visible !important; font-size: 14px; min-height: 26px;
  }
  /* Libellé de colonne (data-label posé en JS) */
  table.grid:not(.matrix) td[data-label]::before {
    content: attr(data-label); flex: 0 0 40%; max-width: 40%;
    font-weight: 700; color: var(--muted); font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .4px;
  }
  /* 1re cellule = titre de la carte (mise en avant, sans libellé) */
  table.grid:not(.matrix) td:first-child { font-weight: 600; font-size: 15.5px; padding-top: 2px !important; }
  table.grid:not(.matrix) td:first-child::before { display: none; }
  table.grid:not(.matrix) td:first-child a { font-weight: 700; }
  /* Cellule d'actions (dernière) : boutons sous le contenu, tapables */
  table.grid:not(.matrix) td:last-child { flex-wrap: wrap; margin-top: 2px; }
  table.grid:not(.matrix) td .btn { flex: 0 0 auto; }
  /* Lignes « vide / message » (colspan) : centrées, sans libellé */
  table.grid:not(.matrix) td[colspan] { justify-content: center; }
  table.grid:not(.matrix) td[colspan]::before { display: none; }
  /* Inputs/selects dans une cellule (éditeur de lignes de devis) : pleine largeur */
  table.grid:not(.matrix) td input, table.grid:not(.matrix) td select { flex: 1; width: 100% !important; }

  /* Boîte mail : pas de <thead>, on soigne la carte message à la main */
  .mail-list td:first-child { font-weight: 400; font-size: 14px; flex: 0 0 auto; }
  .mail-list td:nth-child(2) { flex: 0 0 auto; }                /* étoile à côté de la case */
  .mail-list td:nth-child(4) a { font-weight: 700; font-size: 14.5px; }  /* objet en avant */
  .mail-list tr.unseen td { background: transparent; }

  /* Graphiques bornés en hauteur (cf. .chart-box) */
  .chart-box { height: 200px; }
}

/* ---- Très petits écrans ---- */
@media (max-width: 380px) {
  .content { padding: 11px; }
  .brand-os { display: none; }
  .kcol { flex-basis: 88vw; }
  .tabs a { padding: 9px 12px; }
}

/* ---- Respect des préférences « animations réduites » ---- */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
