/* SilviA — Design tokens
   Direction : sobre & institutionnel, humain.
   Palette : blancs cassés chauds + gris bleutés profonds + accent ambre.
   Dark mode : bleu nuit + ambre chaud.
*/

:root {
  /* Light mode (default) */
  --bg: #fbfaf7;
  --bg-elevated: #ffffff;
  --bg-subtle: #f4f1ec;
  --bg-inset: #efeae2;

  --fg: #1a1d24;
  --fg-muted: #5a6370;
  /* #8a93a1 donnait 3,1:1 sur blanc — sous le seuil AA de 4,5:1 pour du texte
     courant, et axe-core le relevait sur tous les ecrans.
     #666f7e et non #6d7788 : la cible doit etre tenue sur le fond le PLUS
     SOMBRE ou ce texte se pose, `--bg-subtle` (#f4f1ec), et non sur le blanc.
     Mesure apres un premier essai cale sur le blanc : 4,52:1 sur blanc mais
     seulement 4,01:1 sur `--bg-subtle` — toujours en echec. Ici : 4,50 sur
     subtle, 4,86 sur bg, 5,07 sur blanc.
     Seule la clarte change ; teinte et saturation sont conservees. */
  --fg-subtle: #666f7e;

  /* `--warning` EST UNE COULEUR DE DONNEE : elle vaut `--score-mid`, celle de
     la tranche moyenne des palettes SRI/IPS, utilisee pour les polygones de la
     carte et les jauges. L'assombrir changerait la lecture des cartes.
     Pour du TEXTE, elle ne passe pas (#c2760b = 3,2:1). D'ou un jeton distinct,
     a n'employer que comme couleur de texte : la palette de donnees reste
     intacte, et les libelles deviennent lisibles. */
  --warning-text: #9e6009;

  --border: #e6e0d5;
  --border-strong: #d4ccbe;

  /* Accent — ambre chaud, rappelle argenté/silver */
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-subtle: #fef3c7;
  --accent-fg: #ffffff;

  /* Deep institutional navy for titles */
  --navy: #0f1a2e;
  --navy-muted: #1e2a44;

  /* Data viz — score colors */
  --score-bad: #b91c1c;
  --score-mid: #c2760b;
  --score-good: #15803d;
  --score-bad-bg: #fef2f2;
  --score-mid-bg: #fef3c7;
  --score-good-bg: #ecfdf5;

  /* Semantic aliases (used by screens : progress bars, deltas, badges) */
  --success: var(--score-good);
  --warning: var(--score-mid);
  --danger: var(--score-bad);
  --success-bg: var(--score-good-bg);
  --warning-bg: var(--score-mid-bg);
  --danger-bg: var(--score-bad-bg);
  --danger-subtle: var(--score-bad-bg);
  --success-subtle: var(--score-good-bg);
  --warning-subtle: var(--score-mid-bg);

  /* Chart palette (ordered, accessible) */
  --chart-1: #b45309;
  --chart-2: #0f1a2e;
  --chart-3: #1e40af;
  --chart-4: #15803d;
  --chart-5: #7e22ce;
  --chart-6: #9a3412;

  /* Radii & spacing */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows — subtle, institutional */
  --shadow-sm: 0 1px 2px rgba(15, 26, 46, 0.04);
  --shadow-md: 0 1px 3px rgba(15, 26, 46, 0.06), 0 1px 2px rgba(15, 26, 46, 0.04);
  --shadow-lg: 0 4px 12px rgba(15, 26, 46, 0.08), 0 2px 4px rgba(15, 26, 46, 0.04);
  --shadow-xl: 0 12px 32px rgba(15, 26, 46, 0.12), 0 4px 8px rgba(15, 26, 46, 0.06);

  /* Type */
  --font-serif: "Instrument Serif", "Cormorant Garamond", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  /* Premium (landing) — additifs, ne modifient aucune valeur existante */
  --radius-2xl: 20px;
  --radius-3xl: 28px;
  --shadow-2xl: 0 24px 64px rgba(15, 26, 46, 0.16), 0 8px 20px rgba(15, 26, 46, 0.08);
  --shadow-glow-accent: 0 10px 30px rgba(180, 83, 9, 0.28);
  /* Surfaces "always dark" (bandeaux on-dark) — valeurs fixes : ne s'inversent pas en dark mode */
  --gradient-navy: linear-gradient(135deg, #0f1a2e 0%, #1e2a44 100%);
  --gradient-brand: linear-gradient(135deg, #0f1a2e, var(--accent));
  /* Alias manquant (corrige le fallback en dur de ConfidenceBadge) */
  --score-warn: var(--score-mid);
  --score-warn-bg: var(--score-mid-bg);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elevated: #131c2e;
  --bg-subtle: #1a2339;
  --bg-inset: #0f1828;

  --fg: #f5f1e8;
  --fg-muted: #a0a9ba;
  --fg-subtle: #6a7388;

  --border: #232d45;
  --border-strong: #2f3a55;

  --accent: #d97706;
  --accent-hover: #f59e0b;
  --accent-subtle: #78350f;
  --accent-fg: #1a1d24;

  --navy: #f5f1e8;
  --navy-muted: #d4ccbe;

  --score-bad: #f87171;
  --score-mid: #fbbf24;
  --score-good: #4ade80;
  --score-bad-bg: #3b1113;
  --score-mid-bg: #3b2611;
  --score-good-bg: #10331f;

  /* Semantic aliases (dark) */
  --success: var(--score-good);
  /* En sombre, `--score-mid` vaut #fbbf24 sur un fond #0b1220 : le contraste
     depasse largement 4,5:1, le jeton de texte peut donc rester identique. */
  --warning-text: var(--score-mid);
  --warning: var(--score-mid);
  --danger: var(--score-bad);
  --success-bg: var(--score-good-bg);
  --warning-bg: var(--score-mid-bg);
  --danger-bg: var(--score-bad-bg);
  --danger-subtle: var(--score-bad-bg);
  --success-subtle: var(--score-good-bg);
  --warning-subtle: var(--score-mid-bg);

  --chart-1: #f59e0b;
  --chart-2: #f5f1e8;
  --chart-3: #60a5fa;
  --chart-4: #4ade80;
  --chart-5: #c084fc;
  --chart-6: #fb923c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.6), 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-2xl: 0 24px 64px rgba(0, 0, 0, 0.6), 0 8px 20px rgba(0, 0, 0, 0.45);
  --shadow-glow-accent: 0 10px 30px rgba(217, 119, 6, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--navy);
  letter-spacing: -0.01em;
  margin: 0;
}

/* Headings inside elements with white text auto-inherit white for legibility */
[data-on-dark] h1, [data-on-dark] h2, [data-on-dark] h3, [data-on-dark] h4,
.on-dark h1, .on-dark h2, .on-dark h3, .on-dark h4 {
  color: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  color: inherit;
}

a { color: inherit; text-decoration: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-subtle); }

/* Primitives */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-subtle); border-color: var(--border-strong); }

