/* Crash Sentinel — tableau de bord. Palette: dataviz reference instance
   (categorical slots 1-3, status palette, blue<->red diverging pair). */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --neg: #2a78d6; /* less risk */
  --pos: #e34948; /* more risk */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --recovery: #86b6ef;
  --good-text: #006300;
  --band-alpha: 0.13;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --math: "Cambria Math", "STIX Two Math", "Latin Modern Math", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --neg: #3987e5;
    --pos: #e66767;
    --good-text: #0ca30c;
    --band-alpha: 0.2;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.1);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --neg: #3987e5;
  --pos: #e66767;
  --good-text: #0ca30c;
  --band-alpha: 0.2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.55 var(--font);
}
main { max-width: 780px; margin: 0 auto; padding: 16px 16px 64px; }
h1 { font-size: 1.35rem; margin: 0 0 2px; line-height: 1.25; }
h2 { font-size: 1.12rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 10px; }
a { color: var(--s1); }
.sub { color: var(--ink-2); font-size: 0.9rem; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.num { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}
.card > h2 { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

/* status banner */
.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 14px 0;
  border: 1px solid var(--ring);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.banner .icon { font-size: 1.2rem; line-height: 1.3; }
.banner.perime { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); }
.banner.partiel { background: color-mix(in srgb, var(--warning) 16%, var(--surface)); }
.banner.error { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); }

