/* ================================================================
   OpenWhoop dashboard — design system v5  ("Instrument")
   A redesigned light, premium product surface: cool-paper canvas,
   crisp white instrument cards with layered depth, metric-tinted
   ring panels, a filled-pill navigation, and a confident display
   type scale. All CSS custom-property names and JS-coupled class
   names are preserved (the app.js getCss + #id contract).
   ================================================================ */

:root {
  /* ─── Surfaces ─── */
  --bg:           #F4F7FC;            /* cool paper canvas */
  --surface-1:    #FFFFFF;            /* instrument card */
  --surface-2:    #F1F5FA;            /* inset / inputs */
  --surface-3:    #E5ECF5;            /* hover */
  --surface-glow: #DCE6F2;
  --card:         var(--surface-1);
  --border:       rgba(15, 23, 42, 0.08);
  --border-hi:    rgba(15, 23, 42, 0.16);
  --hairline:     rgba(15, 23, 42, 0.06);
  --track:        rgba(15, 23, 42, 0.07);
  --bubble-bot:   #EEF3FA;

  /* ─── Text ─── */
  --text:         #0B1220;
  --text-2:       #3B475C;
  --text-muted:   #697587;
  --text-faint:   #9AA6B8;

  /* ─── Accent ─── */
  --accent:       #2F6BFF;
  --accent-2:     #1D4ED8;
  --accent-soft:  #EAF1FF;
  --accent-ring:  rgba(47, 107, 255, 0.32);

  /* ─── Metric palette (data only) ─── */
  --recovery:     #12A150;
  --recovery-2:   #0E7C3E;
  --recovery-glow: rgba(18, 161, 80, 0.16);
  --strain:       #0EA5E9;
  --strain-2:     #0284C7;
  --strain-glow:  rgba(14, 165, 233, 0.16);
  --sleep:        #6366F1;
  --sleep-2:      #4F46E5;
  --sleep-glow:   rgba(99, 102, 241, 0.16);
  --warn:         #E08600;
  --bad:          #E0322F;
  --good:         var(--recovery);
  --mid:          var(--warn);

  /* legacy aliases (keep app.js getCss + inline styles working) */
  --rec-good: var(--recovery); --rec-mid: var(--warn); --rec-bad: var(--bad);
  --fg: var(--text); --fg-2: var(--text-2); --fg2: var(--text-2);
  --muted: var(--text-muted); --card-bg: var(--surface-1); --card-bg2: var(--surface-2);

  /* Sleep stages */
  --stage-wake: #E0322F; --stage-light: #0EA5E9; --stage-deep: #4F46E5; --stage-rem: #A855F7;
  /* HR zones */
  --zone-1: #2F6BFF; --zone-2: #06B6D4; --zone-3: #12A150; --zone-4: #F59E0B; --zone-5: #E0322F;

  /* ─── Type ─── */
  --font:         'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono:    ui-monospace, 'JetBrains Mono', SFMono-Regular, Menlo, monospace;

  /* ─── Spacing ─── */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 44px;

  /* ─── Elevation ─── */
  --shadow-sm: 0 1px 2px rgba(11,18,32,.05), 0 1px 1px rgba(11,18,32,.03);
  --shadow:    0 4px 16px -8px rgba(11,18,32,.16), 0 2px 6px -3px rgba(11,18,32,.08);
  --shadow-md: 0 18px 40px -20px rgba(11,18,32,.28), 0 8px 18px -12px rgba(11,18,32,.12);

  /* ─── Geometry ─── */
  --radius-xs: 8px; --radius-sm: 12px; --radius: 18px; --radius-lg: 24px; --radius-xl: 30px;
  --gutter: 20px; --sidebar-w: 256px; --topbar-h: 68px;
  --focus: 0 0 0 3px var(--accent-ring);
  --z-nav: 30; --z-modal: 200;
  --sa-top: env(safe-area-inset-top,0px); --sa-bottom: env(safe-area-inset-bottom,0px);
  --sa-left: env(safe-area-inset-left,0px); --sa-right: env(safe-area-inset-right,0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

html {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5;
  font-feature-settings: "ss01","cv11"; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  color-scheme: light;
}
body {
  min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0,1fr);
  background:
    radial-gradient(1100px 520px at 100% -10%, rgba(47,107,255,.06), transparent 55%),
    radial-gradient(900px 500px at -10% 8%, rgba(99,102,241,.045), transparent 55%),
    var(--bg);
}
::selection { background: var(--accent-soft); color: var(--accent-2); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-xs); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-glow); }

