/* VoiceLab — a calibrated lab instrument.
   Cool paper, ink text, one accent: vocal-fold rose for live signal and primary actions. */
:root {
  --font: "IBM Plex Sans Arabic", "Segoe UI", system-ui, sans-serif;
  --paper: #F3F5F4;
  --surface: #FFFFFF;
  --ink: #1C2530;
  --graphite: #5D6A76;
  --line: #DCE2E0;
  --rose: #B83A62;
  --rose-ink: #FFFFFF;
  --rose-tint: #F8E7ED;
  --signal: #2C6AA8;
  --ok: #2F7A57;
  --ok-tint: #E2F0E8;
  --warn: #A86A12;
  --warn-tint: #FAEFD9;
  --danger: #B3261E;
  --grid: rgba(184, 58, 98, .09);
  --grid-major: rgba(184, 58, 98, .2);
  --envelope: rgba(28, 37, 48, .09);
  --shadow: 0 1px 2px rgba(28, 37, 48, .06), 0 8px 24px -12px rgba(28, 37, 48, .14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151B21; --surface: #1D252D; --ink: #E8EDF0; --graphite: #9AA7B2; --line: #2D3843;
    --rose: #E0688E; --rose-ink: #2A0A15; --rose-tint: #3A1E28; --signal: #72A8DF;
    --ok: #5CC08E; --ok-tint: #173226; --warn: #E2A33E; --warn-tint: #382B14; --danger: #F2827A;
    --grid: rgba(224, 104, 142, .09); --grid-major: rgba(224, 104, 142, .2); --envelope: rgba(232, 237, 240, .1);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  font: 400 16px/1.7 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { line-height: 1.3; margin: 0; font-weight: 600; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.1rem); }
/* Never letter-space Arabic: it breaks letter joining (and html2canvas exports). */
:lang(en) h1 { letter-spacing: -.005em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--rose); text-underline-offset: 3px; }
.small { font-size: .875rem; color: var(--graphite); }
.fine { font-size: .8rem; color: var(--graphite); }
.lede { color: var(--graphite); max-width: 62ch; }
.error { color: var(--danger); }
.ok-text { color: var(--ok); }
.caution-text { color: var(--warn); }
.grow { flex: 1; min-width: 0; }
[hidden] { display: none !important; }

/* ---- shell */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.55rem + env(safe-area-inset-top)) 16px .55rem;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: .6rem; align-items: center; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.topbar nav { display: flex; align-items: center; gap: .15rem; }
.topbar nav a, .lang {
  padding: .35rem .8rem; border-radius: 8px; color: var(--graphite); text-decoration: none; font: 500 .95rem var(--font);
  background: none; border: 0; cursor: pointer;
}
.topbar nav a[aria-current] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--rose); border-radius: 0; }
.lang { border: 1px solid var(--line); margin-inline-start: .4rem; }
.lang:hover, .topbar nav a:hover { color: var(--ink); }

