/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  color-scheme: light;
  --bg: #fcfcfb;           /* una sola superficie */
  --surface-1: #fcfcfb;
  --surface-2: #f4f4f1;    /* contenedores sutiles */
  --hover: #efefeb;
  --border: #e8e7e3;
  --grid: #efeee9;
  --band: #e8e7e2;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6e69;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --highlight: rgb(42 120 214 / .07);
  --error: #c62828;
  /* Zonas de FC: rampa ordinal de un solo tono (más oscuro = más intenso) */
  --z1: #86b6ef;
  --z2: #5598e7;
  --z3: #2a78d6;
  --z4: #1c5cab;
  --z5: #104281;
  /* Fases de sueño (categórico) */
  --s-deep: #6250d6;
  --s-rem: #e87ba4;
  --s-light: #1baf7a;
  /* Estado (igual en claro y oscuro); siempre con icono + texto */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1a1a19;
    --surface-1: #1a1a19;
    --surface-2: #222220;
    --hover: #2a2a27;
    --border: #2e2e2b;
    --grid: #262624;
    --band: #30302d;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #aaa9a1;
    --accent: #3987e5;
    --highlight: rgb(57 135 229 / .12);
    --error: #ef6b6b;
    --z1: #184f95;
    --z2: #256abf;
    --z3: #3987e5;
    --z4: #6da7ec;
    --z5: #9ec5f4;
    --s-deep: #9085e9;
    --s-rem: #d55181;
    --s-light: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1a19;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --hover: #2a2a27;
  --border: #2e2e2b;
  --grid: #262624;
  --band: #30302d;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #aaa9a1;
  --accent: #3987e5;
  --highlight: rgb(57 135 229 / .12);
  --error: #ef6b6b;
  --z1: #184f95;
  --z2: #256abf;
  --z3: #3987e5;
  --z4: #6da7ec;
  --z5: #9ec5f4;
  --s-deep: #9085e9;
  --s-rem: #d55181;
  --s-light: #199e70;
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* que ningún display de una clase anule el atributo hidden */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -.02em; margin: 0; }
h2 { font-size: .95rem; font-weight: 500; margin: 0; }
h3 { font-size: 1rem; font-weight: 500; margin: 0; }
p { margin: 0; }
small { font-size: .62em; font-weight: 400; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: .82rem; }

main { max-width: 1040px; margin: 0 auto; padding: 1.5rem 16px 4rem; }

/* ==========================================================================
   Barra superior
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: stretch; justify-content: space-between; gap: 1.5rem;
  padding: 0 max(16px, calc((100% - 1040px) / 2 + 16px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 -1px 0 var(--border);
}
/* Pestañas como texto con subrayado sobre la línea inferior de la barra (igual que las de Fuerza) */
.tabs { display: flex; gap: 1.75rem; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  display: flex; align-items: center; padding: 1.05rem 0 .95rem; color: var(--text-muted); white-space: nowrap;
  box-shadow: inset 0 -2px 0 transparent; transition: color .15s, box-shadow .15s;
}
.tabs a:hover { color: var(--text-primary); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--text-primary); font-weight: 500; box-shadow: inset 0 -2px 0 var(--accent); }
.sync { display: flex; align-items: center; gap: .25rem; }
.sync form { margin: 0; }
.sync .ghost { color: var(--text-muted); font-size: .88rem; padding: .35rem .6rem; }
.sync-icon { display: inline-block; }
button[data-syncing] .sync-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon { width: 1.25rem; height: 1.25rem; flex: none; }
.icon-link { display: inline-grid; place-items: center; color: var(--text-muted); padding: .4rem; border-radius: 8px; line-height: 1; }
.icon-link:hover, .icon-link[aria-current="page"] { color: var(--text-primary); background: var(--surface-2); text-decoration: none; }