h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 800; letter-spacing: -.03em; margin: 0; color: var(--text); }
h1 { font-size: 34px; line-height: 1.05; }
h2 { font-size: 21px; line-height: 1.15; letter-spacing: -.02em; }
h3 { font-size: 16px; line-height: 1.3; font-weight: 700; }
p { margin: 0; }

.eyebrow, .card-eyebrow {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .18em;
  text-transform: uppercase; color: var(--text-faint);
}

/* utilities */
.muted { color: var(--text-muted); } .faint { color: var(--text-faint); }
.tnum { font-variant-numeric: tabular-nums; }
.fs-10 { font-size: 10px; } .fs-11 { font-size: 11px; } .fs-12 { font-size: 12px; }
.center { text-align: center; }
.field-label { font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--text-faint); }

/* ───────────────────────── Sidebar ───────────────────────── */
.sidebar {
  position: sticky; top: 0; height: 100vh; background: linear-gradient(180deg,#FFFFFF, #F7FAFF);
  border-right: 1px solid var(--border); padding: 22px 16px; display: flex; flex-direction: column;
  gap: 4px; overflow-y: auto; z-index: var(--z-nav);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 16px; font-family: var(--font-display);
  font-size: 19px; font-weight: 800; letter-spacing: -.03em; color: var(--text); }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; flex: 0 0 30px; position: relative;
  background: conic-gradient(from 140deg, var(--recovery), var(--strain), var(--sleep), var(--recovery));
  box-shadow: 0 4px 12px -4px rgba(47,107,255,.4); }
.brand-mark::after { content: ""; position: absolute; inset: 6px; background: #fff; border-radius: 5px; }
.brand .brand-accent { color: var(--text); }
.home-link { display: inline-flex; align-items: center; font-size: 11px; color: var(--text-muted);
  text-decoration: none; padding: 4px 10px; margin: 0 8px 12px; border: 1px solid var(--border);
  border-radius: 999px; align-self: flex-start; transition: all 140ms; }
.home-link:hover { color: var(--accent-2); border-color: var(--accent); background: var(--accent-soft); }

.tabs { display: flex; flex-direction: column; gap: 3px; }
.tab {
  appearance: none; background: transparent; border: none; border-radius: 12px; color: var(--text-muted);
  text-align: left; padding: 11px 12px; font: 600 13.5px var(--font); letter-spacing: -.01em;
  display: flex; align-items: center; gap: 12px; cursor: pointer; position: relative;
  transition: background 160ms, color 160ms, box-shadow 160ms;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 8px 18px -8px var(--accent-ring);
}
.tab-icon { width: 30px; height: 30px; border-radius: 9px; display: inline-flex; align-items: center;
  justify-content: center; color: currentColor; flex-shrink: 0; background: var(--surface-2); transition: background 160ms; }
.tab:hover .tab-icon { background: var(--surface-3); }
.tab.active .tab-icon { background: rgba(255,255,255,.18); }
.tab-icon svg { width: 17px; height: 17px; stroke: currentColor; }

/* ─────────────────── Device dock (#mvp-panel) ─────────────────── */
#mvp-panel {
  margin-top: auto; padding: 16px; border-radius: var(--radius); background: var(--surface-1);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); display: flex; flex-direction: column;
  gap: 9px; font-size: 12px;
}
.dock-head { display: flex; justify-content: space-between; align-items: center; }
.dock-head strong { font: 800 11px var(--font-display); letter-spacing: .08em; text-transform: uppercase; }
#mvp-status { font-size: 10px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); }
.dock-hr { display: flex; align-items: baseline; gap: 5px; }
.dock-hr .n { font: 300 30px var(--font-display); line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.dock-hr .u { font-size: 12px; color: var(--muted); }
.dock-vitals { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; margin: 4px 0 6px;
  padding: 10px; background: var(--surface-2); border-radius: 12px; }
.dock-vital { display: flex; flex-direction: column; gap: 2px; }
.dock-vital:last-child { text-align: right; }
.dock-vital:nth-child(2) { text-align: center; }
.dock-vital .k { font-size: 9px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.dock-vital .v { font-size: 14px; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }
.dock-session { font-size: 11px; color: var(--muted); }
.dock-session b { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-2); }
#mvp-error { font-size: 11px; color: var(--bad); word-break: break-word; }
.dock-indicators { display: flex; gap: 8px; font-size: 10.5px; color: var(--muted); flex-wrap: wrap; }
.dock-divider { border-top: 1px solid var(--hairline); margin: 3px 0; }
.dock-section { border-top: 1px solid var(--hairline); margin-top: 6px; padding-top: 10px; }
.dock-weight { font-size: 11px; display: flex; justify-content: space-between; }
.dock-weight b { font-weight: 700; font-variant-numeric: tabular-nums; }
.dock-mono { font-size: 10px; color: var(--muted); margin-top: 4px; min-height: 1em; white-space: pre-wrap;
  max-height: 120px; overflow-y: auto; font-family: var(--font-mono); word-break: break-all; }
.dock-data-status { font-size: 10px; color: var(--muted); min-height: 1em; text-align: center; }

#mvp-panel button {
  appearance: none; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 11px; font: 700 11px var(--font); letter-spacing: .01em; cursor: pointer;
  transition: background 140ms, border-color 140ms, transform 80ms, color 140ms;
}
#mvp-panel button:hover { background: var(--surface-3); border-color: var(--border-hi); color: var(--text); }
#mvp-panel button:active { transform: translateY(1px); }
#mvp-panel button:disabled { opacity: .45; cursor: not-allowed; }
#mvp-connect {
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff; border: none; font-weight: 800;
  padding: 11px 14px; font-size: 12px; letter-spacing: .03em; box-shadow: 0 10px 22px -10px var(--accent-ring);
}
#mvp-connect:hover { filter: brightness(1.05); color: #fff; }
.dock-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.dock-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 5px; }
.dock-grid button, .dock-actions button.sm { font-size: 10px; padding: 6px 8px; }
.dock-export button { background: transparent; color: var(--text-muted); border: 1px solid var(--border);
  padding: 5px 9px; font-size: 10px; }
