/* Feuille de style commune : accueil, partie 1 (carte), partie 2 (récit).
   Aucune ressource externe : le TP doit fonctionner sans internet. */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --ink: #141a2e;
  --ink-2: #3b4358;
  --muted: #6a7389;
  --line: #e2e6ef;
  --line-2: #cfd5e2;
  --brand: #0f6e8c;
  --brand-2: #0b5068;
  --brand-soft: #e3f2f6;
  --accent: #c2185b;
  --warn-bg: #fff7e8;
  --warn-line: #d08a12;
  --danger-bg: #fff1ec;
  --danger-line: #b4381a;
  --ok-bg: #ecf7f0;
  --ok-line: #24774a;
  --halo: #ffffff;
  --map-empty: #e6e9f0;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 26, 46, .05), 0 6px 24px rgba(20, 26, 46, .06);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1220; --surface: #161b2c; --surface-2: #1d2337; --ink: #eef1f8; --ink-2: #c7cddc; --muted: #8f98ae;
    --line: #262d44; --line-2: #343c57; --brand: #4fb3d1; --brand-2: #7cc8de; --brand-soft: #15303b; --accent: #f06292;
    --warn-bg: #2b2414; --warn-line: #e0a63a; --danger-bg: #2d1914; --danger-line: #ee7a5a; --ok-bg: #13281d; --ok-line: #5cc48a;
    --halo: #161b2c; --map-empty: #2a3147;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--font); font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-underline-offset: 3px; }
a:hover { color: var(--brand-2); }
code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- Barre de navigation ---------- */
.nav {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav-inner { max-width: 1200px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #0f6e8c, #41b6c4 60%, #a1dab4); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.nav-links { display: flex; gap: 4px; margin-left: auto; }
.nav-links a { color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500; padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.nav-links a:hover { background: var(--surface-2); color: var(--ink); }
.nav-links a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-2); }
@media (max-width: 560px) { .brand-text { display: none; } .nav-inner { padding: 8px 16px; gap: 8px; } .nav-links a { padding: 6px 9px; font-size: 13px; } }

/* ---------- Mise en page ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 20px 56px; }
@media (max-width: 560px) { .page { padding: 18px 16px 40px; } }
.hero { margin-bottom: 22px; }
.kicker { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); margin: 0 0 8px; }
.kicker::before { content: ""; width: 18px; height: 2px; background: currentColor; border-radius: 2px; }
h1 { font-size: clamp(1.55rem, 1.1rem + 1.9vw, 2.45rem); line-height: 1.15; letter-spacing: -.025em; margin: 0 0 .45em; font-weight: 800; text-wrap: balance; }
h2 { font-size: clamp(1.2rem, 1rem + .7vw, 1.5rem); letter-spacing: -.015em; line-height: 1.25; margin: 0 0 .5em; text-wrap: balance; }
.lead { font-size: clamp(1rem, .95rem + .3vw, 1.15rem); color: var(--ink-2); max-width: 72ch; margin: 0; }
p { max-width: 78ch; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
@media (max-width: 560px) { .card { padding: 14px; border-radius: 12px; } }
.card + .card, .section + .section { margin-top: 18px; }
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 10px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0; line-height: 1.35; }
.card-sub { font-size: 13px; color: var(--muted); margin: 2px 0 0; }

/* ---------- Indicateurs clés ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 20px 0 0; }
@media (max-width: 860px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: clamp(1.3rem, 1.1rem + .8vw, 1.75rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; }
.kpi-note { font-size: 12px; color: var(--muted); }

/* ---------- Commandes (contrôles segmentés) ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
.toolbar .label { font-weight: 600; color: var(--ink-2); font-size: 13px; }
.field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink-2); background: transparent; border: 0;
  padding: 6px 12px; border-radius: 7px; cursor: pointer; transition: background .15s, color .15s;
}
.segmented button:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--brand); color: #fff; box-shadow: 0 1px 3px rgba(15, 110, 140, .35); }
.segmented button:disabled { opacity: .4; cursor: not-allowed; }
select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 9px; padding: 7px 32px 7px 10px; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.hint { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------- Messages ---------- */
.status { background: var(--ok-bg); border: 1px solid var(--ok-line); color: var(--ok-line); padding: 9px 14px; border-radius: 10px; font-size: 14px; }
.error { display: none; background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--ink); padding: 12px 14px; border-radius: 10px; }
.alert { display: none; background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn-line) 45%, transparent); border-left: 4px solid var(--warn-line); padding: 9px 14px; border-radius: 10px; font-size: 14px; max-width: none; margin: 12px 0 0; }

