/* Data share (#523): the viewer's screen at punnbaby.app/s.
   Two jobs: a pairing screen that reads as intentional on a shared
   desktop and scans easily from a phone, and a data-first viewer designed
   for desktop, tablet and phone alike (an overview, plus a focus page per
   category, and an A4 print layout). Palette: the Dusk tokens
   (website/css/style.css :root), in their accessible deep variants. */

:root {
  --coral: #C97870;
  --coral-deep: #9F5950;
  --coral-ink: #4A1F1A;
  --coral-wash: rgba(201, 120, 112, 0.12);
  --ink: #26150F;
  --ink-2: #4A4438;
  --ink-3: #74695D;
  --line: #EADFD1;
  --line-2: #F2EADF;
  --paper: #FFFFFF;
  --canvas: #FBF7EE;
  --bg-top: #F9D4C8;
  --bg-bot: #F4EDD9;

  /* Category accents (deep enough for 3:1 on white as graphics). */
  --c-feeding: #C97870;
  --c-sleep: #7D70AE;
  --c-diapers: #5E9474;
  --c-growth: #5D7FAA;
  --c-milestones: #A98639;
  --c-teeth: #4E8C86;
  --c-health: #9F5950;
  --c-medications: #B5603F;
  --c-pumping: #8B6F8E;
  --who-band: rgba(93, 127, 170, 0.16);

  /* The same hues one step deeper: text and numbers set on a filled shape
     (tooth numbers, badges) reach 4.5:1 against white. */
  --s-feeding: #A85A52;
  --s-sleep: #5F5391;
  --s-diapers: #3F7557;
  --s-growth: #44648C;
  --s-milestones: #86691F;
  --s-teeth: #3A716B;
  --s-health: #9F5950;
  --s-medications: #94492B;
  --s-pumping: #6F5572;

  --radius: 14px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgba(38, 21, 15, 0.04), 0 8px 24px rgba(38, 21, 15, 0.06);
  --body-font: 'Inter', 'Noto Sans Punn', system-ui, -apple-system,
    'Segoe UI', sans-serif;
  --head-font: 'Nunito', var(--body-font);
  --mono-font: ui-monospace, 'SF Mono', 'Roboto Mono', Menlo, Consolas,
    monospace;
}

/* Script faces are named only for the report's own locale, so a Latin
   summary never downloads the large CJK / Indic files. */
[data-script='arabic'] { --script: 'Noto Sans Arabic Punn'; }
[data-script='hebrew'] { --script: 'Noto Sans Hebrew Punn'; }
[data-script='thai'] { --script: 'Noto Sans Thai Punn'; }
[data-script='lao'] { --script: 'Noto Sans Lao Punn'; }
[data-script='jp'] { --script: 'Noto Sans JP Punn'; }
[data-script='kr'] { --script: 'Noto Sans KR Punn'; }
[data-script='sc'] { --script: 'Noto Sans SC Punn'; }
[data-script='devanagari'] { --script: 'Noto Sans Devanagari Punn'; }
[data-script='bengali'] { --script: 'Noto Sans Bengali Punn'; }
[data-script='gujarati'] { --script: 'Noto Sans Gujarati Punn'; }
[data-script='gurmukhi'] { --script: 'Noto Sans Gurmukhi Punn'; }
[data-script='kannada'] { --script: 'Noto Sans Kannada Punn'; }
[data-script='malayalam'] { --script: 'Noto Sans Malayalam Punn'; }
[data-script='tamil'] { --script: 'Noto Sans Tamil Punn'; }
[data-script='telugu'] { --script: 'Noto Sans Telugu Punn'; }
[data-script='sinhala'] { --script: 'Noto Sans Sinhala Punn'; }
[data-script] {
  --body-font: 'Inter', var(--script), 'Noto Sans Punn', system-ui, sans-serif;
  --head-font: 'Nunito', var(--body-font);
  font-family: var(--body-font);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--body-font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

h1, h2, h3 { font-family: var(--head-font); line-height: 1.2; margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* The focus page and print pages come and go with the route, on screen only:
   a print always shows the overview, then every category's page. */
@media screen { .is-hidden { display: none !important; } }
#print-pages { display: none; }

:focus-visible { outline: 3px solid var(--coral-deep); outline-offset: 2px; border-radius: 6px; }

.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; }
.brand-name {
  font-family: var(--head-font);
  font-weight: 800;
  font-size: 19px;
  color: var(--coral-deep);
}
.brand-tag { font-size: 14px; color: var(--ink-3); font-weight: 500; }

.primary-btn, .ghost-btn {
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
}
.primary-btn {
  padding: 0 24px;
  color: #fff;
  background: var(--coral-deep);
  border: 0;
  font-size: 16px;
  min-height: 52px;
}
.primary-btn:hover { background: #8A4B43; }
.ghost-btn {
  padding: 0 18px;
  font-size: 14px;
  color: var(--coral-deep);
  background: transparent;
  border: 1.5px solid rgba(159, 89, 80, 0.45);
}
.ghost-btn:hover { background: var(--coral-wash); }

/* ═══════════════════ Pairing ═══════════════════ */

body[data-view='pairing'], body[data-view='msg'], body[data-view='loading'] {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(249, 212, 200, 0.95), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(230, 168, 158, 0.35), transparent 60%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bot) 70%);
  min-height: 100vh;
}

