/* Villa Didon — tableau de bord.
   Chrome : chaux de Sidi Bou Said, encre du Golfe, pourpre de Tyr (interface uniquement).
   Graphiques : palette categorielle validee (dataviz), jamais la pourpre.
   Jetons clairs par defaut ; sombre via prefers-color-scheme ou data-theme. */
:root {
  color-scheme: light;
  --chaux: #f6f8f9;
  --surface: #ffffff;
  --surface-2: #eef2f4;
  --golfe: #0f2a3d;
  --golfe-texte: #e8eef2;
  --texte: #0f2a3d;
  --texte-2: #4a5b67;
  --muet: #6f7e89;
  --byrsa: #d5dbdf;
  --grille: #e6eaed;
  --axe: #c4ccd2;
  --pourpre: #7a2450;
  --pourpre-doux: #f5e9ef;
  --hausse: #006300;
  --baisse: #c43535;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-vide: #e3e8eb; --seq-plein: #2a78d6;
  --ok: #0ca30c; --alerte: #fab219; --serieux: #ec835a; --critique: #d03b3b;
  --chiffres: Bahnschrift, "DIN Alternate", "Segoe UI Variable Display", "Segoe UI", sans-serif;
  --texte-police: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --chaux: #0c151c; --surface: #121e27; --surface-2: #1a2833;
    --golfe: #08111a; --golfe-texte: #dfe7ec;
    --texte: #e6edf1; --texte-2: #b3c0c9; --muet: #84939d;
    --byrsa: #263642; --grille: #1f2d38; --axe: #34444f;
    --pourpre: #d07aa3; --pourpre-doux: #2b1822;
    --hausse: #0ca30c; --baisse: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-vide: #1f2d38; --seq-plein: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --chaux: #0c151c; --surface: #121e27; --surface-2: #1a2833;
  --golfe: #08111a; --golfe-texte: #dfe7ec;
  --texte: #e6edf1; --texte-2: #b3c0c9; --muet: #84939d;
  --byrsa: #263642; --grille: #1f2d38; --axe: #34444f;
  --pourpre: #d07aa3; --pourpre-doux: #2b1822;
  --hausse: #0ca30c; --baisse: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-vide: #1f2d38; --seq-plein: #3987e5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--chaux); color: var(--texte); font: 15px/1.5 var(--texte-police); }
h1, h2, h3, p { margin: 0; }
button { font: inherit; }
.chiffre { font-family: var(--chiffres); font-variant-numeric: tabular-nums; }

/* ---------- Bandeau ---------- */
.bandeau {
  position: sticky; top: 0; z-index: 5; height: 60px;
  display: flex; align-items: center; gap: 24px; padding: 0 28px;
  background: var(--golfe); color: var(--golfe-texte);
}
.logotype { font-family: var(--chiffres); font-size: 22px; font-weight: 300; letter-spacing: 0.06em; }
.fraicheur { margin-left: auto; font-size: 13px; color: color-mix(in srgb, var(--golfe-texte) 75%, transparent); }
.fraicheur.ko { color: #ffb4b4; }
.btn-ia {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; white-space: nowrap;
  border: 0; border-radius: 6px; padding: 8px 14px; background: var(--pourpre); color: #fff; font-weight: 600;
}
.btn-ia:hover { filter: brightness(1.12); }
.btn-ia[aria-expanded="true"] { background: var(--golfe-texte); color: var(--golfe); }

/* ---------- Cadre & navigation ---------- */
.cadre { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.navigation {
  position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px);
  display: flex; flex-direction: column; gap: 2px; padding: 28px 16px 20px;
}
.navigation button {
  text-align: left; cursor: pointer; background: none; border: 0; border-radius: 6px;
  padding: 8px 12px; color: var(--texte-2);
}
.navigation button:hover { color: var(--texte); background: var(--surface-2); }
.navigation .ico, .navigation .lib-court { display: none; }
.navigation button[aria-selected="true"] { color: var(--pourpre); font-weight: 600; background: var(--pourpre-doux); }
.nav-pied { margin-top: auto; padding: 0 12px; font-size: 12px; color: var(--muet); line-height: 1.5; max-width: 180px; }

main { padding: 32px 36px 96px 20px; min-width: 0; max-width: 1440px; }
body.ia-ouverte .cadre { margin-right: 420px; }

/* ---------- Ouverture de section ---------- */
.ouverture { margin-bottom: 30px; max-width: 72ch; }
.ouverture h1 { font-family: var(--chiffres); font-weight: 400; font-size: 32px; line-height: 1.15; letter-spacing: -0.005em; }
.ouverture p { margin-top: 8px; color: var(--texte-2); }

/* Recit de la nuit (Synthese) */
.recit { font-family: var(--chiffres); font-weight: 300; font-size: 30px; line-height: 1.3; max-width: 30ch; letter-spacing: -0.01em; }
.recit strong { font-weight: 600; }
.recit-suite { margin-top: 12px; color: var(--texte-2); max-width: 68ch; }

/* Hero : les 10 suites, nuit par nuit */
.hero { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(420px, 1.35fr); gap: 40px; align-items: end; margin-bottom: 40px; }
.suites-zone h2 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.suites-zone > p { font-size: 13px; color: var(--muet); margin-bottom: 14px; }
.suites { display: grid; grid-template-columns: repeat(14, minmax(22px, 1fr)); gap: 5px; }
.nuit { display: flex; flex-direction: column; align-items: stretch; gap: 3px; }
.nuit .cases { display: flex; flex-direction: column-reverse; gap: 3px; }
.nuit .case { height: 12px; border-radius: 2px; background: var(--seq-vide); }
.nuit .case.occ { background: var(--seq-plein); }
.nuit .case.hs { background: repeating-linear-gradient(45deg, var(--seq-vide) 0 3px, var(--axe) 3px 5px); }
.nuit .nb { font-family: var(--chiffres); font-size: 12px; text-align: center; color: var(--texte); margin-bottom: 3px; }
.nuit .j { font-size: 11px; color: var(--muet); text-align: center; line-height: 1.2; margin-top: 5px; }
.nuit.weekend .j { color: var(--texte); font-weight: 600; }
.legende-suites { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--texte-2); margin-top: 12px; }
.legende-suites i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
@media (prefers-reduced-motion: no-preference) {
  .suites.anime .case.occ { animation: remplir 0.5s ease-out both; animation-delay: calc(var(--i) * 28ms); }
  @keyframes remplir { from { background: var(--seq-vide); } }
}

/* ---------- Groupes ---------- */
.groupe { margin-top: 44px; }
.groupe > h2 { font-size: 19px; font-weight: 600; font-family: var(--chiffres); }
.groupe > p { color: var(--texte-2); font-size: 13px; margin-top: 2px; margin-bottom: 14px; max-width: 80ch; }

/* Bande de chiffres cles : un seul bloc, cellules separees par des filets */
.bande { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); border-top: 2px solid var(--golfe); border-bottom: 1px solid var(--byrsa); }
.mesure { padding: 14px 18px 14px 0; border-right: 1px solid var(--byrsa); margin-right: 18px; display: flex; flex-direction: column; min-height: 118px; }
.mesure:last-child { border-right: 0; }
.mesure .lib { color: var(--texte-2); font-size: 13px; }
.mesure .val { font-family: var(--chiffres); font-stretch: condensed; font-size: 34px; font-weight: 400; line-height: 1.05; margin-top: 6px; font-variant-numeric: tabular-nums; }
.mesure .val small { font-size: 15px; color: var(--texte-2); margin-left: 3px; font-stretch: normal; }
.mesure .det { color: var(--muet); font-size: 12px; margin-top: 3px; }
.mesure .spark { margin-top: auto; padding-top: 8px; }
.mesure .spark svg { width: 100%; height: 24px; display: block; overflow: visible; }
.delta { font-size: 12px; font-weight: 600; margin-top: 4px; }
.delta.hausse { color: var(--hausse); }
.delta.baisse { color: var(--baisse); }
.delta.neutre { color: var(--muet); }