.btn-ghost {
  color: var(--fg-muted);
}
.btn-ghost:hover { background: var(--bg-subtle); color: var(--fg); }

.btn-navy {
  background: var(--navy);
  color: var(--bg);
}
[data-theme="dark"] .btn-navy { background: var(--fg); color: var(--bg); }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.chip-good { background: var(--score-good-bg); color: var(--score-good); border-color: transparent; }
.chip-mid { background: var(--score-mid-bg); color: var(--score-mid); border-color: transparent; }
.chip-bad { background: var(--score-bad-bg); color: var(--score-bad); border-color: transparent; }
.chip-accent { background: var(--accent-subtle); color: var(--accent); border-color: transparent; }
[data-theme="dark"] .chip-accent { color: #fbbf24; }

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--fg-muted);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
  font-weight: 500;
}

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
}

/* Utility for data numbers */
.num {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Responsive — Mobile / Tablet
   ============================================================ */

/* Mobile-specific helpers */
.mobile-only { display: none; }
.desktop-only { display: block; }

/* Hamburger / mobile menu trigger */
.mobile-menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
}

/* Tablet — under 1024px */
@media (max-width: 1024px) {
  .mobile-only { display: block; }
  .desktop-only { display: none; }
  .mobile-menu-toggle { display: inline-flex; }

  /* Sidebar becomes drawer */
  aside.sv-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh !important;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    width: 260px !important;
    box-shadow: 0 0 0 9999px transparent;
  }
  aside.sv-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15), 0 0 0 9999px rgba(15, 26, 46, 0.45);
  }

  /* Topbar: compact */
  header {
    padding: 12px 16px !important;
    gap: 8px !important;
    flex-wrap: wrap;
  }
  header h1 {
    font-size: 18px !important;
  }
  header .sub-hide-mobile {
    display: none !important;
  }
  /* Hide search button label / use icon only */
  .topbar-search {
    min-width: 40px !important;
    padding: 8px !important;
  }
  .topbar-search > span { display: none !important; }

  /* 3-column screens collapse */
  .territorial-grid {
    grid-template-columns: 1fr !important;
    height: auto !important;
    /* `overflow: hidden` est pose en style inline sur ce conteneur. Une fois la
       hauteur rendue automatique, il n'a plus rien a ecreter horizontalement,
       mais il continuerait d'ecreter la pile VERTICALE : la troisieme colonne,
       devenue troisieme ligne, tomberait hors du cadre. */
    overflow: visible !important;
  }
  .territorial-grid > aside:nth-of-type(1),
  .territorial-grid > aside:nth-of-type(2) {
    height: auto !important;
    max-height: 50vh;
    overflow-y: auto;
  }

  /* LA CARTE A BESOIN D'UNE HAUTEUR EXPLICITE, et c'est la consequence directe
     du `height: auto` ci-dessus.
     La zone Leaflet est un `flex: 1` dans une colonne flex (TerritorialOSM.jsx)
     : tant que la grille imposait `calc(100vh - 77px)`, ce `flex: 1` avait une
     hauteur a remplir. En hauteur automatique, il n'a plus rien a partager et
     s'effondre a 0 — la carte disparaitrait purement et simplement, ce qui
     serait un defaut PIRE que l'ecretage qu'on corrige. */
  .carte-zone {
    min-height: 62vh;
  }

  /* AI assistant */
  .ai-grid {
    grid-template-columns: 1fr !important;
  }
  .ai-grid > aside { display: none; }

  /* Navigation laterale + contenu (Parametres). Meme famille que
     `.territorial-grid`, mais a deux colonnes et sans second aside. */
  .grille-laterale {
    grid-template-columns: 1fr !important;
    height: auto !important;
    overflow: visible !important;
  }
  .grille-laterale > aside {
    height: auto !important;
    max-height: 45vh;
    overflow-y: auto;
  }

  /* Tableau + panneau de detail a largeur fixe (Catalogue des KPI). La rangee
     passe en pile, et le panneau cesse d'imposer ses 380 px. */
  .rangee-detail {
    flex-direction: column !important;
    height: auto !important;
  }
  .panneau-detail {
    width: 100% !important;
    flex-shrink: 1 !important;
    max-height: 60vh;
  }

  /* Cards grids.
     `minmax(0, 1fr)` ET NON `1fr` : une piste `1fr` vaut `minmax(auto, 1fr)`,
     donc elle ne descend JAMAIS sous la largeur minimale de son contenu. Une
     carte effondree en une colonne pouvait ainsi rester a 414 px dans un
     conteneur de 291 px — effondree, et toujours ecretee. C'est la forme
     `minmax(0, …)` qui autorise reellement la reduction. */
  .card-grid-3, .card-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* Phone — under 768px */
