/* HealthSync UI — the single stylesheet for every page.
 *
 * Design rules, so the pages stay consistent as they grow:
 *
 *   1. One accent colour (teal) carries interaction and "this is a link/action". Everything
 *      else is neutral. Metric families get their own tone through --tone, so a heart rate
 *      and a step count never look like the same number in different clothes.
 *   2. Cards are a single layer. A card inside a card means the layout has not decided what
 *      the grouping is; sections inside a card are separated by a rule and a heading instead.
 *   3. Space is the structure. Sections get 24px, cards 16-20px, rows 8-12px — the page keeps
 *      its rhythm without borders on everything.
 *   4. Mobile first: the layout is built at 360px and widens. Most readers are on the phone
 *      the watch talks to.
 */

/* ------------------------------------------------------------------ tokens */

:root {
  color-scheme: light dark;

  /* Neutral ramp — slightly warm so white cards do not look clinical. */
  --bg: #f4f5f7;
  --bg-2: #ecedf1;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e8ebf0;
  --fg: #10131a;
  --fg-2: #3d4553;
  --muted: #6b7482;
  --line: #e4e7ec;
  --line-2: #d3d8e0;

  /* Brand: a single teal. --accent-soft is for selected/active backgrounds only. */
  --accent: #0d7d72;
  --accent-strong: #0a655c;
  --accent-fg: #ffffff;
  --accent-soft: #d9f2ee;
  --accent-line: #a7e0d6;

  --danger: #c9362f;
  --danger-soft: #fdeceb;
  --ok: #0f7a52;
  --ok-soft: #e2f4ec;
  --warn: #a5610a;
  --warn-soft: #fdf1de;

  /* Metric families. Used by .stat[data-tone] and the chart palette. */
  --tone-activity: #0d7d72;
  --tone-heart: #d14b6e;
  --tone-sleep: #5b5bd6;
  --tone-body: #b8730c;
  --tone-neutral: #6b7482;

  --r-xs: 6px;
  --r-sm: 9px;
  --r: 14px;
  --r-lg: 20px;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .04);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, .12);

  --header-h: 58px;
  --maxw: 1080px;
  --pad: 20px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC",
          "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e12;
    --bg-2: #111419;
    --surface: #161a20;
    --surface-2: #1c2129;
    --surface-3: #242a33;
    --fg: #eef1f6;
    --fg-2: #b9c1ce;
    --muted: #808a99;
    --line: #232932;
    --line-2: #313945;

    --accent: #2fb8a6;
    --accent-strong: #47ccb9;
    --accent-fg: #04201c;
    --accent-soft: #12332f;
    --accent-line: #1f544c;

    --danger: #ff8078;
    --danger-soft: #2c1618;
    --ok: #46d59b;
    --ok-soft: #10291f;
    --warn: #e8ac4b;
    --warn-soft: #2a2010;

    --tone-activity: #2fb8a6;
    --tone-heart: #ff7c9c;
    --tone-sleep: #9797f5;
    --tone-body: #e0a94a;
    --tone-neutral: #808a99;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 2px 10px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
  }
}

/* -------------------------------------------------------------- foundations */

* { box-sizing: border-box; }

/* A class that sets `display` outranks the `hidden` attribute (which is display:none from the
   UA sheet at zero specificity). That silently un-hides every button, flex row and grid cell
   the page toggles with `hidden`. This has to win over all of them. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Nothing is allowed to make the page scroll sideways on a phone. */
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.02em; line-height: 1.25; }
h1 { font-size: 26px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }

::selection { background: var(--accent-soft); color: var(--accent-strong); }

/* ------------------------------------------------------------------ header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

/* Named `headbar`, not `bar`: `.bar` is the chart/step bar and a generic name like that
   silently repainted the whole header when both existed. */
.site-header .headbar {
  max-width: var(--maxw);
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 var(--pad);
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  font-size: 15.5px;
  font-weight: 660;
  letter-spacing: -.02em;
  color: var(--fg);
}
.brand:hover { text-decoration: none; }

/* The mark: a small filled tile, so the wordmark has an anchor. */
.brand::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
  flex: none;
}

.nav {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav a {
  padding: 6px 11px;
  border-radius: var(--r-xs);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  flex: none;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--fg-2); text-decoration: none; }