.dock-export button:hover { color: var(--text); border-color: var(--border-hi); background: var(--surface-2); }
#mvp-panel details { margin-top: 2px; font-size: 11px; }
#mvp-panel details > summary { list-style: none; cursor: pointer; font-weight: 700; color: var(--text-muted); padding: 3px 0; }
#mvp-panel details > summary:hover { color: var(--text); }
#mvp-panel details > summary::-webkit-details-marker { display: none; }
#mvp-panel details[open] > summary::before { content: "▾ "; }
#mvp-panel details:not([open]) > summary::before { content: "▸ "; }
#mvp-stats { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
#mvp-stats .v { font-variant-numeric: tabular-nums; color: var(--text-2); }
#mvp-health { font-size: 10px; color: var(--text-faint); cursor: pointer; opacity: .85; }
#mvp-health:hover { opacity: 1; color: var(--text-muted); }

.settings-btn { appearance: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text-muted); padding: 10px 12px; font: 600 12px var(--font); text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 8px; margin-top: 10px; transition: all 140ms; }
.settings-btn:hover { color: var(--text); border-color: var(--border-hi); background: var(--surface-3); }
.status-line { font-size: 10px; color: var(--text-faint); text-align: center; padding-top: 8px;
  border-top: 1px solid var(--hairline); margin-top: 4px; word-break: break-word; }

/* ───────────────────────── Main / Top bar ───────────────────────── */
main.content { padding: 0 36px 96px; min-width: 0; }
.top-bar { position: sticky; top: 0; z-index: 40; height: var(--topbar-h); display: flex; align-items: center;
  justify-content: space-between; background: linear-gradient(180deg, var(--bg) 60%, transparent);
  backdrop-filter: saturate(130%) blur(10px); }
.top-bar-left, .top-bar-right { display: flex; align-items: center; gap: 14px; }
.date-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-1);
  border: 1px solid var(--border); color: var(--text-2); padding: 9px 16px; border-radius: 999px;
  font-size: 12px; font-weight: 700; box-shadow: var(--shadow-sm); }
.date-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--recovery); box-shadow: 0 0 0 3px var(--recovery-glow); }
.icon-btn { appearance: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 13px;
  width: 42px; height: 42px; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; transition: all 140ms; position: relative; box-shadow: var(--shadow-sm); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .badge-count { position: absolute; top: -5px; right: -5px; background: var(--bad); color: #fff;
  font-size: 10px; font-weight: 800; width: 18px; height: 18px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; border: 2px solid var(--bg); }
.user-profile { display: flex; align-items: center; gap: 12px; padding: 5px 14px 5px 5px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface-1); cursor: pointer; transition: all 140ms; box-shadow: var(--shadow-sm); }
.user-profile:hover { background: var(--surface-2); border-color: var(--border-hi); transform: translateY(-1px); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 12px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 4px; }
.user-name .chevron { color: var(--text-muted); font-size: 9px; }
.user-email { font-size: 10px; color: var(--text-muted); }

