:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --border: #e3e2de; --grid: #ecebe7;
  --text: #0b0b0b; --text-2: #52514e; --muted: #75746f;
  --accent: #2a78d6; --accent-ink: #fff;
  --in: #2a78d6; --out: #eb6834; --missed: #e34948; --we: #6250d6;
  --ok-bg: #e6f4ea; --ok-ink: #0d5a26; --ko-bg: #fdecea; --ko-ink: #a1221f; --na-bg: #efefec; --na-ink: #52514e;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --border: #2e2e2c; --grid: #262624;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f;
    --accent: #3987e5;
    --in: #3987e5; --out: #d95926; --missed: #e66767; --we: #9085e9;
    --ok-bg: #12321d; --ok-ink: #8fdba7; --ko-bg: #3d1716; --ko-ink: #f4a3a1; --na-bg: #262624; --na-ink: #c3c2b7;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1rem; margin: 0 0 .6rem; font-weight: 600; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
code { font: 600 1.05rem ui-monospace, monospace; background: var(--surface); padding: .1rem .4rem; border-radius: 4px; user-select: all; }

.topbar { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top, 0px)); background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.brand span { font-weight: 500; color: var(--text-2); margin-left: .4rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center; }
.topbar nav a { color: var(--text-2); text-decoration: none; padding: .2rem 0; border-bottom: 2px solid transparent; }
.topbar nav a.on { color: var(--text); border-color: var(--accent); }
.viewas { background: #fff4d6; color: #5a4300; padding: .5rem 1rem; text-align: center; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .viewas { background: #3a2f0d; color: #f3dc94; } }

main { max-width: 1280px; margin: 0 auto; padding: 1rem; }
main.center { min-height: 100vh; display: grid; place-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.login { width: min(380px, 100%); display: grid; gap: .8rem; }
.login h1 { margin: 0; }

label { display: grid; gap: .25rem; font-size: .85rem; color: var(--text-2); }
input, select, button, .button { font: inherit; font-size: .95rem; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; background: var(--surface); color: var(--text); }
input:focus, select:focus, button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .button { cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
button:hover, .button:hover { border-color: var(--text-2); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
button.link { border: 0; background: none; padding: 0; color: var(--text-2); }
form.inline { display: inline; }
label.check { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--text); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--ko-bg); color: var(--ko-ink); }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: .3rem; }
.filters input[type=search] { width: 10rem; }
.filters:not(.is-custom) .custom { display: none; }
.range { margin: .2rem 0 1rem; font-size: .85rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: grid; gap: .2rem; color: var(--text); text-decoration: none; }
a.kpi:hover { border-color: var(--accent); }
.kpi span { font-size: .8rem; color: var(--text-2); }
.kpi strong { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi strong small { display: block; font-size: .8rem; font-weight: 500; color: var(--text-2); }
.kpi.warn strong { color: var(--ko-ink); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 1rem; }
.wide { grid-column: 1 / -1; }
.chart { position: relative; height: 240px; }
.chart.tall { height: 300px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { font-size: .78rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .02em; }
.num { text-align: right; }
.compare td, .compare thead th { text-align: right; }
.compare .we { color: var(--we); }
.scroll { overflow-x: auto; }
.actions { white-space: nowrap; text-align: right; }
.actions .button, .actions button { padding: .3rem .6rem; font-size: .85rem; margin: .1rem 0; }

.bar { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
.bar h1, .bar h2 { margin: 0; }
.st { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; font-weight: 600; }
.st.ok { background: var(--ok-bg); color: var(--ok-ink); }
.st.ko { background: var(--ko-bg); color: var(--ko-ink); }
.st.na { background: var(--na-bg); color: var(--na-ink); }
.dir { white-space: nowrap; }
.dir.in { color: var(--in); } .dir.out { color: var(--out); }
.tag { font-size: .7rem; padding: 0 .3rem; border-radius: 4px; background: var(--na-bg); color: var(--na-ink); }
.tag.we { color: var(--we); }
.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; padding-top: 1rem; }

.form { display: grid; gap: .9rem; max-width: 720px; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .9rem; }
.inline-form { margin-top: 1rem; display: flex; flex-wrap: wrap; align-items: end; }
.password { font-size: 1rem; }

/* Mobile : tableaux en cartes */
@media (max-width: 720px) {
  main { padding: .7rem; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi strong { font-size: 1.3rem; }
  .filters > label { flex: 1 1 45%; }
  .filters input[type=search] { width: 100%; }
  .journal thead, .scroll > table > thead { display: none; }
  .journal tr, .scroll > table > tbody > tr { display: grid; grid-template-columns: 1fr 1fr; gap: .1rem .8rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
  .journal td, .scroll > table > tbody > tr > td { border: 0; padding: .1rem 0; text-align: left; }
  td[data-l]::before { content: attr(data-l); display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; }
  .actions { grid-column: 1 / -1; white-space: normal; text-align: left; }
}
h2.section { margin: 1.5rem 0 .6rem; }
tr.dim td { color: var(--muted); }
tr.dim td small { font-style: italic; }
.perf td:nth-child(2) { white-space: nowrap; }
.err-text { color: var(--ko-ink); }
.invite { border-color: var(--accent); margin-bottom: 1rem; display: grid; gap: .7rem; }
.copyline { display: flex; gap: .5rem; }
.copyline input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: .85rem; }
.actions-row { display: flex; flex-wrap: wrap; gap: .5rem; }
textarea { font: inherit; font-size: .9rem; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; background: var(--surface); color: var(--text); width: 100%; resize: vertical; }
.wide-form { max-width: 900px; margin: 1rem 0; }
button[disabled] { opacity: .5; cursor: not-allowed; }