.nav a.current { background: var(--accent-soft); color: var(--accent-strong); font-weight: 620; }

.who {
  color: var(--muted);
  font-size: 13px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: none;
}

.signout {
  flex: none;
  font-size: 13.5px;
  padding: 6px 10px;
  border-radius: var(--r-xs);
  color: var(--muted);
}
.signout:hover { background: var(--surface-2); color: var(--fg-2); text-decoration: none; }

@media (max-width: 720px) {
  :root { --pad: 14px; }
  .site-header .headbar { gap: 8px; }
  .who { display: none; }
  .nav a { padding: 6px 8px; font-size: 13.5px; }
  .brand { font-size: 14.5px; }
  .brand::before { width: 18px; height: 18px; border-radius: 5px; }
}

@media (max-width: 360px) {
  .nav a { padding: 6px 6px; font-size: 13px; }
  .signout { padding: 6px 6px; font-size: 13px; }
}

/* -------------------------------------------------------------------- main */

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px var(--pad) 72px;
}

@media (max-width: 720px) {
  main { padding: 18px var(--pad) 56px; }
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.page-head h1 { font-size: 26px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin: 5px 0 0; max-width: 70ch; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
.page-head .actions > select, .page-head .actions > input { width: auto; min-width: 130px; }

@media (max-width: 720px) {
  .page-head { margin-bottom: 16px; align-items: stretch; }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { width: 100%; }
  .page-head .actions > select, .page-head .actions > input { flex: 1 1 auto; width: auto; }
}

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}

@media (max-width: 720px) {
  .card { padding: 14px; border-radius: var(--r-sm); margin-bottom: 10px; }
}

.card > h2:first-child { margin-top: 0; }
.card > h2 { margin-bottom: 4px; }

/* A short line under the card title that explains it, instead of a paragraph body. */
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 76ch; }

/* A section inside a card: a rule and a heading rather than another box. */
.section { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.section:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.section > h3 { margin-bottom: 12px; color: var(--fg-2); font-size: 13px; font-weight: 640; }

/* ---------------------------------------------------------- stat / metrics */

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.narrow { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .grid.wide { grid-template-columns: minmax(0, 1fr); }
  .grid.narrow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* An odd count leaves one half-width card beside a gap, which reads as a missing value;
     let the last one take the row instead. */
  .grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 13px 14px 12px;
  min-width: 0;
  overflow: hidden;
}

/* The tone stripe: a 3px edge that names the metric family at a glance. */
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--tone, var(--tone-neutral));
  opacity: .85;
}

.stat[data-tone="activity"] { --tone: var(--tone-activity); }
.stat[data-tone="heart"]    { --tone: var(--tone-heart); }
.stat[data-tone="sleep"]    { --tone: var(--tone-sleep); }
.stat[data-tone="body"]     { --tone: var(--tone-body); }

/* A date is two tokens that must not split across lines — "2026-10-25 / 16:48" reads as two
   unrelated values, and the cell is tall enough that it looked like the count was missing. */
.stat .v .nb { white-space: nowrap; }

.stat .v {
  display: block;
  font-size: 22px;
  font-weight: 660;
  line-height: 1.15;
  letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.stat .k {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .stat { padding: 11px 12px 10px; border-radius: var(--r-xs); }
  .stat .v { font-size: 19px; }
}

/* --------------------------------------------------------------- hero card */

/* Today's summary: the numbers are the page, so they sit on their own tinted panel rather
   than in a white card that matches everything below it. */
.hero {
  position: relative;
  border-radius: var(--r-lg);
  padding: 20px;
  margin-bottom: 14px;
  color: var(--fg);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--accent-soft) 0%, transparent 62%),
    var(--surface);
  border: 1px solid var(--accent-line);
  box-shadow: var(--shadow);
}

.hero-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hero h2 { font-size: 17px; }
.hero .date { color: var(--muted); font-size: 13px; margin-top: 2px; }
.hero .grid { margin-top: 16px; }
.hero .stat { background: color-mix(in srgb, var(--surface) 72%, transparent); }

@media (max-width: 720px) {
  .hero { padding: 16px 14px; border-radius: var(--r); }
}

/* ------------------------------------------------------------------ forms */

label { display: block; font-size: 13px; font-weight: 550; color: var(--fg-2); margin: 14px 0 6px; }
label:first-child { margin-top: 0; }

