/* Patient app (#1042, #1043). One stylesheet, no external fonts or images.
   Large type and touch targets; light and dark; no motion that matters. */

:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --text: #16191b;
  --muted: #4a5257;
  --line: #9aa4a9;
  --primary: #0b5c6b;
  --primary-text: #ffffff;
  --focus: #b3460a;
  --error: #a1121a;
  --error-bg: #fdecec;
  --warn-bg: #fff3d6;
  --warn-text: #5c3d00;
  --info-bg: #e6f2f4;
  --ok-bg: #e2f3e6;
  --ok-text: #14522a;
  --review-bg: #ece9fb;
  --review-text: #2c2470;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101315;
    --surface: #1a1f22;
    --text: #f2f4f5;
    --muted: #c1c9cd;
    --line: #77838a;
    --primary: #8ad8e6;
    --primary-text: #06262c;
    --focus: #ffb37a;
    --error: #ffb0b0;
    --error-bg: #4a1518;
    --warn-bg: #4a3a0c;
    --warn-text: #ffe7a8;
    --info-bg: #143840;
    --ok-bg: #143a22;
    --ok-text: #b9efc8;
    --review-bg: #2a2558;
    --review-text: #dedaff;
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.125rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0.5rem 0 0.75rem; }
h2 { font-size: 1.25rem; line-height: 1.3; margin: 1.5rem 0 0.5rem; }
h3 { font-size: 1.15rem; margin: 1rem 0 0.5rem; }
h4 { font-size: 1.05rem; margin: 0 0 0.5rem; }
p { margin: 0 0 0.75rem; }

a { color: var(--primary); text-underline-offset: 0.15em; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1:focus, h2:focus, main:focus, .repeat:focus { outline: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

.skip { position: absolute; left: -999rem; top: 0; background: var(--surface); padding: 0.75rem 1rem; z-index: 20; }
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* ---- header ---- */

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-inner, .nav, main {
  max-width: 42rem;
  margin: 0 auto;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}
.top-inner { display: flex; align-items: center; gap: 0.75rem; min-height: 3.5rem; }
.brand { font-weight: 700; margin: 0; white-space: nowrap; }
.who { margin: 0 0 0 auto; color: var(--muted); font-size: 1rem; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logout { white-space: nowrap; flex: none; }

.nav { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; padding-bottom: 0.25rem; }
.nav a, .tab {
  display: inline-flex; align-items: center; min-height: 3rem; padding: 0 0.75rem;
  text-decoration: none; font-weight: 600; border-bottom: 4px solid transparent; color: var(--text);
}
.nav a[aria-current], .tab[aria-current] { border-bottom-color: var(--primary); color: var(--primary); }

main { padding-top: 1rem; padding-bottom: calc(3rem + env(safe-area-inset-bottom)); min-height: 60vh; }

/* ---- buttons ---- */

button, .button {
  font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 3rem; min-width: 3rem; padding: 0.5rem 1.25rem;
  border-radius: 0.6rem; border: 2px solid var(--primary);
  background: var(--surface); color: var(--primary);
  text-decoration: none; cursor: pointer; touch-action: manipulation;
}
button.primary, .button.primary { background: var(--primary); color: var(--primary-text); }
button.quiet { border-color: transparent; background: transparent; min-height: 2.75rem; padding: 0.25rem 0.75rem; }
button.small { min-height: 2.75rem; padding: 0.25rem 1rem; font-size: 1rem; }
button.link { border: 0; background: transparent; padding: 0.25rem 0.5rem; text-decoration: underline; min-height: 2.75rem; }
button[disabled] { opacity: 0.6; cursor: default; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1.25rem 0 0; }
.task-form > .actions .primary { flex: 1 1 10rem; }

/* ---- lists and cards ---- */

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }

.cards { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.75rem; }
.card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem;
  width: 100%; text-align: left; font-weight: 400;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 0.75rem; padding: 0.9rem 1rem;
}
.card-button { border-width: 2px; border-color: var(--primary); min-height: 4.5rem; }
.card-title { font-weight: 700; font-size: 1.15rem; }
.card-meta { color: var(--muted); font-size: 1rem; }
.due { margin: 0; font-size: 1rem; }
.reason { display: block; margin-top: 0.25rem; }

.badge {
  display: inline-block; padding: 0.1rem 0.6rem; border-radius: 1rem;
  font-size: 0.95rem; font-weight: 700; border: 1px solid currentColor;
}
.badge-overdue, .badge-rejected { background: var(--error-bg); color: var(--error); }
.badge-soon, .badge-pending { background: var(--warn-bg); color: var(--warn-text); }
.badge-endorsed { background: var(--ok-bg); color: var(--ok-text); }

.empty, .loading { color: var(--muted); padding: 1rem 0; }
.back { margin: 0; }
.back a { display: inline-flex; align-items: center; min-height: 2.75rem; }

.facts { margin: 0 0 1rem; }
.facts dt { font-weight: 700; margin-top: 0.75rem; }
.facts dd { margin: 0; }
.token { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; user-select: all; -webkit-user-select: all; }

.steps { padding-left: 1.5rem; }
.steps li { margin-bottom: 0.5rem; }

/* ---- notices ---- */

.notice, .instruction {
  background: var(--info-bg); border-left: 6px solid var(--primary);
  border-radius: 0.4rem; padding: 0.75rem 1rem; margin: 0 0 1rem;
}
.instruction h2 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.instruction p, .notice p:last-child, .notice ul { margin-bottom: 0; }
.notice-warn { background: var(--warn-bg); color: var(--warn-text); border-left-color: currentColor; }
.notice-error { background: var(--error-bg); color: var(--error); border-left-color: currentColor; }
.notice-review { background: var(--review-bg); color: var(--review-text); border-left-color: currentColor; }

/* ---- form fields ---- */

.field, fieldset.field { margin: 0 0 1.25rem; padding: 0; border: 0; min-width: 0; }
.field > label, .field > legend, .field-label, .question-title {
  display: block; font-weight: 700; font-size: 1.15rem; margin-bottom: 0.35rem; padding: 0;
}
.optional { font-weight: 400; color: var(--muted); }
.hint { color: var(--muted); font-size: 1rem; margin-bottom: 0.4rem; }
.error { color: var(--error); font-weight: 700; margin: 0.4rem 0 0; }

input[type="text"], input[type="date"], input[type="datetime-local"], input[type="time"], textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  width: 100%; min-height: 3rem; padding: 0.5rem 0.75rem;
  border: 2px solid var(--line); border-radius: 0.5rem;
}
input.short { max-width: 10rem; }
.field-invalid input[type="text"], .field-invalid input[type="date"], .field-invalid input[type="datetime-local"],
.field-invalid input[type="time"], .field-invalid textarea, .field-invalid select { border-color: var(--error); border-width: 3px; }

