/* Care Log styles. Colors are tokens; dark mode redefines them. */
:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --card: #fffffd;
  --ink: #1b1b19;
  --ink-2: #4f4e4a;
  --muted: #696862;
  --line: #e4e2db;
  --line-2: #d1cfc6;
  --accent: #0e6b63;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ee;
  --accent-text: #0b5c55;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --chart: #2a78d6;
  --chart-grid: #e8e6df;
  --chart-axis: #c3c2b7;
  --s0: #cde2fb; --s1: #86b6ef; --s2: #5598e7; --s3: #2a78d6; --s4: #1c5cab; --s5: #0d366b;
  --empty: #efeee9;
  --seg-on: #fffffd;
  --shadow: 0 1px 2px rgba(30, 30, 10, .06), 0 2px 8px rgba(30, 30, 10, .04);
  --radius: 16px;
  --tabbar-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0e0d; --card: #1b1b1a; --ink: #f0efec; --ink-2: #cac9bf; --muted: #a09f96;
    --line: #2d2d2a; --line-2: #3d3d39;
    --accent: #4fc1b3; --accent-ink: #062e29; --accent-soft: #163330; --accent-text: #74d5c8;
    --danger: #f2867d; --danger-soft: #3a1f1c;
    --chart: #3987e5; --chart-grid: #2c2c2a; --chart-axis: #4a4a44;
    --s0: #0d366b; --s1: #184f95; --s2: #256abf; --s3: #3987e5; --s4: #6da7ec; --s5: #b7d3f6;
    --empty: #252523; --seg-on: #45453f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e0d; --card: #1b1b1a; --ink: #f0efec; --ink-2: #cac9bf; --muted: #a09f96;
  --line: #2d2d2a; --line-2: #3d3d39;
  --accent: #4fc1b3; --accent-ink: #062e29; --accent-soft: #163330; --accent-text: #74d5c8;
  --danger: #f2867d; --danger-soft: #3a1f1c;
  --chart: #3987e5; --chart-grid: #2c2c2a; --chart-axis: #4a4a44;
  --s0: #0d366b; --s1: #184f95; --s2: #256abf; --s3: #3987e5; --s4: #6da7ec; --s5: #b7d3f6;
  --empty: #252523; --seg-on: #45453f;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  outline: none;
}
a { color: var(--accent-text); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0 0 10px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- page header ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 2px 16px; }
.head h1 { font-size: 30px; font-weight: 700; letter-spacing: -.01em; }
.head .sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.head .actions { display: flex; gap: 8px; flex-shrink: 0; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--accent-text); text-decoration: none; font-size: 17px; margin: 4px 0 6px -4px; padding: 6px 4px; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card > h2, .card-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-title .count { text-transform: none; letter-spacing: 0; font-weight: 500; }
.section-label { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.big { font-size: 20px; font-weight: 650; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; padding-top: 2px; }
.list > li:last-child { padding-bottom: 2px; }
.linkrow { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; padding: 2px 0; }
.linkrow .chev { color: var(--muted); margin-left: auto; flex-shrink: 0; }
.linkrow .ico-badge { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex-shrink: 0; }
.empty { color: var(--muted); font-size: 15px; padding: 4px 0; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.pill-tag { display: inline-block; font-size: 13px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.pill-tag.gray { background: var(--empty); color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); cursor: pointer; }
.chip:active { background: var(--accent-soft); }
.banner { background: var(--accent-soft); color: var(--ink); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 15px; }
.banner.warn { background: var(--danger-soft); }

/* ---------- buttons & inputs ---------- */
.btn { font: inherit; font-size: 16px; font-weight: 600; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); border-radius: 12px; padding: 10px 16px; min-height: 44px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { font-size: 14px; padding: 6px 12px; min-height: 36px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn { font: inherit; background: none; border: 0; color: var(--accent-text); width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; cursor: pointer; }
.icon-btn:active { background: var(--accent-soft); }
.linkbtn { font: inherit; background: none; border: 0; color: var(--accent-text); padding: 6px 0; cursor: pointer; font-size: 15px; font-weight: 600; }
.linkbtn.danger { color: var(--danger); }
label.field { display: block; margin-bottom: 12px; }
label.field > span, .field-label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  font: inherit; font-size: 17px; width: 100%; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; min-height: 44px;
  -webkit-appearance: none; appearance: none;
}
input[type=date], input[type=time] { min-width: 0; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.inline-check { display: flex; align-items: center; gap: 10px; font-size: 16px; margin: 4px 0 12px; }
.inline-check input { width: 22px; height: 22px; accent-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- tappable check rows ---------- */
.check { display: flex; align-items: center; gap: 12px; width: 100%; font: inherit; text-align: left; background: none; border: 0; color: inherit; padding: 10px 0; cursor: pointer; min-height: 52px; }
.check + .check { border-top: 1px solid var(--line); }
.check .box { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line-2); flex-shrink: 0; display: grid; place-items: center; color: transparent; transition: background .15s, border-color .15s; }
.check[aria-pressed=true] .box, .check[aria-checked=true] .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check .t { flex: 1; min-width: 0; }
.check .t small { display: block; color: var(--muted); font-size: 14px; }
.check[aria-pressed=true] .t > span:first-child, .check[aria-checked=true] .t > span:first-child { color: var(--ink-2); }

/* ---------- date nav ---------- */
.datenav { display: flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.datenav .mid { flex: 1; position: relative; text-align: center; font-weight: 650; padding: 8px 0; }
.datenav .mid input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.datenav .mid small { display: block; font-weight: 500; color: var(--muted); font-size: 13px; }

/* ---------- segmented control ---------- */
.seg { display: flex; background: var(--empty); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; font: inherit; font-size: 15px; font-weight: 600; border: 0; background: none; color: var(--ink-2); padding: 8px 6px; border-radius: 9px; cursor: pointer; min-height: 38px; }
.seg button[aria-pressed=true] { background: var(--seg-on); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- symptom scoring ---------- */
.sx { padding: 12px 0; border-top: 1px solid var(--line); }
.sx:first-child { border-top: 0; padding-top: 0; }
.sx-name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.sx-name small { color: var(--muted); font-weight: 500; font-size: 14px; }
.scores { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.scores button { font: inherit; font-weight: 650; font-size: 17px; height: 44px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); cursor: pointer; padding: 0; }
.scores button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sx textarea, .sx input[type=text] { margin-top: 8px; min-height: 44px; font-size: 16px; }
.scale-key { font-size: 13px; color: var(--muted); margin: -4px 2px 12px; }

/* ---------- stepper ---------- */
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); font-size: 22px; cursor: pointer; }
.stepper input { width: 74px; text-align: center; padding: 8px 4px; }

/* ---------- labs ---------- */
.lab-row { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.lab-row .val { text-align: right; flex-shrink: 0; }
.lab-row .val b { font-size: 19px; font-weight: 650; }
.lab-row .val small { display: block; color: var(--muted); font-size: 13px; }
.stat3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat3 > div { background: var(--bg); border-radius: 12px; padding: 10px; }
.stat3 small { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat3 b { font-size: 20px; font-weight: 650; }
.stat3 span { display: block; font-size: 13px; color: var(--muted); }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: 6px 6px 6px 0; border-bottom: 1px solid var(--line-2); }
table.data td { padding: 9px 6px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }

/* ---------- charts ---------- */
.chart { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .v-label { fill: var(--ink); font-weight: 650; font-size: 13px; }
.tip { position: absolute; top: 0; pointer-events: none; background: var(--card); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px 10px; font-size: 13px; line-height: 1.3; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; transform: translateX(-50%); z-index: 2; }
.tip b { font-size: 15px; display: block; }
.tip .key { display: inline-block; width: 12px; height: 2px; background: var(--chart); vertical-align: middle; margin-right: 6px; }
.strip { margin: 6px 0 2px; }
.strip svg { display: block; width: 100%; height: 22px; cursor: pointer; }
.strip-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 15px; font-weight: 600; margin-top: 12px; }
.strip-head small { font-weight: 500; color: var(--muted); font-size: 13px; text-align: right; }
.strip-detail { font-size: 14px; background: var(--bg); border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.axis-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 13px; color: var(--muted); }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.meter { height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; margin-top: 6px; }
.meter > div { height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- appointments ---------- */
.appt { display: flex; gap: 12px; }
.datebox { width: 52px; flex-shrink: 0; text-align: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent-text); padding: 6px 0; line-height: 1.1; }
.datebox small { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.datebox b { font-size: 22px; }
details > summary { cursor: pointer; font-weight: 600; color: var(--accent-text); padding: 4px 0; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }

/* ---------- research ---------- */
.result { padding: 14px 0; border-top: 1px solid var(--line); }
.result:first-child { border-top: 0; padding-top: 4px; }
.result a.title { font-weight: 650; color: var(--ink); text-decoration: none; display: block; }
.result a.title:hover { text-decoration: underline; }
.result .meta { font-size: 14px; color: var(--muted); margin-top: 3px; }
.result .abstract { font-size: 15px; color: var(--ink-2); margin-top: 8px; white-space: pre-wrap; }

/* ---------- summary (also printed) ---------- */
.report h2 { font-size: 16px; margin: 18px 0 6px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.report h2:first-of-type { margin-top: 4px; }
.report ul { margin: 0; padding-left: 18px; }
.report li { margin: 2px 0; }
.report .data { font-size: 14px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 4px 4px env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 4px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; min-height: 52px; }
.tabbar a[aria-current=page] { color: var(--accent-text); }
.ico { display: inline-grid; place-items: center; line-height: 0; }
.ico svg { width: 24px; height: 24px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- print: only the doctor summary ---------- */
@media print {
  :root { color-scheme: light; --bg: #fff; --card: #fff; --ink: #000; --ink-2: #222; --muted: #555; --line: #ddd; --line-2: #bbb; }
  body { font-size: 12px; background: #fff; }
  .tabbar, #toast, .no-print, .back, .head .actions { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; margin: 0; }
  .head h1 { font-size: 20px; }
  .report h2 { font-size: 13px; margin: 10px 0 4px; }
  table.data { font-size: 11px; }
  table.data td, table.data th { padding: 3px 6px 3px 0; }
}
.card .row.between + .check, .card .row + .check { border-top: 1px solid var(--line); }