input, select, textarea, button { font: inherit; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--fg);
  /* 16px keeps iOS from zooming the page when a field takes focus; it never zooms back. */
  font-size: 16px;
  transition: border-color .12s, box-shadow .12s;
}

@media (min-width: 721px) {
  input, select, textarea { font-size: 14.5px; }
}

input::placeholder, textarea::placeholder { color: var(--muted); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--r-xs);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .06s;
}

button:hover, .btn:hover { background: var(--accent-strong); text-decoration: none; }
button:active, .btn:active { transform: translateY(.5px); }

button.ghost, .btn.ghost {
  background: var(--surface);
  color: var(--fg-2);
  border-color: var(--line-2);
}
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); color: var(--fg); border-color: var(--muted); }

button.danger, .btn.danger { background: var(--danger); color: #fff; }
button.danger:hover, .btn.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }

button:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:hover { background: var(--accent); }

/* Keyboard users get the same affordance the pointer gets. */
:where(a, button, .btn, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* A checkbox and its label: one row, the label not a column heading. */
label.row, .check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-2);
  cursor: pointer;
}
label.row > input[type="checkbox"], label.row > input[type="radio"],
.check > input[type="checkbox"], .check > input[type="radio"] {
  flex: none;
  margin: 0;
  width: 16px;
  height: 16px;
}
.row.tight { gap: 6px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row > input, .row > select { width: auto; flex: 1 1 150px; min-width: 0; }

/* A filter bar: controls share one line and wrap only when they must. */
.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters > input, .filters > select { flex: 0 1 auto; width: auto; min-width: 120px; }
.filters > input[type="text"], .filters > input[type="search"] { flex: 1 1 200px; }

/* A form's submit is the primary action: it gets the full width on a phone. A row of
   controls that merely wraps (filter bars) does not — six full-width buttons stacked is
   noise, and the .row/.filters rules below keep those to their natural size. */
@media (max-width: 640px) {
  form > .row > button[type="submit"], .form-action { flex: 1 1 100%; padding: 11px 16px; }
  /* A checkbox is not a field: making it fill the line pushes its label onto the next row. */
  .row > input:not([type="checkbox"]):not([type="radio"]), .row > select { flex: 1 1 100%; }
  .row > input[type="checkbox"], .row > input[type="radio"] { flex: none; margin: 0; }
  .row > button, .row > .btn { flex: 0 0 auto; }
  .row.tight > button, .row.tight > .btn, .daynav button { flex: 1 1 auto; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters > input, .filters > select, .filters > button, .filters > .btn { flex: 1 1 auto; width: 100%; min-width: 0; }
  .filters > .keep { width: auto; flex: 1 1 auto; }
  .filters > .row { width: 100%; }
}

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -2px; padding: 0 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: .02em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--surface);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

td.wrap, th.wrap { white-space: normal; min-width: 140px; }

/* A six-column table cannot fit 375px without becoming unreadable. On a phone it becomes a
   list of stacked blocks — same data, laid out for the width. */
@media (max-width: 760px) {
  table.stack thead { display: none; }

  table.stack, table.stack tbody { display: block; }

  table.stack tr {
    display: block;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }
  table.stack tr:last-child { border-bottom: none; }
  table.stack tr:hover { background: transparent; }

  table.stack td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 3px 0;
    border: none;
    white-space: normal;
    font-size: 13.5px;
  }

  table.stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12.5px;
    flex: none;
  }

  table.stack td:first-child { font-weight: 620; font-size: 14.5px; padding-bottom: 5px; }
  table.stack td:first-child::before { content: none; }
}

/* --------------------------------------------------------------- item feed */

/* One row per record on a phone: a title line, details, actions. Used where a table would
   be unreadable — tokens, users, uploads, raw samples. */
.item { padding: 14px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: none; }
.item:first-child { padding-top: 0; }

.item .item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.item .item-title { font-weight: 600; font-size: 14px; color: var(--fg); }
.item .item-body { color: var(--muted); font-size: 13px; margin-top: 3px; word-break: break-all; }
.item .item-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.item .item-actions button, .item .item-actions .btn { padding: 6px 12px; font-size: 13px; }

/* -------------------------------------------------------------- messages */