/* ---------- Graphiques ---------- */
.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 18px; }
.carte { background: var(--surface); border-radius: 8px; padding: 18px 20px 16px; min-width: 0; border: 1px solid var(--grille); }
.carte.large { grid-column: 1 / -1; }
.carte-tete { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.carte-tete h3 { font-size: 15px; font-weight: 600; }
.carte-tete p { margin-top: 2px; color: var(--muet); font-size: 12px; }
.bascule {
  margin-left: auto; font-size: 12px; cursor: pointer; color: var(--texte-2); white-space: nowrap;
  background: transparent; border: 1px solid var(--byrsa); border-radius: 5px; padding: 3px 9px;
}
.bascule:hover { color: var(--texte); border-color: var(--axe); }
.groupe > :is(.grille, .carte, .bande, .avertissement) + :is(.grille, .carte) { margin-top: 18px; }
.graphe { position: relative; height: 280px; }
.carte.haute .graphe { height: 360px; }
.note { color: var(--texte-2); font-size: 12px; margin-top: 10px; }
.avertissement { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; border-radius: 6px; background: var(--surface-2); font-size: 13px; color: var(--texte); }
.avertissement svg { flex: none; color: var(--serieux); margin-top: 2px; }

/* ---------- Tables ---------- */
.table-zone { overflow-x: auto; max-height: 460px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 12px 7px 0; text-align: left; border-bottom: 1px solid var(--grille); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); color: var(--texte-2); font-weight: 600; border-bottom-color: var(--byrsa); }
td.n, th.n { text-align: right; font-family: var(--chiffres); font-variant-numeric: tabular-nums; }
th.n { font-family: var(--texte-police); }
tbody tr:hover td { background: var(--surface-2); }
.barre-cellule { display: inline-block; height: 6px; border-radius: 0 3px 3px 0; background: var(--s1); vertical-align: middle; margin-left: 8px; }

