/* =====================================================================
   EEPATHO — style.css  ·  identité « instrument scientifique »
   (conserve le logo image .logo + le titre .brand de l'utilisateur)
   ===================================================================== */

:root{
  --ink:#15212e; --ink-2:#33455a; --muted:#7286a0;
  --accent:#1f6feb; --accent-deep:#1857c0; --accent-soft:#eaf2ff;
  --panel:#ffffff; --surface-2:#f6f9fd; --line:#e7edf4;
  --ring:rgba(31,111,235,.18);
  --font-display:"Space Grotesk","Inter",system-ui,sans-serif;
  --font-body:"Inter",system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
}
*{ box-sizing:border-box }
html,body{ margin:0; height:100%; font-family:var(--font-body); color:var(--ink);
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility; }
#app{ display:flex; height:100vh; width:100vw }

/* ---- Panneau ---- */
#sidebar{
  position:relative; width:344px; min-width:344px; height:100%; background:var(--panel);
  border-right:1px solid var(--line); padding:0 22px 26px; overflow-y:auto;
  box-shadow:6px 0 26px rgba(15,25,40,.05); z-index:2;
}
#sidebar::-webkit-scrollbar{ width:9px }
#sidebar::-webkit-scrollbar-thumb{ background:#d3dded; border-radius:9px; border:2px solid #fff }

/* barre d'accent en haut du panneau */
.topbar{ position:sticky; top:0; height:4px; margin:0 -22px 0;
  background:linear-gradient(90deg,var(--accent),var(--accent-deep)); z-index:3; }

/* ---- Logo équipe ---- */
.logo{ display:block; width:100%; max-width:210px; margin:20px auto 14px;
  border-radius:14px; box-shadow:0 6px 20px rgba(15,25,40,.10); }

/* ---- Titre du projet ---- */
.brand{ font-family:var(--font-display); font-size:18px; font-weight:700; line-height:1.25;
  letter-spacing:-.01em; color:var(--ink); padding-bottom:20px; border-bottom:1px solid var(--line); }
.brand .eyebrow{ display:block; font-family:var(--font-body); font-size:10.5px; font-weight:600;
  letter-spacing:.14em; text-transform:uppercase; color:var(--accent); margin-bottom:6px; }
.brand small{ display:block; font-family:var(--font-body); font-size:12.5px; font-weight:500;
  color:var(--muted); margin-top:8px; line-height:1.5; letter-spacing:0; }

/* ---- Groupes & libellés ---- */
.group{ margin-top:22px }
.label{ display:flex; align-items:center; gap:8px; margin-bottom:9px;
  font-size:11px; font-weight:600; letter-spacing:.07em; text-transform:uppercase; color:var(--ink-2); }
.label .ico{ width:15px; height:15px; color:var(--accent); flex:none }

