/* =====================================================================
   Tokens de tema — Forja (oscuro) y Tempo (claro)
   El tema se aplica con el atributo data-theme en <html>.
   Cambiar de tema = cambiar un atributo + guardar la preferencia.
   ===================================================================== */

:root,
[data-theme="forja"] {
  --bg: #0E0F12;
  --surface: #1A1D23;
  --surface-2: #22262E;
  --accent: #C7F94B;
  --on-accent: #0E0F12;
  --text: #F4F6F8;
  --text-muted: #8A8F99;
  --border: #2A2E36;
  --radius: 14px;
  --radius-pill: 999px;
}

[data-theme="tempo"] {
  --bg: #F7F4EF;
  --surface: #FFFFFF;
  --surface-2: #FBF9F5;
  --accent: #FB4D2C;
  --on-accent: #FFFFFF;
  --text: #16130F;
  --text-muted: #A89F92;
  --border: #EDE7DD;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  /* Respeta las zonas seguras del dispositivo (barra de estado / notch / gesto). */
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); /* barra inferior + gesto */
}

.screen { padding: 16px; }

.eyebrow { font-size: 12px; letter-spacing: 0.14em; color: var(--text-muted); text-transform: uppercase; }
.title { font-size: 20px; font-weight: 600; margin-top: 2px; }

/* Tarjeta de ejercicio */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card .big-number { font-size: 24px; font-weight: 700; color: var(--accent); margin: 8px 0 2px; }
.card .meta { font-size: 12px; color: var(--text-muted); }

/* Botón principal (acción dominante) */
.btn-primary {
  display: block;
  width: 100%;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { transform: scale(0.99); }

.chip {
  display: inline-block;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
}
.chip--active { background: var(--accent); color: var(--on-accent); }

/* Barra de navegación inferior (pulgar-first) */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  box-sizing: border-box;
  height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); /* no tapar el gesto/home */
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.bottom-nav a { color: var(--text-muted); text-decoration: none; font-size: 22px; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav .fab {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; margin-top: -18px;
}

/* Indicador de conexión */
.conn { font-size: 12px; color: var(--text-muted); }
.conn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3ECF6A; margin-right: 4px; }
.conn.offline .dot { background: #888; }

/* =====================================================================
   Componentes de Fase 1 (pantallas reales)
   ===================================================================== */

/* Utilidades */
[x-cloak] { display: none !important; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--text-muted); }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }

/* Formularios e inputs */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 12px;
  font-size: 16px; /* ≥16px evita el zoom de iOS */
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 76px; resize: vertical; }