@media (max-width: 768px) {
  body { font-size: 14px; }

  .card-grid-3, .card-grid-4, .card-grid-2 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Wider main padding compression */
  main > div {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  /* Smaller headings */
  h1 { font-size: 22px !important; }
  h2 { font-size: 18px !important; }
  h3 { font-size: 16px !important; }

  /* Charts and gauges smaller */
  .responsive-gauge svg { max-width: 100%; height: auto; }

  /* Inline buttons stack */
  .btn-row-stack { flex-direction: column !important; align-items: stretch !important; }
  .btn-row-stack > button { width: 100% !important; justify-content: center !important; }

  /* Hide certain decorative bits */
  .hide-mobile { display: none !important; }
}

/* Touch devices: bigger tap targets */
@media (hover: none) and (pointer: coarse) {
  button, a {
    min-height: 36px;
  }
}

/* ============================================================
   Carte territoriale — les deux conteneurs qui debordaient.
   2026-10-10.

   Mesure a l'origine : a 375 px de large, 115 elements de cet ecran
   depassaient le bord droit du viewport. Ce n'etaient pas 115 problemes, mais
   les descendants de DEUX conteneurs :

     - le groupe de granularite (4 boutons + cadre = 401 px) portait
       `flexShrink: 0` et ne pouvait donc pas se reduire ;
     - la legende flottante faisait left:16 + minWidth:340 + 28 px de padding
       = 384 px.

   Et le conteneur de la carte est en `overflow: hidden` : les deux etaient donc
   ECRETES, pas defilables. Le contenu coupe — dont le bouton « IRIS » et les
   boutons de seuil — devenait inatteignable sans aucun signe.

   POURQUOI LA CORRECTION EST ICI ET NON DANS LE JSX : ces conteneurs etaient en
   styles inline, hors d'atteinte de toute media query. C'est la raison
   structurelle pour laquelle cet ecran cassait en mobile alors que le reste du
   produit tient : la strategie responsive du projet vit dans ce fichier, et un
   style inline ne peut pas y participer. Les deux conteneurs portent desormais
   une classe, traitee ici.
   ============================================================ */

@media (max-width: 768px) {
  /* On rend le groupe DEFILABLE plutot que de le laisser ecrete : les quatre
     grains restent tous atteignables, au prix d'un glissement horizontal —
     ce qui est le comportement attendu d'une barre d'outils trop large. */
  .carte-granularite {
    overflow-x: auto;
    max-width: 100%;
    flex-shrink: 1 !important;
    scrollbar-width: thin;
  }
  .carte-granularite > button {
    flex-shrink: 0;
  }

  /* La legende cesse d'imposer 340 px : elle occupe la largeur disponible
     moins les marges gauche et droite. */
  .carte-legende {
    min-width: 0 !important;
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
  }
}

/* ============================================================
   Premium landing — élévation (hover) + scroll-reveal
   Opt-in : n'affecte que les éléments qui portent ces classes.
   ============================================================ */

/* Élévation au survol (cartes, CTA). .card.lift ajoute une ombre de repos. */
.lift {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card.lift { box-shadow: var(--shadow-sm); }
.lift:hover { transform: translateY(-3px); }
.card.lift:hover { box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.btn-primary.lift:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow-accent); }

/* Souligné animé (liens nav) */
.link-underline { position: relative; }
.link-underline::after {
  content: "";
  position: absolute;
  left: 0; bottom: -3px;
  width: 0; height: 1.5px;
  background: var(--accent);
  transition: width 0.22s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.link-underline:hover::after,
.link-underline.is-active::after { width: 100%; }

/* Scroll-reveal — fail-safe : visible par défaut, caché UNIQUEMENT si le JS a posé
   .js-reveal sur <html> (donc si l'observer est actif). On utilise une TRANSITION
   (pas une animation à fill-mode) : l'état final opacity:1 s'applique toujours, même
   si le compositeur ne « tick » pas (headless) — jamais de contenu bloqué invisible. */
.reveal { opacity: 1; }
html.js-reveal .reveal { opacity: 0; transform: translateY(18px); }
html.js-reveal .reveal.is-visible {
  opacity: 1;
  transform: none;
  transition: opacity 0.6s cubic-bezier(0.22, 0.61, 0.36, 1), transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
  transition-delay: var(--reveal-delay, 0ms);
}

@media (prefers-reduced-motion: reduce) {
  .lift, .lift:hover { transition: none; transform: none; }
  html.js-reveal .reveal,
  html.js-reveal .reveal.is-visible {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}
