:root {
  /* iOS / Apple Health light palette */
  --bg: #f2f2f7;              /* systemGroupedBackground */
  --panel: #ffffff;          /* secondarySystemGroupedBackground */
  --panel-2: #ffffff;
  --track: rgba(118, 118, 128, 0.12); /* segmented control / fills */
  --separator: rgba(60, 60, 67, 0.12);
  --separator-strong: rgba(60, 60, 67, 0.2);
  --text: #1c1c1e;           /* label */
  --muted: #8a8a8e;          /* secondaryLabel-ish */
  --faint: #aeaeb2;          /* tertiaryLabel */
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --teal: #30b0c7;
  --purple: #af52de;
  --accent: var(--blue);
  --good: var(--green);
  --warn: var(--orange);
  --bad: var(--red);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 16px -10px rgba(0, 0, 0, 0.16);
  --shadow-lg: 0 0 0 0.5px rgba(0, 0, 0, 0.05), 0 10px 40px -12px rgba(0, 0, 0, 0.2);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); font-size: 13px; }
::selection { background: rgba(0, 122, 255, 0.18); }

/* ---------- Lock screen ---------- */
.lock {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
}
.lock-card {
  background: var(--panel);
  border-radius: 22px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}
.lock-card h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; font-weight: 700; }
.lock-card p { margin: 0; }
.lock-card input[type="password"] {
  padding: 13px 14px;
  border-radius: 12px;
  border: none;
  background: var(--track);
  color: var(--text);
  font-size: 16px;
  transition: box-shadow 0.15s;
}
.lock-card input[type="password"]::placeholder { color: var(--muted); }
.lock-card input[type="password"]:focus {
  outline: none;
  box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.25);
}
.remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.remember input { accent-color: var(--blue); width: 16px; height: 16px; }
.lock-foot { max-width: 380px; text-align: center; line-height: 1.5; }

/* Auth screens (login / MFA) */
.lock-card h1 { margin: 0 0 2px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.lock-card input[type="email"],
.lock-card input[type="text"],
.lock-card input#code {
  padding: 13px 14px; border-radius: 12px; border: none;
  background: var(--track); color: var(--text); font-size: 16px;
}
.lock-card input:focus { outline: none; box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.25); }
.lock-card input#code { text-align: center; letter-spacing: 0.4em; font-variant-numeric: tabular-nums; }
.auth-loading { padding: 22px; text-align: center; color: var(--muted); font-size: 14px; }
.qr { display: flex; justify-content: center; background: #fff; padding: 14px; border-radius: 14px; margin: 6px 0; }
.qr svg, .qr img { width: 190px; height: 190px; }
.linkbtn { background: none; color: var(--blue); box-shadow: none; padding: 8px 0; font-size: 13.5px; font-weight: 500; margin-top: 6px; }
.linkbtn:hover { opacity: 0.8; }
.lock-card code { font-size: 12px; word-break: break-all; }

button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
button:hover { opacity: 0.9; }
button:active { transform: scale(0.98); }
button.ghost {
  background: var(--track);
  color: var(--blue);
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 500;
}
button.ghost:hover { opacity: 0.8; }

/* ---------- App shell ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 22px;
  border-bottom: 0.5px solid var(--separator-strong);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar strong { font-size: 16px; letter-spacing: -0.02em; font-weight: 650; }
.topbar strong::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  background: var(--green);
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.tag {
  margin-left: 8px;
  background: var(--track);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--muted);
  vertical-align: middle;
}
.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 16px;
  overflow-x: auto;
  border-bottom: 0.5px solid var(--separator);
  position: sticky;
  top: 51px;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 9;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 9px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}
main { padding: 22px; max-width: 1120px; margin: 0 auto; }
.foot { text-align: center; padding: 28px; color: var(--faint); }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; margin: 0 0 4px; letter-spacing: -0.02em; font-weight: 650; }
.card h3 {
  font-size: 13px; letter-spacing: -0.01em;
  color: var(--muted); margin: 0 0 10px; font-weight: 600;
}
.stat {
  font-size: 34px; font-weight: 700; line-height: 1.05;
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
  color: var(--text);
}
.stat .unit { font-size: 15px; color: var(--muted); font-weight: 500; letter-spacing: -0.01em; }
.stat-sub { font-size: 13px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }
.section-note { color: var(--muted); font-size: 13.5px; margin: 4px 0 18px; max-width: 74ch; }

/* Status card: small coloured status dot in the corner */
.stat-card { position: relative; }
.stat-card h3 { padding-right: 18px; }
.stat-card::after {
  content: ""; position: absolute; top: 18px; right: 18px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--faint);
}
.stat-card.tone-good::after { background: var(--green); }
.stat-card.tone-warn::after { background: var(--orange); }
.stat-card.tone-bad::after { background: var(--red); }