/* Móvil: sin barra superior; navegación fija abajo con icono y texto */
.bottomnav { display: none; }
@media (max-width: 720px) {
  .topbar { display: none; }
  main { padding-top: 1.25rem; padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .bottomnav {
    position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
    padding: .35rem max(4px, env(safe-area-inset-left)) calc(.35rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
  }
  .bottomnav a {
    display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .35rem 0;
    color: var(--text-muted); font-size: .68rem; border-radius: 10px; min-width: 0;
  }
  .bottomnav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bottomnav a:hover { text-decoration: none; }
  .bottomnav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .bottomnav .icon { width: 1.4rem; height: 1.4rem; }
  .toast { bottom: calc(5rem + env(safe-area-inset-bottom)); }
  main:has(.workout) { padding-bottom: 1rem; }  /* el entreno no lleva barra de navegación abajo */
}

/* ==========================================================================
   Botones
   ========================================================================== */
button, .button {
  font: inherit; cursor: pointer; border: 0; border-radius: 8px;
  padding: .45rem .9rem; background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: .4rem;
}
.button:hover { text-decoration: none; }
button[disabled] { opacity: .55; cursor: default; }
button.ghost, button.secondary, .button.secondary {
  background: transparent; color: var(--text-secondary); border: 1px solid transparent;
}
button.ghost:hover, button.secondary:hover, .button.secondary:hover { background: var(--surface-2); color: var(--text-primary); }
button.secondary, .button.secondary { border-color: var(--border); }
.text-btn { background: none; border: 0; padding: .25rem .4rem; color: var(--accent); font-size: .88rem; cursor: pointer; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 2rem; height: 2rem; padding: 0 .4rem;
  border-radius: 8px; color: var(--text-secondary); background: transparent; border: 1px solid transparent; font-size: 1.15rem; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.icon-btn.disabled, .icon-btn[disabled] { opacity: .3; pointer-events: none; }
.small-btn { padding: .2rem .6rem; font-size: .82rem; }
button.danger { color: var(--critical); }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 20;
  background: var(--text-primary); color: var(--bg); padding: .55rem 1rem; border-radius: 999px;
  font-size: .88rem; box-shadow: 0 6px 24px rgb(0 0 0 / .18); transition: opacity .4s, transform .4s;
}
.toast.hide { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
.notice { padding: .6rem .9rem; border-radius: 8px; background: var(--surface-2); margin-bottom: 1rem; }
.notice.error { color: var(--error); }

/* ==========================================================================
   Estructura
   ========================================================================== */
.page-head, .week-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.eyebrow { color: var(--text-muted); font-size: .8rem; margin-bottom: .15rem; }
.pager-nav, .week-nav { display: flex; gap: .15rem; align-items: center; }

.section { margin-bottom: 2.25rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .85rem; }

/* Las "cards" de las páginas secundarias son secciones planas */
.card { margin-bottom: 2rem; position: relative; }
.card > h2 { margin-bottom: .75rem; }
.card.narrow { max-width: 440px; }
.empty { padding: 2.5rem 0; }
.empty h2 { font-size: 1.15rem; margin-bottom: .35rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 2rem; }

/* Secciones plegables */
.fold { border-top: 1px solid var(--border); }
.fold:last-of-type { border-bottom: 1px solid var(--border); }
.fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  padding: .95rem 0; font-weight: 500;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "›"; display: inline-block; width: .8rem; color: var(--text-muted); transition: transform .2s; }
.fold[open] > summary::before { transform: rotate(90deg); }
.fold > summary .muted { font-weight: 400; margin-left: auto; }
.fold > :not(summary) { margin-bottom: 1.5rem; }

/* ==========================================================================
   Vista semanal
   ========================================================================== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 1.5rem 2rem; margin-bottom: 2.5rem; }
.kpi { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.kpi-label { color: var(--text-muted); font-size: .8rem; }
.kpi-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-value small { font-size: .5em; }
.delta { color: var(--text-muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.meter { height: 4px; border-radius: 2px; background: var(--band); margin-top: .45rem; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.vitals { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(120px, 100%), 1fr)); gap: 1rem 1.5rem; }
.vital { display: flex; flex-direction: column; cursor: default; }
.vital-value { font-size: 1.3rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.vital-value small { font-size: .58em; }
.vital-label { color: var(--text-muted); font-size: .78rem; }

.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .6rem; }
@media (max-width: 760px) { .week-strip { grid-template-columns: repeat(auto-fit, minmax(min(130px, 100%), 1fr)); } }
.day { display: flex; flex-direction: column; gap: .4rem; min-height: 128px; padding: .85rem .8rem; border-radius: var(--radius); background: var(--surface-2); }
.day.future { background: transparent; border: 1px dashed var(--border); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; }
.day-name { color: var(--text-muted); font-size: .78rem; }
.day-num { font-weight: 600; font-variant-numeric: tabular-nums; }
.day.today .day-num { background: var(--accent); color: var(--accent-ink); border-radius: 999px; min-width: 1.6rem; text-align: center; padding: 0 .3rem; }
.day-rest { margin: auto 0; text-align: center; color: var(--text-muted); font-size: .8rem; }
.act { display: flex; flex-direction: column; gap: .1rem; padding: .5rem .55rem; border-radius: 8px; background: var(--bg); color: var(--text-primary); font-size: .8rem; }
.act:hover { text-decoration: none; box-shadow: 0 0 0 1px var(--accent); }
.act-sport { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-time { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.act .zonebar { width: 100%; height: 4px; margin-top: .3rem; }

.zonebar { display: flex; gap: 2px; width: 120px; height: 6px; }
.zonebar span { border-radius: 2px; min-width: 2px; }

.zone-rows { display: flex; flex-direction: column; gap: .7rem; }
.zone-row { display: grid; grid-template-columns: 2rem 1fr 3rem; gap: .75rem; align-items: center; font-size: .85rem; }
.zone-row.wide { grid-template-columns: 8.5rem 1fr 4.5rem; }
.zone-name { color: var(--text-secondary); white-space: nowrap; }
.zone-track { position: relative; height: 8px; background: var(--grid); border-radius: 4px; }
.zone-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; }
.zone-fill.load { background: var(--accent); top: 2px; bottom: 2px; }
.zone-avg { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text-primary); border-radius: 1px; opacity: .7; }
.target-band { position: absolute; top: -3px; bottom: -3px; background: var(--band); border-radius: 4px; }
.zone-val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.split-text { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1.1rem 0 .4rem; font-size: .85rem; color: var(--text-secondary); }
.split-low { background: var(--z2); } .split-mid { background: var(--z3); } .split-high { background: var(--z5); }

.highlights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .9rem; }
.highlights li { display: flex; flex-direction: column; }
.highlights strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.sleepbar { display: flex; gap: 2px; width: 110px; height: 6px; }
.sleepbar span { border-radius: 2px; }
.s-deep { background: var(--s-deep); } .s-rem { background: var(--s-rem); } .s-light { background: var(--s-light); }
.legend-inline { display: flex; gap: .9rem; flex-wrap: wrap; margin-top: .75rem; }
.zone-key { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; margin-top: 2rem; }

.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.z1 { background: var(--z1); } .z2 { background: var(--z2); } .z3 { background: var(--z3); }
.z4 { background: var(--z4); } .z5 { background: var(--z5); }

/* ==========================================================================
   Gráficos
   ========================================================================== */
.chart-card { position: relative; }
.chart-controls { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.strong { fill: var(--text-primary); font-weight: 600; }
.chart .gridline { stroke: var(--grid); }
.chart .highlight { fill: var(--highlight); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--text-primary); fill-opacity: .04; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.segmented button { background: none; color: var(--text-muted); border-radius: 6px; padding: .2rem .65rem; font-size: .82rem; }
.segmented button[aria-pressed="true"] { background: var(--bg); color: var(--text-primary); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .7rem; font-size: .8rem; box-shadow: 0 8px 24px rgb(0 0 0 / .12);
}
.tooltip .t-head { font-weight: 500; margin-bottom: .25rem; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 1rem; color: var(--text-secondary); }
.tooltip .t-row b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
/* Tooltip global para elementos con data-tip (fixed: no lo recorta el scroll de las tablas) */
.tooltip.tip { position: fixed; min-width: 0; max-width: 260px; white-space: pre-line; font-variant-numeric: tabular-nums; }
[data-tip] { cursor: default; }
table.data .zonebar { width: 140px; height: 8px; outline-offset: 4px; }

/* ==========================================================================
   Tablas y formularios
   ========================================================================== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th { text-align: left; color: var(--text-muted); font-weight: 400; font-size: .78rem; border-bottom: 1px solid var(--border); padding: .6rem .65rem; white-space: nowrap; }
table.data td { border-bottom: 1px solid var(--grid); padding: .85rem .65rem; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 600; border-bottom: 0; }
table.data .row-today td { background: var(--highlight); }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.25rem; }

.stack { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.stack label, .goal-form label { display: flex; flex-direction: column; gap: .3rem; color: var(--text-secondary); font-size: .88rem; }
.stack input, .goal-form input:not([type="checkbox"]), .goal-form select {
  font: inherit; padding: .55rem .65rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-primary);
}
.stack input:focus, .goal-form input:focus, .goal-form select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ==========================================================================
   Objetivos
   ========================================================================== */
.tone-good { --tone: var(--good); }
.tone-warning { --tone: var(--warning); }
.tone-critical { --tone: var(--critical); }

.goals-summary { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 2rem; }
.ring {
  --size: 76px; flex: none; width: var(--size); height: var(--size); border-radius: 50%;
  background: radial-gradient(closest-side, var(--bg) calc(100% - 7px), transparent calc(100% - 6px)),
              conic-gradient(var(--good) calc(var(--p) * 1%), var(--band) 0);
  display: grid; place-items: center;
}
.ring-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring-value small { font-size: .6em; }
.summary-title { font-size: 1.15rem; font-weight: 600; }
.summary-counts { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--text-secondary); font-size: .85rem; margin-top: .2rem; }
.summary-counts span { display: inline-flex; align-items: center; gap: .35rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tone); display: inline-block; }
.dot.ring-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--tone); }