.filtre { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; color: var(--texte-2); font-size: 13px; flex-wrap: wrap; }
.filtre select, .filtre input { font: inherit; padding: 5px 10px; border: 1px solid var(--byrsa); border-radius: 6px; background: var(--surface); color: var(--texte); }

.vide { padding: 40px 0; color: var(--texte-2); max-width: 60ch; }
.vide code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }

/* ---------- Assistant ---------- */
.assistant {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100vw; z-index: 10;
  display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--byrsa);
}
.assistant[hidden] { display: none; }
.assistant-tete { display: flex; align-items: flex-start; gap: 8px; padding: 18px 18px 16px; background: var(--golfe); color: var(--golfe-texte); }
.assistant-titre { font-family: var(--chiffres); font-weight: 400; font-size: 21px; }
.assistant-sous { font-size: 13px; margin-top: 4px; color: color-mix(in srgb, var(--golfe-texte) 72%, transparent); max-width: 42ch; }
.assistant-tete .btn-icone { margin-left: auto; color: var(--golfe-texte); }
.btn-icone { background: none; border: 0; cursor: pointer; color: var(--texte-2); padding: 4px 8px; font-size: 16px; }
.assistant-options { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--grille); font-size: 13px; color: var(--texte-2); }
.assistant-options select { margin-left: auto; font: inherit; border: 1px solid var(--byrsa); border-radius: 6px; background: var(--surface); color: var(--texte); padding: 3px 6px; }
.interrupteur { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.interrupteur input { position: absolute; opacity: 0; }
.interrupteur span { width: 30px; height: 17px; border-radius: 999px; background: var(--axe); position: relative; transition: background 0.15s; }
.interrupteur span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.interrupteur input:checked + span { background: var(--pourpre); }
.interrupteur input:checked + span::after { transform: translateX(13px); }
.interrupteur input:focus-visible + span { outline: 2px solid var(--pourpre); outline-offset: 2px; }

.fil { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 10px 13px; border-radius: 10px; max-width: 92%; word-wrap: break-word; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 4px 0; padding-left: 18px; }
.msg.user { align-self: flex-end; background: var(--golfe); color: var(--golfe-texte); }
.msg.assistant { align-self: flex-start; background: var(--surface-2); }
.msg.erreur { align-self: flex-start; color: var(--critique); border: 1px solid var(--critique); }
.msg.attente { color: var(--muet); background: transparent; padding-left: 0; }
.msg .ecouter { display: block; margin-top: 6px; background: none; border: 0; color: var(--pourpre); cursor: pointer; font-size: 12px; padding: 0; }
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.suggestions p { font-size: 13px; color: var(--texte-2); margin-bottom: 2px; }
.suggestions button {
  text-align: left; cursor: pointer; color: var(--texte); background: transparent;
  border: 1px solid var(--byrsa); border-radius: 8px; padding: 9px 12px;
}
.suggestions button:hover { border-color: var(--pourpre); background: var(--pourpre-doux); }
.saisie { display: flex; align-items: flex-end; gap: 8px; border-top: 1px solid var(--grille); padding: 12px 14px 16px; }
.saisie textarea {
  flex: 1; font: inherit; resize: none; padding: 9px 12px; border-radius: 8px; max-height: 140px; min-height: 42px;
  border: 1px solid var(--byrsa); background: var(--chaux); color: var(--texte);
}
.btn-micro {
  flex: none; cursor: pointer; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; border: 1px solid var(--byrsa); background: var(--surface-2); color: var(--texte);
}
.btn-micro.ecoute { background: var(--pourpre); border-color: var(--pourpre); color: #fff; }
@media (prefers-reduced-motion: no-preference) {
  .btn-micro.ecoute { animation: pulse 1.2s infinite; }
  @keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--pourpre) 25%, transparent); } }
}
.btn-micro:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-envoi { flex: none; cursor: pointer; height: 42px; border: 0; border-radius: 8px; padding: 0 14px; background: var(--pourpre); color: #fff; font-weight: 600; }

:focus-visible { outline: 2px solid var(--pourpre); outline-offset: 2px; }

.fab { display: none; }
/* Apercu statique : pas de serveur, donc pas d'assistant */
body.apercu .btn-ia, body.apercu .fab, body.apercu .assistant, body.apercu .btn-sortie { display: none !important; }

.btn-sortie {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--golfe-texte); border: 1px solid color-mix(in srgb, var(--golfe-texte) 30%, transparent);
}
.btn-sortie:hover { background: color-mix(in srgb, var(--golfe-texte) 12%, transparent); }

