/* Layout: sticky top bar with three views; the dashboard reads top-down — état, key figures, selectable curves, week + sessions */
:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --ink: #15211d;
  --muted: #5c6b66;
  --line: #d5ddd9;
  --accent: #127a66;
  --accent-soft: #d6ece6;
  --goal: #b4572e;
  --good: #1f7a3f;
  --warn: #a8660b;
  --bad: #b3322b;
  /* series palette, distinguishable in both themes */
  --s1: #127a66; --s2: #b4572e; --s3: #3d5fb8; --s4: #8a4fb0; --s5: #a8660b; --s6: #2b8aa8; --s7: #b03a6a;
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614; --surface: #18201d; --ink: #e5ece9; --muted: #95a59f; --line: #2b3632;
    --accent: #4cc3a8; --accent-soft: #1d3a33; --goal: #e48a5f;
    --good: #5cc785; --warn: #e0a548; --bad: #ef7a72;
    --s1: #4cc3a8; --s2: #e48a5f; --s3: #7d9cf0; --s4: #c08ae0; --s5: #e0a548; --s6: #5cc2e0; --s7: #ea7aa6;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.5; }
h1, h2 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-weight: 500; font-size: 18px; }
code { font-family: var(--mono); font-size: 0.92em; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.n, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.src { display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; padding: 0 6px; border-radius: 5px; border: 1px solid var(--line); color: var(--muted); vertical-align: 1px; margin-left: 5px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px); }
.topbar-in { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.brand { font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: -0.02em; }
.tabs { display: flex; gap: 4px; }
.tabs a { text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 12px; border-radius: 9px; }
.tabs a:hover { color: var(--ink); background: var(--surface); }
.tabs a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--good); }
a.quiet { color: var(--muted); font-size: 13px; }

.wrap { max-width: 1040px; margin: 0 auto; padding-block: 20px 56px; display: grid; gap: 18px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.view { display: grid; gap: 18px; min-width: 0; }
.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; gap: 14px; min-width: 0; align-content: start; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* État */
.etat { gap: 16px; }
.etat-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.etat h1 { font-size: clamp(26px, 5vw, 34px); font-weight: 700; line-height: 1.1; margin-top: 4px; }
.etat-sum { margin: 6px 0 0; color: var(--muted); max-width: 62ch; }
.etat-score { display: flex; gap: 6px; flex-wrap: wrap; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.check { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 12px 16px; display: grid; gap: 3px; position: relative; overflow: hidden; }
.check::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--muted); opacity: .4; }
.check.good::before { background: var(--good); opacity: 1; }
.check.warn::before { background: var(--warn); opacity: 1; }
.check.bad::before { background: var(--bad); opacity: 1; }
.check-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.check-name { font-weight: 600; font-size: 14px; }
.check-val { font-family: var(--mono); font-size: 13px; font-weight: 600; white-space: nowrap; }
.check.good .check-val { color: var(--good); }
.check.warn .check-val { color: var(--warn); }
.check.bad .check-val { color: var(--bad); }
.check p { margin: 0; font-size: 13px; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); width: fit-content; }
.pill.good { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.pill.muted { color: var(--muted); background: color-mix(in srgb, var(--muted) 12%, transparent); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.kpi { padding: 14px 16px; display: grid; gap: 2px; align-content: start; border-left: 1px solid var(--line); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi .v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 600; line-height: 1.15; white-space: nowrap; }
.kpi .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 2px; }
.kpi .d { font-size: 12px; color: var(--muted); }
.up-bad, .down-bad { color: var(--bad); }
.up-good, .down-good { color: var(--good); }

/* Selectable curves */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 11px; font-size: 13px; font-weight: 500; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 10px; font-size: 13px; font-weight: 500; background: transparent; color: var(--muted); }
.chip i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--c); }
.chip[aria-pressed="true"] { color: var(--ink); border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, transparent); }
.chip[aria-pressed="true"] i { background: var(--c); }
.chip:disabled { opacity: .45; cursor: not-allowed; }
.multi { position: relative; min-height: 120px; }
.multi svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.tip { position: absolute; top: 0; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); min-width: 170px; display: grid; gap: 3px; z-index: 2; }
.tip b { font-weight: 600; }
.tip .r { display: flex; justify-content: space-between; gap: 12px; }
.tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.tip .r i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tip .r span:last-child { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }
.zoom-btn { position: absolute; width: 28px; height: 28px; padding: 0; display: grid; place-items: center; font-size: 15px; line-height: 1; border-radius: 8px; background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--muted); }
.zoom-btn:hover { color: var(--accent); border-color: var(--accent); }
dialog.zoom { width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); }
dialog.zoom::backdrop { background: rgba(10, 20, 16, 0.45); }
.zoom-in { padding: 18px; display: grid; gap: 12px; }
.zoom-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.zoom-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--muted); }
.zoom-stats b { color: var(--ink); font-family: var(--mono); font-weight: 600; }

