:root {
  --bg: #f6f7f5; --card: #ffffff; --ink: #1d2422; --muted: #5d6965; --line: #dfe4e1;
  --accent: #1f6f5c; --accent-ink: #ffffff; --accent-soft: #e3f1ec; --warn: #a3410f; --warn-soft: #fbeadf;
  --danger: #a1192c; --danger-soft: #fbe4e7; --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121614; --card: #1b201e; --ink: #e8ecea; --muted: #a2ada9; --line: #2d3532;
          --accent: #5cc0a3; --accent-ink: #0d1512; --accent-soft: #1f322b; --warn: #f0a172; --warn-soft: #3a261b;
          --danger: #f08a98; --danger-soft: #3a1c21; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.45; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .9em; }
.banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: .85em; padding: 6px 12px; }

/* ---------------- patient ---------------- */
.p-wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 48px; }
.p-head { display: flex; align-items: center; gap: 12px; margin: 8px 0 16px; }
.p-head h1 { font-size: 1.1em; margin: 0; }
.presenter { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
             display: grid; place-items: center; font-weight: 700; flex: none; position: relative; overflow: hidden; }
.presenter video { width: 100%; height: 100%; object-fit: cover; }
.presenter.speaking::after { content: ""; position: absolute; inset: -3px; border-radius: 50%;
                             border: 3px solid var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .2; } }
.toggle { margin-left: auto; font-size: .85em; display: flex; gap: 6px; align-items: center; color: var(--muted); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.q-text { font-size: 1.25em; font-weight: 600; margin: 0 0 16px; }
.choices { display: grid; gap: 10px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 14px 12px; min-height: 52px;
       cursor: pointer; text-align: center; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.quiet { background: transparent; color: var(--muted); }
.btn.small { min-height: 0; padding: 8px 12px; font-size: .9em; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.words { display: flex; gap: 8px; margin-top: 14px; }
.words input, textarea, .num-input { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--card); width: 100%; }
textarea { min-height: 96px; resize: vertical; }
.mic { flex: none; width: 52px; }
.mic.on { background: var(--danger-soft); border-color: var(--danger); }
.divider { text-align: center; color: var(--muted); font-size: .85em; margin: 14px 0 0; }
.confirm-quote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); margin: 0 0 12px; }
.confirm-reading { font-size: 1.2em; font-weight: 600; margin-bottom: 16px; }
.notice { background: var(--danger-soft); color: var(--ink); border-color: var(--danger); }
.err { color: var(--danger); font-size: .9em; min-height: 1.2em; margin-top: 8px; }

/* ---------------- clinician ---------------- */
.c-wrap { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.c-side { border-right: 1px solid var(--line); padding: 16px; background: var(--card); }
.c-main { padding: 20px 24px 60px; max-width: 1100px; }
.c-side h1 { font-size: 1.05em; margin: 0 0 12px; }
.c-list { list-style: none; padding: 0; margin: 12px 0; }
.c-list li { padding: 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; font-size: .92em; }
.c-list li:hover { background: var(--accent-soft); }
.c-list li.sel { border-color: var(--accent); }
.pill { display: inline-block; font-size: .75em; padding: 1px 8px; border-radius: 99px; background: var(--line); margin-right: 4px; }
.pill.flag { background: var(--danger-soft); color: var(--danger); }
.pill.wait { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
h2 { font-size: 1.15em; margin: 26px 0 10px; }
table { border-collapse: collapse; width: 100%; font-size: .9em; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.c-main .btn { min-height: 0; padding: 6px 12px; font-size: .88em; }
pre.note { white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: .85em; }
.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--card); }
.rank-list li .name { flex: 1; }
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: .9em; }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--card); }
details summary { cursor: pointer; color: var(--muted); }
.why { font-size: .8em; color: var(--muted); }
@media (max-width: 800px) { .c-wrap { grid-template-columns: 1fr; } .c-side { border-right: 0; border-bottom: 1px solid var(--line); } .grid2 { grid-template-columns: 1fr; } }
.mt8 { margin-top: 8px; }
.row input, .row select { min-width: 0; }
select { max-width: 100%; }
.c-main a { word-break: break-all; }
#v-video { width: 100%; border-radius: 12px; margin: 10px 0; transform: scaleX(-1); }