.pairing { min-height: 100vh; display: flex; flex-direction: column; }

.pair-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 32px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}
.pair-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.8);
  padding: 6px 12px;
  border-radius: 999px;
}
.pair-badge svg, .pair-privacy svg {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round;
}

.pair-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 440px);
  align-items: center;
  gap: 64px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 32px 40px;
}

.pair-intro h1 {
  font-size: clamp(34px, 3.4vw, 50px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  max-width: 14ch;
}
.pair-lede {
  font-size: 18px;
  color: var(--ink-2);
  margin: 16px 0 28px;
  max-width: 34em;
}

.pair-steps { list-style: none; padding: 0; margin: 0 0 28px; display: grid; gap: 14px; }
.pair-steps li { display: flex; gap: 14px; align-items: center; }
.step-visual { position: relative; flex: none; width: 64px; height: 64px; }
.step-art { display: block; width: 64px; height: 64px; }
.step-visual .step-n {
  position: absolute; top: -6px; left: -6px;
  width: 26px; height: 26px; font-size: 13px;
  color: var(--paper);
  background: var(--coral-deep);
  box-shadow: 0 0 0 2px var(--paper);
}
.step-n {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--head-font);
  font-weight: 800;
  color: var(--coral-deep);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 0 0 1.5px rgba(159, 89, 80, 0.25);
}
.pair-steps strong { display: block; font-size: 16px; color: var(--ink); }
.step-sub { display: block; color: var(--ink-3); font-size: 14px; }

.pair-privacy {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  max-width: 34em;
  font-size: 14px;
  color: var(--ink-2);
}
.pair-privacy svg { margin-top: 2px; color: var(--coral-deep); }

.pair-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  box-shadow: 0 30px 60px rgba(74, 31, 26, 0.12), 0 2px 6px rgba(74, 31, 26, 0.06);
  padding: 32px 32px 26px;
  text-align: center;
}
.qr-frame {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 18px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
  padding: 10px;
}
.qr svg { display: block; width: 100%; height: 100%; }
.qr .qr-ink { fill: var(--ink); }
.qr-refresh {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 18px;
}
.spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--coral-deep);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.code-label { margin: 22px 0 4px; font-size: 14px; color: var(--ink-3); font-weight: 500; }
.pair-code {
  margin: 0;
  font-family: var(--mono-font);
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
}
.pair-code .gap { display: inline-block; width: 0.45em; }