.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 1.25rem; }
.goal {
  display: flex; flex-direction: column; gap: .75rem; padding: 1.5rem 1.6rem 1.6rem;
  border-radius: 14px; background: var(--surface-2); scroll-margin-top: 5rem;
}
.goal.is-done { background: color-mix(in srgb, var(--good) 9%, var(--surface-2)); }
.goal:target { box-shadow: 0 0 0 2px var(--accent); }
.goal-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.goal-head h3 { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; color: var(--text-secondary); white-space: nowrap; }
.status-icon {
  display: inline-grid; place-items: center; width: 1.05rem; height: 1.05rem; border-radius: 50%;
  background: var(--tone); color: #fff; font-size: .62rem; font-weight: 700; line-height: 1;
}
.tone-warning .status-icon { color: #1a1a19; }
.goal-numbers { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
.goal-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.goal-bar { position: relative; height: 8px; border-radius: 4px; background: var(--band); }
.goal-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--tone); min-width: 4px; transition: width .4s ease; }
.goal-expected { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text-primary); border-radius: 1px; opacity: .55; }
.goal-message { font-size: .85rem; color: var(--text-primary); }

.day-dots { display: flex; gap: .35rem; margin: .25rem 0 0; flex-wrap: wrap; }
.dd {
  width: 30px; height: 30px; padding: 0; border-radius: 50%; display: inline-grid; place-items: center;
  font: 600 .75rem/1 system-ui, sans-serif; border: 0; background: var(--bg); color: var(--text-muted);
}
button.dd { cursor: pointer; }
button.dd:hover { box-shadow: inset 0 0 0 2px var(--accent); color: var(--text-primary); }
.dd-auto { background: var(--good); color: #fff; }
.dd-manual { background: color-mix(in srgb, var(--good) 22%, var(--bg)); color: var(--text-primary); box-shadow: inset 0 0 0 2px var(--good); }
.dd-future { background: transparent; box-shadow: inset 0 0 0 1px var(--border); opacity: .6; }
.dd.today { outline: 2px solid var(--accent); outline-offset: 2px; }

.mini-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: .35rem; }
.md-day { display: flex; flex-direction: column; align-items: center; gap: .3rem; cursor: default; outline: none; }
.md { position: relative; width: 100%; height: 40px; background: var(--bg); border-radius: 8px; overflow: hidden; }
.md-fill { position: absolute; inset: auto 0 0 0; background: var(--tone); opacity: .85; border-radius: 8px 8px 0 0; }
.md-label { font-size: .7rem; color: var(--text-muted); line-height: 1; }
.md-day:hover .md, .md-day:focus-visible .md { box-shadow: inset 0 0 0 2px var(--accent); }
.md-day.today .md-label { color: var(--accent); font-weight: 600; }
.md-day.future .md { opacity: .4; }
.goals-foot { margin-top: 1.25rem; }

