/* HRT Diary — styles. Tokens first; light/dark selected, not flipped. */

:root {
  color-scheme: light;
  --bg: #f7f5f8;
  --surface: #ffffff;
  --surface-2: #f2eff5;
  --surface-3: #e8e3ee;
  --text: #1b1820;
  --text-2: #55505c;
  --muted: #7d7884;
  --border: rgba(27, 16, 38, 0.11);
  --border-strong: rgba(27, 16, 38, 0.2);
  --accent: #8e44c4;
  --accent-hover: #7a35ad;
  --accent-soft: #f3e9fa;
  --accent-ink: #ffffff;
  --focus: #8e44c4;
  --ok: #0b7a2b;
  --ok-soft: #e6f4ea;
  --warn: #9a4b00;
  --warn-soft: #fdf0e1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --info: #2b5fa8;
  --info-soft: #e8f0fb;
  --pre: #8a5a00;
  --pre-soft: #fbf1dc;
  --shadow: 0 1px 2px rgba(20, 10, 30, 0.06), 0 4px 16px rgba(20, 10, 30, 0.05);
  --shadow-lg: 0 10px 40px rgba(20, 10, 30, 0.18);
  --radius: 14px;
  --radius-sm: 9px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* charts (dataviz reference palette, light) */
  --surface-1: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --grid: #e9e6ed;
  --axis: #c9c4cf;
  --band: rgba(27, 175, 122, 0.12);
  --band-edge: rgba(27, 175, 122, 0.45);
  --threshold: #1baf7a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #131115;
    --surface: #1c1a1f;
    --surface-2: #252229;
    --surface-3: #302c35;
    --text: #f1eef4;
    --text-2: #c7c1cd;
    --muted: #9a94a1;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --accent: #c592ee;
    --accent-hover: #d4aaf4;
    --accent-soft: #33253f;
    --accent-ink: #1a1020;
    --focus: #c592ee;
    --ok: #5fd07c;
    --ok-soft: #173421;
    --warn: #f2b264;
    --warn-soft: #3a2a15;
    --danger: #ff8a80;
    --danger-soft: #3d1a18;
    --info: #8fb8f2;
    --info-soft: #1a2a40;
    --pre: #f0c46b;
    --pre-soft: #362a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
    --surface-1: #1c1a1f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --grid: #2c2a2f;
    --axis: #3d3a41;
    --band: rgba(25, 158, 112, 0.18);
    --band-edge: rgba(25, 158, 112, 0.55);
    --threshold: #199e70;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #131115;
  --surface: #1c1a1f;
  --surface-2: #252229;
  --surface-3: #302c35;
  --text: #f1eef4;
  --text-2: #c7c1cd;
  --muted: #9a94a1;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --accent: #c592ee;
  --accent-hover: #d4aaf4;
  --accent-soft: #33253f;
  --accent-ink: #1a1020;
  --focus: #c592ee;
  --ok: #5fd07c;
  --ok-soft: #173421;
  --warn: #f2b264;
  --warn-soft: #3a2a15;
  --danger: #ff8a80;
  --danger-soft: #3d1a18;
  --info: #8fb8f2;
  --info-soft: #1a2a40;
  --pre: #f0c46b;
  --pre-soft: #362a12;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
  --surface-1: #1c1a1f;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --grid: #2c2a2f;
  --axis: #3d3a41;
  --band: rgba(25, 158, 112, 0.18);
  --band-edge: rgba(25, 158, 112, 0.55);
  --threshold: #199e70;
}