/* Week facts */
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin: 0; }
.facts div { display: grid; gap: 2px; min-width: 0; }
.facts dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; font-family: var(--mono); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.facts dd + dd { font-family: var(--body); font-size: 13px; font-weight: 400; }

/* Sessions */
.acts { list-style: none; margin: 0; padding: 0; display: grid; }
.acts li { display: grid; grid-template-columns: 82px 1fr; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.acts li:last-child { border-bottom: 0; }
.acts .when { color: var(--muted); font-size: 13px; grid-row: span 2; }
.acts .what { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.acts .what a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.acts .what a:hover { color: var(--accent); border-color: var(--accent); }
.acts .nums { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* Forms */
form.entry { display: grid; gap: 16px; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
legend { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; padding: 0; margin-bottom: 8px; }
.row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.field { display: grid; gap: 4px; min-width: 0; }
.date-field { max-width: 220px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; width: 100%; min-width: 0; }
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input.big-in { font-size: 18px; font-weight: 600; }
input:focus-visible, button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
button { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 14px; font-weight: 600; }
button.small { padding: 5px 11px; font-size: 13px; }
button.primary, a.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
a.primary { display: inline-block; border-radius: 9px; padding: 8px 14px; font-weight: 600; text-decoration: none; justify-self: start; }
button.primary:hover, a.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 10px; font-weight: 500; }
button.ghost:hover { color: var(--ink); background: var(--bg); }
button:disabled { opacity: .6; cursor: default; }
.msg { font-size: 13px; min-height: 1.2em; color: var(--muted); margin: 0; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--good); }
.banner { border-radius: 12px; padding: 12px 16px; font-size: 14px; border: 1px solid var(--line); background: var(--surface); }
.banner.ok { border-color: var(--good); color: var(--good); }
.banner.err { border-color: var(--bad); color: var(--bad); }

/* History */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.note-cell { color: var(--muted); white-space: normal; min-width: 140px; max-width: 240px; }
tr:last-child td { border-bottom: 0; }
.delta-down { color: var(--good); }
.delta-up { color: var(--bad); }

/* Connections */
.conns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.conn { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.conn-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conn-name { font-family: var(--display); font-weight: 500; font-size: 17px; }
.conn .hint { overflow-wrap: anywhere; }
.conn .err { color: var(--bad); font-size: 13px; }
.conn button { justify-self: start; }

/* Login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.login-box { width: 100%; max-width: 420px; }
.login-box h1 { font-size: 30px; }
.group { display: grid; gap: 8px; }
.code { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 10px; white-space: pre-wrap; word-break: break-all; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi:nth-child(4) { border-left: 0; }
  .kpi:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .duo, .conns { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(odd) { border-left: 0; }
  .kpi:nth-child(4) { border-left: 1px solid var(--line); }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--line); }
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; text-align: center; padding: 6px 4px; }
  .top-actions .status span:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