/* Botones */
.btn-primary[disabled] { opacity: .5; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-ghost:active { transform: scale(.99); }
.btn-link { background: none; border: none; color: var(--accent); font-size: 14px; cursor: pointer; padding: 6px; }
.btn-danger { color: #ff6b5e; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* Barra superior de pantalla */
.appbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.appbar h1 { font-size: 20px; font-weight: 700; }
.appbar .back { font-size: 22px; background: none; border: none; color: var(--text); cursor: pointer; }

/* Chips de día / rutina */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { cursor: pointer; border: 1px solid transparent; }
.chip--active { background: var(--accent); color: var(--on-accent); }

/* Barra de progreso del día */
.progress { display: flex; align-items: center; gap: 10px; margin: 6px 0 16px; }
.progress .bar { flex: 1; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress .bar > i { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.progress .label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

/* Tarjeta de ejercicio (estado completado) */
.card.done { border-color: var(--accent); }
.card .badge-done { color: var(--accent); font-weight: 700; font-size: 13px; }
.card .ref { font-size: 12px; color: var(--text-muted); }
.card .actions { display: flex; gap: 10px; margin-top: 12px; }
.card .actions .btn-ghost { flex: 0 0 auto; }
.card .actions .btn-primary { flex: 1; }

/* Stepper +/- (sin teclado) */
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); font-size: 24px; font-weight: 700; cursor: pointer;
  flex: 0 0 auto;
}
.stepper button:active { transform: scale(.96); }
.stepper .val { flex: 1; text-align: center; }
.stepper .val b { font-size: 26px; font-weight: 700; color: var(--accent); display: block; }
.stepper .val small { font-size: 12px; color: var(--text-muted); }

/* Fila de serie en el detalle */
.set-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.set-row .n { color: var(--text-muted); font-size: 13px; width: 18px; flex: 0 0 auto; }
.set-row .set-fields { flex: 1; display: flex; gap: 8px; flex-wrap: wrap; }
.set-row .mini { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 130px; }
.set-row .mini button { width: 34px; height: 34px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 18px; cursor: pointer; }
.set-row .mini span { flex: 1; text-align: center; font-weight: 600; }
.set-row .chk {
  flex: 0 0 auto; min-width: 78px; padding: 9px 10px;
  font-size: 13px; font-weight: 700; cursor: pointer;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 8px;
}
.set-row .chk:active { transform: scale(.96); }
.set-row .chk.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
/* Fila de serie marcada: se resalta por completo */
.set-row.set-done { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); border-radius: 8px; }

/* Nota del entrenador (solo lectura para el cliente) */
.coach-note {
  background: rgba(199, 249, 75, .10);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 10px 0;
}

/* Estado "en progreso" (algunas series marcadas) */
.badge-progress { font-weight: 700; font-size: 13px; color: #E8A93B; }
.card.partial { border-color: #E8A93B; }

/* Flechas de tendencia en el historial */
.trend { font-weight: 700; }
.trend.up { color: #3ECF6A; }
.trend.down { color: #ff6b5e; }

/* Listas (historial, búsqueda, alternativos) */
.list .item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 14px; margin-bottom: 10px; cursor: pointer;
}
.list .item:active { transform: scale(.995); }
.list .item .grow { flex: 1; }
.list .item .grow b { display: block; font-size: 15px; }
.list .item .grow small { color: var(--text-muted); font-size: 12px; }
.list .item.item--sel { border-color: var(--accent); background: var(--surface-2); }

/* Encabezado de día en historial */
.day-head { font-size: 13px; color: var(--text-muted); margin: 18px 0 8px; text-transform: capitalize; }

/* Buscador */
.search-wrap { position: relative; margin-bottom: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%);
  background: var(--accent); color: var(--on-accent);
  padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 50; max-width: 90%;
}

/* Aviso de error fijo (siempre visible, no depende del scroll) */
.toast--error {
  background: #ff6b5e;
  color: #fff;
  bottom: 140px;
}

/* Indicador de conexión / sincronización (banda fija arriba) */
.netstatus {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  text-align: center; font-size: 13px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px; /* bajo la barra de estado */
  color: #161310;
}

/* Fila de fecha: día anterior / selector / día siguiente */
.date-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.date-row .daynav {
  flex: 0 0 auto; width: 46px; height: 46px; padding: 0;
  font-size: 24px; line-height: 1; border-radius: 12px;
}
.date-field {
  flex: 1; min-width: 0; box-sizing: border-box;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; font-size: 15px; text-align: center;
}
.netstatus--off  { background: #f0c04a; }
.netstatus--sync { background: var(--accent); }

/* Modal genérico (overlay centrado) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { text-align: center; }
.stepper .step {
  width: 48px; height: 48px; border-radius: 12px; font-size: 22px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.plate-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.plate-chip {
  background: var(--surface-2); border: 1px solid var(--accent); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 16px;
}

/* Selección múltiple / borrado en lote (historial) */
.sel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 600; }
.sel-row input[type="checkbox"] { width: 22px; height: 22px; }
.bulk-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 55;
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 10px 8px 18px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.bulk-bar .btn-primary { width: auto; padding: 10px 18px; }

/* ── Panel de progreso (Fase 2) ── */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 8px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.stat-card b { font-size: 26px; color: var(--accent); line-height: 1; }
.stat-card small { color: var(--text-muted); font-size: 12px; }

.heatmap { display: flex; gap: 3px; overflow-x: auto; padding: 4px 0; }
.heat-col { display: flex; flex-direction: column; gap: 3px; }
.heat-cell { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.heat-cell.lvl-empty, .heat-cell.lvl-0 { background: var(--surface-2); }
.heat-cell.lvl-1 { background: rgba(199,249,75,.30); }
.heat-cell.lvl-2 { background: rgba(199,249,75,.55); }
.heat-cell.lvl-3 { background: rgba(199,249,75,.80); }
.heat-cell.lvl-4 { background: var(--accent); }
.heat-legend { display: flex; align-items: center; gap: 5px; margin-top: 6px; font-size: 12px; }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart { width: 100%; height: 110px; display: block; }
.chart-foot { display: flex; justify-content: space-between; font-size: 12px; margin-top: 4px; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 8px; }
.bar-label { font-size: 13px; }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-val { font-size: 12px; color: var(--text-muted); }

/* Sugerencia de progresión */
.prog-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(199,249,75,.10); border: 1px solid var(--accent);
  border-radius: 12px; padding: 8px 12px; margin: 10px 0; font-size: 14px;
}

/* Cronómetro de descanso (banda flotante sobre la barra de navegación) */
.rest-timer {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 84px; z-index: 55;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--accent);
  border-radius: 999px; padding: 8px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.rest-main { display: flex; align-items: center; gap: 10px; }
.rest-time { font-size: 22px; font-weight: 700; color: var(--accent); min-width: 56px; text-align: center; }
.rest-adj {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 12px; font-size: 14px; min-width: 48px;
}
.rest-skip {
  background: transparent; color: var(--text-muted); border: none;
  font-size: 13px; padding: 6px 8px;
}

/* Estados vacíos / cargando */
.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Accesibilidad ── */
/* Foco visible y claro para navegación por teclado. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
/* Respeta "reducir movimiento": sin animaciones ni transiciones. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Banner de error */
.banner { background: rgba(255,107,94,.12); border: 1px solid #ff6b5e; color: #ff6b5e; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }

/* Encabezado fijo de "Hoy" (día + progreso visibles al hacer scroll) */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding-top: 8px;
  margin: -16px -16px 0; /* compensa el padding de .screen para cubrir de borde a borde */
  padding-left: 16px;
  padding-right: 16px;
  border-bottom: 1px solid var(--border);
}
.sticky-top .progress { margin-bottom: 12px; }

/* Nota recortada en la tarjeta de ejercicio */
.note-preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Navegación inferior: marca activa por estado */
.bottom-nav button { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }
.bottom-nav button.active { color: var(--accent); }