/* ---- Selects ---- */
select{
  width:100%; padding:11px 13px; font-family:var(--font-body); font-size:14px; color:var(--ink);
  background:#fff; border:1px solid var(--line); border-radius:11px; cursor:pointer; appearance:none;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237286a0' stroke-width='2.4'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat:no-repeat; background-position:right 13px center; transition:border-color .15s, box-shadow .15s;
}
select:hover{ border-color:#c8d6ea }
select:focus{ outline:none; border-color:var(--accent); box-shadow:0 0 0 3px var(--ring) }
select:disabled{ opacity:.5; cursor:not-allowed }
optgroup{ font-family:var(--font-body); font-weight:700; color:var(--ink); font-size:12px;
  text-transform:uppercase; letter-spacing:.05em; }
option{ font-weight:400; text-transform:none; letter-spacing:0; color:var(--ink) }

/* ---- 2 menus côte à côte ---- */
.row2{ margin-top:22px; display:grid; grid-template-columns:1fr 1fr; gap:12px }
.row2 .label{ margin-top:0 }

/* ---- Carte « communes affichées » ---- */
.stat{ margin-top:22px; padding:15px 16px; border:1px solid var(--line); border-radius:14px;
  background:linear-gradient(135deg,#fff,var(--surface-2));
  box-shadow:0 2px 10px rgba(15,25,40,.04); position:relative; overflow:hidden; }
.stat::before{ content:""; position:absolute; left:0; top:0; bottom:0; width:4px;
  background:linear-gradient(var(--accent),var(--accent-deep)); }
.stat .big{ font-family:var(--font-display); font-size:27px; font-weight:700; letter-spacing:-.01em; color:var(--ink); }
.stat .sub{ font-size:11.5px; color:var(--muted); margin-top:1px; text-transform:uppercase; letter-spacing:.05em }

/* ---- Tableau de bord ---- */
#dashboard{ margin-top:2px }
.dash-grid{ display:grid; grid-template-columns:1fr 1fr; gap:11px; margin-bottom:8px }
.dash-grid .dv{ font-family:var(--font-display); font-size:18px; font-weight:600; line-height:1.1; color:var(--ink) }
.dash-grid .dl{ font-size:10.5px; color:var(--muted); text-transform:uppercase; letter-spacing:.05em; margin-top:1px }
.dash-title{ font-size:11px; font-weight:600; color:var(--muted); margin:8px 0 5px; text-transform:uppercase; letter-spacing:.05em }
.dash-empty{ font-size:12.5px; color:var(--muted) }
.dash-extra{ font-size:12px; color:var(--muted); margin:2px 0 8px; padding-top:7px; border-top:1px solid var(--line);
  font-variant-numeric:tabular-nums; }
.cat-row{ display:flex; justify-content:space-between; align-items:baseline; font-size:13px; padding:3px 0 }
.cat-row small{ color:var(--muted); margin-left:5px }

/* ---- Légende interactive ---- */
#legend{ margin-top:4px }
.legend-row{ display:flex; align-items:center; gap:9px; font-size:13px; padding:5px 5px;
  border-radius:8px; cursor:pointer; user-select:none; transition:background .12s }
.legend-row:hover{ background:var(--surface-2) }
.legend-row.off{ opacity:.4 }
.legend-row .lg-check{ font-size:14px; width:16px; flex:none; color:var(--accent) }
.legend-row.off .lg-check{ color:var(--muted) }
.legend-row .lg-lab{ flex:1 }
.legend-row .lg-cnt{ font-size:12px; color:var(--muted); font-variant-numeric:tabular-nums }
.swatch{ width:16px; height:16px; border-radius:5px; flex:none; border:1px solid rgba(15,25,40,.08) }

/* ---- Pied ---- */
.foot{ margin-top:26px; padding-top:18px; border-top:1px solid var(--line);
  font-size:10.5px; color:var(--muted); line-height:1.6 }

/* ---- Carte ---- */
#map{ flex:1; height:100% }
.maplibregl-popup-content{ border-radius:12px; padding:11px 14px; font-family:var(--font-body); font-size:13px;
  box-shadow:0 8px 26px rgba(15,25,40,.20); border:1px solid var(--line) }
.pop-name{ font-weight:700; margin-bottom:2px; color:var(--ink) }
.pop-val{ color:var(--accent); font-weight:600 }

#loading{ position:absolute; top:16px; left:50%; transform:translateX(-50%);
  background:#fff; padding:8px 16px; border-radius:22px; font-size:13px; font-weight:500;
  box-shadow:0 4px 16px rgba(15,25,40,.16); z-index:5; display:none; border:1px solid var(--line) }

/* icône générique inline */
.ico{ width:16px; height:16px; vertical-align:-3px }

/* ---- Embellissements carte : flèche Nord + bouton export ---- */
.north-arrow{ position:absolute; left:14px; bottom:30px; z-index:4; background:rgba(255,255,255,.9);
  border-radius:9px; padding:5px 7px; box-shadow:0 2px 10px rgba(15,25,40,.14); line-height:0 }
.btn-export{ position:absolute; top:14px; left:14px; z-index:5; display:flex; align-items:center; gap:8px;
  background:#fff; color:var(--ink); border:1px solid var(--line); border-radius:11px;
  padding:9px 14px; font-family:var(--font-body); font-size:13px; font-weight:600; cursor:pointer;
  box-shadow:0 3px 14px rgba(15,25,40,.12); transition:border-color .15s, color .15s, transform .05s }
.btn-export:hover{ border-color:var(--accent); color:var(--accent) }
.btn-export:active{ transform:translateY(1px) }
.btn-export svg{ flex:none }

/* =====================================================================
   Barre KPI (cartes de stats flottantes) + Fiche commune au clic
   ===================================================================== */

/* ---- Barre KPI : rangée de cartes en bas de la carte ---- */
#kpibar{
  position:absolute; left:50%; bottom:22px; transform:translateX(-50%);
  z-index:4; display:flex; gap:10px; max-width:calc(100% - 220px);
  pointer-events:none;
}
.kpi{
  min-width:96px; padding:10px 16px; border-radius:14px;
  background:rgba(255,255,255,.82); backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px);
  border:1px solid rgba(15,25,40,.08); box-shadow:0 6px 22px rgba(15,25,40,.14);
  text-align:center;
}
.kpi-l{ font-size:10px; font-weight:600; text-transform:uppercase; letter-spacing:.06em; color:var(--muted) }
.kpi-v{ font-family:var(--font-display); font-size:21px; font-weight:700; color:var(--ink); line-height:1.15; font-variant-numeric:tabular-nums }
.kpi-s{ font-size:11px; color:var(--accent); font-weight:600 }
.kpi-n .kpi-v{ color:var(--accent) }
.kpi-empty{ padding:10px 16px; border-radius:14px; background:rgba(255,255,255,.82);
  font-size:12px; color:var(--muted); box-shadow:0 6px 22px rgba(15,25,40,.14) }

html[data-theme="dark"] .kpi,
html[data-theme="dark"] .kpi-empty{ background:rgba(20,30,42,.82); border-color:rgba(255,255,255,.10) }

/* ---- Fiche commune (au clic) ---- */
#commune-card{
  position:absolute; top:64px; left:14px; width:262px; z-index:6;
  background:var(--panel); border:1px solid var(--line); border-radius:16px;
  padding:16px 16px 14px; box-shadow:0 14px 40px rgba(15,25,40,.22);
  opacity:0; transform:translateY(-8px) scale(.98); pointer-events:none;
  transition:opacity .22s ease, transform .22s ease;
}
#commune-card.show{ opacity:1; transform:translateY(0) scale(1); pointer-events:auto }
.cc-head{ display:flex; justify-content:space-between; align-items:flex-start; gap:8px }
.cc-name{ font-family:var(--font-display); font-size:17px; font-weight:700; color:var(--ink); line-height:1.15 }
.cc-code{ font-size:11px; color:var(--muted); font-variant-numeric:tabular-nums }
.cc-close{ border:none; background:transparent; color:var(--muted); font-size:15px; cursor:pointer; padding:2px 4px; border-radius:6px; line-height:1 }
.cc-close:hover{ background:var(--surface-2); color:var(--ink) }
.cc-badge{ display:inline-block; margin:10px 0 2px; padding:3px 10px; border-radius:999px;
  font-size:11px; font-weight:600; border:1px solid }
.cc-var{ font-size:11.5px; color:var(--muted); margin-top:10px }
.cc-val{ font-family:var(--font-display); font-size:30px; font-weight:700; color:var(--ink); line-height:1.1; margin-top:1px }
.cc-unit{ font-size:13px; font-weight:500; color:var(--muted); margin-left:6px }
.cc-grid{ display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:14px;
  border-top:1px solid var(--line); padding-top:12px }
.cc-l{ font-size:10px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted) }
.cc-n{ font-family:var(--font-display); font-size:15px; font-weight:600; color:var(--ink); font-variant-numeric:tabular-nums }
.cc-spark-t{ font-size:10px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin:14px 0 4px }
.cc-spark{ display:block }

/* =====================================================================
   Assistant de recherche (chatbot local)
   ===================================================================== */
#bot-launch{
  position:absolute; right:18px; bottom:60px; z-index:7; width:52px; height:52px;
  border-radius:50%; border:none; cursor:pointer; color:#fff;
  background:linear-gradient(135deg,var(--accent),var(--accent-deep));
  box-shadow:0 6px 20px rgba(31,111,235,.40); display:flex; align-items:center; justify-content:center;
  transition:transform .12s }
#bot-launch:hover{ transform:scale(1.08) }

#bot-panel{
  position:absolute; right:18px; bottom:122px; z-index:7; width:330px; max-width:calc(100% - 36px);
  height:440px; max-height:calc(100% - 150px); display:flex; flex-direction:column;
  background:var(--panel); border:1px solid var(--line); border-radius:18px; overflow:hidden;
  box-shadow:0 18px 50px rgba(15,25,40,.28);
  opacity:0; transform:translateY(12px) scale(.97); pointer-events:none;
  transition:opacity .2s ease, transform .2s ease;
}
#bot-panel.show{ opacity:1; transform:translateY(0) scale(1); pointer-events:auto }
.bot-head{ display:flex; justify-content:space-between; align-items:center; padding:13px 16px;
  font-family:var(--font-display); font-weight:700; color:#fff;
  background:linear-gradient(135deg,var(--accent),var(--accent-deep)) }