/* ---------- base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html.modal-open {
  overflow: hidden;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.4em;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.6rem;
}
h2 {
  font-size: 1.2rem;
}
h3 {
  font-size: 1rem;
}
p {
  margin: 0 0 0.75em;
}
a {
  color: var(--accent);
}
img {
  max-width: 100%;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 8px;
}
.skip-link:focus {
  left: 8px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.strong {
  font-weight: 650;
}
.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
[hidden] {
  display: none !important;
}

/* ---------- shell: top bar, rail, section tabs ---------- */
:root {
  --topbar-h: 56px;
  --rail-w: 88px;
  --bottombar-h: 62px;
  --tabs-h: 44px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar {
    background: var(--surface);
  }
}
.topbar .spacer {
  flex: 1;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  min-width: 0;
}
.brand img {
  border-radius: 7px;
  flex: none;
}
.btn.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}
.btn.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.topbar .icon-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.rail {
  position: fixed;
  z-index: 20;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  left: 0;
  bottom: 0;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 2px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-2);
  font: 550 0.72rem/1.15 var(--font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.rail-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.rail-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.rail-sep {
  flex: none;
  height: 1px;
  margin: 6px 10px;
  background: var(--border);
}
.rail-narrow,
.section-tabs {
  display: none;
}
.main {
  margin-left: var(--rail-w);
  padding: 24px 28px 48px;
  outline: none;
  min-width: 0;
}
.main > .page {
  max-width: 1120px;
  margin: 0 auto;
}
.boot {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}
.page > * + * {
  margin-top: 16px;
}

.section-tab {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-top: 2px solid transparent;
  margin-top: -1px;
  color: var(--text-2);
  font: 550 0.84rem var(--font);
  text-decoration: none;
  white-space: nowrap;
}
.section-tab[aria-selected='true'] {
  color: var(--accent);
  border-top-color: var(--accent);
}

@media (max-width: 1000px) {
  .hide-md {
    display: none !important;
  }
}

/* Phones: sections in a bottom bar, the section's views as tabs just above it. */
@media (max-width: 760px) {
  :root {
    --topbar-h: 52px;
  }
  .hide-sm {
    display: none !important;
  }
  .topbar {
    gap: 2px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }
  .brand-name {
    font-size: 1rem;
  }
  .top-add {
    padding: 8px 12px;
  }
  .rail {
    top: auto;
    right: 0;
    width: auto;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    flex-direction: row;
    padding: 4px max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    border-right: 0;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
  }
  .rail-wide,
  .rail-sep {
    display: none;
  }
  .rail-narrow {
    display: flex;
    flex: 1 1 0;
    justify-content: center;
    font-size: 0.74rem;
  }
  .rail-narrow.active {
    background: none;
  }
  .rail-narrow.active .icon {
    background: var(--accent-soft);
    border-radius: 999px;
    padding: 3px 14px;
    width: 52px;
    height: 28px;
    box-sizing: border-box;
  }
  .section-tabs {
    position: fixed;
    z-index: 19;
    left: 0;
    right: 0;
    bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    height: var(--tabs-h);
    padding: 0 max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  body.has-section-tabs .section-tabs {
    display: flex;
  }
  .main {
    margin-left: 0;
    padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--bottombar-h) + 28px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  body.has-section-tabs .main {
    padding-bottom: calc(var(--bottombar-h) + var(--tabs-h) + 28px + env(safe-area-inset-bottom));
  }
}
@media (max-width: 380px) {
  .section-tab {
    padding: 0 8px;
    gap: 4px;
    font-size: 0.8rem;
  }
}

/* ---------- menus ---------- */
.menu {
  position: fixed;
  z-index: 60;
  inset: auto;
  margin: 0;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: pop 0.12s ease;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: 500 0.92rem var(--font);
  text-align: left;
  cursor: pointer;
}
.menu-item .icon {
  color: var(--accent);
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

/* ---------- page header ---------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.page-head h1 {
  margin: 0;
}
.subtitle {
  color: var(--text-2);
  margin: 4px 0 0;
}
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.section-title {
  margin-top: 28px !important;
  font-size: 1.05rem;
  color: var(--text-2);
}
.group-title {
  font-size: 0.95rem;
  color: var(--text-2);
  margin-top: 24px !important;
}

/* ---------- cards ---------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.error {
  border-color: var(--danger);
}
.card-title {
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.card-link:hover {
  border-color: var(--border-strong);
}
.stack > * + * {
  margin-top: 12px;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}
.notes {
  white-space: pre-wrap;
  color: var(--text-2);
  margin: 10px 0 0;
}
.row {
  display: flex;
  align-items: center;
}
.gap {
  gap: 8px;
}
.wrap {
  flex-wrap: wrap;
}
.center {
  justify-content: center;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 550 0.92rem/1.2 var(--font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:hover {
  background: var(--surface-2);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger);
  filter: brightness(0.95);
}
.btn-danger-text {
  color: var(--danger);
}
.btn-text {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}
.btn-sm {
  min-height: 34px;
  padding: 5px 10px;
  font-size: 0.85rem;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn:disabled {
  opacity: 0.3;
}
.icon {
  flex-shrink: 0;
}
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font: 500 0.82rem var(--font);
  cursor: pointer;
}
.chip-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* segmented */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  max-width: 100%;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: 550 0.84rem var(--font);
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ---------- badges / pills / chips ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 550;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-hrt {
  background: var(--accent-soft);
  color: var(--accent);
}
.badge-pre {
  background: var(--pre-soft);
  color: var(--pre);
}
.pill {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  margin-top: 4px;
}
.pill-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.chip-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.chip-x {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}
.extras {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ---------- forms ---------- */
.form > * + *,
.form fieldset > * + * {
  margin-top: 12px;
}
fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}
/* Floated legends sit inside the fieldset box instead of breaking its top border. */
legend {
  float: left;
  width: 100%;
  font-weight: 650;
  font-size: 0.95rem;
  padding: 0;
  margin-bottom: 4px;
  color: var(--text);
}
legend + * {
  clear: both;
}
.form fieldset > legend + * {
  margin-top: 0;
}
.form fieldset + fieldset {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.label {
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--text-2);
}
.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}
.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}
.input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 16px/1.3 var(--font); /* 16px stops iOS zoom-on-focus */
  min-width: 0;
}
textarea.input {
  resize: vertical;
}
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.input:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 0;
}
input[type='date'].input,
input[type='datetime-local'].input {
  min-height: 42px;
}
.input-unit {
  width: auto;
  min-width: 96px;
  flex: 0 0 auto;
}
.input-n {
  width: 70px;
  flex: 0 0 70px;
}
.grid-2,
.grid-3 {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}
.grid-2.tight {
  grid-template-columns: 1fr auto;
  align-items: end;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.computed {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.computed-item {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}
.computed-item.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.computed-item strong {
  font-size: 1rem;
}

/* analyte rows */
.analyte {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.analyte:last-of-type {
  border-bottom: 0;
}
.analyte-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}
.analyte-inputs {
  display: flex;
  gap: 8px;
}
.analyte-inputs .input:first-child {
  flex: 1;
  font-variant-numeric: tabular-nums;
}
.conv {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-2);
  margin-top: 6px;
  min-height: 0;
}
.conv:empty {
  display: none;
}
.conv .pill {
  margin-top: 0;
}
.analyte-more {
  margin-top: 8px;
}
.analyte-more summary,
details.method summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}
.analyte-more[open] summary {
  margin-bottom: 8px;
}
.calc-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.85rem;
  color: var(--info);
  background: var(--info-soft);
  border-radius: 10px;
  padding: 10px 12px;
}
.calc-note:empty {
  display: none;
}

