/* Health Records — hand-written styles. No CSS framework or web fonts (nothing loaded from a CDN). */
:root {
  --bg: #060912;
  --surface: #0d1322;
  --surface-2: #131b2e;
  --border: #1f2a40;
  --text: #e6ebf5;
  --muted: #8b97ad;
  --accent: #14b8a6;      /* teal */
  --accent-2: #6366f1;    /* indigo */
  --low: #38bdf8;         /* below range */
  --normal: #34d399;      /* in range */
  --high: #f87171;        /* above range */
  --warn: #fbbf24;
  --radius: 14px;
  --tabbar-h: 64px;
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.zh { color: var(--muted); font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- lock screen ---------- */
.lock { position: fixed; inset: 0; z-index: 100; display: flex; padding: 24px; overflow-y: auto;
  background: radial-gradient(circle at 30% 20%, #10213a 0, var(--bg) 60%); }
.lock-card { width: 100%; max-width: 340px; margin: auto; text-align: center; }
.lock-logo { border-radius: 14px; margin-bottom: 12px; }
.lock-title { font-size: 1.4rem; }
.lock-dots { display: flex; gap: 12px; justify-content: center; margin: 18px 0; min-height: 14px; }
.lock-dots span { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--muted); }
.lock-dots span.on { background: var(--accent); border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); justify-items: center; gap: 12px; margin: 0 auto; max-width: 280px; }
.keypad button { width: 68px; height: 68px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  font-size: 1.4rem; cursor: pointer; }
.keypad button:active { background: var(--surface-2); }
.keypad button.ghost { border-color: transparent; background: none; font-size: 1rem; color: var(--muted); }
.lock-error { color: var(--high); min-height: 1.5em; margin: 12px 0 4px; }
.lock-panel { text-align: left; }
.recovery-key { font: 600 15px/1.6 ui-monospace, monospace; text-align: center; padding: 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); word-break: break-all; user-select: all; }
.check { display: flex; align-items: center; gap: 8px; }
.mono { font-family: ui-monospace, monospace; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 8px; }

/* ---------- app frame ---------- */
.app { min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + var(--safe-top)) 16px 10px; background: rgba(6, 9, 18, .92);
  border-bottom: 1px solid var(--border); backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 9px; }
.brand-name { font-weight: 700; }
.brand-version { font: 10px ui-monospace, monospace; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.profile-switcher { max-width: 170px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); }
.sync-pill { font-size: 11px; padding: 4px 8px; border: 0; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; cursor: pointer; }
.sync-pill[data-state="synced"] { color: var(--normal); }
.sync-pill[data-state="pending"], .sync-pill[data-state="syncing"], .sync-pill[data-state="offline"] { color: var(--warn); }
.sync-pill[data-state="error"] { color: var(--high); }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.main { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- bottom tab bar (5 tabs fit a 360px phone) ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; }
.tabbar a.active { color: var(--accent); }
.tab-icon { font-size: 20px; line-height: 1; }
.tab-add .tab-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 18px; }

/* ---------- shared components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.btn { color: var(--text); text-decoration: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-danger { border-color: #5b2330; color: var(--high); }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); }
.form-error { color: var(--high); min-height: 1.5em; margin: 0 0 8px; }
summary { cursor: pointer; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.flag-L { background: rgba(56, 189, 248, .15); color: var(--low); }
.flag-N { background: rgba(52, 211, 153, .15); color: var(--normal); }
.flag-H { background: rgba(248, 113, 113, .15); color: var(--high); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .btn { margin-top: 12px; }
.steps { margin: 0; padding-left: 20px; }
.mt { margin-top: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.results td { white-space: normal; padding: 8px 6px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.view-head h2 { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; align-items: end; }
.field-check { margin-bottom: 12px; min-height: 44px; }
.person-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
h4 { margin: 12px 0 2px; font-size: .9rem; }
.report-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: inherit; text-decoration: none; margin-bottom: 8px; }
.report-row.selected { border-color: var(--accent); }
.split-list, .split-detail { min-width: 0; }
.split.has-detail .split-list, .split:not(.has-detail) .split-detail { display: none; }
.result-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.result-row label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); min-width: 0; }
.result-row input, .result-row select { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 15px; }
.result-row label { grid-column: span 3; }
.result-row .rr-name { grid-column: 1 / 6; }
.rr-del { grid-column: 6; grid-row: 1; align-self: end; padding: 8px 4px; }
.rr-hints { grid-column: 1 / -1; margin: 0; font-size: 12px; }
.result-row.hint-unknown .rr-hints, .result-row.hint-low .rr-hints, .result-row.hint-dup .rr-hints { color: var(--warn); }
.report-notes { white-space: pre-wrap; }
[data-dup]:empty { display: none; }
.result-row.hint-range:not(.hint-unknown):not(.hint-low):not(.hint-dup) .rr-hints { color: var(--high); }
.result-row.hint-unknown input[data-f="name"], .result-row.hint-low input[data-f="value"] { border-color: var(--warn); }
.result-row.hint-range input[data-f="value"] { color: var(--high); }
.modal { position: fixed; inset: 0; z-index: 50; display: flex; padding: 16px; overflow-y: auto; background: rgba(0, 0, 0, .6); }
.modal-card { width: 100%; max-width: 480px; margin: auto; padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.code-box { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); font: 12px/1.5 ui-monospace, monospace; }
.warn-text { color: var(--warn); }
.masked-text { max-height: 55vh; overflow: auto; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg);
  white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.7 ui-monospace, monospace; }
.masked-text .masked { padding: 1px 4px; border-radius: 4px; background: var(--surface-2); color: var(--warn); }
.word { all: unset; cursor: pointer; border-radius: 4px; }
.word:hover, .word:focus-visible { background: var(--surface-2); outline: 1px solid var(--border); }
label.btn { cursor: pointer; }
.flag-card { display: grid; gap: 4px; margin: 0; color: inherit; text-decoration: none; }
.flag-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.chart-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.chart-grid .card { margin: 0; min-width: 0; }
.chart-box { position: relative; touch-action: pan-y; }
.chart, .spark { display: block; }
.c-band { fill: var(--normal); opacity: .13; }
.c-grid { stroke: var(--border); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 11px; }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.c-dot-H { fill: var(--high); }
.c-dot-L { fill: var(--low); }
.c-flag { fill: var(--text); font-size: 11px; font-weight: 600; }
.c-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip { position: absolute; top: 0; z-index: 2; padding: 4px 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; white-space: nowrap; pointer-events: none; }
.legend-band { display: inline-block; width: 14px; height: 10px; border-radius: 2px; background: var(--normal); opacity: .3; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); transform: translateX(-50%);
  z-index: 200; max-width: 90vw; padding: 10px 16px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--border); opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }

/* phone: the header keeps the logo only, so the switcher and sync pill fit */
@media (max-width: 480px) {
  .brand-text { display: none; }
  .profile-switcher { max-width: 150px; }
}

/* laptop: list + detail side by side where a view supports it */
@media (min-width: 900px) {
  .split { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
  .split.has-detail .split-list, .split:not(.has-detail) .split-detail { display: block; }
  .only-phone { display: none; }
  .result-row { grid-template-columns: 2fr 1fr 1fr 1.2fr 1fr 44px; }
  .result-row label, .result-row .rr-name { grid-column: auto; }
  .rr-del { grid-column: 6; grid-row: 1; }
}