.bot-head button{ border:none; background:transparent; color:#fff; font-size:15px; cursor:pointer; opacity:.85 }
.bot-head button:hover{ opacity:1 }
#bot-msgs{ flex:1; overflow-y:auto; padding:14px; display:flex; flex-direction:column; gap:10px; background:var(--surface-2) }
.bot-msg{ font-size:13px; line-height:1.45; padding:10px 13px; border-radius:13px; max-width:90% }
.bot-msg.bot{ background:var(--panel); color:var(--ink); border:1px solid var(--line); align-self:flex-start; border-bottom-left-radius:4px }
.bot-msg.user{ background:var(--accent); color:#fff; align-self:flex-end; border-bottom-right-radius:4px }
.bot-eg{ display:block; margin-top:6px; color:var(--accent); cursor:default; font-size:12px }
.bot-list{ margin-top:7px; display:flex; flex-direction:column; gap:3px }
.bot-item{ padding:5px 8px; border-radius:8px; cursor:pointer; background:var(--surface-2); transition:background .12s }
.bot-item:hover{ background:var(--accent-soft) }
.bot-hint{ display:block; margin-top:7px; font-size:11px; color:var(--muted) }
.bot-input{ display:flex; gap:8px; padding:11px; border-top:1px solid var(--line); background:var(--panel) }
.bot-input input{ flex:1; padding:10px 13px; font-family:var(--font-body); font-size:13px; color:var(--ink);
  border:1px solid var(--line); border-radius:11px; outline:none; background:var(--panel) }
.bot-input input:focus{ border-color:var(--accent); box-shadow:0 0 0 3px var(--ring) }
.bot-input button{ width:42px; border:none; border-radius:11px; cursor:pointer; color:#fff; font-size:15px;
  background:linear-gradient(135deg,var(--accent),var(--accent-deep)) }
html[data-theme="dark"] .bot-input input{ background:#1a2430 }

.bot-chips{ display:flex; flex-wrap:wrap; gap:7px; margin-top:4px }
.bot-chip{ border:1px solid var(--line); background:var(--panel); color:var(--accent);
  font-family:var(--font-body); font-size:12px; font-weight:600; padding:7px 12px;
  border-radius:999px; cursor:pointer; transition:background .12s, border-color .12s }
.bot-chip:hover{ background:var(--accent-soft); border-color:var(--accent) }
.bot-chip:active{ transform:translateY(1px) }

/* ---- En-tête enrichi de l'assistant (avatar + statut « en ligne ») ---- */
.bot-head{ font-weight:600 }
.bot-id{ display:flex; align-items:center; gap:10px; min-width:0 }
.bot-ava{ width:32px; height:32px; flex:none; border-radius:50%; display:flex; align-items:center;
  justify-content:center; font-size:17px; background:rgba(255,255,255,.18);
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.25) }
.bot-ava .fi{ font-size:18px; line-height:1; color:#fff; display:block }
.bot-titles{ display:flex; flex-direction:column; line-height:1.15; min-width:0 }
.bot-titles b{ font-size:14.5px }
.bot-titles small{ display:flex; align-items:center; gap:5px; font-family:var(--font-body);
  font-weight:500; font-size:10.5px; color:rgba(255,255,255,.82) }
.bot-online{ width:7px; height:7px; border-radius:50%; background:#3ad07a;
  box-shadow:0 0 0 2px rgba(255,255,255,.35); animation:botPulse 2.4s ease-in-out infinite }
@keyframes botPulse{ 0%,100%{ opacity:1 } 50%{ opacity:.45 } }

/* ---- Bouton de lancement : pastille de présence + halo d'appel ---- */
/* NB : #bot-launch est déjà position:absolute (cf. plus haut) — il sert donc de
   bloc conteneur à .bot-dot / ::after sans qu'on ait à redéfinir sa position. */
.bot-dot{ position:absolute; top:2px; right:2px; width:12px; height:12px; border-radius:50%;
  background:#3ad07a; border:2px solid var(--panel); z-index:1 }
#bot-launch::after{ content:""; position:absolute; inset:0; border-radius:50%;
  box-shadow:0 0 0 0 rgba(31,111,235,.45); animation:botRing 2.8s ease-out infinite }
@keyframes botRing{ 0%{ box-shadow:0 0 0 0 rgba(31,111,235,.45) }
  70%,100%{ box-shadow:0 0 0 14px rgba(31,111,235,0) } }
#bot-launch:active{ transform:scale(.96) }
@media (prefers-reduced-motion: reduce){
  .bot-online, #bot-launch::after{ animation:none }
}

/* =====================================================================
   FLUIDITÉ (défilement / rendu) + RESPONSIVE (tablette & téléphone)
   ===================================================================== */

/* défilement du panneau : inertie iOS + confinement (le scroll du panneau
   ne « fuit » pas sur la carte) + rendu accéléré GPU */
#sidebar{ -webkit-overflow-scrolling:touch; overscroll-behavior:contain; scroll-behavior:smooth; }
#map{ will-change:transform; }
.maplibregl-canvas{ outline:none; }

/* bouton menu (☰) et voile — masqués sur grand écran, révélés en mobile */
#sidebar-toggle{ display:none; }
#sidebar-backdrop{ display:none; }

/* ---- TABLETTE : panneau un peu plus étroit ---- */
@media (max-width:1024px){
  #sidebar{ width:296px; min-width:296px; padding:0 18px 22px; }
  /* la barre KPI est centrée : on la borne pour qu'elle ne file pas sous le
     bouton de l'assistant (coin bas-droit) ni sous l'échelle. */
  #kpibar{ max-width:min(560px, calc(100% - 300px)); }
  /* on remonte l'assistant au-dessus de l'échelle MapLibre (bas-droite) */
  #bot-launch{ bottom:86px; }
  #bot-panel{ bottom:148px; max-height:calc(100% - 176px); }
}

/* ---- TÉLÉPHONE / petite tablette : panneau en tiroir coulissant ---- */
@media (max-width:820px){
  #app{ position:relative; }

  /* le panneau devient un tiroir hors-écran, glissé par-dessus la carte */
  #sidebar{
    position:fixed; top:0; left:0; bottom:0; height:100%;
    width:min(88vw,340px); min-width:0; padding:0 18px 24px;
    transform:translateX(-100%);
    transition:transform .28s cubic-bezier(.4,0,.2,1);
    z-index:1000; box-shadow:0 0 46px rgba(10,16,24,.34);
    will-change:transform;
  }
  body.nav-open #sidebar{ transform:translateX(0); }

  #map{ width:100%; }

  /* bouton hamburger flottant */
  #sidebar-toggle{
    display:flex; align-items:center; justify-content:center;
    position:fixed; top:12px; left:12px; z-index:1001;
    width:44px; height:44px; border-radius:12px; border:1px solid var(--line);
    background:var(--panel); color:var(--accent); cursor:pointer;
    box-shadow:0 3px 14px rgba(15,25,40,.20);
    transition:transform .12s ease, border-color .15s;
  }
  #sidebar-toggle:active{ transform:scale(.94); }
  #sidebar-toggle svg{ width:22px; height:22px; }

  /* voile sombre derrière le tiroir ouvert */
  #sidebar-backdrop{
    display:block; position:fixed; inset:0; z-index:999;
    background:rgba(10,16,24,.44); opacity:0; pointer-events:none;
    transition:opacity .28s ease;
  }
  body.nav-open #sidebar-backdrop{ opacity:1; pointer-events:auto; }

  /* on décale les boutons/carte de la carte pour ne pas chevaucher le ☰ */
  .btn-export{ top:12px; left:66px; padding:8px 12px; font-size:12px; }
  #kpibar{ display:none; }              /* trop chargé sur petit écran */
  #commune-card{ top:64px; left:10px; right:10px; width:auto; max-width:none; }

  /* Le coin bas-droit est réservé à l'assistant : on renvoie l'échelle +
     l'attribution MapLibre en bas-à-GAUCHE (elles restent visibles et lisibles)
     et on masque la flèche Nord décorative, superflue sur petit écran. */
  .maplibregl-ctrl-bottom-right{ left:6px; right:auto; bottom:2px; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl{ float:left; clear:both; }
  .north-arrow{ display:none; }

  /* Assistant : pastille en bas-droite (au-dessus de tout) + panneau en
     « feuille » quasi pleine largeur, qui ne recouvre ni le ☰ ni la carte. */
  #bot-launch{ right:14px; bottom:18px; }
  #bot-panel{
    left:8px; right:8px; width:auto; max-width:none;
    top:auto; bottom:80px; height:auto;
    max-height:calc(100vh - 150px);
  }
  /* police ≥16px : empêche le zoom automatique de la carte/page au focus sur iOS */
  .bot-input input{ font-size:16px; }
}

/* ---- très petit écran ---- */
@media (max-width:420px){
  #sidebar{ width:90vw; }
  .brand{ font-size:16px; }
  .stat .big{ font-size:23px; }
  .btn-export span{ display:none; }     /* n'afficher que l'icône export */
  #bot-launch{ width:46px; height:46px; }
}

/* respect de la préférence « animations réduites » */
@media (prefers-reduced-motion: reduce){
  #sidebar, #sidebar-backdrop, #commune-card, #bot-panel{ transition:none !important; }
}