/* ---------------- patient, v2: Dr. Thomas stage, mode switch, sections ---------------- */
body.patient { font-size: 18px; }
.stage { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line);
         border-radius: var(--radius); padding: 12px; margin: 6px 0 12px; }
.stage-face { position: relative; width: 76px; height: 76px; flex: none; border-radius: 50%; overflow: hidden;
              background: var(--accent-soft); display: grid; place-items: center; }
.stage-initials { font-weight: 700; font-size: 1.3em; color: var(--accent); letter-spacing: .04em; }
.stage-video { position: absolute; inset: 0; background: #000; }
.stage-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage.video-on { flex-direction: column; align-items: stretch; }
.stage.video-on .stage-face { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 12px; }
.stage-wave { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); display: none; gap: 3px; align-items: flex-end; height: 16px; }
.stage-wave i { width: 4px; background: var(--accent); border-radius: 2px; height: 30%; animation: wave .9s ease-in-out infinite; }
.stage-wave i:nth-child(2) { animation-delay: .15s; } .stage-wave i:nth-child(3) { animation-delay: .3s; }
.stage-wave i:nth-child(4) { animation-delay: .45s; } .stage-wave i:nth-child(5) { animation-delay: .6s; }
@keyframes wave { 50% { height: 100%; } }
.stage.speaking .stage-wave { display: flex; }
.stage.speaking .stage-face { box-shadow: 0 0 0 3px var(--accent); }
.stage.video-on.speaking .stage-wave { display: none; }
.stage-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.stage-name { font-weight: 700; }
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; align-self: flex-start; margin-top: 2px; }
.mode button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; font-size: .85em; cursor: pointer; color: var(--muted); }
.mode button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; font-size: .88em; align-self: flex-start; text-decoration: underline; text-underline-offset: 3px; }
.mode-note { margin: -4px 0 10px; }
.where { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 0 2px 6px; font-size: .85em; }
.section-name { font-weight: 600; color: var(--accent); }
.lead { font-size: 1.1em; margin-top: 0; }
.ticks { padding-left: 1.1em; margin: 0 0 16px; }
.ticks li { margin-bottom: 4px; }
.btn.wide { width: 100%; }
.q-card .q-text { font-size: 1.3em; line-height: 1.35; }
.choices.scale { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.choices.scale .btn { padding: 14px 4px; font-size: .92em; }
@media (max-width: 380px) { .choices.scale { grid-template-columns: 1fr 1fr; } }
.quiet-row { margin-top: 10px; }
.own-words { margin-top: 12px; }
.own-words summary { color: var(--accent); font-size: .9em; padding: 6px 0; list-style-position: inside; }
.own-words .words { margin-top: 8px; }
.q-foot { display: flex; justify-content: flex-start; margin-top: 4px; }
.changing { margin: 0 0 6px; color: var(--warn); }
.saved { text-align: center; margin-top: 18px; font-size: .8em; }
.quiet-row { justify-content: center; gap: 18px; }
.quiet-row > * { flex: 0 0 auto; }
.quiet-row .btn.quiet { border: 0; min-height: 40px; padding: 8px 14px; text-decoration: underline; text-underline-offset: 3px; font-size: .92em; }
@media (max-width: 430px) { .choices.scale { grid-template-columns: 1fr 1fr; } }
.stage:not(.voice):not(.video-on) .stage-face { width: 52px; height: 52px; }
.stage:not(.voice):not(.video-on) .stage-initials { font-size: 1em; }
#contact-a { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--card); margin: 8px 0; }
#contact-scale { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* avatar side-by-side test page (clinician only) */
.at-wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.at-script li { display: flex; gap: 12px; align-items: flex-start; margin: 10px 0; }
.at-log { width: 100%; border-collapse: collapse; font-size: 0.9em; }
.ac-lag { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; margin: 12px 0; }
.ac-lag > div:not(.muted) { display: flex; flex-direction: column; }
.ac-lag strong { font-size: 1.6em; }
.ac-lag #lag-parts { flex-basis: 100%; }
.ac-controls { flex-wrap: wrap; gap: 8px; align-items: center; }
.ac-presets, .ac-typed { flex-wrap: wrap; }
.ac-presets > * { flex: 0 0 auto; }
.ac-typed input { flex-basis: 100%; }
.ac-talk { padding-left: 1.2em; }
.ac-talk li { margin: 4px 0; }
.ac-talk li.you { color: #555; }
.ac-scroll { overflow-x: auto; }
.at-log th, .at-log td { border-bottom: 1px solid #ddd; padding: 4px 6px; text-align: left; }

/* between-visit messages (D-022): patient chat and Dr. Thomas's inbox */
.chat-body { display: flex; flex-direction: column; min-height: 100vh; }
.chat-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
             background: var(--card); border-bottom: 1px solid var(--line); }
.chat-face { width: 48px; height: 48px; flex: none; border-radius: 50%; overflow: hidden; background: var(--accent-soft);
             display: grid; place-items: center; position: relative; }
.chat-face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chat-who { flex: 1; min-width: 0; }
.chat-label { font-size: .75em; line-height: 1.3; }
.chat-voice { font-size: .8em; color: var(--muted); display: flex; gap: 6px; align-items: center; flex: none; }
.chat-wrap { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 12px 16px 8px; }
.chat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.msg.me .msg-who, .msg.me .play { color: var(--accent-ink); opacity: .85; }
.msg.them { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { border-bottom-right-radius: 4px; }
.msg.clinician { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.msg.safety { background: var(--danger-soft); border-color: var(--danger); }
.msg-who { font-size: .72em; margin-bottom: 3px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.msg-actions.col { flex-direction: column; }
.play { font-size: .8em; margin-top: 4px; }
.play.on { font-weight: 700; }
.chat-compose { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end; width: 100%; max-width: 640px;
                margin: 0 auto; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.chat-compose textarea { flex: 1; min-height: 48px; max-height: 160px; resize: none; border-radius: 22px; padding: 12px 16px; }
.chat-compose .btn { min-height: 48px; border-radius: 24px; }
.chat-rec { flex: 1; display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 12px; color: var(--danger); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s infinite; }
.chat-safety { text-align: center; font-size: .72em; margin: 0 16px 6px; }
.chat-err { text-align: center; margin: 0 16px 8px; }
.ib-thread { display: flex; flex-direction: column; gap: 8px; list-style: none; padding: 0; max-height: 60vh; overflow-y: auto;
             border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); }
.ib-thread .msg { font-size: .9em; }
.ib-q { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--card); }
.ib-q.now { border-color: var(--danger); background: var(--danger-soft); }
.ib-q.today { border-color: var(--warn); }
.ib-q textarea { min-height: 60px; margin: 8px 0; }
.ib-hold { border: 1px solid var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 10px; margin-bottom: 12px; }
a.btn { display: block; text-decoration: none; color: inherit; }

/* ---------------- landing (front page at /) ---------------- */
.l-wrap { max-width: 520px; margin: 0 auto; padding: 16px 16px 20px; min-height: 100vh; min-height: 100dvh;
          display: flex; flex-direction: column; }
.l-head { margin: 0 0 14px; }
.l-row { display: flex; align-items: center; gap: 14px; }
.l-logo { display: block; height: 46px; width: auto; max-width: 100%; margin: 0 0 10px; }
/* brand colours (PR 31 logo): navy #022B50, cyan #00A0EA */
body.landing { --accent: #022B50; --accent-ink: #ffffff; --accent-soft: #e0f2fc; }
@media (prefers-color-scheme: dark) { body.landing { --accent: #00A0EA; --accent-ink: #04121f; --accent-soft: #0d2a3f; } }
.l-photo { width: 48px; height: 48px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
           display: grid; place-items: center; font-weight: 700; font-size: 1.1em; flex: none; overflow: hidden; }
.l-photo img { width: 100%; height: 100%; object-fit: cover; }
.l-name { font-size: 1.3em; margin: 0; line-height: 1.2; }
.l-tag { margin: 2px 0 0; color: var(--muted); font-size: .95em; }
.l-q { font-size: 1.3em; margin: 0 0 14px; outline: none; }
.l-choices { display: grid; gap: 10px; margin: 0 0 14px; }
.l-choices.two { grid-template-columns: 1fr 1fr; }
.l-choices:empty { display: none; }
.l-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
         border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 14px;
         padding: 11px 14px; min-height: 56px; font-size: 1.05em; font-weight: 600; cursor: pointer;
         text-decoration: none; text-align: center; }
.l-btn small { font-weight: 400; font-size: .8em; color: var(--muted); }
.l-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.l-btn.primary small { color: var(--accent-ink); opacity: .85; }
.l-btn:active { transform: scale(.98); }
.l-how { font-size: .9em; margin: 4px 0 6px; color: var(--muted); }
.l-how strong { color: var(--ink); }
.l-where { margin: 0 0 4px; font-size: .85em; }
.l-code input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--card);
                margin-bottom: 10px; }
.l-back { background: none; border: 0; color: var(--accent); padding: 8px 0; cursor: pointer; }
.l-foot { margin-top: auto; padding-top: 12px; display: flex; justify-content: space-between; align-items: center;
          gap: 12px; flex-wrap: wrap; font-size: .85em; }
.l-emerg { margin: 0; color: var(--muted); }
.landing a { color: var(--accent); }
.landing a.l-btn { color: var(--ink); }
.landing a.l-btn.primary { color: var(--accent-ink); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
pre.plan-text { white-space: pre-wrap; font-family: inherit; font-size: .95em; line-height: 1.5; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-wrap: anywhere; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--card); }

/* hands-free talking (listen.js) */
.hands { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 10px; }
.hands .btn[aria-pressed="true"] { background: var(--danger-soft); border-color: var(--danger); }
.hands.listening #hear-status::before { content: "● "; color: var(--danger); }

/* ---------------- patient app (/app, D-036) ---------------- */
.pt-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pt-head .link { white-space: nowrap; }
.pt-sub { font-size: 1em; margin: 14px 0 8px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0 0 14px; }
.tab { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px; cursor: pointer; }
.tab.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.a-form { display: grid; gap: 12px; margin: 0 0 14px; }
.a-form label { display: grid; gap: 4px; font-size: .92em; color: var(--muted); }
.a-form input, .a-form select { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 1rem; color: var(--ink); }
.video-box { margin: 0 0 14px; }
.video-box video { width: 100%; border-radius: var(--radius); background: #000; aspect-ratio: 16 / 9; }
.unconfirmed { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: .92em; }
.areas { margin: 8px 0 10px; padding-left: 20px; font-weight: 600; }
.areas li { margin: 4px 0; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 14px; }
.slots .pt-sub { grid-column: 1 / -1; margin: 10px 0 0; }
.slot { min-height: 44px; padding: 8px; }
.ok { color: var(--accent); }
.tile { display: grid; gap: 4px; }
.tile-label { font-size: .9em; color: var(--muted); }
.tile-value { font-size: 1.3em; font-weight: 700; }
.spark { width: 100%; height: 36px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.wide-admin { max-width: 960px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .9em; }
.admin-table td, .admin-table th { border-top: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.scope { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: .92em; }
.scope p { margin: 0 0 4px; }