main { width: 100%; max-width: 960px; margin: 0 auto; padding: 1.75rem 16px 3rem; flex: 1; outline: none; }
.disclaimer { text-align: center; font-size: .8rem; color: var(--graphite); padding: 1rem 16px calc(1rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

.page-head { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.5rem; }
.page-head > div { display: grid; gap: .35rem; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.meta { display: flex; flex-wrap: wrap; gap: .25rem .9rem; color: var(--graphite); font-size: .92rem; }
.back { display: inline-flex; align-items: center; gap: .5rem; margin-bottom: .75rem; text-decoration: none; font-weight: 500; color: var(--graphite); }
.back:hover { color: var(--ink); }
.back-arrow { width: .5rem; height: .5rem; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
[dir="rtl"] .back-arrow { transform: rotate(-135deg); }
[dir="ltr"] .back-arrow { transform: rotate(45deg); }

/* ---- buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px;
  padding: .5rem 1.1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 600 .95rem var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--graphite); }
.btn.primary { background: var(--rose); border-color: var(--rose); color: var(--rose-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: none; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: .3rem .8rem; font-size: .88rem; }
.btn.big { min-height: 52px; padding-inline: 1.6rem; font-size: 1.05rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--rose) 50%, transparent); outline-offset: 2px; }
.rec-dot { width: .6rem; height: .6rem; border-radius: 50%; background: currentColor; flex-shrink: 0; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .8rem; width: 100%; min-height: 46px;
}
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--graphite) 55%, var(--line)); }
textarea { line-height: 1.8; }
.form { display: grid; gap: 1rem; }
.form h2 { margin-top: .75rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.form h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
label { display: grid; gap: .35rem; font-weight: 500; font-size: .95rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > label { flex: 1 1 220px; min-width: 0; }
.row.inline { align-items: center; flex-wrap: nowrap; }
.row.inline input { max-width: 10rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .25rem; }
.search { margin-bottom: 1rem; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--paper); width: max-content; }
.segmented label { display: block; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: block; padding: .4rem 1.1rem; border-radius: 7px; cursor: pointer; font-weight: 500; }
.segmented input:checked + span { background: var(--surface); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--rose) 50%, transparent); }

/* ---- surfaces: panels hold measurements, sheets hold forms */
.panel, .sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem; margin-bottom: 1.25rem; display: grid; gap: .75rem; align-content: start; grid-template-columns: minmax(0, 1fr); }
.block { margin-top: 2rem; display: grid; gap: .9rem; }
.note { border-inline-start: 3px solid var(--signal); padding: .25rem 1rem; margin-bottom: 1.75rem; display: grid; gap: .25rem; color: var(--graphite); }
.note strong { color: var(--ink); }
.caution { background: var(--warn-tint); color: var(--ink); border-radius: 10px; padding: .6rem .9rem; font-size: .92rem; }
.caution-block { background: var(--warn-tint); border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: 1.25rem; }
.caution-block ul { margin: .4rem 0 0; padding-inline-start: 1.2rem; }

/* ---- register (patient + evaluation lists) */
.register { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.register li { border-bottom: 1px solid var(--line); }
.register a { display: flex; align-items: center; gap: .75rem 1.25rem; padding: .95rem .25rem; color: inherit; text-decoration: none; flex-wrap: wrap; }
.register a:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.register .who { display: grid; gap: .1rem; flex: 1 1 14rem; min-width: 0; }
.register .who strong { font-size: 1.05rem; font-weight: 600; }
.register .last { color: var(--graphite); font-size: .88rem; }
.readings { display: flex; gap: 1.1rem; flex-wrap: wrap; }
.reading { display: grid; text-align: center; font-weight: 600; font-size: 1.15rem; line-height: 1.2; min-width: 3.2rem; }
.reading small { font-size: .7rem; font-weight: 500; color: var(--graphite); }
.reading.ok { color: var(--ok); }
.reading.warn { color: var(--warn); }
.empty { padding: 3.5rem 1rem; text-align: center; display: grid; gap: .75rem; justify-items: center; border: 1px dashed var(--line); border-radius: 14px; }
.empty p { color: var(--graphite); max-width: 34rem; }

/* ---- recording protocol */
.protocol { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: 1.25rem; }
.step {
  counter-increment: step; position: relative; display: grid; gap: .7rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.25rem; padding-inline-start: 4.5rem;
}
.step::before {
  content: counter(step); position: absolute; inset-inline-start: 1.25rem; top: 1.15rem;
  width: 2.25rem; height: 2.25rem; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--rose); color: var(--rose); font-weight: 700;
}
.opt { font-size: .8rem; font-weight: 500; color: var(--graphite); border: 1px solid var(--line); border-radius: 6px; padding: .05rem .45rem; margin-inline-start: .35rem; vertical-align: middle; }
.passage { margin: .25rem 0; padding: 1rem 1.25rem; border-inline-start: 3px solid var(--rose); background: var(--rose-tint); border-start-end-radius: 12px; border-end-end-radius: 12px; font-size: 1.15rem; line-height: 2; }
.trials { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: .9rem; }
.trial { border: 1px solid var(--line); border-radius: 12px; padding: .8rem; display: grid; gap: .45rem; align-content: start; min-width: 0; }

/* the signature: strip-chart recorder */
.recorder { display: grid; gap: .6rem; }
.strip { position: relative; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; transition: border-color .2s; }
.strip canvas { display: block; width: 100%; height: 132px; }
.recorder.compact .strip canvas { height: 76px; }
.readouts { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .75rem; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 55%, var(--surface)); }
.ro { display: inline-flex; align-items: baseline; gap: .25rem; }
.ro b { font-size: 1.25rem; font-weight: 600; min-width: 2.6ch; text-align: end; }
.recorder.compact .ro b { font-size: 1.05rem; }
.ro i { font-style: normal; font-size: .75rem; color: var(--graphite); }
.recorder.live .strip { border-color: var(--rose); }
.recorder.live .rec-dot { animation: blink 1s steps(2, start) infinite; }
.recorder.voicing .time { color: var(--rose); }
.recorder.clipping .strip { border-color: var(--danger); }
.recorder .actions audio { flex: 1 1 200px; height: 40px; min-width: 0; }
.status:empty { display: none; }
@keyframes blink { to { visibility: hidden; } }

.submit-bar { margin-top: 1.75rem; display: grid; gap: .8rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress div { height: 100%; width: 35%; background: var(--rose); animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
[dir="rtl"] .progress div { animation-name: slide-rtl; }
[dir="ltr"] .progress div { animation-name: slide; }
@keyframes slide-rtl { from { transform: translateX(100%); } to { transform: translateX(-300%); } }

/* ---- results: score instruments with measuring rulers */
.instruments { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.instrument { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem 1.25rem 1rem; display: grid; gap: .4rem; box-shadow: var(--shadow); }
.instrument header { display: grid; gap: .1rem; }
.instrument h2 { font-size: 1.3rem; justify-self: start; }
.dial { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
.dial .value { font-size: clamp(2.8rem, 2rem + 3vw, 3.8rem); font-weight: 600; line-height: 1.05; letter-spacing: -.02em; }
.dial i { font-style: normal; color: var(--graphite); font-size: 1.1rem; }
.verdict { font-weight: 600; }
.ok .dial .value, .ok .verdict { color: var(--ok); }
.warn .dial .value, .warn .verdict { color: var(--warn); }
.ruler { width: 100%; height: auto; overflow: visible; }
.ruler .base { stroke: var(--ink); stroke-width: 1.5; }
.ruler .tick { stroke: var(--graphite); stroke-width: 1; }
.ruler .tick.major { stroke: var(--ink); stroke-width: 1.5; }
.ruler .tick-label { fill: var(--graphite); font: 500 9px var(--font); text-anchor: middle; }
.ruler .zone { fill: var(--warn-tint); }
.ruler .cut { stroke: var(--warn); stroke-width: 2; stroke-dasharray: 3 2; }
.ruler .pointer { fill: var(--ink); }

.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 1rem 1.25rem; margin: .25rem 0; }
.figures.tight { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.fig { display: grid; gap: .05rem; align-content: start; padding-inline-start: .75rem; border-inline-start: 2px solid var(--line); }
.fig dt { font-size: .82rem; color: var(--graphite); }
.fig dd { margin: 0; }
.fig dd b { font-size: 1.45rem; font-weight: 600; }
.fig dd i { font-style: normal; font-size: .8rem; color: var(--graphite); }
.fig dd.ref { font-size: .78rem; color: var(--graphite); }
.fig.ok { border-color: var(--ok); }
.fig.ok b { color: var(--ok); }
.fig.warn { border-color: var(--warn); }
.fig.warn b { color: var(--warn); }
.chart-box { position: relative; height: 260px; }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.pair .panel { margin: 0; }
.instrument-lite.ok .dial .value { color: var(--ok); }
.instrument-lite.warn .dial .value { color: var(--warn); }
.abbr { font-size: .85rem; font-weight: 500; color: var(--graphite); }

details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .6rem; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: ""; width: .45rem; height: .45rem; border-right: 2px solid var(--graphite); border-bottom: 2px solid var(--graphite); transform: rotate(45deg); margin-top: -.2rem; transition: transform .15s; }
details[open] > summary::after { transform: rotate(-135deg); margin-top: .2rem; }
details > summary h2 { display: inline; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 1rem 2rem; margin-top: .75rem; }
.features { width: 100%; border-collapse: collapse; }
.features caption { text-align: start; font-weight: 600; padding-bottom: .35rem; }
.features th { text-align: start; font-weight: 400; color: var(--graphite); }
.features td { text-align: end; font-weight: 600; }
.features td.unit { font-weight: 400; color: var(--graphite); width: 3rem; }
.features th, .features td { padding: .35rem .25rem; border-top: 1px solid var(--line); }

.audio-row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; padding: .35rem 0; }
.audio-row span { min-width: 9rem; font-weight: 500; }
.audio-row audio { flex: 1; min-width: 200px; height: 40px; }

/* ---- settings: calibration */
.cal-state { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; padding: .6rem .9rem; border-radius: 10px; }
.cal-state.ok { background: var(--ok-tint); }
.cal-state.ok strong { color: var(--ok); }
.cal-state.warn { background: var(--warn-tint); }
.cal-state.warn strong { color: var(--warn); }
.cal-steps { margin: 0; padding-inline-start: 1.3rem; display: grid; gap: .35rem; }
.subpanel { border-top: 1px solid var(--line); padding-top: .9rem; display: grid; gap: .5rem; }
.subpanel ul { margin: .3rem 0 0; padding-inline-start: 1.2rem; display: grid; gap: .25rem; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(1.25rem + env(safe-area-inset-bottom)); margin: 0 auto; width: max-content; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper); padding: .7rem 1.1rem; border-radius: 10px; font-weight: 500;
  transform: translateY(200%); transition: transform .25s; z-index: 50;
}
#toast.show { transform: none; }

@media (max-width: 560px) {
  main { padding-top: 1.25rem; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  .step { padding: 1rem; padding-top: 3.6rem; }
  .step::before { top: 1rem; }
  .topbar nav a, .lang { padding-inline: .55rem; }
  .brand span { display: none; }
  .fig dd b { font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- off-screen report used for PNG/PDF export (always light) */
.report {
  position: fixed; left: -10000px; top: 0; width: 794px; padding: 40px 44px; background: #fff; color: #1C2530;
  font: 400 12.5px/1.6 var(--font);
}
.report, .report * { letter-spacing: 0 !important; }
.report header { display: flex; justify-content: space-between; align-items: flex-end; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 2px solid #B83A62; }
.report h1 { font-size: 21px; font-weight: 700; }
.report h2 { font-size: 14px; margin: 18px 0 6px; font-weight: 600; }
.report .r-sub, .report .r-end { color: #5D6A76; }
.report .r-end { text-align: end; }
.r-info { width: 100%; border-collapse: collapse; }
.r-info th { text-align: start; color: #5D6A76; font-weight: 400; width: 17%; }
.r-info th, .r-info td { padding: 4px 6px; border-bottom: 1px solid #E3E8E6; }
.r-scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.r-score { border: 1px solid #DCE2E0; border-radius: 8px; padding: 8px 10px; display: grid; gap: 1px; }
.r-score span { color: #5D6A76; font-size: 11px; }
.r-score strong { font-size: 22px; font-weight: 600; }
.r-score em { font-style: normal; color: #5D6A76; font-size: 10.5px; }
.r-score.warn strong { color: #A86A12; }
.r-score.ok strong { color: #2F7A57; }
.r-chart { width: 100%; border: 1px solid #DCE2E0; border-radius: 8px; }
.r-small { color: #5D6A76; font-size: 10.5px; margin-top: 6px; }
.r-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-top: 6px; }
.r-feat { width: 100%; border-collapse: collapse; font-size: 11px; }
.r-feat caption { text-align: start; font-weight: 600; padding: 4px 0; }
.r-feat td { padding: 2px 4px; border-bottom: 1px solid #E3E8E6; }
.r-feat td:nth-child(2) { text-align: end; font-weight: 600; }
.report ul { margin: 4px 0; padding-inline-start: 18px; }
.report footer { margin-top: 18px; padding-top: 8px; border-top: 1px solid #DCE2E0; color: #5D6A76; font-size: 10px; }

/* ---- sign-in screens */
.gate { max-width: 26rem; margin: 2rem auto 0; display: grid; gap: 1rem; }
.gate-mark img { display: block; border-radius: 16px; }
.gate .form { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem; margin-top: .5rem; }
.code-input { font-size: 1.6rem; font-weight: 600; text-align: center; letter-spacing: .12em; text-transform: uppercase; }

/* ---- badges and patient access */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .5rem; border-radius: 6px; background: var(--rose); color: var(--rose-ink); vertical-align: middle; margin-inline-start: .35rem; }
.badge.quiet { background: var(--rose-tint); color: var(--rose); }
.access-state { display: flex; flex-wrap: wrap; gap: .2rem 1rem; align-items: baseline; }
.access.active .access-state strong { color: var(--ok); }
.access.off .access-state strong, .access.locked .access-state strong { color: var(--warn); }
.access-state span { color: var(--graphite); font-size: .9rem; }
.handover { border: 2px solid var(--rose); border-radius: 12px; padding: 1rem; display: grid; gap: .75rem; background: var(--rose-tint); }
.handover dl { margin: 0; display: grid; gap: .6rem; }
.handover dt { font-size: .85rem; color: var(--graphite); }
.handover dd { margin: 0; }
.mono-wrap { overflow-wrap: anywhere; font-size: .9rem; }
.code-show { font-size: 1.9rem; font-weight: 700; color: var(--ink); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.check input { width: 1.1rem; height: 1.1rem; min-height: 0; }
.import { border-color: var(--signal); }
.link-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem; }

/* ---- roles: patient home, provider filter, team */
.patient-hero { display: grid; gap: .9rem; justify-items: start; padding: 1.75rem 1.5rem; margin-bottom: 1.5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; border-inline-start: 4px solid var(--rose); }
.patient-hero h1 { font-size: clamp(1.7rem, 1.3rem + 2vw, 2.3rem); }
.patient-hero .btn.big { min-height: 60px; padding-inline: 2rem; font-size: 1.15rem; }
.filter { display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem; font-weight: 500; }
.filter select { width: auto; min-width: 12rem; }
.link-box { display: grid; gap: .6rem; padding: .9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.team-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .85rem .25rem; }
.team-row .actions { margin: 0; }
.team-row.inactive .who { opacity: .55; }
.row.inline > label { flex: 1 1 16rem; }
.row.inline { align-items: flex-end; gap: .75rem; }

/* ---- GRBAS grading */
.grade-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; align-items: start; }
.grade-layout .panel { margin: 0; }
.grbas.pending { border-color: var(--rose); box-shadow: var(--shadow); }
.grbas.graded { border-color: var(--ok); }
.grbas-form { display: grid; gap: .6rem; }
.grbas-row { min-width: 0; border: 0; margin: 0; padding: .55rem 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; align-items: center; }
.grbas-row legend { float: inline-start; padding: 0; font-weight: 600; }
.grbas-row legend b { color: var(--rose); margin-inline-end: .3rem; }
.grbas-row .est { grid-column: 1; }
.grbas-row .grades { grid-column: 2; grid-row: 1 / span 2; display: inline-flex; gap: .3rem; }
.grades label { display: block; }
.grades input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.grades span { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 10px; border: 1px solid var(--line); font-weight: 700; cursor: pointer; background: var(--surface); }
.grades input:checked + span { background: var(--rose); border-color: var(--rose); color: var(--rose-ink); }
.grades input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--rose) 50%, transparent); }
.scale-key { display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.grbas-chip { font-size: 1.05rem; white-space: nowrap; }
.grbas-chip.graded { color: var(--ok); }
.grbas-chip.estimate { color: var(--graphite); }
.instruments.compact { margin-top: .75rem; }
.waiting.failed { border-color: var(--warn); }
.recordings .audio-row span { min-width: 7rem; }

/* ---- patient: sent */
.sent-list li { display: flex; justify-content: space-between; align-items: center; padding: .8rem .25rem; }
.sent-mark { color: var(--ok); font-weight: 600; }
.patient-hero.sent { justify-items: center; text-align: center; border-inline-start-width: 1px; }
.tick { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-tint); position: relative; }
.tick::after { content: ""; position: absolute; left: 22px; top: 14px; width: 16px; height: 28px; border-right: 5px solid var(--ok); border-bottom: 5px solid var(--ok); transform: rotate(45deg); }

/* ---- legal pages, consent, audit log, two-step sign-in */
.legal { max-width: 46rem; display: grid; gap: .9rem; }
.legal h2 { font-size: 1.05rem; margin-top: .6rem; }
.legal ul { margin: 0; padding-inline-start: 1.3rem; display: grid; gap: .35rem; }
.legal .draft { background: var(--warn-tint); border-radius: 8px; padding: .5rem .8rem; font-size: .9rem; }
.legal-box { max-height: 22rem; overflow: auto; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; background: var(--surface); display: grid; gap: .6rem; }
.consent ul { font-size: 1.02rem; }
.footer-links { display: inline-flex; gap: 1rem; margin-inline-start: 1rem; }
.footer-links a { color: var(--graphite); }
.badge.ok { background: var(--ok-tint); color: var(--ok); }
.badge.warn { background: var(--warn-tint); color: var(--warn); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table.audit { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.audit th { text-align: start; font-weight: 600; color: var(--graphite); background: var(--paper); position: sticky; top: 0; }
table.audit th, table.audit td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.audit tr.flag td:nth-child(3) { color: var(--warn); font-weight: 600; }
table.audit td:first-child { white-space: nowrap; }
.totp-pair { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.totp-qr { background: #fff; padding: 10px; border-radius: 10px; width: max-content; }
.totp-qr img, .totp-qr canvas { display: block; }
.totp-key { font-size: 1rem; letter-spacing: .04em; overflow-wrap: anywhere; }
.panel.requests { border-color: var(--rose); box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.panel.requests .register { margin: .5rem 0 0; }

/* ---- small screens: kept last so these rules win over the ones above */
/* Phones and small tablets: the page links move to a tab bar at the bottom (thumb reach);
   the top bar keeps only the logo, sign out and the language switch, on one line. */
@media (max-width: 760px) {
  .topbar { gap: .5rem; }
  /* backdrop-filter would make the fixed tab bar position itself inside the top bar */
  body.has-tabs .topbar { backdrop-filter: none; background: var(--paper); }
  .topbar nav { gap: .25rem; }
  body.has-tabs #nav-links {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
    display: flex; background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.has-tabs #nav-links a {
    flex: 1 1 0; min-width: 0; min-height: 54px; padding: .4rem .2rem; border-radius: 0;
    display: flex; align-items: center; justify-content: center; gap: .2rem;
    text-align: center; line-height: 1.25; font-size: .88rem;
  }
  body.has-tabs #nav-links a[aria-current] { box-shadow: inset 0 2px 0 var(--rose); color: var(--rose); }
  body.has-tabs #nav-links .badge { margin: 0; }
  body.has-tabs main { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  body.has-tabs .disclaimer { padding-bottom: calc(4.75rem + env(safe-area-inset-bottom)); }
  body.has-tabs #toast { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 560px) {
  .page-head { gap: .75rem; }
  .audio-row span, .recordings .audio-row span { min-width: 0; flex-basis: 100%; }
  .audio-row audio { min-width: 0; }
  .filter { flex-wrap: wrap; }
  .filter select { width: 100%; min-width: 0; }
}
@media (max-width: 860px) {
  /* Activity log: one card per entry instead of a wide table. */
  .table-wrap { overflow: visible; border: 0; background: none; }
  .table-wrap table.audit, .table-wrap table.audit tbody { display: block; }
  .table-wrap table.audit thead { display: none; }
  .table-wrap table.audit tr {
    display: grid; grid-template-columns: 1fr auto; gap: .15rem .75rem; margin-bottom: .5rem;
    padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  }
  .table-wrap table.audit td { padding: 0; border: 0; min-width: 0; overflow-wrap: anywhere; }
  .table-wrap table.audit td:empty { display: none; }
  .table-wrap table.audit .c-what { grid-column: 1; grid-row: 1; font-weight: 600; }
  .table-wrap table.audit .c-when { grid-column: 2; grid-row: 1; font-size: .8rem; color: var(--graphite); }
  .table-wrap table.audit .c-who, .table-wrap table.audit .c-patient, .table-wrap table.audit .c-detail { grid-column: 1 / -1; }
}
@media (max-width: 380px) {
  .grades span { width: 2.35rem; height: 2.35rem; }
  .grbas-row .grades { gap: .2rem; }
  .panel, .sheet { padding: 1rem; }
}