/* extra labs + meds */
.extra-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  position: relative;
}
.extra-row .icon-btn {
  position: absolute;
  right: -8px;
  top: 4px;
}
.extra-row > :first-child {
  grid-column: 1 / -1;
  margin-right: 36px;
}
@media (min-width: 700px) {
  .extra-row {
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 40px;
    border-bottom: 0;
    padding: 4px 0;
  }
  .extra-row > :first-child {
    grid-column: auto;
    margin-right: 0;
  }
  .extra-row .icon-btn {
    position: static;
  }
}
.med-row {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 4px 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 8px;
}
.med-cat {
  grid-column: 1;
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.med-row .icon-btn {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.med-fields {
  grid-column: 1;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr;
}
@media (min-width: 480px) {
  .med-fields {
    grid-template-columns: 1fr 1fr;
  }
}
.dose {
  display: flex;
  gap: 6px;
  min-width: 0;
}
.dose > .input:first-child {
  flex: 1 1 auto;
  min-width: 64px;
}
.dose > .input-unit {
  min-width: 84px;
}
.meds {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text-2);
  font-size: 0.92rem;
}

/* ratings */
.rating-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rating-value {
  min-width: 2ch;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.rating-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}
.rating.unset .range {
  opacity: 0.45;
}
.range {
  flex: 1;
  accent-color: var(--accent);
  min-height: 32px;
}
.change-list {
  display: grid;
  gap: 10px;
}
@media (min-width: 760px) {
  .change-list {
    grid-template-columns: 1fr 1fr;
  }
}
.change-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.change-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.ratings {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  margin: 12px 0 0;
}
.rating-item dt {
  font-size: 0.82rem;
  color: var(--text-2);
}
.rating-item dd {
  margin: 2px 0 0;
}
.meter {
  --v: 0;
  display: block;
  position: relative;
  height: 20px;
  border-radius: 6px;
  background: var(--accent-soft);
  overflow: hidden;
}
.meter::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--v) * 10%);
  background: var(--accent);
  border-radius: 6px;
  opacity: 0.85;
}
.meter-num {
  position: relative;
  font-size: 0.75rem;
  font-weight: 650;
  padding-left: 8px;
  line-height: 20px;
  color: var(--text);
  mix-blend-mode: normal;
}
.rating-note {
  display: block;
  font-size: 0.85rem;
  color: var(--text-2);
  margin-top: 2px;
}