/* Page de connexion */
.page-connexion { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--golfe); }
.connexion {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 32px 28px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.connexion-logo { font-family: var(--chiffres); font-weight: 300; font-size: 24px; letter-spacing: 0.06em; color: var(--pourpre); }
.connexion h1 { font-family: var(--chiffres); font-weight: 400; font-size: 28px; margin-top: 18px; }
.connexion > p { color: var(--texte-2); margin-top: 4px; font-size: 14px; }
.connexion form { display: flex; flex-direction: column; margin-top: 22px; }
.connexion label { font-size: 13px; color: var(--texte-2); margin: 12px 0 6px; }
.connexion input {
  font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 8px;
  border: 1px solid var(--byrsa); background: var(--chaux); color: var(--texte);
}
.connexion input:focus-visible { outline: 2px solid var(--pourpre); outline-offset: 1px; }
.connexion .btn-envoi { margin-top: 22px; height: 46px; }
.connexion .btn-envoi:disabled { opacity: 0.6; cursor: wait; }
.connexion-erreur { margin-top: 14px; color: var(--critique); font-size: 14px; }

@media (max-width: 1200px) { body.ia-ouverte .cadre { margin-right: 0; } .hero { grid-template-columns: 1fr; } }

/* ---------- Mobile : rendu d'application native ---------- */
@media (max-width: 860px) {
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
  button, select, label { touch-action: manipulation; }

  /* Barre du haut compacte, sous la barre d'etat */
  .bandeau {
    height: auto; padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; gap: 12px;
    position: sticky; top: 0;
  }
  .logotype { font-size: 18px; }
  .fraicheur, .btn-ia { display: none; }
  .btn-sortie { margin-left: auto; width: 44px; height: 44px; }

  /* Barre d'onglets en bas */
  .cadre { display: block; }
  .navigation {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 8;
    flex-direction: row; gap: 0; padding: 6px 4px calc(env(safe-area-inset-bottom, 0px) + 6px);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(160%) blur(16px); -webkit-backdrop-filter: saturate(160%) blur(16px);
    border-top: 1px solid var(--byrsa);
  }
  .navigation button {
    flex: 1 1 0; min-width: 0; min-height: 50px; padding: 4px 2px; border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 10.5px; color: var(--muet); background: none;
  }
  .navigation button:hover { background: none; color: var(--muet); }
  .navigation button[aria-selected="true"] { background: none; color: var(--pourpre); }
  .navigation .ico { display: block; width: 24px; height: 24px; fill: currentColor; }
  .navigation .lib-court { display: block; }
  .navigation .lib-long, .nav-pied { display: none; }

  main { padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 150px); }

  /* Grand titre de section, facon iOS */
  .ouverture h1 { font-size: 30px; font-weight: 600; }
  .ouverture p { font-size: 14px; }
  .recit { font-size: 23px; }
  .recit-suite { font-size: 14px; }
  .hero { gap: 26px; margin-bottom: 26px; }
  .suites { gap: 3px; }
  .nuit .case { height: 10px; }

  .groupe { margin-top: 32px; }
  .groupe > h2 { font-size: 20px; }

  /* Chiffres cles : cartes en grille de deux */
  .bande { grid-template-columns: 1fr 1fr; gap: 10px; border: 0; }
  .mesure { margin: 0; border: 0; border-radius: 14px; background: var(--surface); padding: 12px 14px; min-height: 112px; box-shadow: 0 1px 0 var(--byrsa); }
  .mesure .val { font-size: 27px; }
  .mesure .lib { font-size: 12px; }

  .grille { grid-template-columns: 1fr; gap: 12px; }
  .carte { border-radius: 14px; padding: 14px 14px 12px; border: 0; box-shadow: 0 1px 0 var(--byrsa); }
  .graphe, .carte.haute .graphe { height: 240px; }
  .bascule { min-height: 32px; }
  th, td { padding: 9px 12px 9px 0; }

  /* Bouton flottant de l'assistant */
  .fab {
    display: grid; place-items: center; position: fixed; z-index: 9;
    right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
    width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--pourpre); color: #fff;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--pourpre) 40%, transparent);
  }
  body.ia-ouverte .fab { display: none; }

  /* Assistant en feuille plein ecran */
  .assistant { width: 100vw; border-left: 0; z-index: 20; }
  .assistant-tete { padding-top: calc(env(safe-area-inset-top, 0px) + 14px); }
  .assistant-sous { display: none; }
  .assistant-tete .btn-icone { min-width: 44px; min-height: 44px; }
  .saisie { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
  .saisie textarea { font-size: 16px; } /* evite le zoom automatique d'iOS */
  .btn-micro { width: 48px; height: 48px; }
  .suggestions button { min-height: 44px; }
  @media (prefers-reduced-motion: no-preference) {
    .assistant:not([hidden]) { animation: monter 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
    @keyframes monter { from { transform: translateY(100%); } }
  }
}
@media (max-width: 380px) {
  .bande { grid-template-columns: 1fr; }
  .navigation button { font-size: 10px; }
}