/* Clickable summary cards */
.card.clickable { cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card.clickable:active { transform: translateY(0); }
.stat-card .go {
  position: absolute; right: 16px; bottom: 14px; color: var(--faint);
  font-size: 22px; line-height: 1; opacity: 0; transition: opacity 0.15s, transform 0.15s;
}
.stat-card.clickable:hover .go { opacity: 1; transform: translateX(3px); }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 590;
  letter-spacing: -0.01em;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { background: rgba(52, 199, 89, 0.14); color: #248a3d; }
.pill.warn { background: rgba(255, 149, 0, 0.16); color: #b25f00; }
.pill.bad { background: rgba(255, 59, 48, 0.13); color: #d70015; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 9px 12px; border-bottom: 0.5px solid var(--separator); }
th:first-child, td:first-child { text-align: left; }
thead th {
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  letter-spacing: -0.005em;
  border-bottom: 0.5px solid var(--separator-strong);
}
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: rgba(0, 122, 255, 0.04); }
tbody tr:last-child td { border-bottom: none; }
td.hi { color: var(--red); font-weight: 650; }
td.lo { color: var(--orange); font-weight: 650; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

/* ---------- Charts ---------- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px;
  font-size: 12px; color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .cm-leg { cursor: pointer; user-select: none; transition: opacity 0.15s; }
.legend .cm-leg:hover { color: var(--text); }
.legend .cm-leg.off { opacity: 0.4; text-decoration: line-through; }

/* Interactive tooltip */
#cm-tip {
  position: fixed; z-index: 1000; pointer-events: none; display: none;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  padding: 9px 11px; font-size: 12.5px; min-width: 132px;
}
.tip-date { font-weight: 650; margin-bottom: 5px; font-size: 12px; letter-spacing: -0.01em; }
.tip-row { display: flex; align-items: center; gap: 7px; line-height: 1.7; }
.tip-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.tip-name { color: var(--muted); margin-right: auto; }
.tip-val { font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- Timeline ---------- */
.timeline { position: relative; margin: 10px 0 0; padding-left: 22px; }
.timeline::before {
  content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px;
  background: var(--separator-strong);
}
.tl-item { position: relative; padding: 0 0 20px 18px; }
.tl-item::before {
  content: ""; position: absolute; left: -18px; top: 5px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--blue);
  border: 2.5px solid var(--bg);
}
.tl-item.imaging::before { background: var(--orange); }
.tl-item.pathology::before { background: var(--blue); }
.tl-item.regulatory::before { background: var(--green); }
.tl-date { font-size: 11.5px; color: var(--faint); letter-spacing: -0.005em; }
.tl-title { font-weight: 590; margin-top: 1px; }
.tl-body { font-size: 13px; color: var(--muted); }

/* ---------- Card head with action ---------- */
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 26px 16px; color: var(--muted); }
.empty-plus {
  width: 44px; height: 44px; line-height: 44px; margin: 0 auto 8px;
  border-radius: 50%; background: var(--track); color: var(--muted);
  font-size: 24px; font-weight: 300;
}
.empty p { margin: 0 0 12px; font-size: 13.5px; }

/* ---------- Watch list / flags ---------- */
.flags { display: flex; flex-direction: column; gap: 9px; margin-top: 6px; }
.flag {
  display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px;
  padding: 11px 13px; border-radius: 12px; background: var(--track); line-height: 1.45;
}
.flag-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--faint); }
.flag.bad .flag-dot { background: var(--red); }
.flag.warn .flag-dot { background: var(--orange); }
.flag.good .flag-dot { background: var(--green); }