/* chips select (hair areas) */
.chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.chip-toggle {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font: 500 0.85rem var(--font);
  cursor: pointer;
}
.chip-toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- dashboard ---------- */
.hero {
  padding: 22px 20px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
  border: 1px solid var(--border);
}
.hero-kicker {
  margin: 0;
  color: var(--text-2);
  font-weight: 550;
}
.hero-value {
  margin: 4px 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.hero-value small {
  font-size: 0.45em;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0;
}
.hero-value-sm {
  font-size: 1.5rem;
}
.hero-sub {
  margin: 0;
  color: var(--muted);
}
.quick-add {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
@media (min-width: 700px) {
  .quick-add {
    grid-template-columns: repeat(6, 1fr);
  }
}
.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: 550 0.8rem var(--font);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.quick-btn .icon {
  color: var(--accent);
}
.quick-btn:hover {
  border-color: var(--accent);
}
.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 760px) {
  .tiles {
    grid-template-columns: repeat(4, 1fr);
  }
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  min-width: 0;
}
.tile:hover {
  border-color: var(--border-strong);
}
.tile-label {
  font-size: 0.8rem;
  color: var(--text-2);
  font-weight: 550;
}
.tile-value {
  font-size: 1.25rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.tile-sub {
  font-size: 0.78rem;
  color: var(--muted);
}
.tile-warn {
  border-color: var(--warn);
  background: var(--warn-soft);
}
.tile-warn .tile-value {
  color: var(--warn);
}
.lab-values {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.lab-value {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
}
.lab-name {
  font-size: 0.8rem;
  color: var(--text-2);
  font-weight: 550;
}
.lab-num {
  font-size: 1.35rem;
  font-weight: 700;
}
.lab-unit {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}
.regimen h3 {
  margin-top: 14px;
  font-size: 0.9rem;
  color: var(--text-2);
}
.mini-title {
  font-size: 0.9rem;
  margin: 0 0 4px;
}
.insights {
  display: grid;
  gap: 10px;
}
@media (min-width: 900px) {
  .insights {
    grid-template-columns: 1fr 1fr;
  }
}
.insight {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.insight-attention {
  border-left-color: var(--warn);
}
.insight-ok {
  border-left-color: var(--ok);
}
.insight-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.insight-head h3 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}
.insight-badge {
  display: inline-flex;
  color: var(--info);
  margin-top: 1px;
}
.insight-attention .insight-badge {
  color: var(--warn);
}
.insight-ok .insight-badge {
  color: var(--ok);
}
.insight p {
  color: var(--text-2);
  font-size: 0.92rem;
}
.checklist {
  list-style: none;
  padding: 0;
  margin: 8px 0 12px;
}
.checklist li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.checklist label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}
.checklist li.done span {
  text-decoration: line-through;
  color: var(--muted);
}

/* claims & citations */
.claim {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.88rem;
}
.claim-compact {
  padding: 8px 10px;
  font-size: 0.82rem;
}
.claim-text {
  display: block;
  margin: 0 0 4px;
  color: var(--text-2);
}
q.claim-text {
  font-style: italic;
}
.claim-src {
  font-size: 0.8rem;
}
.cites {
  display: inline;
}
.cite {
  display: inline-block;
  margin-right: 8px;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.cite-loc {
  color: var(--muted);
}
.disclaimer {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 28px !important;
}
.callout {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--accent-soft);
  padding: 8px 12px;
  border-radius: 10px;
}

/* ---------- tables ---------- */
.table-scroll {
  /* Positioned so absolutely positioned children (e.g. .sr-only headers) stay inside
     the scroll box instead of widening the page. */
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.table th,
.table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th {
  font-weight: 600;
  color: var(--text-2);
  font-size: 0.8rem;
}
.table th.num,
.table td.num {
  text-align: right;
  white-space: nowrap;
}
.row-reached td:first-child {
  font-weight: 650;
}
.row-reached {
  background: var(--accent-soft);
}
.row-actions {
  white-space: nowrap;
  text-align: right;
}
.notes-cell {
  max-width: 220px;
  color: var(--text-2);
}
.footnotes {
  font-size: 0.8rem;
  color: var(--text-2);
  padding-left: 22px;
}
.kv {
  display: grid;
  gap: 6px 16px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  margin: 10px 0;
}
.kv-wide {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.kv dt {
  font-size: 0.78rem;
  color: var(--muted);
}
.kv dd {
  margin: 0;
  font-weight: 550;
}
.timeline {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}
.timeline li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.bra {
  font-size: 1.1rem;
}

/* ---------- labs ---------- */
.lab-card .lab-values {
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}

/* ---------- photos ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 8px !important;
}
@media (min-width: 900px) {
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}
.photo-tile {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
}
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 4px;
  padding: 20px 6px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  color: #fff;
  font-size: 0.75rem;
  text-align: left;
}
.photo-cap .badge {
  background: rgba(255, 255, 255, 0.9);
  color: #3b2150;
}
.photo-cap .badge-pre {
  color: #6b4500;
}
.photo-pose {
  opacity: 0.9;
}
.photo-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
  margin-top: 10px;
  scroll-snap-type: x mandatory;
}
.strip-thumb {
  flex: 0 0 auto;
  width: 84px;
  height: 112px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  scroll-snap-align: start;
}
.strip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-sources {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.source-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 0.85rem var(--font);
  text-align: left;
  cursor: pointer;
}
.source-btn .icon {
  color: var(--accent);
}
.source-btn span {
  color: var(--muted);
}
.source-btn:hover {
  border-color: var(--accent);
}
.add-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.add-item {
  display: grid;
  grid-template-columns: 96px 1fr 40px;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-2);
  align-items: start;
}
.add-thumb {
  width: 96px;
  height: 128px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-3);
}
.add-thumb-bad {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  text-align: center;
  color: var(--muted);
}
.add-fields {
  display: grid;
  gap: 8px;
}

/* viewer */
.modal-viewer .modal-body {
  display: flex;
  flex-direction: column;
  padding: 0;
}
.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  touch-action: pan-y;
}
.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
}
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
}
.viewer-nav:hover {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
}
.viewer-nav.prev {
  left: 10px;
}
.viewer-nav.next {
  right: 10px;
}
.viewer-info {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: grid;
  gap: 4px;
}
.viewer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* compare */
.compare-controls {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  align-items: end;
}
@media (min-width: 760px) {
  .compare-controls {
    grid-template-columns: 1fr 1fr auto;
  }
}
.compare-between {
  text-align: center;
  color: var(--text-2);
  font-weight: 600;
  margin: 10px 0;
}
.compare-stage.side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.compare-stage figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.compare-stage img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  background: #000;
  border-radius: 10px;
}
.compare-stage figcaption {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}
.slider-box {
  position: relative;
  margin: 0 auto;
  max-width: min(640px, 55vh);
  touch-action: none;
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
.slider-box img {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
  border-radius: 0;
  pointer-events: none;
}
.slider-top {
  position: absolute;
  inset: 0;
}
.slider-top img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.slider-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: #fff;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.slider-range {
  display: block;
  width: 100%;
  max-width: min(640px, 55vh);
  margin: 10px auto;
}
.slider-caps {
  display: flex;
  justify-content: space-between;
  max-width: min(640px, 55vh);
  margin: 0 auto;
}
.slider-caps figcaption:last-child {
  text-align: right;
}