/* hero */
.hero { display: grid; gap: 10px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 12px;
  font-weight: 650;
  font-size: 0.95rem;
  color: #fff;
  width: fit-content;
}
.badge code { font: inherit; font-weight: 500; opacity: 0.85; font-size: 0.8rem; }
.r-EXPANSION { background: var(--good); }
.r-WATCH { background: var(--warning); color: #0b0b0b; }
.r-STRESS { background: var(--serious); color: #0b0b0b; }
.r-CRISIS { background: var(--critical); }
.r-RECOVERY { background: var(--recovery); color: #0b0b0b; }
.r-DEGRADED, .r-PERIME { background: var(--muted); }
.hero-number { font-size: 3.4rem; font-weight: 700; line-height: 1; }
.hero-number small { display: block; font-size: 0.9rem; font-weight: 500; color: var(--ink-2); margin-top: 6px; }
.action { font-size: 1.08rem; font-weight: 550; }

/* gauge of Z along the ladder */
.gauge { position: relative; height: 34px; margin: 6px 0 2px; }
.gauge .track { position: absolute; left: 0; right: 0; top: 10px; height: 8px; display: flex; border-radius: 4px; overflow: hidden; }
.gauge .track span { height: 100%; }
.gauge .marker { position: absolute; top: 2px; width: 2px; height: 24px; background: var(--ink); }
.gauge .marker::after { content: attr(data-label); position: absolute; top: 24px; left: 50%; transform: translateX(-50%); font-size: 0.75rem; white-space: nowrap; font-weight: 650; }
.gauge-ticks { position: relative; height: 16px; font-size: 0.72rem; color: var(--muted); }
.gauge-ticks span { position: absolute; transform: translateX(-50%); }

/* period bar */
.periods {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(6px);
  padding: 8px 0;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.periods button {
  font: inherit;
  font-size: 0.85rem;
  border: 1px solid var(--ring);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
  min-height: 32px;
}
.periods button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.periods button:disabled { opacity: 0.35; cursor: default; }

/* charts */
.chart { position: relative; margin: 10px 0 4px; }
.chart-title { font-size: 0.9rem; font-weight: 600; margin: 12px 0 2px; }
.chart-note { font-size: 0.8rem; color: var(--muted); margin: 2px 0 8px; }
.chart svg { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .ref { stroke: var(--ink-2); stroke-width: 1; opacity: 0.55; }
.chart .ref-label { fill: var(--ink-2); font-size: 10.5px; }
.chart .tick { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.12; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82rem; color: var(--ink-2); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .key i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.legend .key b { display: inline-block; width: 12px; height: 10px; border-radius: 2px; opacity: 0.6; }
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
  padding: 6px 9px;
  font-size: 0.8rem;
  min-width: 130px;
  z-index: 3;
}
.tooltip .t-date { color: var(--muted); margin-bottom: 2px; }
.tooltip .row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tooltip .row i { width: 10px; height: 2px; display: inline-block; }
.tooltip .row strong { font-variant-numeric: tabular-nums; }
.tooltip .row span { color: var(--ink-2); }

/* formulas */
.eq {
  display: block;
  font-family: var(--math);
  font-size: 1.05rem;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
  overflow-x: auto;
  white-space: nowrap;
}
.calc { font-variant-numeric: tabular-nums; }
i { font-family: var(--math); }
sub, sup { font-size: 0.72em; line-height: 0; }

/* bars (contributions, scenarios) */
.bars { display: grid; gap: 6px; margin: 8px 0; }
.bar-row { display: grid; grid-template-columns: 112px 1fr 56px; gap: 8px; align-items: center; font-size: 0.86rem; }
.bar-row .lab { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bar-track { position: relative; height: 14px; }
.bar-track .mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--axis); }
.bar-track .fill { position: absolute; top: 2px; height: 10px; border-radius: 4px; }
.bar-track .fill.pos { background: var(--pos); }
.bar-track .fill.neg { background: var(--neg); }
.bar-track .fill.loss { background: var(--pos); right: 0; }
.bar-row.excluded .lab { text-decoration: line-through; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.st { font-weight: 650; white-space: nowrap; }
.st-OK { color: var(--good-text); }
.st-PERIME, .st-ABSENT { color: var(--critical); }

/* indicator cards */
.ind { border-top: 1px solid var(--grid); padding-top: 14px; margin-top: 14px; }
.ind:first-of-type { border-top: 0; padding-top: 0; margin-top: 4px; }
.ind-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.ind-meta { font-size: 0.82rem; color: var(--muted); }
.zchip { font-weight: 700; font-variant-numeric: tabular-nums; }
.zchip.pos { color: var(--pos); }
.zchip.neg { color: var(--neg); }
.flag { display: inline-block; font-size: 0.75rem; font-weight: 650; border-radius: 6px; padding: 1px 6px; background: color-mix(in srgb, var(--critical) 18%, transparent); color: var(--ink); }
details { margin: 8px 0; }
details > summary { cursor: pointer; color: var(--s1); font-size: 0.9rem; font-weight: 550; }
details > div { padding-top: 6px; }
.k { font-weight: 650; color: var(--ink-2); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; margin-top: 8px; }

.warn { border-left: 3px solid var(--warning); padding: 6px 10px; background: color-mix(in srgb, var(--warning) 10%, transparent); border-radius: 0 8px 8px 0; margin: 8px 0; font-size: 0.9rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 8px 0 12px; }
.kv div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.kv .v { font-size: 1.25rem; font-weight: 700; }
.kv .l { font-size: 0.78rem; color: var(--ink-2); }
dl.gloss dt { font-weight: 650; margin-top: 8px; }
dl.gloss dd { margin: 2px 0 0; color: var(--ink-2); }
footer { color: var(--muted); font-size: 0.82rem; margin-top: 24px; }
.toc { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 0.86rem; }
@media (max-width: 480px) {
  .hero-number { font-size: 2.9rem; }
  table { font-size: 0.8rem; }
  th, td { padding: 5px 4px; }
}

/* Actualité */
.lead { font-size: 1.05rem; font-weight: 600; }
.news-action { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin: 6px 0 10px; }
.news-action code { font-size: 0.82rem; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

.news-events { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 10px; }
.news-events li { border-left: 3px solid var(--grid); padding: 2px 0 2px 10px; }
.news-events p { margin: 4px 0 0; }
.ev-title { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 4px; }
.chip { display: inline-block; line-height: 1.5; font-size: 0.74rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.chip.up { background: color-mix(in srgb, var(--pos) 18%, transparent); color: var(--ink); }
.chip.down { background: color-mix(in srgb, var(--neg) 18%, transparent); color: var(--ink); }
.chip.chip-ind { border: 1px solid var(--grid); background: transparent; }
.news-action .badge { background: var(--surface-2); color: var(--ink); font-size: 0.88rem; }
.news-action .badge.attn { background: var(--warning); color: #0b0b0b; }
