:root {
  color-scheme: light dark;
  --bg: #F2F6F9;
  --surface: #FFFFFF;
  --surface-2: #E9F1F5;
  --ink: #10212B;
  --ink-2: #40535E;
  --ink-3: #5A6C77;
  --line: #DCE6EC;
  --hero: linear-gradient(90deg, #007F55, #0069B4);
  --brand-ink: #FFFFFF;
  --brand-soft: #E6F7F0;
  --flag: #FFD23F;
  --accent: #007A56;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6F7F0;
  --gold: #8F5B00;
  --amber: #F5A800;
  --danger: #D1291C;
  --danger-soft: #FEECEA;
  --warn-soft: #FFF4D1;
  --shadow: 0 1px 2px rgba(16, 33, 43, 0.06), 0 4px 14px rgba(16, 33, 43, 0.06);
  --series-1: #00936A;
  --series-2: #E8590C;
  --badge-doctor: #00704E;
  --badge-therapist: #0B6FD6;
  --badge-sheet: #8F5B00;
  --badge-general: #5A6C77;
  --serif: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D171E;
    --surface: #15222B;
    --surface-2: #1F2F3A;
    --ink: #F1F6F8;
    --ink-2: #C3D0D8;
    --ink-3: #9FB0BA;
    --line: #2B3C47;
    --hero: linear-gradient(90deg, #007F55, #0069B4);
    --brand-ink: #FFFFFF;
    --brand-soft: #E6F7F0;
    --accent: #34D399;
    --accent-ink: #06140E;
    --accent-soft: #12352B;
    --gold: #FFC94D;
    --amber: #F5A800;
    --danger: #FF8A7A;
    --danger-soft: #3A1D18;
    --warn-soft: #33290F;
    --shadow: none;
    --series-1: #14A67C;
    --series-2: #DA6F24;
    --badge-doctor: #00704E;
    --badge-therapist: #1670CC;
    --badge-sheet: #8F5B00;
    --badge-general: #5A6C77;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--sans);
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
h1, h2, h3, h4, p, ul, ol { margin: 0; }
h1, h2 { font-family: var(--serif); font-weight: 750; letter-spacing: -0.02em; }
h3 { font-size: 1.06rem; font-weight: 650; }
h4 { font-size: 0.82rem; margin-top: 16px; margin-bottom: 4px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); font-weight: 650; }
a { color: var(--accent); }
ul, ol { padding-left: 1.2em; }
li + li { margin-top: 4px; }
code { font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--ink-3); font-size: 0.92rem; }
.fine { color: var(--ink-3); font-size: 0.82rem; margin-top: 12px; }
.empty { color: var(--ink-2); font-size: 0.95rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--hero); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.brand { font: 700 1.05rem var(--serif); letter-spacing: -0.01em; }
.topbar-link { color: var(--brand-ink); text-decoration: none; font-size: 0.95rem; min-height: 32px; display: inline-flex; align-items: center; padding: 0 2px; }

.main { max-width: 620px; margin: 0 auto; padding: 0 16px; }
.main > * + * { margin-top: 12px; }
.page-head { padding-top: 20px; }
.page-head h2 { font-size: 1.75rem; }
.page-head p { color: var(--ink-2); margin-top: 6px; font-size: 0.95rem; }
.page-head .btn { margin-top: 10px; }

.hero {
  margin: 0 -16px;
  background: var(--hero); color: var(--brand-ink);
  padding: 12px 16px 22px;
}
.eyebrow { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--brand-soft); }
.hero h2 { font-size: 3rem; line-height: 1.1; }
.hero-phase { margin-top: 4px; }
.hero-focus { color: var(--brand-soft); font-size: 0.95rem; margin-top: 4px; }
.hero-golf {
  display: block; color: inherit; text-decoration: none; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 0.95rem;
}
.hero-golf > span { display: block; }
.ladder-bar { display: flex !important; gap: 3px; margin: 7px 0; }
.ladder-bar i { flex: 1; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.3); }
.ladder-bar i.on { background: var(--flag); }
.hero-note { color: var(--brand-soft); font-size: 0.85rem; }
.hero-due { margin-top: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card > p, .card > ul, .card > ol { margin-top: 6px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.count { color: var(--ink-3); font-size: 0.9rem; white-space: nowrap; }
.card-rules { border: 1.5px solid var(--amber); background: var(--warn-soft); }
.card-alert { background: var(--surface); }
.card-danger { background: var(--danger-soft); border: 1.5px solid var(--danger); color: var(--ink); }
.card-danger h3 { color: var(--danger); }
.card-note { background: var(--accent-soft); border-color: var(--accent); }
.rule-list { list-style: none; padding: 0; }
.rule { font-weight: 600; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; font-size: 0.85rem; color: var(--ink-2); }
.rule-list li + li { margin-top: 12px; }

.badge {
  display: inline-block; color: #fff; font-size: 0.72rem; font-weight: 600;
  padding: 1px 7px; border-radius: 999px; line-height: 1.5; vertical-align: 1px;
}
.badge-doctor { background: var(--badge-doctor); }
.badge-therapist { background: var(--badge-therapist); }
.badge-sheet { background: var(--badge-sheet); }
.badge-general { background: var(--badge-general); }
.kind { font-weight: 650; color: var(--ink); }
.kind-restriction { color: var(--gold); }
.kind-clearance { color: var(--accent); }

.suggest { list-style: none; padding: 0; }
.suggest li { padding: 10px 0; border-top: 1px solid var(--line); margin: 0; }
.suggest li:first-child { border-top: 0; padding-top: 4px; }
.suggest-title { font-weight: 600; }
.why { color: var(--ink-2); font-size: 0.9rem; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  font: 600 1rem var(--sans); text-decoration: none; cursor: pointer; text-align: center;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-call { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.link { background: none; border: 0; padding: 8px 8px 8px 0; color: var(--accent); font: 600 0.9rem var(--sans); cursor: pointer; text-decoration: underline; min-height: 36px; }
.link-danger { color: var(--danger); }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.stack > label:not(.check):not(.btn):not(.slider) { display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; font-weight: 550; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 44px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink);
  font: 400 16px var(--sans);
}
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
/* iOS gives date fields a fixed minimum width, which pushes them past the card. */
input[type="date"], input[type="datetime-local"] { -webkit-appearance: none; appearance: none; display: block; width: 100%; max-width: 100%; min-width: 0; min-height: 48px; }
input::-webkit-date-and-time-value { text-align: left; }
.inline-form input { flex: 1; min-width: 0; }

.checks { list-style: none; padding: 0; }
.checks li { margin: 0; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; min-height: 44px; font-weight: 400; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--accent); }
.check input:checked + span { color: var(--ink-3); }

.slider { display: block; font-weight: 550; font-size: 0.95rem; }
.slider output { font-weight: 700; font-size: 1.15rem; margin-left: 4px; }
.slider input { width: 100%; height: 40px; accent-color: var(--accent); margin: 2px 0 0; }

fieldset.chips { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
fieldset.chips legend { padding: 0; font-weight: 550; font-size: 0.95rem; margin-bottom: 6px; }
.chip { flex: 1 1 auto; position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: flex; justify-content: center; align-items: center; min-height: 44px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 0.92rem;
}
.chip input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.details { margin-top: 10px; }
.details > summary { cursor: pointer; font-weight: 600; font-size: 0.95rem; color: var(--accent); min-height: 40px; display: flex; align-items: center; gap: 6px; list-style: none; }
.details > summary::-webkit-details-marker { display: none; }
.details > summary::before { content: "+"; font-weight: 700; width: 14px; }
.details[open] > summary::before { content: "–"; }

.appt-time { font: 700 1.25rem var(--serif); letter-spacing: -0.01em; }
.card > .btn { margin-top: 10px; }

.questions { list-style: none; padding: 0; margin-top: 6px; }
.questions li { padding: 10px 0; border-top: 1px solid var(--line); margin: 0; }
.q-priority { background: var(--warn-soft); border: 1.5px solid var(--amber) !important; border-radius: 12px; padding: 10px 12px !important; margin-top: 8px; }
.q-text { font-weight: 550; }
.answer { color: var(--ink-2); margin-top: 3px; }

.entries { list-style: none; padding: 0; margin-top: 6px; }
.entry { padding: 10px 0; border-top: 1px solid var(--line); margin: 0; }
.entry:first-child { border-top: 0; }
.entry .link { margin-right: 10px; }
.entry .meta { margin: 0 0 3px; }

.status { flex: none; font-size: 0.72rem; font-weight: 700; color: var(--ink-2); background: var(--surface-2); text-align: center; max-width: 48%; padding: 3px 9px; border-radius: 999px; }
.status-current, .status-open { color: var(--accent); background: var(--accent-soft); }
.status-ask { color: var(--gold); background: var(--warn-soft); }
.status-blocked { color: var(--danger); background: var(--danger-soft); }
.phase-current { border: 2px solid var(--accent); }
.phase h4 + ul, .phase h4 + p { margin-top: 2px; }
.gate-line { font-size: 0.92rem; font-weight: 550; margin-top: 6px; }
.ask { font-size: 0.92rem; margin-top: 8px; color: var(--ink-2); }
.sources { list-style: none; padding: 0; font-size: 0.92rem; }
.sources li { margin-top: 10px; }

.ladder { list-style: none; padding: 0; position: relative; }
.rung { display: flex; gap: 10px; margin: 0; position: relative; padding-bottom: 12px; }
.rung::before { content: ""; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--line); }
.rung:last-child::before { display: none; }
.rung-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  font-weight: 700; font-size: 0.88rem;
}
.rung-open .rung-num { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rung-next .rung-num { background: var(--surface); color: var(--accent); border: 2px solid var(--accent); }
.rung-body { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.rung-body > p { margin-top: 4px; }
.rung-next .rung-body { border: 2px solid var(--accent); }
.rung:not(.rung-next):not(.rung-open) .rung-body { background: transparent; box-shadow: none; }
.card-rung-start { border: 1.5px solid var(--amber); background: var(--warn-soft); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 12px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile-num { font: 750 1.7rem var(--serif); line-height: 1.1; letter-spacing: -0.02em; color: var(--accent); }
.tile-label { font-size: 0.82rem; font-weight: 600; margin-top: 4px; }
.tile-sub { font-size: 0.74rem; color: var(--ink-3); }

.chart { position: relative; margin-top: 8px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; }
.grid { stroke: var(--line); stroke-width: 1; }
.axis { fill: var(--ink-3); font-size: 10px; }
.line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.line.dash { stroke-dasharray: 5 5; }
.line.series-1 { stroke: var(--series-1); }
.line.series-2 { stroke: var(--series-2); }
.dot { stroke: var(--surface); stroke-width: 2; }
.dot.series-1 { fill: var(--series-1); }
.dot.series-2 { fill: var(--series-2); }
.endlabel { fill: var(--ink-2); font-size: 10px; font-weight: 600; }
.crosshair { stroke: var(--ink-3); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 0.85rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.tooltip {
  position: absolute; top: 0; right: 8px; background: var(--ink); color: var(--surface);
  font-size: 0.8rem; padding: 6px 8px; border-radius: 6px; pointer-events: none; z-index: 2;
}
.tooltip.tooltip-left { right: auto; left: 28px; }
.table-wrap { overflow-x: auto; margin-top: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line); }
th { color: var(--ink-2); font-weight: 600; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; color: var(--ink-3); font-size: 0.72rem; font-weight: 600; text-decoration: none;
}
.nav a.active { color: var(--accent); }
.nav a.active svg { background: var(--accent-soft); border-radius: 999px; }
.nav svg { width: 44px; height: 26px; padding: 1px 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--surface); padding: 9px 16px; border-radius: 999px;
  font-size: 0.92rem; z-index: 6; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}

.welcome { padding-top: calc(env(safe-area-inset-top) + 36px); }
.welcome > * + * { margin-top: 12px; }
.welcome h1 { font-size: 2.6rem; color: var(--accent); letter-spacing: -0.03em; }
.lede { font-size: 1.05rem; color: var(--ink-2); }
.welcome .file-btn { margin-top: 10px; position: relative; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip span { transition: background-color 0.12s; }
}

@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 12pt; }
  .nav, .topbar, .toast, .no-print { display: none !important; }
  .card { border: 0; padding: 4px 0; background: none; break-inside: avoid; }
  .main { max-width: none; }
  .badge { color: #000; background: none; border: 1px solid #000; }
}

.docs { list-style: none; padding: 0; margin-top: 6px; }
.doc { display: flex; align-items: center; gap: 8px; margin: 0; padding: 4px 0; border-top: 1px solid var(--line); }
.doc:first-child { border-top: 0; }
.doc-open { flex: 1; min-width: 0; min-height: 56px; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 6px 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.doc-kind { flex: none; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 0.72rem; font-weight: 750; }
.doc-info { min-width: 0; display: flex; flex-direction: column; }
.doc-title { font-weight: 600; }
.doc .link { flex: none; }
.btn:disabled { opacity: 0.6; cursor: default; }
.stack .file-btn { position: relative; }

.viewer-open { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column;
  background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.viewer-title { font-size: 1.05rem; letter-spacing: -0.01em; min-width: 0; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.viewer-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-img { display: block; width: 100%; height: auto; }
.viewer-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--line); }
.viewer-foot .btn { flex: 1 1 auto; }

@media print {
  .viewer { display: none !important; }
}