.pair-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 12px;
  font-weight: 600;
  color: var(--ink-2);
}
.pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c-diapers);
  box-shadow: 0 0 0 0 rgba(94, 148, 116, 0.5);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(94, 148, 116, 0.45); }
  100% { box-shadow: 0 0 0 12px rgba(94, 148, 116, 0); }
}
.pair-timer {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  font-size: 13px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.pair-timer .bar {
  width: 120px; height: 4px; border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
.pair-timer .bar span {
  display: block; height: 100%; width: 100%;
  background: var(--coral);
  transform-origin: left;
}
.pair-tip { margin: 14px 0 0; font-size: 12.5px; color: var(--ink-3); }

.pair-foot {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0 32px 24px;
  font-size: 12.5px;
  color: var(--ink-3);
}

/* Tablet: the code card leads, the explanation follows. */
@media (max-width: 1023px) {
  .pair-main {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
    max-width: 640px;
    padding-top: 8px;
  }
  .pair-intro { order: 2; }
  .pair-intro h1 { max-width: none; font-size: 32px; }
  .pair-card { order: 1; }
}

/* Phone: the QR as large as the screen allows, the code under it. */
@media (max-width: 560px) {
  .pair-top { padding: 14px 16px; }
  .brand-tag { display: none; }
  .pair-main { padding: 4px 14px 24px; gap: 24px; }
  .pair-card { padding: 18px 16px 20px; border-radius: 24px; }
  .qr-frame { max-width: none; padding: 8px; }
  .pair-code { font-size: 38px; letter-spacing: 0.1em; }
  .pair-intro h1 { font-size: 26px; }
  .pair-lede { font-size: 16px; margin: 10px 0 20px; }
  .pair-foot { padding: 0 16px 20px; }
}

/* ═══════════════════ Messages ═══════════════════ */

.msg-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.msg-card {
  width: 100%;
  max-width: 480px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 28px;
  box-shadow: 0 30px 60px rgba(74, 31, 26, 0.12);
  padding: 40px 32px 32px;
  text-align: center;
}
.msg-icon {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--coral-wash);
  color: var(--coral-deep);
}
.msg-icon svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.msg-card h1 { font-size: 26px; font-weight: 800; }
.msg-card h1:focus { outline: none; }
.msg-card p { color: var(--ink-2); margin: 10px 0 24px; }
.msg-card .primary-btn { width: 100%; }

/* ═══════════════════ Viewer ═══════════════════ */

body[data-view='viewer'] { background: var(--canvas); }

.viewer {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

/* Rail (desktop) */
.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 20px;
  background: linear-gradient(180deg, #FFF6F1 0%, #FBF3E6 100%);
  border-inline-end: 1px solid var(--line);
}
.rail-name { margin: 0; font-family: var(--head-font); line-height: 1.2; font-size: 22px; font-weight: 800; }
.muted-name { color: var(--ink-3); font-style: italic; font-weight: 600; }
.rail-name.muted-name { font-size: 18px; }
.facts { margin: 12px 0 0; display: grid; gap: 8px; }
.facts div { min-width: 0; }
.facts dt {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.facts dd { margin: 0; font-weight: 600; }

.rail-nav { display: grid; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 600;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.8); }
.nav-link[aria-current='page'] { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
/* The card being read on the overview: a lighter mark than the open page. */
.nav-link[aria-current='location'] { background: rgba(255, 255, 255, 0.6); color: var(--ink); }
.acc-overview { --accent: var(--coral-deep); }
.acc-feeding { --accent: var(--c-feeding); --accent-strong: var(--s-feeding); }
.acc-sleep { --accent: var(--c-sleep); --accent-strong: var(--s-sleep); }
.acc-diapers { --accent: var(--c-diapers); --accent-strong: var(--s-diapers); }
.acc-growth { --accent: var(--c-growth); --accent-strong: var(--s-growth); }
.acc-milestones { --accent: var(--c-milestones); --accent-strong: var(--s-milestones); }
.acc-teeth { --accent: var(--c-teeth); --accent-strong: var(--s-teeth); }
.acc-health { --accent: var(--c-health); --accent-strong: var(--s-health); }
.acc-medications { --accent: var(--c-medications); --accent-strong: var(--s-medications); }
.acc-pumping { --accent: var(--c-pumping); --accent-strong: var(--s-pumping); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent, var(--coral)); flex: none; }

.rail-foot { margin-top: auto; display: grid; gap: 8px; }
.access {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.access::before {
  content: '';
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c-diapers);
}

/* Board */
.board { padding: 28px 36px 40px; min-width: 0; max-width: 1240px; }
.board-head { display: none; }
.chips { display: none; }
.board-title {
  font-size: 13px;
  font-family: var(--body-font);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin: 0 0 12px;
}

/* The dates being read: a period dropdown, a custom range, and the result. */
.range-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  padding: 10px 14px;
  margin-bottom: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.range-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.range-select, .range-bar input[type='date'] {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  min-height: 40px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid rgba(159, 89, 80, 0.45);
  border-radius: 10px;
}
/* The native chevron sits inside the padding box and, with this 12px padding,
   lands on the label in Safari. Draw our own (--coral-deep, inlined because a
   data: URI cannot read custom properties) and reserve room for it. */
.range-select {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  -webkit-appearance: none;
  appearance: none;
  padding-inline-end: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239F5950' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
[dir='rtl'] .range-select { background-position: left 12px center; }
.range-custom { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.range-custom[hidden] { display: none; }
.range-text {
  margin: 0;
  margin-inline-start: auto;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.glance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.kpi {
  display: block;
  color: inherit;
  text-decoration: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 14px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.kpi:hover { border-color: #DCCDBB; box-shadow: var(--shadow); }
.kpi::before {
  content: '';
  position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 4px;
  background: var(--accent);
}
.kpi-cat { font-size: 12.5px; font-weight: 700; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi-value {
  font-family: var(--head-font);
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.kpi-value small { font-size: 15px; font-weight: 700; color: var(--ink-2); margin-inline-start: 3px; }
.kpi-label { font-size: 12.5px; color: var(--ink-3); }
.kpi-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.trend-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin-top: 8px; }
.trend-note { font-size: 11.5px; color: var(--ink-3); }
.trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--line-2);
  border-radius: 999px;
  padding: 2px 8px;
}

.cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: row dense;
  align-items: start;
  gap: 18px;
}
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  min-width: 0;
  scroll-margin-top: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 9px; }
.card-head h2 .dot { width: 11px; height: 11px; }
.tracked { font-size: 12.5px; color: var(--ink-3); }

/* A card title and "All entries" lead to the category's focus page. */
.card-link, .card-more, .back-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}
.card-link:hover { color: var(--coral-deep); }
.card-more, .back-link {
  gap: 6px;
  min-height: 44px;
  font-weight: 700;
  font-size: 14px;
  color: var(--coral-deep);
}
.card-more { display: flex; margin-top: 6px; border-top: 1px solid var(--line-2); }
.chev {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}
.card-link .chev { color: var(--ink-3); }
.card-link:hover .chev { color: var(--coral-deep); }
[dir='rtl'] .chev { transform: scaleX(-1); }
.back-link .chev { transform: scaleX(-1); }
[dir='rtl'] .back-link .chev { transform: none; }

.stats { display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 14px 0 6px; }
.stat-value { font-family: var(--head-font); font-size: 22px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--ink-3); }
.stat-sub { font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.stat .trend-row { margin-top: 4px; }

.empty { color: var(--ink-3); font-style: italic; margin: 12px 0 0; }

/* Charts */
.chart-wrap { position: relative; margin: 10px 0 4px; }
.chart { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--line-2); stroke-width: 1; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 11px; font-family: var(--body-font); }
.chart { direction: ltr; }  /* time runs left to right in every language */
.chart .bar { opacity: 0.9; }
.chart .bar.partial { opacity: 0.45; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .bar, .chart .point { pointer-events: none; }
.chart .bar.on { opacity: 1; }
.chart .band-row { fill: rgba(38, 21, 15, 0.04); }
.chart .axis-label.strong { fill: var(--ink-2); font-weight: 600; }
.chart .who-label { font-size: 10.5px; }
.chart .tooth-n { font-family: var(--head-font); font-size: 12px; font-weight: 800; pointer-events: none; }
.tooth-map { display: block; width: 100%; max-width: 600px; height: auto; margin: 4px auto 0; }
.chart .avg { stroke: var(--ink-2); stroke-width: 1.25; stroke-dasharray: 5 4; }
.chart .avg-label {
  fill: var(--ink-2); font-size: 11px; font-weight: 700;
  paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round;
}
.chart-cap { margin: 8px 0 0; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.chart-note { font-size: 12px; color: var(--ink-3); margin: 2px 0 0; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { flex: none; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-inline-end: 5px; }
.legend .l-band { background: var(--who-band); }
.legend .l-series { height: 0; border-top: 2.5px solid var(--ink); border-radius: 0; vertical-align: 3px; }

/* Two or three exclusive choices (Count / Volume, Weight / Length / Head). */
.toggle { display: inline-flex; background: var(--line-2); border-radius: 999px; padding: 3px; gap: 2px; margin: 14px 0 4px; }
.panel-head .toggle { margin: 0; }
.toggle-btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.toggle-btn[aria-pressed='true'] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(38, 21, 15, 0.12); }

/* Lists (milestones, teeth, health) */
.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list li {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line-2);
}
.list li:first-child { border-top: 0; }
.list .when { color: var(--ink-3); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.list .what { font-weight: 600; }
.list .meta { display: block; font-weight: 400; color: var(--ink-2); font-size: 13.5px; }
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--coral-wash);
  color: var(--coral-ink);
  margin-inline-start: 6px;
}

/* Details on demand */
details.more { margin-top: 12px; border-top: 1px solid var(--line-2); }
details.more > summary {
  list-style: none;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--coral-deep);
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before {
  content: '';
  width: 7px; height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  margin: 0 4px 0 2px;
}
details.more[open] > summary::before { transform: rotate(45deg); }
[dir='rtl'] details.more > summary::before, [dir='rtl'] .day-toggle::before { transform: rotate(135deg); }
[dir='rtl'] details.more[open] > summary::before, [dir='rtl'] .day-toggle[aria-expanded='true']::before { transform: rotate(45deg); }
details.more > summary .count { color: var(--ink-3); font-weight: 500; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; overflow-wrap: normal; }
th, td { text-align: start; padding: 8px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { font-size: 11.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
td.num, th.num { text-align: end; }
td:first-child { white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FDFAF5; }

/* A day in a table that expands to that day's individual entries. */
.day-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 700;
  color: var(--coral-deep);
  cursor: pointer;
  text-align: start;
}
.day-toggle::before {
  content: '';
  width: 6px; height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  margin: 0 3px 0 1px;
  flex: none;
}
.day-toggle[aria-expanded='true']::before { transform: rotate(45deg); }
.day-toggle .count { color: var(--ink-3); font-weight: 500; }
tbody tr:has(> td > .day-toggle) > td { vertical-align: middle; }
tr.day-entries[hidden] { display: none; }
tr.day-entries > td { padding: 0 0 10px; padding-inline-start: 14px; white-space: normal; font-weight: 400; background: #FDFAF5; }
.show-earlier { margin-top: 12px; }
/* A day table reads best at a measure that keeps a date near its numbers. */
.day-log .table-wrap { max-width: 760px; }
td.num + td { padding-inline-start: 24px; }
.delta-list span { display: block; white-space: nowrap; }
tr.day-entries .table-wrap { margin-top: 2px; }
tr.day-entries tbody tr:last-child td { border-bottom: 0; }

/* Stacked rows when a table can't fit its card (set by fitTables). */
@media screen {
  .table-wrap.stacked thead { display: none; }
  .table-wrap.stacked tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
  .table-wrap.stacked tbody tr:last-child { border-bottom: 0; }
  .table-wrap.stacked td { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; border: 0; text-align: end; white-space: normal; }
  .table-wrap.stacked td:first-child { font-weight: 700; text-align: start; }
  .table-wrap.stacked td::before { content: attr(data-label); flex: none; max-width: 50%; text-align: start; font-size: 12px; color: var(--ink-3); }
  .table-wrap.stacked td:first-child::before { content: none; }
  .table-wrap.stacked tr.day-entries > td { display: block; }
}

.board-foot { margin-top: 24px; font-size: 12.5px; color: var(--ink-3); max-width: 60em; }
.board-foot p { margin: 0 0 4px; }

/* Tooltip */
.tip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, calc(-100% - 10px));
}

/* ═══════════════════ Focus pages ═══════════════════ */

.focus-page { min-width: 0; }
.back-link { margin-bottom: 4px; }
.focus-head {
  background: var(--paper);
  border: 1px solid var(--line);
  border-inline-start: 5px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px 24px 22px;
}
.focus-head h1 { font-size: 30px; font-weight: 800; display: flex; align-items: center; gap: 11px; }
.focus-head h1:focus { outline: none; }
.focus-head h1 .dot { width: 13px; height: 13px; }
.focus-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  margin: 8px 0 0; font-size: 14px; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.days-chip {
  padding: 2px 10px; border-radius: 999px; background: var(--line-2);
  color: var(--ink-2); font-weight: 700; font-size: 12.5px;
}
.stats.big {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0 0;
}
.stats.big .stat {
  min-width: 0;
  padding: 12px 14px;
  background: #FFFBF4;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
}
.stats.big .stat-value { font-size: 28px; }
.stats.big .stat-label { font-size: 12.5px; margin-top: 2px; }

.panels { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; margin-top: 18px; }
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 22px 20px;
  min-width: 0;
}
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; }
.panel-title { font-size: 16px; font-weight: 800; }
.panel-note { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-3); }
.panels > .panel-note { grid-column: 1 / -1; margin: 0; }
.panel .legend { margin-top: 10px; }
.panel .chart-wrap { margin-top: 10px; }
.panel .table-wrap { margin-top: 6px; }