/* camera */
.modal-camera .modal-body {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: #000;
}
.cam-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.cam-video,
.cam-ghost {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cam-ghost {
  pointer-events: none;
}
.cam-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.cam-controls {
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
  color: #fff;
  background: #000;
}
.cam-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.cam-ctl {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.14) !important;
  border-color: transparent !important;
}
.cam-ctl[aria-pressed='true'] {
  background: rgba(255, 255, 255, 0.32) !important;
}
.cam-ghost-ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
.shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  box-shadow: inset 0 0 0 3px #000;
}
.shutter:active {
  transform: scale(0.94);
}

/* hair */
.area-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.area-card {
  display: flex;
  gap: 12px;
}
.area-thumb {
  flex: 0 0 90px;
  height: 120px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
}
.area-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.area-body {
  flex: 1;
  min-width: 0;
}
.big-num {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
  margin: 6px 0;
}

/* ---------- charts ---------- */
.chart-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 1000px) {
  .chart-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.small-multiples {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.chart {
  margin: 0;
  position: relative;
}
.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 6px;
}
.chart-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.chart-title h3 {
  margin: 0;
  font-size: 0.98rem;
}
.chart-unit {
  font-size: 0.78rem;
  color: var(--muted);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  width: 100%;
  font-size: 0.78rem;
  color: var(--text-2);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-key {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}
.legend-band {
  width: 14px;
  height: 10px;
  background: var(--band);
  border-top: 1px solid var(--band-edge);
  border-bottom: 1px solid var(--band-edge);
}
.legend-marker {
  width: 0;
  height: 12px;
  border-left: 1.5px dashed var(--series-7);
}
.legend-band-lab,
.legend-band-personal {
  background: none;
  border: 1.25px dashed var(--series-7);
}
.legend-band-personal {
  border-color: var(--series-1);
}
.legend-threshold {
  width: 14px;
  height: 0;
  border-top: 2px dashed var(--threshold);
}
.chart-plot {
  position: relative;
  width: 100%;
  touch-action: pan-y;
}
.chart-svg {
  display: block;
  overflow: visible;
}
.chart-svg:focus-visible {
  outline: 2px solid var(--focus);
  border-radius: 6px;
}
.chart-svg .grid {
  stroke: var(--grid);
  stroke-width: 1;
}
.chart-svg .axis {
  stroke: var(--axis);
  stroke-width: 1;
}
.chart-svg .tick {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.chart-svg .band {
  fill: var(--band);
}
.chart-svg .band-lab,
.chart-svg .band-personal {
  fill: none;
  stroke: var(--series-7);
  stroke-width: 1.25;
  stroke-dasharray: 4 3;
}
.chart-svg .band-personal {
  stroke: var(--series-1);
}
.chart-svg .regimen-span {
  fill: var(--accent-soft);
}
.chart-svg .regimen-span.alt {
  fill: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
}
.chart-svg .regimen-label {
  fill: var(--text-2);
  font-size: 10.5px;
  font-weight: 600;
  font-family: var(--font);
}
.chart-note {
  margin: 8px 0 0;
  font-size: 0.86rem;
  color: var(--text-2);
}
.chart-svg .threshold {
  stroke: var(--threshold);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}
.chart-svg .marker {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.7;
}
.chart-svg .marker-regimen {
  stroke: var(--series-7);
  opacity: 0.8;
}
.chart-svg .marker-label {
  fill: var(--muted);
  font-size: 10px;
  font-family: var(--font);
}
.chart-svg .line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-svg .dot {
  stroke: var(--surface-1);
  stroke-width: 2;
}
.chart-svg .dot-qualified {
  stroke-width: 2;
}
.chart-svg .crosshair {
  stroke: var(--text-2);
  stroke-width: 1;
  opacity: 0.5;
}
.chart-svg .focus-ring {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.5;
}
.chart-svg .hit {
  fill: transparent;
  cursor: crosshair;
}
.chart-mini .chart-svg .tick {
  font-size: 10px;
}
.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
}
.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 140px;
  max-width: 260px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 0.8rem;
  pointer-events: none;
}
.tip-date {
  color: var(--muted);
  margin-bottom: 2px;
}
.tip-row strong {
  font-size: 0.95rem;
}
.tip-key {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}
.tip-name {
  margin-left: 6px;
  color: var(--text-2);
}
.tip-detail {
  color: var(--text-2);
}
.chart-table {
  position: relative;
  margin-top: 10px;
  overflow-x: auto;
}

/* ---------- tools ---------- */
.tool-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-items: start;
}
.tool-grid .card > * + * {
  margin-top: 10px;
}
.result {
  font-size: 1rem;
  font-weight: 600;
}
.result .big-num {
  font-size: 1.8rem;
}
.formula {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--surface-2);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
}
.conv-table .table td {
  padding: 4px 6px;
}

