:root {
  --bg: #f5f5f7; --card: #ffffff; --ink: #1d1d1f; --muted: #6e6e73; --line: #e5e5ea;
  --blue: #0071e3; --green: #248a3d; --orange: #c93400; --red: #d70015; --soft: #f0f0f3;
  --radius: 18px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 24px rgba(0,0,0,.05);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --ink: #f5f5f7; --muted: #98989d; --line: #2c2c2e; --soft: #2c2c2e;
          --blue: #0a84ff; --green: #30d158; --orange: #ff9f0a; --red: #ff453a; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
body { font-size: 15px; line-height: 1.45; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 30px; letter-spacing: -.02em; margin: 8px 0 4px; }
h2 { font-size: 19px; letter-spacing: -.01em; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 40px 0; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
       padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
       background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(180%) blur(20px);
       -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--blue); }
.brand svg { width: 24px; height: 24px; }
.brand span { color: var(--ink); }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { color: var(--ink); padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.top nav a:hover { text-decoration: none; background: var(--soft); }
.top nav a.on { background: var(--ink); color: var(--bg); }
button.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; }

main { max-width: 1100px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) 48px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); grid-column: span 12; min-width: 0; }
.span6 { grid-column: span 6; } .span4 { grid-column: span 4; } .span8 { grid-column: span 8; }
@media (max-width: 800px) { .span6, .span4, .span8 { grid-column: span 12; } h1 { font-size: 26px; } }

/* Grandes barres */
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .bars { grid-template-columns: 1fr; } }
.bigbar .label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.bigbar .pct { font-size: 44px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.track { height: 14px; background: var(--soft); border-radius: 999px; overflow: hidden; margin: 10px 0 8px; }
.fill { height: 100%; border-radius: 999px; background: var(--blue); transition: width .6s ease; }
.fill.warn { background: var(--orange); } .fill.crit { background: var(--red); }
.minibars { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-top: 16px; }
.minibar { flex: 1 1 160px; }
.minibar .track { height: 6px; margin: 6px 0 0; }
.notice { background: var(--soft); border-radius: 12px; padding: 10px 14px; font-size: 13px; color: var(--muted); margin-top: 14px; }

/* Alertes */
.alerts { display: grid; gap: 10px; }
.alert { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--soft); }
.alert .ico { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; background: var(--orange); }
.alert.crit .ico { background: var(--red); }
.alert b { display: block; }
.alert .advice { margin-top: 4px; }
.ok { display: flex; align-items: center; gap: 10px; color: var(--green); }

/* Tableaux */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 500; color: var(--muted); font-size: 13px; }
td.num, th.num { text-align: right; }
tr.clic { cursor: pointer; } tr.clic:hover td { background: var(--soft); }
tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--soft); font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

/* Aide au survol */
.help { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; border: 1.5px solid var(--muted);
        color: var(--muted); font-size: 11px; font-weight: 700; cursor: help; flex: none; }
#tip { position: fixed; z-index: 50; max-width: 300px; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 10px;
       font-size: 13px; line-height: 1.4; pointer-events: none; box-shadow: var(--shadow); }

/* Graphiques */
.chart { width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; }
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-wrap svg { width: 180px; height: 180px; flex: none; }
.donut-wrap .legend { flex-direction: column; flex: 1; min-width: 180px; }
.legend .row { display: flex; justify-content: space-between; gap: 12px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 8px; font: inherit; font-size: 13px; color: var(--ink); cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.head h2 { margin: 0; }

/* Chiffres cles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { background: var(--soft); border-radius: 14px; padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .k { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* Formulaires */
input, select { font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.btn { font: inherit; border: 0; border-radius: 10px; padding: 9px 16px; background: var(--blue); color: #fff; cursor: pointer; font-weight: 500; }
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: none; color: var(--red); padding: 6px 8px; }
.btn:disabled { opacity: .5; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row input { flex: 1 1 120px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.field label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--soft); padding: 12px; border-radius: 10px; word-break: break-all; user-select: all; }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
         padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60; }

/* Connexion */
.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 28px; }
.login .brand { justify-content: center; font-size: 22px; margin-bottom: 18px; }
.login .brand svg { width: 40px; height: 40px; }
.login input { width: 100%; margin-bottom: 10px; }
.login .btn { width: 100%; margin-top: 6px; }
.err { color: var(--red); font-size: 14px; min-height: 20px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.donut-bg { stroke: var(--soft); }
.donut-wrap svg text { fill: var(--ink); }
a.alert { color: inherit; }
a.alert:hover { text-decoration: none; filter: brightness(.97); }
.alert .pill { background: var(--card); }
.kpi .v .smaller { font-size: 16px; font-weight: 600; letter-spacing: 0; }
td input, td select { width: 100%; min-width: 110px; }
@media (max-width: 600px) {
  .hide-sm { display: none; }
  .top { gap: 10px; }
  .brand span { display: none; }
  .top nav a { padding: 6px 9px; font-size: 14px; }
  button.link { font-size: 14px; }
  .card { padding: 16px; }
  .bigbar .pct { font-size: 36px; }
}
