/* ============================================================
   Ferro — estilos de la PWA
   Diseño mobile-first, tema claro con acento naranja "hierro".
   ============================================================ */

:root {
  --bg: #f7f6f4;
  --surface: #ffffff;
  --ink: #1c1917;
  --ink-soft: #44403c;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #ea580c;
  --accent-dark: #c2410c;
  --accent-soft: #ffedd5;
  --accent-ink: #7c2d12;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 3px rgba(28, 25, 23, .07), 0 4px 14px rgba(28, 25, 23, .05);
  --nav-h: 62px;
  --header-h: 58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  font-size: 15px;
  line-height: 1.45;
}

button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-header-inner {
  max-width: 760px; margin: 0 auto;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.app-logo { display: flex; align-items: center; gap: 10px; }
.app-logo-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--ink); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.app-logo-name { font-weight: 800; font-size: 17px; letter-spacing: .3px; }
.app-logo-sub { font-size: 11px; color: var(--muted); margin-top: -2px; }
.header-actions { display: flex; gap: 8px; }
.avatar-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--accent-soft); color: var(--accent-dark);
  font-weight: 700; font-size: 14px; cursor: pointer;
}

/* ---------- Layout ---------- */
.app-content {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 28px);
}
.splash {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60vh; gap: 10px; color: var(--muted);
}
.splash-icon { font-size: 48px; }

.page-title { font-size: 22px; font-weight: 800; margin: 6px 0 4px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 20px 0 8px;
  display: flex; align-items: center; gap: 6px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10.5px; font-weight: 600; color: var(--muted);
}
.nav-item.active { color: var(--accent-dark); }
.nav-item.active svg { stroke: var(--accent); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card-row { display: flex; align-items: center; gap: 12px; }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { color: var(--muted); font-size: 12.5px; }
.card-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.empty {
  text-align: center; color: var(--muted); padding: 34px 16px;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); margin-bottom: 12px;
}
.empty-icon { font-size: 34px; display: block; margin-bottom: 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft);
  padding: 10px 15px; font-weight: 700; font-size: 14px; cursor: pointer;
  transition: filter .12s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.05); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-danger { background: var(--red-soft); border-color: var(--red-soft); color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Formularios ---------- */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
  margin-bottom: 5px;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 15px; outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.form-inline > * { flex: 1 1 110px; min-width: 0; }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- Chips (selección múltiple) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-soft);
  padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.selected {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent-ink);
}
.chip-count { color: var(--muted); font-weight: 500; font-size: 11.5px; }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex; background: #edebe8; border-radius: var(--radius-sm);
  padding: 3px; gap: 3px; margin-bottom: 14px;
}
.segmented button {
  flex: 1; border: 0; background: transparent; padding: 8px 2px;
  border-radius: 7px; font-weight: 700; font-size: 12.5px; color: var(--muted);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 3px 9px;
  font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent-ink);
}
.badge-gray { background: #f0efed; color: var(--muted); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }

/* ---------- Login ---------- */
.login-page {
  min-height: calc(100vh - 40px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 20px;
}
.login-logo { text-align: center; }
.login-logo-icon {
  width: 84px; height: 84px; border-radius: 24px; margin: 0 auto 12px;
  background: var(--ink); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.login-logo-name { font-size: 30px; font-weight: 800; letter-spacing: .5px; }
.login-logo-sub { color: var(--muted); font-size: 13.5px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px;
}
.login-title { font-weight: 800; font-size: 17px; margin-bottom: 16px; text-align: center; }
.pin-input-wrap { display: flex; gap: 10px; justify-content: center; }
.pin-digit {
  width: 52px; height: 56px; text-align: center; font-size: 24px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); outline: none;
}
.pin-digit:focus { border-color: var(--accent); background: var(--surface); }
.login-btn {
  width: 100%; margin-top: 8px; padding: 12px;
  background: var(--accent); border: 0; border-radius: var(--radius-sm);
  color: #fff; font-weight: 800; font-size: 15px; cursor: pointer;
}
.login-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Ejercicios (cards con thumbnail) ---------- */
.exercise-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; margin-bottom: 10px; cursor: pointer;
}
.exercise-thumb {
  width: 58px; height: 58px; border-radius: var(--radius-sm);
  object-fit: cover; background: #fff; border: 1px solid var(--line);
  flex-shrink: 0;
}
.exercise-name { font-weight: 700; font-size: 14px; text-transform: capitalize; }
.exercise-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.exercise-body { flex: 1; min-width: 0; }

.exercise-gif {
  width: 100%; max-width: 280px; border-radius: var(--radius);
  border: 1px solid var(--line); display: block; margin: 0 auto 12px;
  background: #fff;
}
.steps-list { padding-left: 20px; display: grid; gap: 7px; font-size: 14px; }
.attribution { font-size: 10.5px; color: var(--muted); margin-top: 12px; text-align: center; }

/* ---------- Plan generado / rutina ---------- */
.plan-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; margin-bottom: 10px;
}
.plan-pos {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 800;
}
.plan-scheme { font-size: 12.5px; color: var(--accent-dark); font-weight: 700; }