/* ---------- Grilles ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); gap: 18px; margin-top: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.grid-2 > .card, .grid-cards > .card { margin-top: 0; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

/* ---------- Récit (étapes) ---------- */
.step { position: relative; margin-top: 40px; }
.step-tag { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.step-num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-grid; place-items: center; font-size: 11.5px; letter-spacing: 0; }
.prose p { color: var(--ink-2); }
.prose b, .prose strong { color: var(--ink); }

.analyse { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 14px 0 0; padding: 0; }
.analyse div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.analyse dt { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); margin-bottom: 2px; }
.analyse dd { margin: 0; font-size: 14px; color: var(--ink-2); }

.conclusion { border-left: 4px solid var(--brand); background: linear-gradient(90deg, var(--brand-soft), var(--surface) 70%); }

/* ---------- Tableau ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
thead th { background: var(--surface-2); font-size: 12.5px; font-weight: 700; color: var(--ink-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); }
td.nat, th.nat { color: var(--muted); }
.empty-state { padding: 22px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- SVG et cartes ---------- */
svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font); }
svg text { fill: var(--ink); }
.wilaya { stroke: var(--surface); stroke-width: .9; transition: opacity .2s; }
.wilaya, .barre, .bulle, .cercle { cursor: pointer; }
.wilaya.survol, .barre.survol, .bulle.survol, .cercle.survol { stroke: var(--ink); stroke-width: 2.5; }
.wilaya.choisi, .barre.choisi, .bulle.choisi, .cercle.choisi { stroke: var(--accent); stroke-width: 3; }
.wilaya:focus, .barre:focus, .bulle:focus, .cercle:focus { outline: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 4 2; }
.etiquette { font-size: 11px; paint-order: stroke; stroke: var(--halo); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.etiquette.claire { fill: #fff; stroke: rgba(10, 20, 40, .75); stroke-width: 2.5px; }
.etiquette-bulle { font-size: 10.5px; paint-order: stroke; stroke: var(--halo); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.carton-cadre { fill: var(--surface-2); stroke: var(--line-2); stroke-width: 1; }
.rappel { stroke: var(--ink-2); stroke-width: .8; stroke-dasharray: 3 2; fill: none; }
.legende text { font-size: 12px; }
.legende .titre-leg { font-weight: 700; }
.legende .sous-leg { fill: var(--muted); }
.sw { stroke: var(--line-2); stroke-width: .6; }
.vide-carte { fill: var(--map-empty); }
.hach-fond { fill: var(--surface); }
.hach-trait { stroke: var(--muted); }
.val { font-size: 11px; }
.ref { stroke: var(--ink-2); stroke-dasharray: 4 3; }
.axe text { font-size: 11px; fill: var(--muted); }
.axe path, .axe line { stroke: var(--line-2); }
.grille line { stroke: var(--line); }
.grille path { display: none; }

/* ---------- Infobulle ---------- */
.tooltip {
  position: absolute; pointer-events: none; opacity: 0; z-index: 30; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 10px 12px; font-size: 13.5px; line-height: 1.45; box-shadow: 0 10px 30px rgba(20, 26, 46, .18);
  transition: opacity .12s;
}
.tooltip .tt-titre { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.tooltip .tt-val { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.tooltip .tt-ligne { color: var(--ink-2); }
.tooltip .tt-warn { color: var(--warn-line); font-weight: 600; }
.tooltip .tt-aide { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- Accueil ---------- */
.link-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); transition: transform .15s, box-shadow .15s, border-color .15s; }
.link-card:hover { transform: translateY(-2px); border-color: var(--brand); color: var(--ink); box-shadow: 0 2px 4px rgba(20,26,46,.06), 0 14px 34px rgba(20,26,46,.1); }
.link-card .lc-num { font-size: 12px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .07em; }
.link-card .lc-titre { font-size: 1.15rem; font-weight: 750; letter-spacing: -.01em; }
.link-card .lc-texte { color: var(--ink-2); font-size: 14.5px; margin: 0; }
.link-card .lc-cta { margin-top: auto; padding-top: 8px; color: var(--brand); font-weight: 600; font-size: 14px; }

/* ---------- Pied de page ---------- */
.footer { border-top: 1px solid var(--line); margin-top: 40px; padding-top: 16px; font-size: 13px; color: var(--muted); }
.footer p { max-width: none; margin: 4px 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .nav, .toolbar { display: none; } body { background: #fff; } .card, .kpi { box-shadow: none; } }