.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: .6rem; margin: 1.25rem 0; }
.preset-grid form { margin: 0; }
.preset {
  width: 100%; height: 100%; text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: .15rem;
  background: var(--surface-2); color: var(--text-primary); border-radius: 12px; padding: 1rem 1.1rem;
}
.preset:hover { box-shadow: inset 0 0 0 1px var(--accent); }
.preset span { color: var(--text-muted); font-size: .82rem; }
.preset .preset-add { color: var(--accent); }

.goal-form { display: flex; flex-direction: column; gap: 1rem; max-width: 640px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 1rem; }
.goal-form fieldset { border: 0; border-radius: 10px; padding: 1rem 1.1rem 1.1rem; margin: 0; background: var(--surface-2); }
.goal-form legend { color: var(--text-secondary); font-size: .88rem; padding: 0; float: left; width: 100%; margin-bottom: .5rem; }
.check-row { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; clear: both; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr)); gap: .3rem 1rem; clear: both; }
.goal-form label.check { flex-direction: row; align-items: center; gap: .45rem; color: var(--text-primary); }
.goal-form label.check .swatch { margin: 0; }
.form-actions { display: flex; gap: .5rem; }
.row-actions { display: flex; gap: .15rem; justify-content: flex-end; align-items: center; }
.row-actions form { margin: 0; }

