:root {
  --navy: #0E1A2B;
  --rail: #08111D;
  --panel: #13233A;
  --panel-2: #172B46;
  --line: #23395A;
  --text: #E6EEF7;
  --muted: #8DA2BC;
  --safe: #3DDC97;
  --margin: #F2B84B;
  --limit: #F0606A;
  --focus: #7FB4FF;
  --radius-s: 6px;
  --radius-m: 10px;
  color-scheme: dark;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--navy); color: var(--text); }
body { min-height: 100vh; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.narrow { max-width: 68ch; }
.error { color: var(--limit); min-height: 1.4em; }
.num, td.num, .kpi b { font-variant-numeric: tabular-nums; }
a { color: var(--focus); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

button, input, select { font: inherit; color: inherit; }
button { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .55rem .9rem; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--safe); color: #062417; border-color: var(--safe); font-weight: 600; }
button.danger { border-color: var(--limit); color: var(--limit); background: transparent; }
button.small { padding: .25rem .6rem; font-size: .85rem; }
input, select { width: 100%; background: var(--rail); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .5rem .6rem; }
input[type=checkbox] { width: auto; }
label { display: grid; gap: .3rem; font-size: .88rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: .6rem; margin: .5rem 0 1rem; }
label.inline select { width: auto; }

/* Connexion */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.6rem; display: grid; gap: .9rem; }
.auth-card .secret { font-family: ui-monospace, Menlo, monospace; word-break: break-all; background: var(--rail); padding: .6rem; border-radius: var(--radius-s); color: var(--text); }
.brand { display: flex; align-items: center; gap: .55rem; }
.brand small { color: var(--muted); }
.mark { width: 22px; height: 22px; border-radius: 5px; background: linear-gradient(transparent 62%, var(--limit) 62% 70%, transparent 70%), var(--panel-2); border: 1px solid var(--line); position: relative; }
.mark::after { content: ""; position: absolute; left: 4px; right: 3px; top: 5px; height: 8px; border-top: 2px solid var(--safe); transform: skewY(-24deg); }

/* Structure */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.rail { background: var(--rail); border-right: 1px solid var(--line); padding: 1.2rem .8rem; display: flex; flex-direction: column; gap: .15rem; position: sticky; top: 0; height: 100vh; }
.rail .brand { padding: 0 .5rem 1rem; }
.rail a { color: var(--muted); text-decoration: none; padding: .5rem .6rem; border-radius: var(--radius-s); font-size: .93rem; }
.rail a:hover { color: var(--text); }
.rail a.active { color: var(--text); background: var(--panel); box-shadow: inset 3px 0 0 var(--safe); }
.rail-note { margin-top: auto; font-size: .8rem; color: var(--muted); padding: .5rem; }
.main { padding: 0 2rem 3rem; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1.2rem 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--navy); z-index: 5; }
.topbar h1 { flex: 1; }
.sync { font-size: .85rem; }
.kill { background: transparent; color: var(--limit); border: 2px solid var(--limit); font-weight: 700; padding: .55rem 1.1rem; }
.kill[aria-pressed=true] { background: var(--limit); color: #2A0709; }
.banner { margin: 1rem 0 0; padding: .8rem 1rem; border-radius: var(--radius-s); border: 1px solid var(--limit); color: var(--limit); }
.page { padding-top: 1.2rem; }
.stack { display: grid; gap: .8rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1rem 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.1rem 1.2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .9rem 1rem; margin-top: 1.2rem; align-items: end; }
.form-grid h2 { margin: 0; }
.span { grid-column: 1 / -1; }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.kpi { padding: .9rem 1rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.kpi small { display: block; color: var(--muted); font-size: .8rem; }
.kpi b { font-size: 1.35rem; font-weight: 600; }
.pos { color: var(--safe); }
.neg { color: var(--limit); }
.warn { color: var(--margin); }

/* Pistes de drawdown : l'élément signature */
.runways { display: grid; gap: 1.1rem; }
.runway { display: grid; grid-template-columns: minmax(160px, 220px) 1fr; gap: .4rem 1.2rem; align-items: center; }
.runway header strong { display: block; }
.runway header small { color: var(--muted); }
.runway svg { width: 100%; height: 46px; display: block; }
.rw-track { fill: var(--rail); }
.rw-margin { fill: var(--margin); opacity: .35; }
.rw-room { fill: var(--safe); opacity: .85; }
.rw-room.rw-warning { fill: var(--margin); }
.rw-room.rw-danger, .rw-room.rw-breached { fill: var(--limit); }
.rw-floor { stroke: var(--limit); stroke-width: 3; }
.rw-equity { stroke: var(--text); stroke-width: 2; }
.runway .legend { grid-column: 2; display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.state { display: inline-block; white-space: nowrap; font-size: .78rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid currentColor; margin-left: .4rem; }

.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.alerts li { padding: .6rem .8rem; border-left: 3px solid var(--line); background: var(--panel); border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.alerts li.critical, .alerts li.high { border-left-color: var(--limit); }
.alerts li.medium { border-left-color: var(--margin); }
.alerts li.empty { color: var(--muted); }

.card-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; flex-wrap: wrap; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .4rem 1rem; margin: .8rem 0; }
.facts div small { display: block; color: var(--muted); font-size: .78rem; }
.reasons { margin: .3rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .85rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-m); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: .6rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.empty { color: var(--muted); text-align: center; padding: 1.2rem; }

.score { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.checks { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: .2rem; font-size: .88rem; }
.checks li::before { content: "✕ "; color: var(--limit); }
.checks li.ok::before { content: "✓ "; color: var(--safe); }

.toast { position: fixed; bottom: 1.2rem; right: 1.2rem; max-width: min(440px, calc(100vw - 2.4rem)); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .75rem 1rem; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; transform: none; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-m); max-width: min(520px, 92vw); }
dialog::backdrop { background: rgba(4, 9, 16, .7); }
dialog .secret { font-family: ui-monospace, Menlo, monospace; word-break: break-all; background: var(--rail); padding: .6rem; border-radius: var(--radius-s); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; top: 0; height: auto; flex-direction: row; overflow-x: auto; padding: .5rem; z-index: 10; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail .brand, .rail-note { display: none; }
  .rail a { white-space: nowrap; }
  .main { padding: 0 1rem 2rem; }
  .topbar { top: 49px; flex-wrap: wrap; }
  .runway { grid-template-columns: 1fr; }
  .runway .legend { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
