/* =================================================================
   Body Composition — design tokens
   Dark-first, the way Whoop and Apple Health present health data.
   ================================================================= */

:root {
  color-scheme: dark;

  --bg:            #07080b;
  --bg-glow-1:     rgba(0, 229, 160, 0.06);
  --bg-glow-2:     rgba(123, 158, 255, 0.05);
  --surface:       rgba(255, 255, 255, 0.035);
  --surface-2:     rgba(255, 255, 255, 0.055);
  --surface-solid: #101218;
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text:      #f2f4f8;
  --text-dim:  #9ba3b4;
  --text-mute: #7d8698;   /* 5.5:1 on --bg — WCAG AA for small text */

  --mint:   #00e5a0;
  --coral:  #ff6b5a;
  --peri:   #7b9eff;
  --amber:  #ffb020;
  --sky:    #38bdf8;
  --violet: #b388ff;
  --rose:   #ff5c8a;

  --good: var(--mint);
  --warn: var(--amber);
  --bad:  var(--coral);
  /* Dark-theme accents are bright, so ink on them is near-black. */
  --on-accent: #04120d;
  --accent-2:  #00c48c;   /* second stop of the primary gradient */

  --r-sm: 10px;
  --r:    16px;
  --r-lg: 22px;
  --r-xl: 28px;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.35);
  --ease: cubic-bezier(.32, .72, 0, 1);

  --maxw: 1360px;
  /* Sticky header height — anything scrolled to must clear it. */
  --header-h: 84px;
}

html[data-theme='light'] {
  color-scheme: light;
  --bg:            #f5f6fa;
  --bg-glow-1:     rgba(0, 190, 135, 0.08);
  --bg-glow-2:     rgba(96, 130, 235, 0.08);
  --surface:       rgba(255, 255, 255, 0.92);
  --surface-2:     rgba(255, 255, 255, 1);
  --surface-solid: #ffffff;
  --border:        rgba(10, 15, 30, 0.09);
  --border-strong: rgba(10, 15, 30, 0.18);
  --text:      #10141c;
  --text-dim:  #5b6474;
  --text-mute: #656d7d;
  /* Every accent below clears 4.5:1 on --bg. The vivid dark-theme values
     dropped to ~2.5:1 on white, which failed as text and looked washed out
     in the charts too — these read better in both roles. */
  --mint:   #006f4d;
  --coral:  #b62816;
  --peri:   #2755d9;
  --amber:  #8b5606;
  --sky:    #096690;
  --violet: #6129ff;
  --rose:   #b61d47;
  /* Text drawn ON an accent fill. Light accents are dark, so it flips. */
  --on-accent: #ffffff;
  --accent-2:  #00875c;
  --shadow: 0 1px 2px rgba(16,20,28,.06), 0 10px 30px rgba(16,20,28,.08);
}

/* ---------------- base ---------------- */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter',
               'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: -30% -10% auto -10%;
  height: 70vh;
  background:
    radial-gradient(60% 60% at 20% 20%, var(--bg-glow-1), transparent 70%),
    radial-gradient(55% 55% at 80% 10%, var(--bg-glow-2), transparent 70%);
  pointer-events: none;
  z-index: 0;
  /* Own layer: scrolls as a composited texture instead of repainting. */
  transform: translateZ(0);
  backface-visibility: hidden;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px 20px 90px;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }

button { font: inherit; color: inherit; cursor: pointer; }

a { color: var(--peri); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 20px;
  border: 3px solid transparent;
  background-clip: content-box;
}

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--mint), var(--sky));
  color: var(--on-accent);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.04em;
  box-shadow: 0 6px 18px rgba(0, 229, 160, 0.25);
  flex: none;
}

.brand h1 { font-size: 19px; letter-spacing: -0.03em; }
.brand p  { margin: 1px 0 0; font-size: 12.5px; color: var(--text-mute); }

.topbar-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: scale(.97); }

.btn-primary {
  background: linear-gradient(140deg, var(--mint), var(--accent-2));
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 650;
  box-shadow: 0 6px 18px rgba(0, 229, 160, .22);
}
/* The gradient must be restated here: `.btn:hover` is specificity 0,2,0 and
   would otherwise beat `.btn-primary` (0,1,0) and paint the button with the
   neutral hover surface — white text on white. Brightness handles the actual
   hover feedback so neither theme inverts its contrast. */