.msg {
  padding: 10px 13px;
  border-radius: var(--r-xs);
  margin: 0 0 14px;
  display: none;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.msg.err { display: block; background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.msg.ok  { display: block; background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }

.tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 550;
  padding: 1.5px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.6;
}
.tag.ok   { border-color: transparent; background: var(--ok-soft); color: var(--ok); }
.tag.warn { border-color: transparent; background: var(--danger-soft); color: var(--danger); }
.tag.accent { border-color: transparent; background: var(--accent-soft); color: var(--accent-strong); }

.empty { color: var(--muted); padding: 28px 0; text-align: center; font-size: 14px; }

.secret {
  background: var(--surface-2);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-xs);
  padding: 12px;
  word-break: break-all;
  margin-top: 10px;
}

/* ------------------------------------------------------------------- auth */

.auth { max-width: 400px; margin: 6vh auto 0; }
.auth h1 { font-size: 26px; margin-bottom: 4px; }
.auth .sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }

.tabs {
  display: flex;
  gap: 3px;
  margin-bottom: 16px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: var(--r-xs);
}

.tabs button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 7px 10px;
  font-size: 13.5px;
  font-weight: 550;
  border-radius: 5px;
}
.tabs button:hover { background: transparent; color: var(--fg-2); }
.tabs button.active { background: var(--surface); color: var(--fg); font-weight: 620; box-shadow: var(--shadow-xs); }

/* ----------------------------------------------------------------- charts */

.chart-wrap { position: relative; margin-top: 2px; touch-action: pan-y; }
.chart-svg { width: 100%; display: block; overflow: visible; color: var(--fg); touch-action: pan-y; }
.chart-wrap .hit { cursor: crosshair; touch-action: pan-y; }

/* The gesture hint sits under the plot and disappears on the pointer being there: it explains
   the interaction once, and then it is in the way of the values it describes. */
.chart-hint {
  font-size: 11.5px;
  text-align: right;
  margin-top: 2px;
  user-select: none;
  transition: opacity 160ms ease;
  pointer-events: none;
}
.chart-wrap:hover .chart-hint { opacity: 0; }
@media (hover: none) { .chart-wrap .chart-hint { opacity: 0.75; } }

.crosshair line { stroke: currentColor; }
.markers circle { pointer-events: none; }

.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 130px;
  max-width: 230px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xs);
  padding: 9px 11px;
  font-size: 12.5px;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

.chart-tip .tip-head {
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--fg-2);
  font-size: 12px;
}
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.chart-tip .tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.chart-tip .tip-row strong { margin-left: auto; font-variant-numeric: tabular-nums; }

/* One metric per block inside a card, separated by a rule — not one card each. */
.metric-block { padding: 16px 0; border-top: 1px solid var(--line); }
.metric-block:first-child { padding-top: 0; border-top: none; }
.metric-block:last-child { padding-bottom: 0; }

.metric-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.metric-head .name {
  font-size: 14px;
  font-weight: 620;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.metric-block[data-tone="activity"] { --tone: var(--tone-activity); }
.metric-block[data-tone="heart"]    { --tone: var(--tone-heart); }
.metric-block[data-tone="sleep"]    { --tone: var(--tone-sleep); }
.metric-block[data-tone="body"]     { --tone: var(--tone-body); }

.metric-head .name::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--tone, var(--accent));
  flex: none;
}
.metric-head .meta { color: var(--muted); font-size: 12px; }

@media (max-width: 560px) {
  .metric-head { flex-wrap: wrap; gap: 2px 10px; }
  .metric-head .meta { font-size: 11.5px; }
}

.stage-bar {
  display: flex;
  height: 18px;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 8px;
  background: var(--surface-3);
}
.stage-bar .stage { display: block; height: 100%; }