/* "By type" shares */
.share-bars { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 12px; }
.share-bars li { display: grid; grid-template-columns: minmax(70px, 34%) minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.sb-label { font-weight: 600; font-size: 14px; }
.sb-bar { display: block; width: 100%; height: 10px; border-radius: 6px; overflow: hidden; }
.sb-track { fill: var(--line-2); }
.sb-fill { fill: var(--accent); }
.sb-val { display: flex; justify-content: flex-end; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; white-space: nowrap; }
.sb-val small { color: var(--ink-3); font-weight: 600; font-size: 12.5px; }

/* Milestones: a vertical timeline grouped by month */
.timeline { display: grid; gap: 22px; }
.tl-month {
  margin: 0 0 6px; font-family: var(--body-font); font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3);
}
.tl-list { list-style: none; margin: 0; padding: 0; padding-inline-start: 24px; position: relative; }
.tl-list::before {
  content: ''; position: absolute; inset-block: 8px; inset-inline-start: 5px;
  width: 2px; border-radius: 2px; background: var(--line);
}
.tl-list li { position: relative; padding: 8px 0; }
.tl-dot {
  position: absolute; inset-inline-start: -24px; top: 13px; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; border: 3px solid var(--accent);
}
.tl-body strong { display: block; font-size: 16px; font-weight: 700; }
.tl-meta { color: var(--ink-3); font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* Teeth: numbered in the order they came through */
.tooth-list { list-style: none; margin: 0; padding: 0; }
@media (min-width: 900px) {
  /* Read down the first column, then the second: 1-10, 11-20. */
  .tooth-list { display: grid; grid-auto-flow: column; grid-template-rows: repeat(10, auto); grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; }
  .tooth-list li:nth-child(11) { border-top: 0; }
}
.tooth-list li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line-2); }
.tooth-list li:first-child { border-top: 0; }
.tooth-list li.later { opacity: 0.55; }
.tooth-badge {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-strong); color: #fff; font-family: var(--head-font); font-weight: 800; font-size: 13px;
}
.tooth-list li.later .tooth-badge { background: #fff; color: var(--ink-3); box-shadow: inset 0 0 0 1.5px var(--ink-3); }

/* Health: events grouped by day */
.health-log { display: grid; gap: 16px; margin-top: 8px; }
.hl-date {
  margin: 0 0 6px; font-family: var(--body-font); font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3);
}
.hl-day ul { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line-2); border-radius: 12px; overflow: hidden; }
.hl-day li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 10px 14px; border-top: 1px solid var(--line-2); }
.hl-day li:first-child { border-top: 0; }
.hl-day .pill { margin: 0; }
.hl-time { min-width: 72px; font-size: 13.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.hl-temp { font-weight: 700; font-variant-numeric: tabular-nums; }
.hl-detail { color: var(--ink-2); }

/* Wide desktop: category cards two-up, growth full width. */
@media (min-width: 1024px) {
  .glance-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card.wide { grid-column: 1 / -1; }
}

@media (min-width: 1100px) {
  .panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel.wide { grid-column: 1 / -1; }
}

/* Tablet + phone: no rail; a header card and sticky section chips. */
@media (max-width: 1023px) {
  .viewer { display: block; }
  .rail { display: none; }
  .board { padding: 16px 24px 32px; max-width: none; }
  .board-head {
    display: block;
    background: linear-gradient(135deg, #FFF3EE 0%, #FBF3E6 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 14px;
  }
  .head-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .head-name { margin: 10px 0 0; font-family: var(--head-font); font-size: 24px; font-weight: 800; line-height: 1.2; }
  /* On a focus page the header shrinks to name and actions: the page below
     carries the category's own title and numbers. */
  .viewer[data-route='focus'] .board-head .facts { display: none; }
  .board-head .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; }
  .head-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
  .head-actions .access { flex: 1 1 100%; }
  .chips {
    display: flex;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 -24px 16px;
    padding: 10px 24px;
    overflow-x: auto;
    scrollbar-width: none;
    background: rgba(251, 247, 238, 0.94);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line-2);
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink-2);
    font-weight: 700;
    font-size: 14px;
    text-decoration: none;
  }
  .chip[aria-current='true'] { border-color: var(--ink); color: var(--ink); }
  .glance-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card { scroll-margin-top: 72px; }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  .board { padding: 12px 12px 28px; }
  .board-head { padding: 16px; }
  .board-head .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chips { margin: 0 -12px 14px; padding: 8px 12px; }
  .glance-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 12px 12px 14px; }
  .kpi-value { font-size: 25px; }
  .card { padding: 16px 14px; border-radius: 18px; }
  .card-head h2 { font-size: 18px; }
  .stats { gap: 8px 18px; }
  .stat-value { font-size: 19px; }
  .list li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  th, td { padding: 8px 5px; }
  .range-bar { padding: 10px 12px; }
  .range-select { flex: 1 1 100%; }
  .range-custom { flex: 1 1 100%; }
  .range-text { margin-inline-start: 0; flex: 1 1 100%; }
  .focus-head { padding: 16px 16px 18px; }
  .focus-head h1 { font-size: 25px; }
  .stats.big { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stats.big .stat-value { font-size: 23px; }
  .panel { padding: 16px 14px 18px; border-radius: 18px; }
  .share-bars li { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .share-bars .sb-bar { grid-column: 1 / -1; grid-row: 2; }
}

/* ═══════════════════ Print ═══════════════════ */

/* The overview first, then one A4 page per category (#print-pages, built on
   beforeprint). Black ink only: series differ by pattern, not colour. */

@page { size: A4; margin: 14mm; }

@media print {
  body, body[data-view='viewer'] { background: #fff; color: #000; font-size: 10.5pt; }
  .rail, .chips, .tip, .head-actions, .pairing, .msg-screen, .range-bar,
  .card-link .chev, .card-more, .show-earlier, details > summary, .toggle, button {
    display: none !important;
  }
  details.more { display: none; }
  .viewer { display: block; }
  .board { padding: 0; max-width: none; }
  #overview { display: block !important; }
  #focus { display: none !important; }
  #print-pages { display: block; }
  .print-page { break-before: page; }
  .board-head { display: block; border: 1px solid #ccc; border-radius: 0; background: #fff; padding: 10pt; margin-bottom: 10pt; }
  .board-head .facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .board-head .facts dt, .tracked, .kpi-label, .stat-label, .trend-note { color: #333; }
  .glance-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6pt; }
  .kpi, .card { border: 1px solid #999; border-radius: 0; box-shadow: none; break-inside: avoid; }
  .kpi::before { background: #000; }
  .cards { display: block; }
  .card { margin-bottom: 8pt; padding: 8pt 10pt; }
  .card .stats { margin: 6pt 0 2pt; }
  .card .chart-wrap { margin: 4pt 0 0; }
  .card-head, .chart-wrap, tr, figure, .panel, .stats { break-inside: avoid; }
  .card-link { color: #000; }
  .table-wrap { overflow: visible; }
  .day-toggle { color: inherit; }
  .day-toggle::before { display: none; }
  tr.day-entries > td { background: none; }

  /* A category's page: a one-line header, the numbers, charts, then tables. */
  .print-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12pt;
    padding-bottom: 4pt; margin-bottom: 8pt; border-bottom: 1.5pt solid #000;
  }
  .print-head .ph-name { font-weight: 700; }
  .print-head .ph-cat { font-size: 14pt; display: flex; align-items: center; gap: 6pt; }
  .print-head .ph-range { color: #333; font-size: 9.5pt; }
  .print-page .dot, .card-head h2 .dot { background: #000; }
  .print-page .stats { gap: 6pt 18pt; margin: 0 0 8pt; }
  .print-page .stat-value { font-size: 13pt; color: #000; }
  .print-page .panels { display: block; margin: 0; }
  .panel { border: 0; border-radius: 0; padding: 0 0 8pt; margin: 0; }
  .panel.log { break-inside: auto; }
  .panel.log-cols .table-wrap { column-count: 2; column-gap: 20pt; }
  .panel.log-cols tr { break-inside: avoid; }
  .panel-title { font-size: 10.5pt; margin-bottom: 2pt; }
  .panel-head, .panel-head + .panel-note { break-after: avoid; }
  .panel-note { color: #333; }
  .print-page table, .print-page th, .print-page td { font-size: 8.5pt; }
  .print-page th, .print-page td { padding: 2pt 3pt; border-bottom: 0.5pt solid #bbb; color: #000; white-space: nowrap; }
  .print-page th { color: #000; border-bottom: 0.75pt solid #000; }
  .print-page tbody tr:hover td { background: none; }
  .hl-day ul { border-color: #999; }
  .hl-day li { border-color: #bbb; padding: 3pt 6pt; }
  .pill { background: none; color: #000; box-shadow: inset 0 0 0 0.75pt #000; }

  /* Charts in black and grey: grid #bbb, axes and text #000. */
  .chart .axis-label, .chart .avg-label { fill: #000; }
  .chart .grid { stroke: #bbb; }
  .chart .axis, .chart .avg { stroke: #000; }
  .chart .band-row { fill: #f0f0f0; }
  .chart .avg-label { stroke: #fff; }
  .legend, .legend > span { color: #000; }
  .legend .l-series { border-top-color: #000; }
  .legend .l-band { background: #e6e6e6; }
  .sb-track { fill: #ddd; }
  .sb-fill { fill: #000; }
  .tl-dot { border-color: #000; }
  .tl-list::before { background: #999; }
  .tooth-badge { background: #000; color: #fff; }
  .tooth-list li.later .tooth-badge { background: #fff; color: #000; box-shadow: inset 0 0 0 1pt #000; }
  .tooth-map { max-width: 400pt; }
  .tooth-list { display: grid; grid-auto-flow: column; grid-template-rows: repeat(10, auto); grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20pt; }
  .tooth-list li { padding: 3pt 0; border-color: #bbb; break-inside: avoid; }
  .tooth-list li:nth-child(11) { border-top: 0; }
  .tooth-badge { width: 18pt; height: 18pt; font-size: 8.5pt; }
  .tl-body strong { font-size: 10pt; }
  .tl-meta { color: #333; font-size: 8.5pt; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) {
  .pulse, .spinner { animation: none; }
  .day-toggle::before { transition: none; }
  details.more > summary::before { transition: none; }
}