.btn-primary:hover {
  background: linear-gradient(140deg, var(--mint), var(--accent-2));
  filter: brightness(1.09);
}

.btn-ghost { background: transparent; }
.btn-danger { color: var(--coral); border-color: rgba(255,107,90,.3); }
.btn-danger:hover { background: rgba(255,107,90,.1); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ---------------- layout primitives ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.section { margin-top: 26px; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.section-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .11em; color: var(--text-mute); font-weight: 650; }
.section-head .hint { font-size: 12.5px; color: var(--text-mute); margin-left: auto; }

.grid { display: grid; gap: 14px; }
/* Grid and flex items default to `min-width: auto`, meaning they refuse to
   shrink below their content. A wide child then forces its track past the
   container instead of wrapping — which pushed the projection card to 770px
   inside a 390px phone and clipped half of it. */
.grid > * { min-width: 0; }

/* ---------------- hero ---------------- */

.hero {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 26px;
  align-items: center;
  padding: 26px 28px;
  border-radius: var(--r-xl);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(70% 120% at 12% 50%, rgba(0,229,160,.09), transparent 62%);
  pointer-events: none;
}

.score-block { display: flex; align-items: center; gap: 20px; position: relative; z-index: 1; }

.score-ring { position: relative; width: 168px; height: 168px; flex: none; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .score-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0;
}
.score-value { font-size: 50px; font-weight: 250; letter-spacing: -.05em; line-height: 1; }
.score-of { font-size: 11px; color: var(--text-mute); letter-spacing: .12em; text-transform: uppercase; margin-top: 6px; }

.score-meta h2, .score-verdict { font-size: 21px; letter-spacing: -.03em; text-transform: none; color: inherit; font-weight: 600; }
.score-meta p { margin: 6px 0 0; font-size: 13.5px; color: var(--text-dim); max-width: 30ch; line-height: 1.55; }

.hero-stats {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px 18px;
}
.hero-stat { padding: 10px 0; }
.hero-stat .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-mute); }
.hero-stat .val { font-size: 25px; font-weight: 300; letter-spacing: -.035em; margin-top: 3px; }
.hero-stat .val small { font-size: 13px; color: var(--text-mute); font-weight: 400; margin-left: 2px; }
.hero-stat .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ---------------- rings row ---------------- */

.rings {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.ring-card { display: flex; align-items: center; gap: 16px; padding: 18px; }
.ring-card .ring { width: 88px; height: 88px; flex: none; position: relative; }
.ring-card .ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-card .ring .pct {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 17px; font-weight: 450; letter-spacing: -.03em;
}
.ring-card .meta { min-width: 0; }
.ring-card .meta .t { font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.ring-card .meta .d { font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.45; }

/* ---------------- metric tiles ---------------- */

.tiles { grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); }

.tile {
  padding: 15px 16px 12px;
  border-radius: var(--r);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color .18s var(--ease), transform .18s var(--ease), background .18s var(--ease);
}
.tile:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.tile.is-active { border-color: var(--accent, var(--mint)); background: var(--surface-2); }
.tile::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent, var(--mint)); opacity: 0; transition: opacity .2s;
}
.tile.is-active::before { opacity: 1; }

.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-mute); font-weight: 600; }
.tile-val { font-size: 29px; font-weight: 280; letter-spacing: -.04em; margin: 7px 0 2px; line-height: 1.1; }
.tile-val small { font-size: 13px; color: var(--text-mute); font-weight: 400; margin-left: 3px; letter-spacing: 0; }
.tile-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: 6px; }
.tile-spark { width: 76px; height: 26px; flex: none; opacity: .95; }

.delta { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta.up::before   { content: '▲'; font-size: 8px; }
.delta.down::before { content: '▼'; font-size: 8px; }
.delta.flat::before { content: '–'; }
.delta.good { color: var(--good); }
.delta.bad  { color: var(--bad); }
.delta.neutral { color: var(--text-mute); }

/* ---------------- charts ---------------- */

.chart-card { padding: 20px 20px 12px; }

.chart-toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 6px;
}
.chart-title { font-size: 15px; font-weight: 600; letter-spacing: -.02em; }
.chart-sub { font-size: 12.5px; color: var(--text-mute); }

