:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e1e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-i: #2a78d6;
  --series-h: #eb6834;
  --series-o: #1baf7a;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2c2c2a;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --accent: #3987e5;
    --series-i: #3987e5;
    --series-h: #d95926;
    --series-o: #199e70;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2c2c2a;
  --text: #ffffff; --text-2: #c3c2b7; --accent: #3987e5;
  --series-i: #3987e5; --series-h: #d95926; --series-o: #199e70; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
.muted { color: var(--text-2); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: .6rem 1rem; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--critical); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .75rem; min-height: 44px; width: 100%;
}
label.field { display: block; margin-bottom: .9rem; }
label.field > span { display: block; font-size: .875rem; color: var(--text-2); margin-bottom: .25rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }

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

/* ---------- Patient (mobile d'abord) ---------- */
.patient { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.patient header { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.patient .brand { font-weight: 700; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: .25rem 0 1.25rem; }
.progress > div { height: 100%; background: var(--accent); transition: width .25s; }
.q-meta { font-size: .85rem; color: var(--text-2); margin-bottom: .5rem; }
.q-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 1.25rem; }
.choices { display: grid; gap: .6rem; }
.choice { justify-content: flex-start; text-align: left; min-height: 56px; padding: .8rem 1rem; font-size: 1.05rem; border-width: 2px; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-weight: 600; }
.patient .nav { margin-top: auto; padding-top: 1.25rem; display: flex; justify-content: space-between; gap: .75rem; }
.notice { background: var(--surface-2); border-radius: 10px; padding: .8rem 1rem; font-size: .9rem; color: var(--text-2); }
.check { display: flex; gap: .6rem; align-items: flex-start; margin: 1rem 0; }
.check input { width: 22px; height: 22px; min-height: 0; margin-top: 2px; flex: none; }
.qr-box { display: flex; justify-content: center; background: #fff; border-radius: 12px; padding: 12px; margin: 1rem auto; max-width: 340px; }
.qr-box svg, .qr-box img { width: 100%; height: auto; display: block; }
.code-text { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-all; background: var(--surface-2); padding: .6rem; border-radius: 8px; user-select: all; }

/* ---------- Praticien ---------- */
.shell { max-width: 1200px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; margin-right: auto; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 1.25rem; }
.tabs button { border: 0; background: transparent; min-height: 40px; }
.tabs button[aria-selected="true"] { background: var(--surface-2); font-weight: 600; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.tiles { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.tile .k { font-size: .8rem; color: var(--text-2); }
.tile .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .s { font-size: .8rem; color: var(--muted); }
.chart-box { position: relative; width: 100%; }
.chart-title { font-weight: 600; margin-bottom: .1rem; }
.chart-sub { font-size: .8rem; color: var(--text-2); margin-bottom: .75rem; }

table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { font-size: .78rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.num { font-variant-numeric: tabular-nums; text-align: right !important; }

.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.faible::before { background: var(--good); }
.badge.moderee::before { background: var(--warning); }
.badge.elevee::before { background: var(--critical); }
.level-banner { display: flex; gap: 1rem; align-items: center; padding: 1rem 1.25rem; border-radius: var(--radius); border: 1px solid var(--border); border-left-width: 6px; background: var(--surface); }
.level-banner.faible { border-left-color: var(--good); }
.level-banner.moderee { border-left-color: var(--warning); }
.level-banner.elevee { border-left-color: var(--critical); }
.level-banner .big { font-size: 1.4rem; font-weight: 700; }

.analysis h3 { margin-top: 1.25rem; }
.analysis ul { margin: .25rem 0 .8rem; padding-left: 1.2rem; }
.analysis li { margin-bottom: .3rem; }

#reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: 12px; overflow: hidden; }
.lock { max-width: 420px; margin: 10vh auto 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
#pdf-stage { position: fixed; left: -10000px; top: 0; width: 1000px; }

@media (max-width: 600px) {
  .card { padding: 1rem; }
  .hide-sm { display: none; }
}
@media print { .tabs, .topbar button { display: none; } }

/* ---------- Application mobile (PWA) ---------- */
.tabs button { gap: .45rem; }
.tabs .ti { width: 18px; height: 18px; flex: none; }
.tabs .sm { display: none; }
.shell { padding-top: max(16px, env(safe-area-inset-top)); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }

@media (max-width: 700px) {
  .shell { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
    border-radius: 0; border-width: 1px 0 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  }
  .tabs button { flex-direction: column; gap: 2px; min-height: 56px; padding: 6px 2px; font-size: .72rem; color: var(--text-2); border-radius: 10px; }
  .tabs button[aria-selected="true"] { background: transparent; color: var(--accent); }
  .tabs .ti { width: 24px; height: 24px; }
  .tabs .lg { display: none; }
  .tabs .sm { display: block; }
  .topbar { margin-bottom: .75rem; }
  .topbar .brand { font-size: 1rem; }
  .topbar button { min-height: 38px; padding: .35rem .75rem; font-size: .9rem; }
  .tile .v { font-size: 1.35rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .tile { padding: .8rem; }
  h1 { font-size: 1.35rem; }
  #view .row > button { flex: 1 1 auto; }
}

.qr-full {
  position: fixed; inset: 0; z-index: 100; background: #ffffff;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.qr-full-inner { width: 100%; max-width: 480px; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.qr-full-code { width: min(100%, 62vh); }
.qr-full-code svg { width: 100%; height: auto; display: block; }

.sm-only { display: none; }
@media (max-width: 600px) { .sm-only { display: inline; } }

.code-pass { font-family: ui-monospace, Consolas, monospace; font-size: 1.1rem; letter-spacing: .12em; background: var(--surface-2); padding: .05rem .4rem; border-radius: 6px; }
.card.send { border-left: 6px solid var(--accent); }

.toast { pointer-events: none; }
@media (max-width: 700px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }
