:root {
  --bg: #f6f4f1; --surface: #ffffff; --surface2: #efece7; --text: #1f1b16; --muted: #6b645b;
  --line: #ddd8d0; --accent: #d9381e; --accent-text: #ffffff; --ok: #2f8f5b; --warn: #b7791f;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141210; --surface: #1d1a17; --surface2: #26221e; --text: #f1ede7; --muted: #a39b90; --line: #36312b; --accent: #ef5a3f; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- en-tête et onglets ---- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 1.1rem; margin: 0; }
.conn { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); margin-left: auto; order: 3; }
.conn i { width: .55rem; height: .55rem; border-radius: 50%; background: var(--warn); }
.conn.ok i { background: var(--ok); }
.tabs { display: flex; gap: .25rem; order: 2; }
.tabs button { border: 0; background: transparent; padding: .45rem .8rem; border-radius: 999px; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--accent); color: var(--accent-text); }
main { max-width: 980px; margin: 0 auto; padding: 1rem 1rem 2rem; }
@media (max-width: 720px) {
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; justify-content: space-around; padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
  .tabs button { flex: 1; border-radius: 10px; padding: .6rem .2rem; font-size: .85rem; }
  main { padding-bottom: 6rem; }
}

/* ---- composants ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.grow { flex: 1 1 10rem; }
.btn { border: 1px solid var(--line); background: var(--surface2); padding: .55rem .9rem; border-radius: 10px; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--accent); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .65rem; min-width: 0; }
input[type=color] { padding: .1rem; width: 2.6rem; height: 2.3rem; }
textarea { width: 100%; resize: vertical; }
label.f { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.dot { display: inline-block; width: .75rem; height: .75rem; border-radius: 50%; vertical-align: -1px; margin-right: .35rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); background: var(--surface2); border-radius: 999px; padding: .25rem .7rem; font-size: .9rem; }
button.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; }
.kpi b { display: block; font-size: 1.5rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .8rem; color: var(--muted); }
.list { display: grid; gap: .5rem; }
.item { display: flex; gap: .75rem; align-items: center; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .85rem; }
.item .grow { flex: 1; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---- onglet En direct ---- */
.banner { display: grid; gap: .5rem; }
.banner .stats { display: flex; flex-wrap: wrap; gap: 1.2rem; font-variant-numeric: tabular-nums; }
.banner .stats b { font-size: 1.3rem; }
.big { display: block; width: 100%; min-height: clamp(180px, 32vh, 420px); border: 0; border-radius: 28px; background: var(--accent); color: var(--accent-text); font-size: clamp(2rem, 8vw, 3.4rem); font-weight: 800; letter-spacing: .02em; box-shadow: var(--shadow); margin: 1rem 0; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.big small { display: block; font-size: 1.1rem; font-weight: 600; opacity: .9; }
.big.running { background: #8f1d0e; animation: pulse 1.6s ease-in-out infinite; }
@media (prefers-color-scheme: dark) { .big.running { background: #b3321d; } }
@keyframes pulse { 50% { filter: brightness(1.2); } }
@media (prefers-reduced-motion: reduce) { .big.running { animation: none; } }
.undo { display: flex; justify-content: center; margin: -.4rem 0 1rem; }
.endpanel { border-color: var(--accent); }
.hint { text-align: center; }

/* ---- séances ---- */
.timeline { position: relative; height: 30px; background: var(--surface2); border-radius: 8px; overflow: hidden; margin: .6rem 0 .3rem; }
.timeline i { position: absolute; top: 3px; bottom: 3px; min-width: 3px; border-radius: 5px; background: var(--accent); }
.timeline-scale { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); }

/* ---- stats ---- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1rem; }
.chart { position: relative; height: 280px; }
.chart.wide { grid-column: 1 / -1; }

/* ---- divers ---- */
.toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); max-width: calc(100% - 2rem); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 20; }
@media (min-width: 721px) { .toast { bottom: 1.5rem; } }
dialog { width: min(520px, calc(100% - 1.5rem)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.1rem; max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: grid; gap: .8rem; }
.login { max-width: 360px; margin: 18vh auto 0; }
.sr { position: absolute; left: -9999px; }