.chips { display: inline-flex; gap: 3px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; }
.chip {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 550;
  transition: background .15s, color .15s;
}
.chip:hover { color: var(--text); }
.chip.is-on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }

.chart-host { position: relative; width: 100%; }
.chart-host svg { display: block; width: 100%; height: auto; overflow: visible; }

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0;
  transition: opacity .12s;
  z-index: 8;
  min-width: 130px;
  white-space: nowrap;
}
.tip.on { opacity: 1; }
.tip .tip-date { color: var(--text-mute); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 5px; }
.tip .tip-row { display: flex; align-items: center; gap: 7px; justify-content: space-between; }
.tip .tip-row + .tip-row { margin-top: 3px; }
.tip .swatch { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.tip .tip-name { color: var(--text-dim); margin-right: 10px; }
.tip .tip-val { font-weight: 600; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-dim); margin-top: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* ---------------- zone bars ---------------- */

.zones { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.zone-row { padding: 15px 17px; border-radius: var(--r); }
.zone-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.zone-name { font-size: 13.5px; font-weight: 600; }
.zone-val { font-size: 15px; font-weight: 500; }
.zone-status { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; letter-spacing: .02em; }

.zone-track { position: relative; height: 8px; border-radius: 999px; margin: 13px 0 6px; display: flex; overflow: hidden; gap: 2px; }
.zone-seg { height: 100%; }
.zone-marker {
  position: absolute; top: 50%; width: 3px; height: 20px;
  border-radius: 3px; background: var(--text);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 3px var(--bg), 0 2px 8px rgba(0,0,0,.6);
  transition: left .5s var(--ease);
}
.zone-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-mute); }

/* ---------------- insights ---------------- */

.insights { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.insight {
  padding: 16px 18px;
  border-radius: var(--r);
  border-left: 3px solid var(--accent, var(--peri));
  display: flex; gap: 13px; align-items: flex-start;
}
.insight .ico { font-size: 19px; line-height: 1.2; flex: none; }
.insight h3 { margin: 0 0 4px; font-size: 13.5px; font-weight: 650; letter-spacing: -.01em; }
.insight p { margin: 0; font-size: 13px; color: var(--text-dim); line-height: 1.55; }

/* ---------------- table ---------------- */

/* The wrapper owns the horizontal scroll. `overscroll-behavior-x: contain`
   stops a swipe that runs off the end of the table from triggering the
   browser's back gesture — the single most annoying thing about scrollable
   tables on a phone. */
.table-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 20px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: content-box; }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }

thead th {
  position: sticky; top: 0;
  background: var(--surface-solid);
  text-align: right;
  padding: 11px 14px;
  font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-mute);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  z-index: 2;
}

/* Body cells: `tbody th` matters as much as `tbody td` — the first column is a
   row header for screen readers, so it must be styled as a cell, not inherit
   the browser's bold-and-centred default. */
tbody th, tbody td {
  padding: 11px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-weight: 400;
  color: var(--text);
  background: var(--surface-solid);
}
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }

/* Frozen first column. */
thead th:first-child,
tbody th:first-child,
tbody td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface-solid);
  z-index: 1;
}
thead th:first-child { z-index: 3; }

/* Its right edge only casts a shadow once there is something scrolled under
   it, so a table that fits shows no stray line. */
thead th:first-child::after,
tbody th:first-child::after,
tbody td:first-child::after {
  content: '';
  position: absolute;
  top: 0; bottom: -1px; right: -1px;
  width: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s var(--ease);
  background: linear-gradient(to right, rgba(0,0,0,.28), transparent);
}
html[data-theme='light'] thead th:first-child::after,
html[data-theme='light'] tbody th:first-child::after,
html[data-theme='light'] tbody td:first-child::after {
  background: linear-gradient(to right, rgba(16,20,28,.13), transparent);
}
.table-wrap.is-scrolled-x thead th:first-child::after,
.table-wrap.is-scrolled-x tbody th:first-child::after,
.table-wrap.is-scrolled-x tbody td:first-child::after { opacity: 1; }