/* ==========================================================================
   Fuerza
   ========================================================================== */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.next-card {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; flex-wrap: wrap;
  padding: 1.5rem 1.6rem; border-radius: 14px; background: var(--surface-2);
}
.next-main { flex: 1; min-width: min(280px, 100%); }
.next-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: .2rem; }
.next-list { margin: 1rem 0 0; padding: 0; list-style: none; display: grid; gap: .35rem; font-size: .9rem; counter-reset: ex; }
.next-list li { display: flex; justify-content: space-between; gap: 1rem; counter-increment: ex; }
.next-list li > span:first-child::before { content: counter(ex) ". "; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.next-list .muted { font-variant-numeric: tabular-nums; white-space: nowrap; }
.next-actions { margin: 0; }
.other-starts { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: .9rem 0 0; }

.lagging { margin-top: 1.25rem; padding: 1rem 1.1rem; border-radius: 10px; background: color-mix(in srgb, var(--warning) 10%, var(--surface-2)); font-size: .88rem; }
.lagging-title { font-weight: 500; margin-bottom: .35rem; }
.lagging ul { margin: 0; padding-left: 1.1rem; display: grid; gap: .25rem; }
.lagging strong { font-weight: 600; }

.workout-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.workout-list li { border-bottom: 1px solid var(--border); }
.workout-list a {
  display: grid; grid-template-columns: 7rem 1fr auto 1rem; gap: 1rem; align-items: baseline;
  padding: .85rem .25rem; color: var(--text-primary);
}
.workout-list a:hover { text-decoration: none; background: var(--surface-2); }
.wl-date { color: var(--text-muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.wl-name { font-weight: 500; }
.wl-meta { font-size: .82rem; font-variant-numeric: tabular-nums; text-align: right; }
.wl-go { color: var(--text-muted); }
@media (max-width: 560px) {
  .workout-list a { grid-template-columns: 1fr auto; }
  .wl-date { grid-column: 1 / -1; }
  .wl-go { display: none; }
}

/* Registro del entreno */
.workout { display: flex; flex-direction: column; gap: 1rem; }
.ex { padding: 1.25rem 1.4rem; border-radius: 14px; background: var(--surface-2); scroll-margin-top: 5rem; }
.ex-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.ex-name { color: var(--text-primary); }
.ex-meta { margin-top: .15rem; }
.ex-count {
  font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-secondary);
  background: var(--bg); padding: .15rem .55rem; border-radius: 999px; white-space: nowrap;
}
.ex-count.complete { background: var(--good); color: #fff; }
.ex-last { margin-top: .75rem; font-size: .88rem; font-variant-numeric: tabular-nums; }
.ex-hint { margin-top: .3rem; font-size: .85rem; color: var(--text-secondary); }
.ex-hint.up { color: var(--good); font-weight: 500; }

.sets { display: flex; flex-direction: column; gap: .4rem; margin: .9rem 0 .4rem; }
.set-row { display: grid; grid-template-columns: 2.5rem minmax(0, 6rem) minmax(0, 6rem) 2.75rem; gap: .6rem; align-items: center; }
.set-row.no-weight { grid-template-columns: 2.5rem minmax(0, 6rem) 2.75rem; }
.set-head { font-size: .75rem; }
.set-no { color: var(--text-muted); font-variant-numeric: tabular-nums; text-align: center; }
.set-row input[type="number"] {
  font: inherit; font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; width: 100%;
  padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text-primary);
}
.set-row input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.done-toggle { position: relative; display: inline-grid; place-items: center; width: 2.6rem; height: 2.6rem; cursor: pointer; }
.done-toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.done-toggle span[aria-hidden] {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%;
  border: 2px solid var(--border); color: var(--text-muted); font-weight: 700; background: var(--bg);
  transition: background .15s, border-color .15s, color .15s;
}
.done-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.done-toggle input:checked + span { background: var(--good); border-color: var(--good); color: #fff; }
.set-row:has(.done-toggle input:checked) input[type="number"] { border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }

.add-ex h3 { margin-bottom: .6rem; }
.add-ex-row, .add-item-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.add-ex-row select, .add-ex-row input {
  font: inherit; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text-primary);
}
.add-ex-row select { flex: 1; min-width: 12rem; }
.sets-input { width: 4.5rem; }
.workout-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-top: .5rem; }
.day-field { display: flex; flex-direction: column; gap: .3rem; color: var(--text-secondary); font-size: .85rem; }
.day-field input { font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text-primary); }
.danger-zone { margin-top: 2rem; }