.with-unit { display: flex; align-items: center; gap: 0.6rem; }
.unit { font-weight: 600; }

.options { display: grid; gap: 0.5rem; }
.option {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 3.25rem; padding: 0.5rem 0.9rem;
  background: var(--surface); border: 2px solid var(--line); border-radius: 0.6rem; cursor: pointer;
}
.option input { width: 1.5rem; height: 1.5rem; flex: none; margin: 0; accent-color: var(--primary); }
.option:has(input:checked) { border-color: var(--primary); background: var(--info-bg); }
.field-invalid .option { border-color: var(--error); }

.step-title { font-size: 1rem; color: var(--muted); margin: 1rem 0 0.25rem; font-weight: 600; }
progress { width: 100%; height: 0.6rem; margin-bottom: 1rem; accent-color: var(--primary); }
.section { color: var(--muted); font-weight: 600; margin-bottom: 0.25rem; }
.intro { margin-bottom: 1rem; }

.instance { background: var(--surface); border: 1px solid var(--line); border-radius: 0.75rem; padding: 1rem; margin-bottom: 1rem; }
.subgroup { border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.75rem; margin: 0 0 1rem; }
.subgroup > legend { font-weight: 700; padding: 0 0.4rem; }

.review { list-style: none; margin: 0 0 1rem; padding: 0; }
.review li { display: grid; gap: 0.1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.review-label { color: var(--muted); font-size: 1rem; }
.review-value { font-weight: 700; }
.review .link { justify-self: start; padding-left: 0; }

/* ---- idle warning ---- */

.overlay {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.6); padding: 1rem;
}
.dialog { background: var(--surface); color: var(--text); border-radius: 0.9rem; padding: 1.25rem; max-width: 28rem; width: 100%; }
.dialog h2 { margin-top: 0; }
.dialog button { width: 100%; }

@media (min-width: 40rem) {
  body { font-size: 1.2rem; }
  h1 { font-size: 1.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .option:has(input:checked) { outline: 3px solid Highlight; }
}

/* ---- v2 (#1049): landing, card, events ---- */

.lead { font-size: 1.2rem; }
.actions-stack { flex-direction: column; align-items: stretch; }
.actions-stack .button { width: 100%; min-height: 3.5rem; font-size: 1.2rem; }
.notice-ok { background: var(--ok-bg); color: var(--ok-text); border-left-color: currentColor; }
.badge-none { background: var(--surface); color: var(--muted); }
.card-section h2.card-title { margin: 0; font-size: 1.25rem; }
.card-section .actions { margin-top: 0.5rem; }
.card-section .actions .button { min-width: 8rem; }
.review-short { margin: 0.25rem 0 0; width: 100%; }
.review-short li { padding: 0.35rem 0; }
.timeline .card-title { font-size: 1.1rem; }