/* "There is more to the right" hint, hidden once you reach the end. */
.table-scroller { position: relative; }
.table-scroller::after {
  content: '';
  position: absolute;
  top: 1px; bottom: 1px; right: 1px;
  width: 44px;
  border-radius: 0 var(--r-lg) var(--r-lg) 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s var(--ease);
  background: linear-gradient(to left, var(--surface-solid) 12%, transparent);
}
.table-scroller.has-more::after { opacity: 1; }

tbody tr:hover th, tbody tr:hover td { background: var(--surface-2); }
.cell-dim { color: var(--text-mute); }
.row-actions { display: inline-flex; gap: 4px; }
.icon-btn {
  border: 1px solid var(--border); background: transparent;
  width: 27px; height: 27px; border-radius: 8px;
  display: grid; place-items: center; font-size: 12px; color: var(--text-dim);
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--coral); border-color: rgba(255,107,90,.4); }

.tag { font-size: 10.5px; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-mute); border: 1px solid var(--border); }

/* ---------------- modal ---------------- */

.modal-back {
  position: fixed; inset: 0;
  background: rgba(4, 6, 10, .72);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 60;
  animation: fade .18s var(--ease);
}
@keyframes fade { from { opacity: 0 } }
.modal {
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  width: min(720px, 100%);
  max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  box-shadow: 0 30px 90px rgba(0,0,0,.6);
  animation: pop .22s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98) } }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; letter-spacing: -.02em; text-transform: none; color: var(--text); font-weight: 600; }
.modal-head .close { margin-left: auto; border: 0; background: transparent; color: var(--text-mute); font-size: 21px; line-height: 1; padding: 4px 8px; border-radius: 8px; }
.modal-head .close:hover { color: var(--text); background: var(--surface-2); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 15px 22px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------------- forms ---------------- */

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 13px; }
.field label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-mute); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  transition: border-color .15s, background .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--mint);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px rgba(0,229,160,.12);
}
.field input::placeholder { color: var(--text-mute); }
.field .hint { font-size: 11.5px; color: var(--text-mute); margin-top: 4px; }
.field.parsed input { border-color: rgba(0,229,160,.4); }
.field.low-conf input { border-color: rgba(255,176,32,.5); }
.field .badge { font-size: 10px; padding: 1px 6px; border-radius: 5px; margin-left: 6px; vertical-align: middle; letter-spacing: .04em; }
.badge-ok  { background: rgba(0,229,160,.15); color: var(--mint); }
.badge-low { background: rgba(255,176,32,.15); color: var(--amber); }

/* ---------------- dropzone ---------------- */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: 30px 20px;
  text-align: center;
  transition: border-color .18s, background .18s, transform .18s;
  cursor: pointer;
  background: var(--surface);
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--mint);
  background: rgba(0,229,160,.05);
}
.dropzone.drag { transform: scale(1.01); }
.dropzone .dz-ico { font-size: 30px; }
.dropzone .dz-title { font-size: 15px; font-weight: 600; margin-top: 8px; }
.dropzone .dz-sub { font-size: 12.5px; color: var(--text-mute); margin-top: 4px; }

.parse-note {
  font-size: 12.5px; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 9px 12px; margin: 14px 0;
  display: flex; gap: 8px; align-items: flex-start;
}
.parse-note.err { border-color: rgba(255,107,90,.35); color: var(--coral); }

details.raw { margin-top: 14px; }
details.raw summary { font-size: 12.5px; color: var(--text-mute); cursor: pointer; }
details.raw pre {
  margin: 9px 0 0; padding: 11px; max-height: 220px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 11.5px; line-height: 1.5; color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
}

/* ---------------- misc ---------------- */

.empty { text-align: center; padding: 54px 20px; color: var(--text-mute); }
.empty .e-ico { font-size: 40px; opacity: .5; }
.empty h3 { margin: 14px 0 6px; font-size: 17px; color: var(--text); }
.empty p { margin: 0 auto 18px; max-width: 42ch; font-size: 13.5px; line-height: 1.6; }

.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface-solid); border: 1px solid var(--border-strong);
  padding: 11px 17px; border-radius: 999px; font-size: 13.5px;
  box-shadow: 0 12px 36px rgba(0,0,0,.5);
  animation: toastIn .25s var(--ease);
  max-width: 90vw;
}
.toast.ok  { border-color: rgba(0,229,160,.4); }
.toast.err { border-color: rgba(255,107,90,.45); color: var(--coral); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) } }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--mint);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg) } }