/* ---------- settings ---------- */
.settings-section > * + * {
  margin-top: 12px;
}
.section-danger {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}
.toggle-list {
  display: grid;
  gap: 2px;
}
@media (min-width: 760px) {
  .toggle-list {
    grid-template-columns: 1fr 1fr;
    column-gap: 20px;
  }
}
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 40px;
}
.toggle-row label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.add-cat {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  align-items: end;
}
@media (min-width: 700px) {
  .add-cat {
    grid-template-columns: 2fr 1fr 1fr auto;
  }
}
.backup-actions {
  display: grid;
  gap: 10px;
}
.link-list li {
  margin: 4px 0;
}
.biblio li {
  margin-bottom: 8px;
  font-size: 0.9rem;
}

/* onboarding */
.onboarding {
  max-width: 560px;
  margin: 0 auto;
  padding-top: 24px;
  text-align: left;
}
.onboarding-logo {
  border-radius: 16px;
}
.lead {
  font-size: 1.1rem;
  color: var(--text-2);
}
.features {
  list-style: none;
  padding: 0;
}
.features li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 8px 0;
  color: var(--text-2);
}
.features .icon {
  color: var(--accent);
  margin-top: 2px;
}
.onboarding .card > * + * {
  margin-top: 14px;
}
.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.choice {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 0.9rem var(--font);
  text-align: left;
  cursor: pointer;
}
.choice span {
  color: var(--muted);
  font-size: 0.8rem;
}
.choice.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* empty */
.empty {
  text-align: center;
  padding: 40px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-2);
}
.empty .icon {
  color: var(--accent);
  margin-bottom: 8px;
}
.empty p {
  max-width: 440px;
  margin: 0 auto 16px;
}

