/* Pulse design tokens (same system as TRING, coral accent) */
:root {
  --bg: oklch(0.965 0.003 20);
  --surface: oklch(0.995 0 0);
  --surface-2: oklch(0.955 0.004 20);
  --surface-3: oklch(0.925 0.005 20);
  --text: oklch(0.2 0.006 20);
  --muted: oklch(0.5 0.01 20);
  --border: oklch(0.9 0.005 20);
  --grid: oklch(0.2 0.006 20 / 0.07);
  --accent: oklch(0.58 0.19 22);
  --accent-ink: oklch(0.99 0 0);
  --accent-soft: oklch(0.94 0.035 22);
  --success: oklch(0.52 0.14 152);
  --danger: oklch(0.55 0.2 15);
  --warning: oklch(0.55 0.13 70);
  --z0: oklch(0.72 0.01 260);
  --z1: oklch(0.68 0.09 230);
  --z2: oklch(0.62 0.13 160);
  --z3: oklch(0.72 0.15 85);
  --z4: oklch(0.65 0.17 45);
  --z5: oklch(0.56 0.2 22);
  --shadow: 0 1px 2px oklch(0.2 0 0 / 0.04), 0 6px 20px oklch(0.2 0 0 / 0.05);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.135 0.004 20);
    --surface: oklch(0.185 0.005 20);
    --surface-2: oklch(0.225 0.006 20);
    --surface-3: oklch(0.265 0.007 20);
    --text: oklch(0.95 0.003 20);
    --muted: oklch(0.7 0.01 20);
    --border: oklch(0.28 0.007 20);
    --grid: oklch(1 0 0 / 0.06);
    --accent: oklch(0.7 0.17 22);
    --accent-ink: oklch(0.15 0.02 20);
    --accent-soft: oklch(0.3 0.07 22);
    --success: oklch(0.78 0.16 152);
    --danger: oklch(0.7 0.19 5);
    --warning: oklch(0.8 0.13 80);
    --z0: oklch(0.6 0.01 260);
    --shadow: 0 1px 0 oklch(0 0 0 / 0.3), 0 10px 30px oklch(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.small { font-size: 14px; }
.muted { color: var(--muted); }
.up { color: var(--success); }
.down { color: var(--danger); }
.i { flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.eyebrow { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* ---------- Shell */
.app { min-height: 100dvh; }
.nav {
  position: fixed; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%); width: min(440px, calc(100% - 24px));
  display: flex; gap: 2px; padding: 6px; border-radius: 22px; border: 1px solid var(--border);
  background: color-mix(in oklch, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.2);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; border-radius: 16px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}
.nav a[aria-current='page'] { color: var(--text); background: var(--surface-3); }
.nav a[aria-current='page'] .i { color: var(--accent); }
.main { padding: 0 16px calc(104px + env(safe-area-inset-bottom)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1200px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 0 14px;
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }
#view { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 900px) {
  .main { padding: 0 32px calc(112px + env(safe-area-inset-bottom)); }
  .topbar { padding-top: 24px; }
}

/* ---------- Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600; white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color 150ms ease-out, transform 150ms ease-out;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn.spinning .i { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.check { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; }
label, .label { font-size: 14px; font-weight: 500; color: var(--muted); }
.field.check label { color: var(--text); font-size: 16px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
input[type='checkbox'] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 48px; }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.stat canvas { display: block; width: 100%; height: 40px; margin-top: 8px; }
.delta { font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- Empty / error / skeleton */
.empty { text-align: left; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.empty ol { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.error { border-color: color-mix(in oklch, var(--danger) 40%, var(--border)); }
.skeleton { border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Live */
.live-hero { display: flex; flex-direction: column; gap: 16px; }
.bpm-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.bpm { font-size: clamp(72px, 22vw, 120px); font-weight: 700; line-height: 0.9; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.bpm .unit { font-size: 18px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: 6px; }
.bpm.stale { color: var(--muted); }
.zone-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); font-size: 14px; font-weight: 600; }
.zone-dot { width: 10px; height: 10px; border-radius: 50%; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--z0); }
.status.on .dot { background: var(--success); }
.status.warn .dot { background: var(--warning); }
.chart { display: block; width: 100%; height: 160px; }
.chart.tall { height: 200px; }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini-stats div { display: flex; flex-direction: column; }
.mini-stats strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 12px; color: var(--muted); }
.session-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.timer { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Zones */
.zones { display: flex; flex-direction: column; gap: 6px; }
.zone-row { display: grid; grid-template-columns: 96px 1fr 56px; gap: 8px; align-items: center; font-size: 14px; }
.zone-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.zone-fill { height: 100%; border-radius: 4px; }
.zone-row .num { text-align: right; color: var(--muted); }

/* ---------- Lists */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0;
  border: 0; border-bottom: 1px solid var(--border); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; width: 100%;
}
.row:last-child { border-bottom: 0; }
.row .right { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Coach */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.msgs { display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 12px 14px; border-radius: var(--r-md); max-width: 88%; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--accent-soft); }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.msg p + p, .msg ul + p, .msg p + ul { margin-top: 8px; }
.msg ul { margin: 0; padding-left: 20px; }
.composer { display: flex; gap: 8px; align-items: flex-end; }

/* ---------- Sheet + toasts */
.sheet {
  width: min(560px, 100%); max-height: 90dvh; margin: auto auto 0; padding: 0; border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text); overflow: auto;
}
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: oklch(0 0 0 / 0.4); }
.sheet-inner { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.toasts { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: var(--r-md); background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); animation: rise 200ms ease-out; }
.toast button { border: 0; background: none; color: inherit; font: inherit; font-weight: 700; cursor: pointer; min-height: 32px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Tappable cards, goals, detail sheets */
.tap { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; transition: transform 150ms ease-out, border-color 150ms ease-out; }
.tap:active { transform: scale(0.985); }
@media (hover: hover) { .tap:hover { border-color: color-mix(in oklch, var(--accent) 35%, var(--border)); } }
.readiness { display: flex; flex-direction: column; gap: 4px; }
.section-title { margin: 8px 2px 0; font-size: 16px; color: var(--muted); font-weight: 600; }
.link-head { border: 0; padding: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.meter { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--success); border-radius: 2px; }
.chart-box { position: relative; }
.chart { touch-action: pan-y; }
.tip {
  position: absolute; z-index: 3; transform: translate(-50%, -100%); margin-top: -6px;
  display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 10px; border-radius: var(--r-sm);
  background: var(--text); color: var(--bg); font-size: 12px; line-height: 1.35; white-space: nowrap; pointer-events: none;
  font-variant-numeric: tabular-nums; box-shadow: var(--shadow);
}
.tip strong { font-size: 14px; }
.tip span { opacity: 0.75; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); }
.seg button { min-height: 36px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button[aria-selected='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px 16px; }
.stat-grid div { display: flex; flex-direction: column; min-width: 0; }
.stat-grid span { font-size: 12px; color: var(--muted); }
.stat-grid strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.sheet-inner h3 { margin-bottom: 8px; }