.weekly { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.week-card { padding: 14px 15px; border-radius: var(--r); }
.week-card .wk { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-mute); font-weight: 600; }
.week-card .wv { font-size: 21px; font-weight: 300; letter-spacing: -.03em; margin: 6px 0 3px; }
.week-card .wd { font-size: 12px; color: var(--text-dim); }

/* ---------------- responsive ---------------- */

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 20px; padding: 22px; }
  .score-block { flex-direction: row; }
  .score-ring { width: 138px; height: 138px; }
  .score-value { font-size: 42px; }
}

@media (max-width: 620px) {
  .wrap { padding: 16px 13px 80px; }
  .brand h1 { font-size: 17px; }
  .brand p { display: none; }
  .topbar-actions { width: 100%; margin-left: 0; }
  .topbar-actions .btn { flex: 1; justify-content: center; }
  .score-block { flex-direction: column; align-items: flex-start; gap: 14px; }
  .score-ring { width: 124px; height: 124px; }
  .score-value { font-size: 38px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .tile-val { font-size: 25px; }
  .card { padding: 16px; }
  .hero-stat .val { font-size: 22px; }
}

@media print {
  html.motion-ready [data-reveal] { opacity: 1 !important; transform: none !important; }
  body::before, .topbar-actions, .row-actions, .chips, .install-bar { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 820px) {
  .section > .grid[style*="minmax(255px"] { grid-template-columns: 1fr !important; }
}

/* =================================================================
   MOTION
   ================================================================= */

/* Entrance: elements marked [data-reveal] rise into place once seen.
   The hidden state is gated on html.motion-ready, which motion.js only sets
   once it has an observer running — so a script error, an old browser, or a
   blocked module can never leave the page blank. */
html.motion-ready [data-reveal] {
  opacity: 0;
  transform: translate3d(0, 10px, 0);
}
html.motion-ready [data-reveal] {
  transition:
    opacity .34s var(--ease),
    transform .34s var(--ease);
}
html.motion-ready [data-reveal].is-in {
  opacity: 1;
  transform: none;
}

/* Cards lift toward the pointer and settle on press. */
.card { transition: transform .28s var(--ease), border-color .22s var(--ease), background .22s var(--ease), box-shadow .28s var(--ease); }

.tile { position: relative; overflow: hidden; }
.tile:hover { transform: translate3d(0, -3px, 0); box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 16px 40px rgba(0,0,0,.4); }
.tile:active { transform: scale(.985); transition-duration: .1s; }
.tile:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

/* Pointer ripple */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: .14;
  pointer-events: none;
  transform: scale(0);
  animation: rippleOut .55s var(--ease) forwards;
}
@keyframes rippleOut {
  to { transform: scale(1); opacity: 0; }
}

/* Score ring gets a gentle breathing glow once drawn */
/* Decorative only — restricted to pointer devices, where an always-on
   compositor animation costs nothing that matters. */
@media (hover: hover) and (pointer: fine) {
  .score-ring::after {
    content: '';
    position: absolute;
    inset: 12%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0,229,160,.14), transparent 70%);
    animation: pulseGlow 4.5s ease-in-out infinite;
    pointer-events: none;
  }
}
@keyframes pulseGlow {
  0%, 100% { opacity: .5; transform: scale(.94); }
  50%      { opacity: 1;  transform: scale(1.04); }
}

/* Theme cross-fade */
html.theming,
html.theming * {
  transition: background-color .35s var(--ease), color .35s var(--ease), border-color .35s var(--ease) !important;
}

/* View Transitions */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: .32s;
  animation-timing-function: cubic-bezier(.32,.72,0,1);
}
html[data-vt='theme']::view-transition-old(root) { animation: none; }
html[data-vt='theme']::view-transition-new(root) { animation: vtFade .4s var(--ease); }
@keyframes vtFade { from { opacity: 0 } }