.legend {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.bar {
  display: block;
  height: 8px;
  border-radius: 3px;
  background: var(--accent);
  opacity: .85;
  min-width: 2px;
}

/* ------------------------------------------------------- hour breakdown */

.hour-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 64px 64px 52px;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.hour-row:last-child { border-bottom: none; }
.hour-row.idle { opacity: .4; }

.hour-of { color: var(--muted); font-size: 12px; }

.hour-bar {
  display: block;
  height: 7px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}

.hour-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hour-num em { font-style: normal; color: var(--muted); font-size: 11px; margin-left: 2px; }

.hours-head {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 64px 64px 52px;
  gap: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line-2);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.hours-head span { text-align: right; }
.hours-head span:nth-child(2) { text-align: left; }

/* On a wide card the bar column would swallow the row and an 8px sliver of colour per hour
   would be unreadable; hold it to a normal column width instead. */
@media (min-width: 721px) {
  .hour-row, .hours-head { grid-template-columns: 54px minmax(0, 300px) 62px 62px 50px; }
}

/* On a phone the bar has no room to mean anything; the numbers do. The hidden bar leaves the
   layout, so the remaining four cells need their own four-column track. */
@media (max-width: 720px) {
  .hour-row { grid-template-columns: 42px minmax(0, 1fr) 56px 48px; gap: 6px; font-size: 12.5px; }
  .hour-bar, .hours-head { display: none; }
  .hour-row .hour-num:first-of-type { text-align: left; }
}

/* ------------------------------------------------------- metric picker */

.picker { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); }

@media (max-width: 560px) {
  .picker { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
}

.picker .pick {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-2);
  background: var(--surface);
  min-width: 0;
  transition: border-color .12s, background .12s;
}
.picker .pick:hover { background: var(--surface-2); border-color: var(--line-2); }
.picker .pick:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.picker .pick input { width: auto; margin: 0; flex: none; }
.picker .pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker .pick .count {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ code */

pre.raw, .cmd pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 11px;
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: 300px;
}

.cmd {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 13px 15px;
  margin: 10px 0;
}

.cmd pre {
  margin: 0;
  padding: 0 64px 0 0;
  border: none;
  background: none;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: none;
}

.cmd button.copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 550;
  background: var(--surface);
  color: var(--fg-2);
  border: 1px solid var(--line-2);
}
.cmd button.copy:hover { background: var(--surface-3); color: var(--fg); }

/* ---------------------------------------------------------- day navigation */

.daynav { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .daynav { width: 100%; }
  .daynav button { flex: 1; padding: 8px 0; }
}

/* --------------------------------------------------------------- printing */

@media print {
  .site-header, .daynav, .filters, button, .btn { display: none !important; }
  body { background: #fff; }
  .card, .stat, .hero { box-shadow: none; border-color: #ddd; break-inside: avoid; }
}

/* --------------------------------------------------------- screen readers */

.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;
}

/* ------------------------------------------------- coverage disclosure */

/* Per-metric sample counts: real data, but reference detail rather than the headline. */
.coverage { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.coverage > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
}
.coverage > summary::-webkit-details-marker { display: none; }
.coverage > summary::before { content: "▸"; font-size: 9px; transition: transform .12s; }
.coverage[open] > summary::before { transform: rotate(90deg); }
.coverage > summary:hover { border-color: var(--line-2); color: var(--fg-2); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--fg-2);
  white-space: nowrap;
}
.chip i { width: 6px; height: 6px; border-radius: 2px; flex: none; }
.chip b { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Per-database inventory on the data page: one collapsible block per uploaded database. */
.db-block {
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 10px 12px;
  margin-top: 10px;
  background: var(--surface);
}
.db-block > summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  list-style: none;
}
.db-block > summary::-webkit-details-marker { display: none; }
.db-block > summary::before {
  content: "▸";
  font-size: 9px;
  color: var(--muted);
  margin-right: 4px;
  transition: transform .12s;
}
.db-block[open] > summary::before { transform: rotate(90deg); }
.db-block .item { padding: 10px 0 2px; border-top: 1px solid var(--line); }
.db-block .item:first-of-type { border-top: none; }
.db-block pre.raw { max-height: 220px; overflow: auto; white-space: pre; }

/* The disclaimer is one sentence on every page, not a paragraph under the dashboard. */
.disclaimer {
  max-width: 1180px;
  margin: 4px auto 22px;
  padding: 0 18px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

/* The clock range under a stat label: present, but never louder than the number. */
.stat .k .time {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
/* Compact expandable raw JSON inside the data tables. */
.raw-details summary { cursor: pointer; color: var(--accent-strong); font-size: 12.5px; white-space: nowrap; }
.raw-details pre.raw { max-height: 240px; overflow: auto; white-space: pre-wrap; min-width: 280px; }
