:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --grid: #e8e7e2;
  --track: #ebeae6;
  --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --other: #a3a29c;
  --system: #c9c8c2;
  --reclaim: #d9d8d2;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-bg: #e8f5e8; --warning-bg: #fdf3dc; --critical-bg: #fbe7e7; --stale-bg: #eeeeec;
  --good-ink: #006300; --warning-ink: #7a5200; --critical-ink: #a32525;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 12px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --grid: #2a2a27; --track: #262624;
    --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --other: #6b6a64; --system: #4a4945; --reclaim: #3a3a37;
    --good-bg: #16301a; --warning-bg: #352a10; --critical-bg: #3a1a1a; --stale-bg: #262624;
    --good-ink: #6fd46f; --warning-ink: #fac655; --critical-ink: #f08a8a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --grid: #2a2a27; --track: #262624;
  --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --other: #6b6a64; --system: #4a4945; --reclaim: #3a3a37;
  --good-bg: #16301a; --warning-bg: #352a10; --critical-bg: #3a1a1a; --stale-bg: #262624;
  --good-ink: #6fd46f; --warning-ink: #fac655; --critical-ink: #f08a8a;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand img { border-radius: 7px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

main { max-width: 980px; margin: 0 auto; padding: 16px; }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 11px 18px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.danger { background: transparent; color: var(--critical-ink); border: 1px solid var(--border); }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--text-2); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.stack > * + * { margin-top: 14px; }

/* ---- Connexion ---- */
.auth { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.auth h1 { font-size: 22px; margin: 14px 0 6px; }
.auth p { color: var(--text-2); margin: 0 0 18px; }
.auth .lock { width: 64px; height: 64px; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; margin: 0 auto; color: var(--text-2); }
.auth form { display: grid; gap: 10px; text-align: left; margin-top: 14px; }
.auth label { font-size: 13px; color: var(--text-2); }
.auth input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
.auth .msg { min-height: 20px; font-size: 14px; color: var(--critical-ink); margin-top: 10px; }
.auth .switch { margin-top: 22px; font-size: 14px; }
.linkish { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }

/* ---- Vue d'ensemble (plusieurs serveurs) ---- */
.overview { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 16px; }
.overview a { text-decoration: none; color: inherit; }
.ov { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.ov .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Serveur ---- */
.server { margin-bottom: 28px; scroll-margin-top: 70px; }
.server-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 2px 12px; }
.server-head h2 { margin: 0; font-size: 21px; }
.server-head .meta { font-size: 13px; color: var(--muted); }

.verdict { display: flex; gap: 12px; align-items: flex-start; border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border); }
.verdict.ok { background: var(--good-bg); }
.verdict.warn { background: var(--warning-bg); }
.verdict.crit { background: var(--critical-bg); }
.verdict.stale, .verdict.waiting { background: var(--stale-bg); }
.verdict .vicon { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; margin-top: 1px; }
.verdict.ok .vicon { background: var(--good); }
.verdict.warn .vicon { background: var(--warning); color: #3a2a00; }
.verdict.crit .vicon { background: var(--critical); }
.verdict.stale .vicon, .verdict.waiting .vicon { background: var(--muted); }
.verdict strong { display: block; font-size: 16px; }
.verdict.ok strong { color: var(--good-ink); }
.verdict.warn strong { color: var(--warning-ink); }
.verdict.crit strong { color: var(--critical-ink); }
.verdict span { color: var(--text-2); font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 640px) { .kpis { grid-template-columns: 1fr; } }
.kpi { padding: 14px 16px; }
.kpi .label { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .big { font-size: 28px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; }
.kpi .big small { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi .sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; padding: 2px 8px; border-radius: 99px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--good-ink); background: var(--good-bg); }
.pill.warn { color: var(--warning-ink); background: var(--warning-bg); }
.pill.crit { color: var(--critical-ink); background: var(--critical-bg); }
.meter { height: 8px; border-radius: 4px; background: var(--track); margin-top: 10px; overflow: hidden; display: flex; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* Barres de répartition */
.section-title { font-size: 15px; font-weight: 650; margin: 0 0 4px; }
.section-sub { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.split { display: flex; height: 28px; border-radius: 6px; overflow: hidden; background: var(--track); gap: 2px; }
.split > div { height: 100%; min-width: 2px; cursor: default; transition: filter .15s; }
.split > div:hover { filter: brightness(1.08); }
.split > div.free { background: transparent; }
.split > div.reclaim { background: repeating-linear-gradient(135deg, var(--reclaim) 0 5px, var(--system) 5px 7px); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend i.free { background: var(--track); outline: 1px solid var(--border); }
.legend i.reclaim { background: repeating-linear-gradient(135deg, var(--reclaim) 0 3px, var(--system) 3px 5px); }
.legend b { color: var(--text); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

/* Prévisions & conseils */
.advice { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.advice li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--text-2); }
.advice li .dot { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; margin-top: 1px; }
.advice li.info .dot { background: var(--accent); }
.advice li.warn .dot { background: var(--warning); color: #3a2a00; }
.advice li.crit .dot { background: var(--critical); }
.advice li.ok .dot { background: var(--good); }
.advice code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-all; }

.forecast { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.forecast div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.forecast .k { font-size: 12px; color: var(--muted); }
.forecast .v { font-size: 17px; font-weight: 650; margin-top: 2px; }

/* Tableau des projets */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; }
td { padding: 9px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr.proj { cursor: pointer; }
tr.proj:hover td { background: var(--surface-2); }
tr.detail td { background: var(--surface-2); font-size: 13px; color: var(--text-2); padding: 8px 12px 12px; }
.pname { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.pname i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.bar-cell .mini { width: 54px; height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.bar-cell .mini i { display: block; height: 100%; background: var(--text-2); opacity: .55; border-radius: 3px; }
.ctr { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 14px; }
.ctr .state { font-size: 12px; }
.ctr .state.down { color: var(--critical-ink); font-weight: 600; }

/* Graphiques */
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 11px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 860px) { .charts { grid-template-columns: 1fr; } }
.chart h4 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); }
.chart .now { font-size: 20px; font-weight: 650; }
.chart svg { display: block; width: 100%; height: 130px; overflow: visible; touch-action: pan-y; }
.chart .axis { font-size: 10px; fill: var(--muted); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .limit { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dotm { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.empty-chart { height: 130px; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--text); color: var(--bg); border-radius: 8px; padding: 7px 10px;
  font-size: 12.5px; line-height: 1.35; max-width: 260px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.tooltip b { font-weight: 650; }

/* Réglages */
details.settings { margin-top: 8px; }
details.settings summary { cursor: pointer; font-weight: 600; color: var(--text-2); padding: 6px 2px; list-style: none; }
details.settings summary::-webkit-details-marker { display: none; }
details.settings summary::before { content: "▸ "; }
details.settings[open] summary::before { content: "▾ "; }
.device { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.device:last-child { border-bottom: 0; }
.invite-code { font: 600 28px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-align: center; padding: 14px; background: var(--surface-2); border-radius: 10px; margin: 10px 0 6px; user-select: all; }
pre.cmd { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.footer { text-align: center; color: var(--muted); font-size: 12px; margin: 24px 0 10px; }
.brand span, .btn { white-space: nowrap; }
@media (max-width: 480px) {
  #updated { display: none; }
  .kpi .big { font-size: 24px; }
}
[hidden] { display: none !important; }