/* Skeleton shimmer for the first paint */
.skeleton {
  border-radius: var(--r);
  background:
    linear-gradient(100deg, transparent 20%, rgba(255,255,255,.055) 40%, transparent 60%),
    var(--surface);
  background-size: 250% 100%, auto;
  animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer { to { background-position: -250% 0, 0 0; } }

.skeleton-grid { display: grid; gap: 14px; }
.sk-hero  { height: 190px; }
.sk-row   { height: 108px; }
.sk-chart { height: 300px; }

/* Toast exit */
.toast { transition: opacity .3s var(--ease), transform .3s var(--ease); }

/* =================================================================
   HEADER — condenses on scroll, sticky on every size
   ================================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 12px 0;
  margin-bottom: 12px;
  transition: padding .28s var(--ease), background .28s var(--ease), border-color .28s var(--ease);
  border-bottom: 1px solid transparent;
}
html.is-scrolled .topbar {
  padding: 8px 0;
  background: var(--bg);
  border-bottom-color: var(--border);
}
@media (hover: hover) and (pointer: fine) {
  html.is-scrolled .topbar {
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
  }
}
html.is-scrolled .brand-mark { transform: scale(.88); }
.brand-mark { transition: transform .28s var(--ease); }

/* =================================================================
   PWA / INSTALL
   ================================================================= */

.install-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 16px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: linear-gradient(120deg, color-mix(in srgb, var(--mint) 12%, transparent), var(--surface));
  animation: riseIn .5s var(--ease) backwards;
}
@keyframes riseIn { from { opacity: 0; transform: translateY(12px); } }
.install-bar .ib-ico { font-size: 22px; flex: none; }
.install-bar .ib-text { min-width: 0; flex: 1; }
.install-bar .ib-actions { display: flex; gap: 8px; flex: none; }
.install-bar .ib-text b { display: block; font-size: 14px; }
.install-bar .ib-text span { font-size: 12.5px; color: var(--text-dim); }

.offline-pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  z-index: 80;
  background: var(--amber);
  color: #1b1200;
  font-size: 12.5px;
  font-weight: 650;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: riseIn .35s var(--ease);
}

/* =================================================================
   RESPONSIVE — phone first, then the desktop affordances
   ================================================================= */

html { -webkit-text-size-adjust: 100%; }

body {
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

button, a, input, select, summary { touch-action: manipulation; }

@media (min-width: 1100px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); }
}

@media (max-width: 1000px) {
  .section-head .hint { display: none; }
}

@media (max-width: 820px) {
  .section > .grid[style*="minmax(255px"] { grid-template-columns: 1fr !important; }
}

