/* Tokens y componentes copiados VERBATIM del mockup aprobado (docs/fitpanel-mockup.html). */
:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --blue: #2a78d6;
  --aqua: #1baf7a;
  --violet: #4a3aa7;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --z1: #86b6ef; --z2: #5598e7; --z3: #2a78d6; --z4: #1c5cab; --z5: #0d366b;
  --band: rgba(42,120,214,0.10);
  --safe-band: rgba(12,163,12,0.10);
  --ring-track: #eceae4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --blue: #3987e5;
    --aqua: #199e70;
    --violet: #9085e9;
    --good: #0ca30c;
    --good-text: #0ca30c;
    --z1: #9ec5f4; --z2: #6da7ec; --z3: #3987e5; --z4: #256abf; --z5: #184f95;
    --band: rgba(57,135,229,0.14);
    --safe-band: rgba(12,163,12,0.12);
    --ring-track: #2c2c2a;
  }
}
:root[data-theme="light"] {
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e;
  --muted: #898781; --grid: #e1e0d9; --baseline: #c3c2b7; --border: rgba(11,11,11,0.10);
  --blue: #2a78d6; --aqua: #1baf7a; --violet: #4a3aa7;
  --good: #0ca30c; --good-text: #006300; --warning: #fab219; --critical: #d03b3b;
  --z1: #86b6ef; --z2: #5598e7; --z3: #2a78d6; --z4: #1c5cab; --z5: #0d366b;
  --band: rgba(42,120,214,0.10); --safe-band: rgba(12,163,12,0.10); --ring-track: #eceae4;
}
:root[data-theme="dark"] {
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255,255,255,0.10);
  --blue: #3987e5; --aqua: #199e70; --violet: #9085e9;
  --good: #0ca30c; --good-text: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  --z1: #9ec5f4; --z2: #6da7ec; --z3: #3987e5; --z4: #256abf; --z5: #184f95;
  --band: rgba(57,135,229,0.14); --safe-band: rgba(12,163,12,0.12); --ring-track: #2c2c2a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
  padding-bottom: 84px;
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.wordmark {
  font-weight: 800; letter-spacing: 0.14em; font-size: 15px;
}
.wordmark span { color: var(--blue); }
.sync-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; background: var(--surface);
  white-space: nowrap;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
.sync-chip.stale .sync-dot { background: var(--critical); }

main { max-width: 980px; margin: 0 auto; padding: 8px 16px 24px; }

.date-line { margin: 18px 2px 10px; display: flex; align-items: baseline; justify-content: space-between; }
.date-line h1 { font-size: 20px; margin: 0; font-weight: 700; }
.date-line .sub { font-size: 12.5px; color: var(--muted); }

.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); margin: 26px 2px 10px;
}

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .grid.today { grid-template-columns: 1.1fr 1fr 1fr; }
  .grid.trends { grid-template-columns: 1fr 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
}
.card h2 {
  margin: 0 0 2px; font-size: 12px; font-weight: 600;
  letter-spacing: 0.10em; text-transform: uppercase; color: var(--ink-2);
}
.card .h2-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .h2-note { font-size: 11.5px; color: var(--muted); }

/* ---- Recovery ring ---- */
.ring-wrap { display: flex; align-items: center; gap: 18px; margin-top: 10px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .val {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
}
.ring .val b { font-size: 38px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; display: block; }
.ring .val small { font-size: 10px; letter-spacing: 0.10em; color: var(--muted); text-transform: uppercase; }
.facts { display: grid; gap: 8px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.facts b { color: var(--ink); font-weight: 700; }
.delta-up { color: var(--good-text); font-weight: 600; }
.delta-down { color: var(--critical); font-weight: 600; }
.status-line { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; }
.status-line.verde { color: var(--good-text); }
.status-line.amarillo { color: var(--warning); }
.status-line.rojo { color: var(--critical); }
.status-line.calibrando { color: var(--muted); }

/* ---- Strain meter ---- */
.hero-num { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; margin-top: 12px; }
.hero-num small { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.meter { margin-top: 14px; height: 10px; border-radius: 5px; background: var(--ring-track); position: relative; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--blue); border-radius: 5px; }
.meter-scale { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: 5px; }
.kv { display: flex; gap: 16px; margin-top: 14px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.kv b { color: var(--ink); }

/* ---- Sleep stage strip ---- */
.stage-strip { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; margin-top: 14px; }
.stage-strip i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; font-size: 11.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }

/* ---- Charts ---- */
.chart { margin-top: 10px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.axis-note { font-size: 10.5px; color: var(--muted); }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--page);
  font-size: 11.5px; line-height: 1.35;
  padding: 6px 9px; border-radius: 7px;
  transform: translate(-50%, calc(-100% - 10px));
  opacity: 0; transition: opacity 0.12s ease;
  white-space: nowrap;
}
.tooltip.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .tooltip { transition: none; } }

/* ---- Workouts ---- */
.wo { display: grid; gap: 10px; }
.wo-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px;
}
.wo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wo-title { font-weight: 700; font-size: 15px; }
.wo-date { font-size: 12px; color: var(--muted); }
.chip {
  display: inline-block; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em;
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px;
  color: var(--ink-2); margin-left: 8px; vertical-align: 1px;
}
.wo-stats { display: flex; gap: 18px; margin: 8px 0 10px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.wo-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.zone-strip { display: flex; height: 12px; border-radius: 4px; overflow: hidden; gap: 2px; }
.zone-strip i { height: 100%; }
.zone-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 4px; letter-spacing: 0.06em; }
.wo-row { cursor: pointer; }
.wo-detail { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; cursor: default; }
.wo-detail[hidden] { display: none; }

/* ---- Bottom nav ---- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.bottomnav a {
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
  display: grid; justify-items: center; gap: 3px; padding: 2px 10px; border-radius: 8px;
}
.bottomnav a.active { color: var(--blue); }
.bottomnav svg { width: 20px; height: 20px; }
.bottomnav a:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
@media (min-width: 720px) { .bottomnav { display: none; } body { padding-bottom: 24px; } }

/* ---- Vistas (router por hash; en escritorio se apilan todas) ---- */
.view[hidden] { display: none; }
@media (min-width: 720px) { .view[hidden] { display: block; } }

/* ---- Estados vacíos ---- */
.empty { color: var(--muted); font-size: 13px; padding: 18px 2px; text-align: center; }

/* ---- Auth overlay ----
   Gotcha heredado de Captalia: un display propio ANULA [hidden] del navegador,
   por eso la regla .auth-overlay[hidden] es obligatoria. */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--page); padding: 16px;
}
.auth-overlay[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; display: grid; gap: 14px;
}
.auth-card .wordmark { font-size: 18px; text-align: center; }
.auth-card label { font-size: 12px; color: var(--ink-2); display: grid; gap: 5px; }
.auth-card input {
  font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
.auth-card input:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.auth-card button {
  font: inherit; font-weight: 700; color: #fff; background: var(--blue);
  border: 0; border-radius: 8px; padding: 10px; cursor: pointer;
}
.auth-card button:disabled { opacity: 0.6; cursor: default; }
.auth-error { color: var(--critical); font-size: 12.5px; min-height: 1.2em; }

/* ---- Botón secundario (cerrar sesión en Ajustes) ---- */
.btn-ghost {
  font: inherit; font-weight: 600; font-size: 13px; color: var(--ink-2);
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
}
.btn-ghost:hover { color: var(--ink); }