/* ---------- Summary ---------- */
.summary h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
.summary-list { margin: 6px 0 0; padding-left: 18px; }
.summary-list li { margin-bottom: 8px; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.summary-list strong { color: var(--text); }
.tl-item.event::before { background: var(--purple); }

/* ---------- Visual summary ---------- */
.sum-hero { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: stretch; }
@media (max-width: 760px) { .sum-hero { grid-template-columns: 1fr; } }
.kidney3d-hero { height: 380px; }
.sum-caption { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: 8px; }
.vitals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: center; }
.vital {
  background: var(--panel); border-radius: 16px; padding: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
}
.vital h4 { margin: 0; font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: -0.01em; }
.ring { width: 96px; height: 96px; }
.ring-val { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.ring-sub { font-size: 9px; fill: var(--muted); }
.vital .spark { width: 100%; height: 34px; }
.vital .v-sub { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }

.sum-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.sum-tile { background: var(--panel); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.sum-tile .t-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sum-tile .t-name { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.sum-tile .t-val { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sum-tile .t-val .unit { font-size: 12px; color: var(--muted); font-weight: 500; }
.sum-tile .spark { width: 100%; height: 42px; margin-top: 6px; }
.sum-tile .t-foot { font-size: 11px; color: var(--faint); margin-top: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 550; padding: 7px 12px; border-radius: 999px; background: var(--track); }
.chip .flag-dot { margin: 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--panel); border-radius: 20px; width: 100%; max-width: 430px;
  box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 0.5px solid var(--separator);
  position: sticky; top: 0; background: var(--panel); z-index: 1;
}
.modal-head strong { font-size: 16px; letter-spacing: -0.01em; }
#modal-body { padding: 16px 18px; }
.add-form { display: flex; flex-direction: column; gap: 13px; }
.add-field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.add-field input, .add-field select {
  padding: 11px 12px; border-radius: 10px; border: 1px solid var(--separator-strong);
  background: var(--panel); color: var(--text); font-size: 16px; font-family: inherit;
}
.add-field input:focus, .add-field select:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}
.add-actions { margin-top: 2px; }
.add-actions button { width: 100%; }
.add-hint { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-grid button { justify-content: flex-start; text-align: left; }
.add-done { text-align: center; }
.add-done p { font-size: 13.5px; }

/* ---------- How-it-works / therapy ---------- */
.equation { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0; flex-wrap: wrap; }
.eq-term { padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; text-align: center; }
.eq-top { background: rgba(0, 122, 255, 0.12); color: #0058b8; }
.eq-bottom { background: rgba(52, 199, 89, 0.14); color: #248a3d; }
.eq-vs { color: var(--muted); font-weight: 600; font-size: 13px; }
.kidney3d {
  height: 460px; border-radius: 16px; margin-top: 4px; position: relative;
  background: radial-gradient(circle at 50% 38%, #ffffff, #eef0f5);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.kidney-svg { max-height: 340px; width: auto; }

/* 3D overlays */
.k3d-controls { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 3; }
.k3d-controls button {
  font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: 999px; border: none; cursor: pointer;
  background: rgba(255, 255, 255, 0.85); color: var(--muted); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.k3d-controls button.on { background: var(--blue); color: #fff; }
.k3d-zoom { position: absolute; right: 10px; bottom: 12px; display: flex; flex-direction: column; gap: 5px; z-index: 3; }
.k3d-zoom button {
  width: 36px; height: 36px; border-radius: 9px; border: none; cursor: pointer;
  font-size: 20px; font-weight: 500; line-height: 1; color: var(--muted);
  background: rgba(255, 255, 255, 0.9); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.k3d-zoom button:hover { color: var(--blue); }
.k3d-label {
  position: absolute; transform: translate(-50%, -50%); font-size: 11.5px; font-weight: 600; color: var(--text);
  background: rgba(255, 255, 255, 0.82); border-radius: 6px; padding: 2px 7px; pointer-events: none; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); z-index: 2;
}
.k3d-tip {
  position: absolute; transform: translate(-50%, -100%); background: #1c1c1e; color: #fff; font-size: 12px; font-weight: 650;
  padding: 3px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; z-index: 4;
}
.k3d-info {
  position: absolute; left: 12px; bottom: 12px; max-width: 62%;
  background: rgba(255, 255, 255, 0.92); border-radius: 12px; padding: 10px 13px; z-index: 3;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14); display: flex; flex-direction: column; gap: 2px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.k3d-info strong { font-size: 14px; letter-spacing: -0.01em; }
.k3d-info span { font-size: 12.5px; color: var(--muted); }
.lever-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-top: 12px; }
.lever-card { border: 1px solid var(--separator); border-radius: 14px; padding: 15px; border-top: 3px solid var(--lv); background: var(--panel); }
.lever-badge {
  display: inline-block; font-size: 11.5px; font-weight: 650; color: var(--lv);
  padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--lv) 14%, transparent);
}
.lever-name { font-weight: 650; margin-top: 9px; font-size: 15.5px; letter-spacing: -0.01em; }
.lever-class { font-size: 12px; color: var(--muted); margin-top: 1px; }
.lever-mech { font-size: 13px; color: var(--muted); margin: 9px 0 0; line-height: 1.5; }
a[data-goto-link] { color: var(--blue); cursor: pointer; border-bottom: 1px solid rgba(0, 122, 255, 0.3); }
a[data-goto-link]:hover { border-bottom-color: var(--blue); }

/* ---------- Print ---------- */
@media print {
  .topbar, .tabs, .foot, #add-btn, #lock-btn, #print-btn,
  .card-head button, .empty button, #cm-tip, .modal-overlay { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .tab-panel[hidden] { display: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}

/* ---------- Medication ---------- */
.med { border-left: 2.5px solid var(--blue); padding: 4px 0 4px 14px; margin-bottom: 14px; }
.med .name { font-weight: 600; }
.med .meta { font-size: 13px; color: var(--muted); }
.callout {
  background: var(--track);
  border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 13.5px;
}