/* ---------- Programas especiales ---------- */
.program-card { cursor: pointer; transition: border-color .12s, background .12s; }
.program-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.program-icon {
  font-size: 26px; width: 44px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border-radius: var(--radius-sm);
}
.program-card.selected .program-icon { background: #fff; }

/* ---------- Stats / progreso ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 4px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 14px;
}
.stat-value { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 6px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  min-height: 3px;
}
.bar-label { font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.bar-value { font-size: 9.5px; color: var(--ink-soft); font-weight: 700; }

/* ---------- Calendario de actividad ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-head { margin-bottom: 5px; }
.cal-dow { text-align: center; font-size: 10.5px; font-weight: 700; color: var(--muted); }
.cal-day {
  aspect-ratio: 1; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: var(--bg); border: 1px solid var(--line);
}
.cal-day small { font-size: 8.5px; line-height: 1; margin-top: 1px; }
.cal-empty { background: transparent; border: none; }
.cal-day[data-day] { cursor: pointer; }
.cal-lvl-1 { background: var(--accent-soft); border-color: #fdba74; color: var(--accent-ink); }
.cal-lvl-2 { background: #fdba74; border-color: var(--accent); color: var(--accent-ink); }
.cal-lvl-3 { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.cal-today { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ---------- Gráficas de línea ---------- */
.line-chart { width: 100%; height: auto; display: block; }
.chart-label { font-size: 9px; fill: var(--muted); font-family: inherit; }

/* ---------- Player de entreno ---------- */
.set-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px dashed var(--line);
  font-size: 14px;
}
.set-row:last-child { border-bottom: 0; }
.set-num {
  width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0;
  background: var(--green-soft); color: var(--green);
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 800;
}
.set-add { display: flex; gap: 7px; align-items: center; margin-top: 9px; }
.set-add input {
  width: 76px; padding: 8px 10px; text-align: center;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); outline: none;
}
.set-add input:focus { border-color: var(--accent); }

.rest-chip {
  position: fixed; bottom: calc(var(--nav-h) + 14px); left: 50%; transform: translateX(-50%);
  z-index: 40;
  background: var(--ink); color: #fff;
  border-radius: 999px; padding: 10px 20px;
  font-weight: 800; font-size: 15px;
  display: flex; align-items: center; gap: 9px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.rest-chip button { background: none; border: 0; color: var(--accent); font-weight: 800; cursor: pointer; }

/* ---------- Tablas ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 7px 8px; border-bottom: 1.5px solid var(--line);
}
.table td { padding: 8px; border-bottom: 1px solid var(--line); }

/* ---------- Modal (popup emergente centrado) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(28, 25, 23, .45);
  display: none; align-items: center; justify-content: center;
  padding: 18px;
}
.modal.open { display: flex; }
.modal--stacked { z-index: 60; }
.modal-box {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 18px;
  max-height: 85vh;
  max-height: min(85vh, 85dvh); /* navegadores sin dvh se quedan con la línea anterior */
  overflow-y: auto;
  /* sin padding-top: la cabecera sticky queda pegada al borde superior */
  padding: 0 18px 18px;
  box-shadow: 0 18px 50px rgba(28, 25, 23, .3);
  animation: popIn .16s ease-out;
  overscroll-behavior: contain;
}
.modal--stacked .modal-box { max-width: 380px; padding-top: 18px; }
@keyframes popIn {
  from { transform: scale(.95) translateY(10px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
/* Cabecera pegajosa: el título y la X quedan fijos mientras el
   contenido del popup hace scroll por debajo. */
.modal-title {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  margin: 0 -18px 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 17px; font-weight: 800;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.modal-close {
  border: 0; background: #f0efed; border-radius: 8px;
  width: 30px; height: 30px; flex-shrink: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
}
.modal-close:hover { background: var(--line); color: var(--ink); }
.modal-footer { display: flex; gap: 8px; margin-top: 16px; }
.modal-footer .btn { flex: 1; }
/* Sin scroll de la página de fondo mientras hay un popup abierto */
body.modal-open { overflow: hidden; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 18px); z-index: 70;
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  max-width: min(90vw, 480px); text-align: center;
}
.toast-error { background: var(--red); }
.toast-success { background: var(--green); }

/* ---------- Utilidades ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; min-width: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.center { text-align: center; }
.capitalize { text-transform: capitalize; }
.flex { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