/* ---------- modal ---------- */
dialog.modal {
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  max-height: calc(100vh - 48px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  flex-direction: column;
}
@supports (height: 100dvh) {
  dialog.modal {
    max-height: calc(100dvh - 48px);
  }
}
dialog.modal[open] {
  display: flex;
  animation: pop 0.16s ease;
}
dialog.modal::backdrop {
  background: rgba(10, 5, 15, 0.45);
}
.modal-wide {
  width: min(900px, calc(100vw - 32px)) !important;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  margin: 0;
  font-size: 1.1rem;
}
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.modal-foot.inline {
  border-top: 0;
  padding: 16px 0 0;
}
dialog.modal-full {
  width: 100vw !important;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: none !important;
  border-radius: 0;
  margin: 0;
}
.modal-full .modal-head {
  padding-top: calc(12px + env(safe-area-inset-top));
}
.modal-camera,
.modal-viewer {
  background: #000 !important;
  color: #fff !important;
}
.modal-camera .modal-head,
.modal-viewer .modal-head {
  border-color: rgba(255, 255, 255, 0.12);
}
.modal-camera .icon-btn,
.modal-viewer .modal-head .icon-btn {
  color: #fff;
}
.modal-viewer .viewer-info {
  background: var(--surface);
  color: var(--text);
}
@keyframes pop {
  from {
    transform: scale(0.97);
    opacity: 0;
  }
}
@media (max-width: 640px) {
  dialog.modal:not(.modal-full) {
    width: 100vw !important;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    max-height: calc(100vh - 24px);
    animation: up 0.2s ease;
  }
  @supports (height: 100dvh) {
    dialog.modal:not(.modal-full) {
      max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
    }
  }
  .modal-body {
    padding: 16px;
  }
}

/* toasts */
.toasts {
  position: fixed;
  z-index: 1000;
  inset: auto auto auto 50%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
@media (max-width: 760px) {
  .toasts {
    bottom: calc(var(--bottombar-h) + var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  }
}
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  pointer-events: auto;
  animation: up 0.2s ease;
  transition: opacity 0.3s, transform 0.3s;
}
.toast .btn-text {
  color: var(--accent-soft);
  min-height: 0;
  padding: 4px 8px;
}
.toast-error {
  background: var(--danger);
  color: #fff;
}
.toast-success {
  background: var(--ok);
  color: #fff;
}
:root[data-theme='dark'] .toast-success,
:root[data-theme='dark'] .toast-error {
  color: #10100f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .toast-success,
  :root:not([data-theme='light']) .toast-error {
    color: #10100f;
  }
}
.toast.out {
  opacity: 0;
  transform: translateY(8px);
}

/* ---------- report / print ---------- */
.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.report-toolbar p {
  margin: 0;
  flex: 1 1 300px;
}
.report section,
.report header,
.report footer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.report-charts {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 760px) {
  .report-charts {
    grid-template-columns: 1fr;
  }
}
.report-foot ol {
  font-size: 0.8rem;
  padding-left: 18px;
}
.report-foot a,
.biblio li,
.claim-text {
  overflow-wrap: anywhere;
}

@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --surface-1: #fff;
    --text: #000;
    --text-2: #222;
    --muted: #555;
    --border: #ccc;
  }
  body {
    background: #fff;
    font-size: 11pt;
  }
  .topbar,
  .rail,
  .section-tabs,
  .no-print,
  .toasts,
  .skip-link,
  .chart-head .btn {
    display: none !important;
  }
  .main {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none;
  }
  .report section,
  .report header,
  .report footer {
    border: 0;
    padding: 0 0 10pt;
    break-inside: avoid;
  }
  .report-charts {
    grid-template-columns: 1fr 1fr;
  }
  .table-scroll {
    overflow: visible;
  }
  a {
    color: #000;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
@media (forced-colors: active) {
  .chart-svg .line {
    stroke: CanvasText !important;
  }
  .chart-svg .band {
    fill: Highlight;
    opacity: 0.2;
  }
}

/* ---------- spreadsheet import ---------- */
.import > * + * {
  margin-top: 14px;
}
.import-options {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
}
.import-columns summary {
  cursor: pointer;
  font-weight: 600;
}
.import-columns[open] summary {
  margin-bottom: 8px;
}
.import-map th {
  width: 45%;
  font-weight: 550;
  color: var(--text);
  font-size: 0.88rem;
}
.import-map td > * + * {
  margin-top: 6px;
}
.col-header {
  white-space: pre-line;
}
.col-sample {
  font-weight: 400;
  overflow-wrap: anywhere;
}
.col-ignored th {
  color: var(--muted);
}
.import-preview td,
.import-preview th {
  white-space: nowrap;
}
.import-preview td.small {
  white-space: normal;
  min-width: 160px;
}
.import-preview tr.st-skip td,
.import-preview tr.st-duplicate td {
  color: var(--muted);
}
.import-msg {
  white-space: normal;
  font-size: 0.78rem;
  color: var(--warn);
  max-width: 240px;
}
.pill-info {
  background: var(--info-soft);
  color: var(--info);
}
.pill-muted {
  background: var(--surface-2);
  color: var(--muted);
}

.more-exports summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 10px;
}
.more-exports[open] summary {
  margin-bottom: 8px;
}

/* ---------- published timeframes (progress bars) ---------- */
.tf-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 0.8rem;
  color: var(--text-2);
}
.tf-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tf-key {
  display: inline-block;
  width: 16px;
  height: 8px;
  border-radius: 3px;
}
.tf-key-onset {
  background: color-mix(in srgb, var(--series-1) 45%, transparent);
}
.tf-key-max {
  background: color-mix(in srgb, var(--series-3) 55%, transparent);
}
.tf-key-you {
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--text);
}
.tf-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 14px;
}
.tf-row {
  display: grid;
  gap: 5px;
}
.tf-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 10px;
}
.tf-bar {
  position: relative;
  height: 12px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}