/* Gestión de rutinas */
.inline-form { margin: .25rem 0 1rem; max-width: none; }
.add-item { margin-top: 1rem; max-width: none; }
.add-item-row label { flex: 0 1 6rem; }
.add-item-row label:first-child { flex: 1 1 14rem; }
.add-day { margin-top: 1.25rem; }
.add-day .add-item-row label:first-child, .inline-form .add-item-row label:first-child:last-of-type { flex: 0 1 22rem; }

/* El subrayado va con box-shadow (no con borde y margen negativo) para no desbordar y sacar barra de scroll */
.subnav { display: flex; gap: .25rem; margin: -.5rem 0 1.5rem; box-shadow: inset 0 -1px 0 var(--border); overflow-x: auto; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { padding: .5rem .8rem; color: var(--text-muted); white-space: nowrap; }
.subnav a:hover { color: var(--text-primary); text-decoration: none; }
.subnav a[aria-current="page"] { color: var(--text-primary); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 500; }

.other-group { display: inline-flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.other-group + .other-group, .other-group + button { margin-left: .5rem; }
.pill { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .72rem; background: color-mix(in srgb, var(--warning) 22%, var(--bg)); color: var(--text-primary); }

/* Guardado por serie: borde verde breve al guardar, rojo si falla */
.set-row.saved input[type="number"] { animation: saved-flash 1.2s ease; }
@keyframes saved-flash { 0% { box-shadow: 0 0 0 2px var(--good); } 100% { box-shadow: 0 0 0 0 transparent; } }
.set-row.failed input[type="number"] { box-shadow: 0 0 0 2px var(--critical); }

.routine-table input {
  font: inherit; font-variant-numeric: tabular-nums; width: 4.2rem; padding: .3rem .4rem; text-align: right;
  border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text-primary);
}
.routine-table input.note-input { width: 100%; min-width: 9rem; text-align: left; }
.routine-table td { padding-top: .5rem; padding-bottom: .5rem; }

.set-row { grid-template-columns: 2.5rem minmax(0, 6rem) minmax(0, 6rem) 2.75rem 2rem; }
.set-row.no-weight { grid-template-columns: 2.5rem minmax(0, 6rem) 2.75rem 2rem; }
.set-del { min-width: 2rem; height: 2rem; font-size: .85rem; opacity: .55; }
.set-del:hover, .set-del:focus-visible { opacity: 1; }
.set-error { margin: -.15rem 0 .2rem 3.1rem; font-size: .8rem; color: var(--critical); }

/* Rutinas: cada programa es una tarjeta plegada y cada día otra tarjeta plegable dentro */
.program { margin-bottom: 1rem; border-radius: 14px; background: var(--surface-2); }
.program > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .75rem 1rem; flex-wrap: wrap;
  padding: 1.15rem 1.4rem; border-radius: 14px;
}
.program > summary::-webkit-details-marker, .routine > summary::-webkit-details-marker { display: none; }
.program > summary::before, .routine > summary::before {
  content: "›"; display: inline-block; width: .8rem; color: var(--text-muted); transition: transform .2s; font-size: 1.1rem;
}
.program[open] > summary::before, .routine[open] > summary::before { transform: rotate(90deg); }
.program > summary:hover { background: var(--hover); }
.program-name { font-size: 1.1rem; font-weight: 600; }
.program-days { display: flex; gap: .35rem; flex-wrap: wrap; margin-left: auto; }
.day-chip { font-size: .78rem; padding: .15rem .55rem; border-radius: 999px; background: var(--bg); color: var(--text-secondary); }
.program-body { padding: 0 1.4rem 1.4rem; }