@media (max-width: 700px) {
  :root { --maxw: 100%; }

  .wrap {
    padding-left: max(13px, env(safe-area-inset-left));
    padding-right: max(13px, env(safe-area-inset-right));
    padding-top: 0;
  }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 13px 13px 11px; }
  .tile-val { font-size: 23px; }
  .tile-spark { width: 58px; height: 22px; }

  .hero { padding: 20px 18px; gap: 18px; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; }
  .hero-stat .val { font-size: 21px; }

  .rings { grid-template-columns: 1fr; }
  .ring-card { padding: 14px; }
  .ring-card .ring { width: 72px; height: 72px; }

  .zones, .insights { grid-template-columns: 1fr; }
  .weekly { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .chart-card { padding: 16px 14px 10px; }
  .chart-toolbar { gap: 8px; }
  .chips { width: 100%; justify-content: space-between; }
  .chip { flex: 1; text-align: center; padding: 7px 8px; }

  .card { border-radius: 18px; }
  .section { margin-top: 20px; }

  table { font-size: 12.5px; }
  thead th, tbody th, tbody td { padding: 10px 11px; }

  /* Modal becomes a bottom sheet. */
  .modal-back { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: 24px 24px 0 0;
    border-bottom: 0;
    animation: sheetUp .34s var(--ease);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-head { padding: 14px 18px; position: relative; }
  .modal-head::before {
    content: '';
    position: absolute;
    top: 6px; left: 50%;
    width: 38px; height: 4px;
    border-radius: 99px;
    background: var(--border-strong);
    transform: translateX(-50%);
  }
  .modal-head h2 { font-size: 15px; }
  .modal-body { padding: 16px 18px; overscroll-behavior: contain; }
  .modal-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; justify-content: center; min-height: 44px; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  /* 16px keeps iOS from zooming the viewport on focus. */
  .field input, .field select { font-size: 16px; min-height: 44px; }
  .icon-btn { width: 34px; height: 34px; }
}

@keyframes sheetUp { from { transform: translateY(100%); } }

@media (max-width: 380px) {
  .tiles { grid-template-columns: 1fr; }
  .weekly { grid-template-columns: 1fr; }
  .hero-stats { grid-template-columns: 1fr 1fr; }
}

/* Standalone (installed) — reclaim the space the browser chrome used. */
@media (display-mode: standalone) {
  .wrap { padding-top: calc(env(safe-area-inset-top) + 6px); }
  .install-bar { display: none; }
}

/* Coarse pointers get no hover lift — it sticks after a tap. */
@media (hover: none) {
  .tile:hover { transform: none; box-shadow: var(--shadow); }
  .btn:hover { background: var(--surface); }
}

@media (prefers-reduced-motion: reduce) {
  html.motion-ready [data-reveal] { opacity: 1 !important; transform: none !important; }
  .score-ring::after { animation: none; }
  .skeleton { animation: none; }
}

/* =================================================================
   TOUCH TARGETS
   Touch devices get a 44px minimum. Icon buttons keep their compact
   look and gain the extra area through a transparent overlay, so the
   table layout is unaffected.
   ================================================================= */

@media (pointer: coarse) {
  .chip { min-height: 44px; }
  .btn-sm { min-height: 44px; padding-inline: 14px; }
  .install-bar .btn { min-height: 44px; }

  .icon-btn { position: relative; }
  .icon-btn::after {
    content: '';
    position: absolute;
    inset: -6px;
  }

  .row-actions { gap: 10px; }
  .modal-head .close { min-width: 44px; min-height: 44px; }
  details.raw summary { padding: 8px 0; }
}

/* =================================================================
   SCROLL PERFORMANCE
   ================================================================= */

/* Repeated leaf cards can't affect anything outside themselves, so scope
   their layout and paint work. Chart and table cards are excluded: paint
   containment would clip tooltips, and layout containment breaks the
   table's sticky header. */
.tile, .ring-card, .insight, .zone-row, .week-card {
  contain: layout paint style;
}

/* The blurred modal scrim is affordable on desktop; on phones the sheet
   already covers the screen, so the blur is pure cost. */
@media (pointer: coarse) {
  .modal-back {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4, 6, 10, .82);
  }
}

/* Charts redraw on demand, never during scroll. */
.chart-host svg { contain: paint; }

/* =================================================================
   MOBILE HEADER + FLOATING ACTION BUTTON

   A title and four actions cannot share a 390px row without looking
   crowded, and stacking them into a second row wastes ~50px of a
   844px screen on every scroll. So on phones the bar carries only
   identity plus one overflow control, and the primary action moves
   to a FAB where the thumb already is.
   ================================================================= */

#btnMore { display: none; }

.fab {
  display: none;
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  z-index: 50;
  place-items: center;
  color: var(--on-accent);
  background: linear-gradient(140deg, var(--mint), var(--accent-2));
  box-shadow: 0 10px 28px rgba(0, 229, 160, .34), 0 3px 10px rgba(0, 0, 0, .45);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
  animation: fabIn .42s var(--ease) backwards;
  animation-delay: .25s;
}
.fab:active { transform: scale(.92); box-shadow: 0 4px 14px rgba(0,229,160,.3); }
@keyframes fabIn { from { opacity: 0; transform: scale(.6) translateY(10px); } }

/* Action sheet rows */
.sheet-actions { display: flex; flex-direction: column; gap: 2px; margin: -6px 0; }
.sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  border-radius: var(--r-sm);
  font-size: 15px;
  text-align: left;
  transition: background .15s var(--ease);
}
.sheet-item:hover, .sheet-item:focus-visible { background: var(--surface-2); }
.sheet-item .si-ico {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 16px;
  flex: none;
}
.sheet-item .si-sub { display: block; font-size: 12px; color: var(--text-mute); margin-top: 1px; }
.sheet-item + .sheet-item { border-top: 1px solid var(--border); }