.tf-bar > span {
  position: absolute;
  top: 0;
  bottom: 0;
}
.tf-progress {
  left: 0;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.tf-onset {
  background: color-mix(in srgb, var(--series-1) 45%, transparent);
  border-radius: 6px;
}
.tf-max {
  background: color-mix(in srgb, var(--series-3) 55%, transparent);
  border-radius: 6px;
}
.tf-open {
  border-radius: 6px 0 0 6px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--series-3) 55%, transparent), transparent);
}
.tf-you {
  width: 3px;
  margin-left: -1.5px;
  background: var(--text);
  border-radius: 2px;
}
.tf-status {
  color: var(--text-2);
}
.tf-nobar .tf-status {
  color: var(--muted);
}
.tf-axis {
  position: relative;
  height: 18px;
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}
.tf-axis span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}
.tf-axis span:first-child {
  transform: none;
}
.tf-axis span:last-child {
  transform: translateX(-100%);
}

.compare-line {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--text-2);
}

.card-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.card-derived {
  background: color-mix(in srgb, var(--surface) 70%, var(--surface-2));
}
.badge-auto {
  background: var(--info-soft);
  color: var(--info);
}
.schedule-btn {
  margin-top: 6px;
}

.target-list {
  display: grid;
  gap: 8px;
}
.target-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px auto 80px auto;
  align-items: center;
  gap: 6px;
}
.target-name {
  font-weight: 550;
  font-size: 0.9rem;
}
@media (max-width: 520px) {
  .target-row {
    grid-template-columns: 1fr auto 1fr auto;
  }
  .target-name {
    grid-column: 1 / -1;
  }
}

/* Tables that become stacked cards on phones (cells carry data-label). */
@media (max-width: 560px) {
  .table-stack thead {
    display: none;
  }
  .table-stack,
  .table-stack tbody,
  .table-stack tr {
    display: block;
    width: 100%;
  }
  .table-stack tr {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .table-stack th[scope='row'] {
    grid-column: 1 / -1;
    padding: 0;
    border: 0;
    color: var(--text);
  }
  .table-stack td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 0;
    border: 0;
    white-space: normal;
  }
  .table-stack td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    color: var(--muted);
  }
}

.grid-2.tight-gap {
  gap: 8px;
}

@media (max-width: 400px) {
  .brand-name {
    display: none;
  }
}