.routine { margin-bottom: .6rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.routine > summary {
  list-style: none; cursor: pointer; display: grid; grid-template-columns: auto auto 1fr; align-items: baseline;
  gap: .25rem .75rem; padding: .85rem 1rem;
}
.routine > summary:hover { background: var(--hover); border-radius: 10px; }
.routine-name { font-weight: 600; }
.routine-preview { grid-column: 2 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.routine[open] .routine-preview { display: none; }
.routine-body { padding: 0 1rem 1rem; }
.program-extra { margin-top: 2rem; }

.muscle-filter { flex: 0 1 9rem !important; }
.add-item-row label.ex-pick { flex: 1 1 14rem; }
.add-ex-row .muscle-select { flex: 0 1 11rem; min-width: 8rem; }

/* Filtros del listado de ejercicios */
.ex-filters { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.ex-filters input[type="search"] {
  font: inherit; max-width: 22rem; padding: .5rem .7rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-primary);
}
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip {
  background: var(--surface-2); color: var(--text-secondary); border-radius: 999px; padding: .25rem .75rem; font-size: .82rem;
}
.chip:hover { color: var(--text-primary); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* Entrenar: tarjetas de día de la semana, resumen y músculos */
.day-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: .75rem; margin: 0; }
.day-card {
  display: flex; flex-direction: column; align-items: stretch; gap: .35rem; text-align: left; height: 100%;
  padding: 1rem 1.1rem; border-radius: 12px; background: var(--surface-2); color: var(--text-primary);
  border: 1px solid transparent; transition: border-color .15s, background .15s;
}
.day-card:hover { border-color: var(--accent); background: var(--hover); }
.day-card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.day-card-head strong { font-size: 1.1rem; }
.day-card-list { color: var(--text-secondary); line-height: 1.4; }
.day-card-foot { margin-top: auto; padding-top: .5rem; display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.day-card-cta { color: var(--accent); font-weight: 500; white-space: nowrap; }
a.day-card:hover { text-decoration: none; }
.day-card-form { margin: 0; }
.day-card.st-done { background: color-mix(in srgb, var(--good) 8%, var(--surface-2)); }
.day-card.st-done .day-card-cta { color: var(--text-secondary); }
.day-card.st-progress { border-color: color-mix(in srgb, var(--warning) 55%, transparent); }
.status-tag { font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; }
.status-tag.st-pending { background: var(--bg); color: var(--text-muted); }
.status-tag.st-progress { background: var(--warning); color: #1a1a19; }
.status-tag.st-done { background: var(--good); color: #fff; }
.week-progress { display: flex; gap: 4px; margin: -.25rem 0 1rem; max-width: 22rem; }
.week-progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--band); }
.week-progress .wp-done { background: var(--good); }
.week-progress .wp-progress { background: var(--warning); }
.program-switch { margin: 0; }
.program-switch label { display: flex; align-items: center; gap: .5rem; }
.program-switch select { font: inherit; font-size: .85rem; padding: .35rem .5rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text-primary); }
.program-actions { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .9rem; }
.program > summary .badge { margin-left: -.25rem; }
.badge { font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.free-start { margin: .6rem 0 0; }
.free-start .text-btn { padding-left: 0; }

.strength-kpis { margin-bottom: 0; }

.muscle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(120px, 100%), 1fr)); gap: .5rem; }
.muscle {
  display: flex; flex-direction: column; gap: .05rem; padding: .7rem .8rem; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) var(--heat), var(--surface-2));
}
.muscle-name { font-size: .8rem; color: var(--text-secondary); }
.muscle-val { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.muscle-avg { font-size: .72rem; color: var(--text-muted); }
.muscle.hot, .muscle.hot .muscle-name, .muscle.hot .muscle-avg { color: var(--accent-ink); }
.muscle.empty .muscle-val { color: var(--text-muted); font-weight: 500; }

/* Entreno: ejercicio plegado al completarlo, barra fija inferior y ajustes para móvil */
.ex-count { cursor: pointer; border: 0; font: inherit; font-size: .8rem; font-weight: 600; }
.ex-summary { display: none; margin-top: .5rem; font-size: .9rem; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.ex.complete { background: color-mix(in srgb, var(--good) 7%, var(--surface-2)); }
.ex.collapsed .ex-summary { display: block; }
.ex.collapsed .sets, .ex.collapsed .add-set, .ex.collapsed .ex-last, .ex.collapsed .ex-hint { display: none; }
.ex.collapsed .ex-meta { display: none; }
.set-del { margin-left: .25rem; }

.workout-foot { justify-content: space-between; }
.sync-info { margin: .35rem 0 0; line-height: 1.5; }
.workout-bar {
  position: sticky; bottom: 0; z-index: 9; display: flex; align-items: center; gap: 1rem;
  margin: .5rem -16px 0; padding: .7rem 16px calc(.7rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.wb-info { flex: 1; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .15rem .75rem; min-width: 0; }
.wb-progress { font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wb-track { height: 6px; border-radius: 3px; background: var(--band); overflow: hidden; }
.wb-track span { display: block; height: 100%; background: var(--good); border-radius: 3px; transition: width .3s; }
.wb-info #save-state { grid-column: 1 / -1; min-height: 1em; }
.workout-bar button { padding: .6rem 1.2rem; }

@media (max-width: 600px) {
  main:has(.workout) { padding-bottom: 1rem; }
  .workout { gap: .75rem; }
  .ex { padding: 1rem .9rem; border-radius: 12px; }
  .ex-last, .ex-hint { font-size: .85rem; }
  .set-row { grid-template-columns: 1.4rem minmax(0, 1fr) minmax(0, 1fr) 3rem 2.25rem; gap: .5rem; }
  .set-row.no-weight { grid-template-columns: 1.4rem minmax(0, 1fr) 3rem 2.25rem; }
  .set-row input[type="number"] { padding: .7rem .6rem; }
  .done-toggle { width: 3rem; height: 3rem; }
  .set-del { min-width: 2.25rem; height: 2.25rem; margin-left: 0; }
  .add-set { padding: .6rem 0; }
  .add-ex-row select, .add-ex-row .muscle-select { flex: 1 1 100%; min-width: 0; font-size: 1rem; }
  .add-ex-row .sets-input { font-size: 1rem; }
  .day-field input { font-size: 1rem; }
  .page-head { margin-bottom: 1.1rem; }
}

/* Tablas que en móvil se apilan: título + dato a la derecha, el resto a todo el ancho y las acciones al final */
@media (max-width: 600px) {
  table.stack-sm thead { display: none; }
  table.stack-sm tbody tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem; align-items: baseline;
    padding: .85rem 0; border-bottom: 1px solid var(--grid);
  }
  table.stack-sm td { display: block; padding: 0; border: 0; text-align: left; }
  table.stack-sm td.c-title { grid-column: 1; font-size: 1rem; }
  table.stack-sm td.c-side { grid-column: 2; grid-row: 1; text-align: right; font-weight: 600; }
  table.stack-sm td.c-full { grid-column: 1 / -1; }
  table.stack-sm td[data-label]::before { content: attr(data-label) ": "; }
  table.stack-sm td.c-actions { grid-column: 1 / -1; margin-top: .25rem; }
  table.stack-sm td.c-actions .row-actions { justify-content: flex-start; margin-left: -.4rem; }
  table.stack-sm tbody tr:hover td { background: none; }
  .table-wrap:has(table.stack-sm) { overflow-x: visible; }

  /* Cabecera de página: título y navegación (‹ › ✎) en la misma línea */
  .page-head { flex-wrap: nowrap; align-items: flex-end; gap: .5rem; margin-bottom: 1.25rem; }
  .page-head > div:first-child { min-width: 0; }
  .page-head h1 { font-size: 1.45rem; }
  .page-head .pager-nav, .page-head .week-nav { flex: none; margin-bottom: .1rem; }
  .page-head .pager-nav .icon-btn { min-width: 1.9rem; height: 1.9rem; }
}

/* Login y registro: tarjeta centrada, sin navegación */
main.auth-main { max-width: 400px; padding-top: max(3rem, 12vh); }
.auth-card h1 { margin-bottom: 1.25rem; }
.auth-card .stack { margin-top: .75rem; }
.auth-card .stack input { font-size: 1rem; }
.auth-card button[type="submit"] { justify-content: center; padding: .65rem 1rem; margin-top: .25rem; }
.auth-alt { margin-top: 1.5rem; }
.account-fold { margin-top: 1.25rem; }
.account-fold:last-of-type { border-bottom: 0; }