/* ───────────────────────── Panels ───────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: panel-in .4s cubic-bezier(.22,1,.36,1); }
@keyframes panel-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.panel-header { padding: 8px 0 26px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.panel-header h1 { font-size: 38px; }
.panel-subtitle { color: var(--text-muted); font-size: 14px; margin-top: 8px; max-width: 60ch; }
.panel-date { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; padding: 6px 12px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px; }
.welcome-text { color: var(--text); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 36px 0 18px; }
.section-head h2 { position: relative; padding-left: 14px; }
.section-head h2::before { content: ""; position: absolute; left: 0; top: 8%; height: 84%; width: 4px;
  border-radius: 4px; background: linear-gradient(180deg, var(--accent), var(--sleep)); }

.controls { display: flex; gap: 8px; }
.controls select, .select-mini { appearance: none; background: var(--surface-1); color: var(--text);
  border: 1px solid var(--border); padding: 9px 14px; font: 700 12px var(--font); border-radius: 999px;
  cursor: pointer; box-shadow: var(--shadow-sm);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.controls select:hover, .select-mini:hover { border-color: var(--border-hi); }
.controls select:focus-visible, .select-mini:focus-visible { box-shadow: var(--focus); border-color: var(--accent); }
.select-mini { padding: 5px 28px 5px 12px; font-size: 11px; background-color: var(--surface-2); }

.btn-soft { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); padding: 6px 13px;
  border-radius: 999px; font: 700 11px var(--font); letter-spacing: .03em; cursor: pointer; transition: all 140ms; }
.btn-soft:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ───────────────────────── Cards & grid ───────────────────────── */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px 24px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: box-shadow 220ms cubic-bezier(.22,1,.36,1), transform 220ms cubic-bezier(.22,1,.36,1), border-color 220ms;
}
.card::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.9), transparent); pointer-events: none; }
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--border-hi); }
.card .card-eyebrow { margin-bottom: 14px; display: block; }
.card .big-num { font-family: var(--font-display); font-size: 38px; font-weight: 300; line-height: 1;
  letter-spacing: -.04em; color: var(--text); display: inline-flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
.card .big-num .unit { font-size: 13px; font-weight: 700; color: var(--text-muted); letter-spacing: 0; }
.card .muted { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.card-hero { padding: 32px 24px 28px; text-align: center; }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: var(--gutter); }
.grid > .span-2 { grid-column: span 2; } .grid > .span-3 { grid-column: span 3; } .grid > .span-4 { grid-column: span 4; }
@media (max-width: 1100px) { .grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid > .span-3, .grid > .span-4 { grid-column: span 2; } }

.stat-row { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 18px; align-items: flex-end; }
.stat .num { font-family: var(--font-display); font-size: 34px; font-weight: 300; letter-spacing: -.04em;
  color: var(--text); font-variant-numeric: tabular-nums; line-height: 1; }
.stat .num.warn { color: var(--warn); }
.stat .lbl { font-size: 10px; color: var(--text-muted); margin-top: 6px; letter-spacing: .02em; }

/* ───────────────────────── Hero rings ───────────────────────── */
.hero-ring-row { display: grid; grid-template-columns: repeat(3,1fr); gap: var(--gutter); }
@media (max-width: 880px) { .hero-ring-row { grid-template-columns: 1fr; } }
.ring-card { padding: 26px 24px 22px; text-align: center; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: box-shadow 220ms, transform 220ms; }
.ring-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 180px; pointer-events: none; opacity: .7; }
.ring-card.recovery::before { background: radial-gradient(120% 80% at 50% -20%, var(--recovery-glow), transparent 70%); }
.ring-card.strain::before   { background: radial-gradient(120% 80% at 50% -20%, var(--strain-glow), transparent 70%); }
.ring-card.sleep::before    { background: radial-gradient(120% 80% at 50% -20%, var(--sleep-glow), transparent 70%); }
.ring-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.ring-card.col { display: flex; flex-direction: column; }
.ring-eyebrow { position: relative; font-size: 10px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: var(--text-muted); }
.ring-card.recovery .ring-eyebrow { color: var(--recovery-2); }
.ring-card.strain .ring-eyebrow { color: var(--strain-2); }
.ring-card.sleep .ring-eyebrow { color: var(--sleep-2); }
.ring-wrap { position: relative; width: 220px; height: 220px; margin: 16px auto 8px; }
.ring-wrap.big { width: 300px; height: 300px; }
.ring-wrap.big.center { margin: 18px auto; }
.ring-wrap.strain-hero { width: 260px; height: 260px; margin: 18px auto; }
.ring-wrap svg { width: 100%; height: 100%; overflow: visible; }
.ring-value { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.ring-value .num { font-family: var(--font-display); font-size: 74px; font-weight: 300; letter-spacing: -.05em; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.ring-value .num .unit { font-size: 26px; font-weight: 500; color: var(--text-muted); margin-left: 2px; letter-spacing: 0; }
.ring-value .num.big { font-size: 96px; }
.ring-value .sub { font-size: 11px; font-weight: 700; color: var(--text-muted); letter-spacing: .1em; text-transform: uppercase; margin-top: 8px; }
.ring-foot { margin-top: 8px; font-size: 12px; color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 14px; font-variant-numeric: tabular-nums; }
.ring-foot strong { color: var(--text); font-weight: 700; }
.ring-coach { font-size: 13px; color: var(--text-2); text-align: center; line-height: 1.55; min-height: 1.4em; max-width: 340px; margin: 8px auto 0; }
.spark-wrap { position: relative; width: 100%; height: 38px; max-height: 38px; margin-top: 16px; overflow: hidden; }
canvas.spark { display: block; width: 100% !important; height: 38px !important; max-height: 38px; }

/* ───────────────────────── Now tile ───────────────────────── */
.now-tile { display: grid; grid-template-columns: auto 1fr; gap: 26px; align-items: center; }
.now-hr { display: flex; align-items: baseline; gap: 4px; font-family: var(--font-display); font-size: 66px; font-weight: 300; letter-spacing: -.04em; color: var(--text); line-height: 1; font-variant-numeric: tabular-nums; }
.now-hr .unit { font-size: 14px; font-weight: 700; color: var(--text-muted); }
.heart-pulse { display: inline-flex; align-items: center; margin-left: 10px; color: var(--bad); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.18); opacity: 1; } }
.now-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.now-grid > div { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--hairline); padding-bottom: 6px; }
.now-grid .lbl { font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); }
.now-grid span:last-child { font-size: 14px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* ───────────────────────── Wake alarm ───────────────────────── */
.alarm-row { display: flex; align-items: baseline; gap: 12px; margin-top: 8px; }
.alarm-time { background: var(--surface-2); color: var(--fg); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font: 800 30px var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.04em; width: auto; }
.alarm-time:focus-visible { box-shadow: var(--focus); border-color: var(--accent); }
.alarm-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.alarm-actions .primary { flex: 1; min-width: 92px; }
#wake-alarm-status { font-size: 11px; color: var(--muted); margin-top: 10px; min-height: 1.2em; }
.alarm-clock { border-top: 1px solid var(--hairline); margin-top: 12px; padding-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#wake-clock-drift { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ───────────────────────── Plan / insights / workouts ───────────────────────── */
.plan-card { background: linear-gradient(180deg, #fff, #FBFCFF); }
.plan-illust { font-size: 38px; line-height: 1; margin-bottom: 6px; }
#plan-zone { font: 700 28px var(--font-display); letter-spacing: -.02em; margin: 2px 0; }
#plan-label { font-size: 15px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; }
#plan-message { font-size: 12px; color: var(--text-muted); line-height: 1.6; white-space: pre-line; }
#plan-target { font-size: 11px; color: var(--text-faint); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hairline); }

.workout-list { display: flex; flex-direction: column; gap: 8px; }
.workout-row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; transition: all 140ms; }
.workout-row:hover { background: #fff; border-color: var(--border-hi); box-shadow: var(--shadow-sm); }
.workout-row .wo-time { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.workout-row .wo-name { font-size: 13px; font-weight: 700; color: var(--text); }
.workout-row .wo-strain { font-family: var(--font-display); font-size: 19px; font-weight: 600; color: var(--strain); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

.insight { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 13px 15px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 14px; font-size: 12px; transition: all 140ms; }
.insight:hover { background: #fff; box-shadow: var(--shadow-sm); }
.insight .ins-icon { width: 30px; height: 30px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.insight.warn .ins-icon { background: rgba(224,134,0,.14); color: var(--warn); }
.insight.info .ins-icon { background: var(--accent-soft); color: var(--accent-2); }
.insight.critical .ins-icon { background: rgba(224,50,47,.13); color: var(--bad); }
.insight .ins-icon svg { width: 16px; height: 16px; }
.insight .ins-title { font-size: 12px; font-weight: 800; color: var(--text); margin-bottom: 2px; }
.insight .ins-body { color: var(--text-muted); line-height: 1.55; }
#insights-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px 12px; color: var(--text-muted); font-size: 12px; text-align: center; }
.empty-state svg { width: 64px; height: 64px; opacity: .3; }

/* Consistency / habit */
.habit-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 12px; }
.streak-block { display: flex; flex-direction: column; gap: 2px; }
.streak-num { font: 300 46px var(--font-display); line-height: 1; letter-spacing: -.04em; color: var(--text); display: inline-flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.streak-num .streak-unit { font-size: 14px; font-weight: 700; color: var(--text-muted); letter-spacing: 0; }
.streak-lbl { font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted); }
.week-ring-wrap { position: relative; width: 88px; height: 88px; flex-shrink: 0; }
.week-ring-wrap svg { width: 100%; height: 100%; }
.week-ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.week-ring-center #habit-week-num { font: 700 18px var(--font-display); color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.week-ring-lbl { font-size: 8px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); }
.habit-dots { display: flex; gap: 6px; margin-top: 18px; }
.habit-dots .hd { flex: 1; height: 7px; border-radius: 999px; background: var(--track); }
.habit-dots .hd.on { background: linear-gradient(180deg, var(--accent), var(--accent-2)); }
.habit-dots .hd.today { box-shadow: 0 0 0 2px var(--accent-soft); }

/* ───────────────────────── Journal ───────────────────────── */
.journal-grid { display: flex; gap: 14px; align-items: flex-start; margin-top: 8px; flex-wrap: wrap; }
.journal-compose { flex: 1; min-width: 220px; }
.journal-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.journal-tag { appearance: none; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 999px; padding: 7px 13px; font: 700 11px var(--font); cursor: pointer; transition: all 140ms; }
.journal-tag:hover { border-color: var(--border-hi); color: var(--text); transform: translateY(-1px); }
.journal-tag.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.journal-input { width: 100%; box-sizing: border-box; min-height: 66px; background: var(--surface-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; font: 13px/1.5 var(--font); resize: vertical; }
.journal-input:focus-visible { box-shadow: var(--focus); border-color: var(--accent); }
.journal-side { display: flex; flex-direction: column; gap: 8px; }
.journal-date { background: var(--surface-2); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font: 12px var(--font); cursor: pointer; color-scheme: light; }
#journal-save { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff; border: none; border-radius: 10px; padding: 9px 16px; font: 800 12px var(--font); cursor: pointer; white-space: nowrap; transition: filter 140ms; }
#journal-save:hover { filter: brightness(1.05); }
#journal-status { font-size: 10px; color: var(--muted); }
#journal-history { margin-top: 10px; font-size: 11px; color: var(--muted); }

/* ───────────────────────── Charts / data viz ───────────────────────── */
.chart-wrap { position: relative; width: 100%; height: 210px; }
.chart-wrap.tall { height: 290px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.hypnogram-wrap { width: 100%; height: 220px; margin-top: 14px; }
.hypnogram-wrap svg { width: 100%; height: 100%; }
.legend { display: flex; gap: 16px; margin-top: 14px; flex-wrap: wrap; font-size: 11px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }

.stage-bars { display: flex; flex-direction: column; gap: 11px; }
.stage-bars .row { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; font-size: 12px; }
.stage-bars .lbl { color: var(--text-muted); font-weight: 700; letter-spacing: .04em; }
.stage-bars .v { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.stage-bars .barwrap { height: 9px; background: var(--track); border-radius: 999px; overflow: hidden; }
.stage-bars .bar { height: 100%; border-radius: inherit; }

.components { display: flex; flex-direction: column; gap: 13px; margin-top: 14px; }
.component-row { display: grid; grid-template-columns: 92px 1fr 40px; gap: 12px; align-items: center; font-size: 12px; }
.component-row .name { color: var(--text-muted); font-weight: 600; }
.component-row .val { color: var(--text); font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.component-row .barwrap { height: 9px; background: var(--track); border-radius: 999px; overflow: hidden; }
.component-row .bar { height: 100%; border-radius: inherit; }

.zones-row { display: grid; grid-template-columns: repeat(5,1fr); gap: 8px; margin-top: 14px; }
.zone-cell { text-align: center; background: var(--surface-2); border-radius: 14px; padding: 14px 4px; border: 1px solid var(--border); transition: all 140ms; }
.zone-cell:hover { background: #fff; box-shadow: var(--shadow-sm); }
.zone-cell .zlbl { font-size: 10px; font-weight: 800; color: var(--text-muted); letter-spacing: .04em; }
.zone-cell .zval { font: 600 18px var(--font-display); color: var(--text); margin-top: 6px; font-variant-numeric: tabular-nums; }

.donut-wrap { display: flex; justify-content: center; padding: 8px 0; }
.donut-wrap svg { width: 180px; height: 180px; }

.energy-row { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 16px; align-items: flex-end; }
.energy-track { margin-top: 16px; height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; }
.energy-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--strain), var(--sleep)); border-radius: 999px; transition: width .5s cubic-bezier(.22,1,.36,1); }

.acwr-row { display: flex; align-items: baseline; gap: 12px; margin-top: 8px; }
#acwr-band { font-size: 11px; font-weight: 800; letter-spacing: .04em; }
#acwr-detail { font-size: 10px; color: var(--muted); margin-top: 6px; }

.quality-row { display: flex; align-items: center; gap: 20px; margin-top: 10px; }
#sleep-quality-breakdown { flex: 1; display: grid; grid-template-columns: 1fr auto; gap: 5px 14px; font-size: 11px; color: var(--text-muted); }
#personal-records { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 10px; margin-top: 10px; }
#weekly-summary-text { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7; color: var(--text-2); white-space: pre-wrap; margin: 12px 0 0; background: var(--surface-2); border-radius: 12px; padding: 14px 16px; }
#recovery-cal { margin-top: 10px; }

/* ───────────────────────── Tables ───────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; margin-top: 6px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; font-variant-numeric: tabular-nums; }
table th, table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--hairline); }
table th { font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); background: var(--surface-2); position: sticky; top: 0; }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--accent-soft); }
table td { color: var(--text-2); }

.cal-cell { transition: transform 120ms; }
.cal-cell:hover { transform: scale(1.18); z-index: 2; position: relative; }
@media (max-width: 720px) { #recovery-cal-grid { grid-template-columns: repeat(10,1fr) !important; } }

/* ───────────────────────── Live lists ───────────────────────── */
.row { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--hairline); font-size: 13px; }
.row:last-child { border-bottom: none; }
.row .k { color: var(--text-muted); font-weight: 600; }
.row .v { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.ev { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--hairline); font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.ev:last-child { border-bottom: none; }
.ev .kind { display: inline-block; padding: 2px 9px; background: var(--surface-2); border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }

/* ───────────────────────── Coach ───────────────────────── */
.coach-card { display: flex; flex-direction: column; min-height: 62vh; }
.coach-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px 2px; }
.coach-form { display: flex; gap: 10px; margin-top: 14px; }
.coach-input { flex: 1; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px; }
.coach-input:focus-visible { box-shadow: var(--focus); border-color: var(--accent); }
.hint { font-size: 11px; color: var(--text-faint); margin-top: 10px; }

.primary { appearance: none; background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff; border: none;
  border-radius: 12px; padding: 11px 18px; font: 800 13px var(--font); cursor: pointer; transition: filter 140ms, transform 80ms; box-shadow: 0 10px 22px -12px var(--accent-ring); }
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .5; cursor: not-allowed; }
.big-num { font-family: var(--font-display); }
.unit { font-size: .5em; color: var(--text-muted); font-weight: 700; margin-left: 4px; }

/* ───────────────────────── Modals + drawer ───────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11,18,32,.4); backdrop-filter: blur(6px); z-index: var(--z-modal); display: none; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal-card { background: var(--surface-1); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px 32px; max-width: 540px; width: 92%; box-shadow: var(--shadow-md); max-height: 88vh; overflow-y: auto; }
.modal-card h2 { margin: 0 0 12px; } .modal-card h3 { font-size: 13px; margin: 16px 0 4px; }
.modal-card p { font-size: 13px; line-height: 1.55; color: var(--text-muted); }
.modal-card ol { font-size: 13px; line-height: 1.6; margin-top: 2px; padding-left: 18px; }
.modal-card code { font-family: var(--font-mono); font-size: 11px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.modal-card a { color: var(--accent-2); }

.backdrop { position: fixed; inset: 0; background: rgba(11,18,32,.4); backdrop-filter: blur(6px); z-index: 90; display: none; }
.backdrop.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; width: 440px; max-width: 92vw; height: 100vh; background: var(--surface-1);
  border-left: 1px solid var(--border); padding: 30px 32px; z-index: 100; display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto; transform: translateX(100%); visibility: hidden; transition: transform 280ms cubic-bezier(.22,1,.36,1), visibility 0s linear 280ms; box-shadow: -24px 0 60px -30px rgba(11,18,32,.4); }
.drawer.open { transform: translateX(0); visibility: visible; transition: transform 280ms cubic-bezier(.22,1,.36,1); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 14px; border-bottom: 1px solid var(--hairline); }
.drawer-head h2 { font-size: 23px; }
.close-btn { appearance: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; width: 38px; height: 38px; font-size: 20px; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.close-btn:hover { color: var(--text); border-color: var(--border-hi); }
.settings-form { display: flex; flex-direction: column; gap: 15px; }
.settings-form label { display: flex; flex-direction: column; gap: 7px; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); }
.settings-form input, .settings-form select { appearance: none; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 11px 13px; font: 500 14px var(--font); border-radius: 12px; font-variant-numeric: tabular-nums; }
.settings-form input:focus-visible, .settings-form select:focus-visible { box-shadow: var(--focus); border-color: var(--accent); }
.settings-form .primary { margin-top: 4px; }
.settings-form .hint { font-size: 11px; color: var(--text-faint); font-weight: normal; letter-spacing: 0; text-transform: none; }
.drawer hr { border: none; border-top: 1px solid var(--hairline); margin: 0; }
.drawer .actions { display: flex; flex-direction: column; gap: 10px; }
.drawer .actions button { appearance: none; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 11px 14px; border-radius: 12px; font: 700 12px var(--font); cursor: pointer; transition: all 140ms; }
.drawer .actions button:hover { background: var(--surface-3); }
.drawer .actions .hint { font-size: 11px; color: var(--text-muted); }

/* ───────────────────────── Mobile ───────────────────────── */
@media (max-width: 720px) {
  body { grid-template-columns: 1fr; padding-left: var(--sa-left); padding-right: var(--sa-right); }
  .sidebar { display: none; }
  main.content { padding: 12px 16px calc(84px + var(--sa-bottom)); }
  .top-bar { height: auto; min-height: 54px; padding-top: var(--sa-top); margin-bottom: 6px; }
  .user-profile .user-info { display: none; } .user-profile { padding: 4px; }
  .date-pill { padding: 7px 12px; font-size: 11px; }
  .panel-header { padding: 8px 0 18px; flex-direction: column; align-items: flex-start; gap: 10px; }
  .panel-header h1 { font-size: 28px; } .panel-subtitle { font-size: 13px; }
  .section-head { margin: 26px 0 14px; }
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .grid > .span-2, .grid > .span-3, .grid > .span-4 { grid-column: span 1; }
  .hero-ring-row { grid-template-columns: 1fr; gap: 14px; }
  .ring-wrap { width: 184px; height: 184px; } .ring-wrap.big { width: 224px; height: 224px; }
  .ring-value .num { font-size: 58px; } .ring-value .num.big { font-size: 74px; } .ring-value .num .unit { font-size: 22px; }
  .card { padding: 18px; border-radius: var(--radius); } .card .card-eyebrow { margin-bottom: 10px; } .card .big-num { font-size: 30px; }
  h1 { font-size: 26px; } h2 { font-size: 18px; }
  .now-tile { grid-template-columns: 1fr; gap: 14px; } .now-hr { font-size: 46px; } .now-grid { grid-template-columns: 1fr 1fr; }
  .chart-wrap { height: 168px; } .chart-wrap.tall { height: 210px; }
  .drawer { width: 100vw; max-width: 100vw; padding: 24px 20px calc(24px + var(--sa-bottom)); }
  .mobile-nav { display: flex !important; }
}
.mobile-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: calc(66px + var(--sa-bottom));
  padding: 0 6px var(--sa-bottom); background: rgba(255,255,255,.9); backdrop-filter: saturate(150%) blur(22px);
  -webkit-backdrop-filter: saturate(150%) blur(22px); border-top: 1px solid var(--border); justify-content: space-around; align-items: stretch; z-index: 50; }
.mobile-nav .mtab { flex: 1; appearance: none; background: transparent; border: none; color: var(--text-faint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer;
  font: 700 9px var(--font); letter-spacing: .04em; text-transform: uppercase; padding: 8px 0 6px; min-height: 44px; transition: color 140ms; }
.mobile-nav .mtab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mobile-nav .mtab.active { color: var(--accent); }
.mobile-nav .mtab.active svg { filter: drop-shadow(0 4px 8px var(--accent-ring)); }
.mobile-nav .mtab:active { transform: scale(.92); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .heart-pulse { animation: none; } .tab-panel.active { animation: none; }
}