@media (max-width: 700px) {
  .topbar {
    gap: 11px;
    flex-wrap: nowrap;
    padding-top: 12px;
  }

  /* Identity takes the row; it truncates rather than wrapping. */
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; font-size: 14px; }
  .brand h1 { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* The last-scan line is worth its space now that the row is free. */
  .brand p {
    display: block;
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions { width: auto; margin-left: auto; flex: 0 0 auto; gap: 0; }
  #btnUpload, #btnSettings, #btnTheme, #btnExport, #btnLogout { display: none; }
  #btnMore {
    display: inline-flex;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 19px;
    letter-spacing: 0;
  }

  .fab { display: grid; }

  /* Keep the FAB clear of the last card and of toasts. */
  .wrap { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
  .toast-host { bottom: calc(22px + env(safe-area-inset-bottom)); left: 16px; right: 88px; transform: none; align-items: flex-start; }

  /* Hero: ring beside the verdict, prose underneath. */
  .score-block { flex-direction: row; align-items: center; gap: 15px; }
  .score-ring { width: 100px; height: 100px; }
  .score-value { font-size: 31px; }
  .score-of { font-size: 9px; margin-top: 3px; letter-spacing: .1em; }
  .score-meta h2 { font-size: 18px; }
  .score-meta p {
    font-size: 12.5px;
    max-width: none;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .hero { padding: 18px 16px; gap: 14px; }
  .hero-stat { padding: 7px 0; }

  .install-bar { flex-wrap: wrap; padding: 13px 14px; gap: 10px 12px; }
  .install-bar .ib-text { flex: 1 1 0; min-width: 0; }
  .install-bar .ib-actions { flex: 1 1 100%; }
  .install-bar .btn { flex: 1; justify-content: center; }
}

/* Scrolled: tighten only. Nothing moves or disappears, so there is no jump. */
@media (max-width: 700px) {
  html.is-scrolled .topbar { padding-top: 8px; padding-bottom: 8px; }
  /* overflow:hidden is what makes height:0 actually clip the text. */
  html.is-scrolled .brand p {
    opacity: 0;
    height: 0;
    margin: 0;
    overflow: hidden;
    transition: opacity .18s var(--ease), height .22s var(--ease);
  }
  .brand p { height: 15px; transition: opacity .18s var(--ease), height .22s var(--ease); }
  html.is-scrolled .brand-mark { transform: none; }
}

/* FAB tucks away on downward scroll so it never sits on top of content. */
.fab.is-tucked {
  transform: translateY(96px) scale(.85);
  opacity: 0;
  pointer-events: none;
}

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

/* Skip link — the first stop for keyboard users. */
.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 0 0 12px 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 650;
  font-size: 14px;
  transition: top .2s var(--ease);
}
.skip-link:focus { top: 0; }

/* Destructive confirmation */
.confirm-body { font-size: 14.5px; color: var(--text-dim); line-height: 1.6; margin: 0; }
.confirm-body strong { color: var(--text); }

/* Toast with an inline action (undo) */
.toast-action {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.toast-action button {
  border: 0;
  background: transparent;
  color: var(--mint);
  font-weight: 650;
  font-size: 13.5px;
  padding: 4px 2px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* =================================================================
   OUTBOX — pending offline writes
   ================================================================= */

.outbox-badge {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: riseIn .3s var(--ease);
}
.outbox-badge .ob-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber);
  animation: obPulse 1.8s ease-in-out infinite;
}
@keyframes obPulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

@media (max-width: 700px) {
  /* Sit above the FAB rather than under it. */
  .outbox-badge { bottom: calc(88px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .outbox-badge .ob-dot { animation: none; }
}

/* Password strength meter */
.pw-meter {
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  margin: 8px 0 6px;
  overflow: hidden;
}
.pw-meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--coral);
  transition: width .25s var(--ease), background .25s var(--ease);
}

/* Projection goal stats: a responsive grid rather than a flex row, so the four
   figures reflow to 2x2 on a phone instead of forcing the card wider. */
.goal-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 26px;
  align-items: baseline;
  margin-top: 6px;
}
.goal-stats > div { min-width: 0; }
.goal-stats .num { white-space: nowrap; }

@media (max-width: 700px) {
  .goal-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
  /* The arrival date is the headline — give it the full row. */
  .goal-stats > div:first-child { grid-column: 1 / -1; }
}

/* Anything the app scrolls to (a metric chart, the projection shortcut, an
   anchor) must not land underneath the sticky header. */
.section,
#trendCard,
[data-section] {
  scroll-margin-top: calc(var(--header-h) + 12px);
}

@media (max-width: 700px) {
  :root { --header-h: 66px; }
}
