/* =============================================================
   app.css — tema, layout y componentes
   Paleta oscura por defecto; el tema claro se activa con
   data-theme="light" o siguiendo el sistema.
   ============================================================= */

:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --card: #171b23;
  --card-2: #1d222c;
  --line: #262c38;
  --text: #e9edf5;
  --muted: #96a0b5;
  --accent: #c9f45c;
  --accent-ink: #16200a;
  --accent-soft: rgba(201, 244, 92, .14);
  --accent-mid: rgba(201, 244, 92, .5);
  --danger: #ff6b5e;
  --ok: #4ade80;
  --radius: 14px;
  --radius-s: 10px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  --bg: #f5f6f9;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-2: #f0f2f7;
  --line: #e0e4ec;
  --text: #141821;
  --muted: #667089;
  --accent: #4d7c0f;
  --accent-ink: #f7ffe8;
  --accent-soft: rgba(77, 124, 15, .12);
  --accent-mid: rgba(77, 124, 15, .45);
  --danger: #d63a2c;
  --ok: #15803d;
  --shadow: 0 6px 20px rgba(20,24,33,.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f9;
    --bg-soft: #ffffff;
    --card: #ffffff;
    --card-2: #f0f2f7;
    --line: #e0e4ec;
    --text: #141821;
    --muted: #667089;
    --accent: #4d7c0f;
    --accent-ink: #f7ffe8;
    --accent-soft: rgba(77, 124, 15, .12);
    --accent-mid: rgba(77, 124, 15, .45);
    --danger: #d63a2c;
    --ok: #15803d;
    --shadow: 0 6px 20px rgba(20,24,33,.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body.modal-open { overflow: hidden; }

h1 { font-size: 1.5rem; margin: .2em 0 .4em; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: .8em 0 .4em; letter-spacing: -.01em; }
h3 { font-size: 1.1rem; margin: .4em 0; }
p { margin: .3em 0 .8em; }
a { color: inherit; text-decoration: none; }

/* ---------- layout ------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.02em; }
.brand-mark { color: var(--accent); font-size: .9rem; }
.brand-text { font-size: .95rem; }
.brand-dim { color: var(--muted); font-weight: 500; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px calc(150px + var(--safe-b));
}

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 8px; font-size: .68rem; color: var(--muted);
}
.nav-item.active { color: var(--text); }
.nav-item.active .nav-icon { filter: none; }
.nav-icon { font-size: 1.15rem; position: relative; filter: grayscale(.4) opacity(.85); }
.nav-badge {
  position: absolute; top: -1px; right: -5px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--bg-soft);
}

/* ---------- utilidades --------------------------------------- */

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mt-s { margin-top: 8px; }
.grow { flex: 1; }
.wrap { flex-wrap: wrap; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 10px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.danger-text { color: var(--danger); }

/* ---------- tarjetas ----------------------------------------- */

.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.card.accent { border-color: var(--accent-mid); }
.session-card:active { background: var(--card-2); }
.section { margin-top: 18px; }

.chips-inline { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip-mini {
  font-size: .72rem; color: var(--muted);
  background: var(--card-2); border-radius: 999px; padding: 2px 9px;
}

.pulse-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); animation: pulse 1.6s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pulse-dot { animation: none; } }

/* ---------- botones ------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: 1px solid transparent; border-radius: var(--radius-s);
  padding: 11px 16px; font-size: .92rem; font-weight: 600; font-family: inherit;
  background: var(--card-2); color: var(--text);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.big { padding: 15px 18px; font-size: 1rem; }
.btn.full { width: 100%; }
.btn.small { padding: 8px 12px; font-size: .85rem; }
.tiny-btn { padding: 4px 9px; font-size: .75rem; border-radius: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 1.05rem;
  cursor: pointer; font-family: inherit;
}
.icon-btn:active { background: var(--card-2); }
.icon-btn.tiny { min-width: 26px; height: 26px; font-size: .8rem; }

.link { color: var(--accent); font-size: .85rem; font-weight: 600; }

/* ---------- inicio ------------------------------------------- */

.hero h1 { margin-bottom: 0; }
.start-block { margin: 14px 0; }
.routine-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; }
.routine-strip.center { justify-content: center; flex-wrap: wrap; }

.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card);
  color: var(--text); border-radius: 999px; padding: 7px 13px;
  font-size: .84rem; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.stats-grid.tight { grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.stats-grid.tight .stat-value { font-size: 1.05rem; }
.stat-label { font-size: .72rem; color: var(--muted); }

.empty { text-align: center; padding: 40px 16px; }
.empty-icon { font-size: 2.4rem; }
.empty p { color: var(--muted); max-width: 30ch; margin: .4em auto 1.2em; }

/* ---------- entreno ------------------------------------------ */

.workout-head { margin-bottom: 12px; }
.title-input {
  width: 100%; background: transparent; border: 0; border-bottom: 1px dashed var(--line);
  color: var(--text); font-size: 1.35rem; font-weight: 700; font-family: inherit;
  padding: 4px 0; letter-spacing: -.02em;
}
.title-input:focus { outline: none; border-bottom-color: var(--accent); }

.summary { display: flex; gap: 14px; color: var(--muted); font-size: .82rem; margin-top: 6px; }
.summary span:last-child { margin-left: auto; font-variant-numeric: tabular-nums; }

.entry { padding-bottom: 10px; }
.note {
  background: var(--card-2); border-radius: var(--radius-s);
  padding: 6px 10px; font-size: .82rem; color: var(--muted); margin: 8px 0 0;
}

.set-head, .set-row {
  display: grid;
  grid-template-columns: 30px 1fr 1fr 52px 42px 26px;
  gap: 6px; align-items: center;
}
.set-head { margin: 10px 0 4px; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.set-head span { text-align: center; }
.set-row { margin-bottom: 6px; position: relative; }
.set-row.done .cell { background: var(--accent-soft); }
.set-row.warmup .cell { opacity: .7; }

.set-index {
  height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: .8rem;
  font-family: inherit; cursor: pointer;
}
.set-index.static { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; }
.set-row.warmup .set-index { color: var(--accent); border-color: var(--accent-mid); }

.cell {
  width: 100%; height: 38px; text-align: center;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 9px;
  color: var(--text); font-size: 1rem; font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.cell:focus { outline: none; border-color: var(--accent); }
.cell::-webkit-outer-spin-button, .cell::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell[type=number] { -moz-appearance: textfield; }
.small-cell { font-size: .9rem; }

.check {
  height: 38px; border-radius: 9px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 1rem;
  font-family: inherit; cursor: pointer;
}
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.pr-flag {
  position: absolute; right: -2px; top: -6px;
  font-size: .7rem; color: var(--accent);
}

.notes-input {
  width: 100%; margin-top: 12px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); font-family: inherit; font-size: .9rem; resize: vertical;
}
.notes-input:focus { outline: none; border-color: var(--accent); }

.set-list { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.set-static {
  display: grid; grid-template-columns: 26px 1fr auto auto; gap: 8px;
  align-items: center; font-size: .9rem;
  padding: 4px 0; border-bottom: 1px solid var(--line);
}
.set-static:last-child { border-bottom: 0; }
.set-static.warmup { opacity: .6; }

.pr-card { border-color: var(--accent-mid); }
.pr-card strong { color: var(--accent); }

/* ---------- progreso / marcas -------------------------------- */

.chart { width: 100%; height: auto; display: block; margin: 6px 0 2px; }
.chart .grid { stroke: var(--line); stroke-width: .7; }
.chart .axis { fill: var(--muted); font-size: 7px; font-family: inherit; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .area { fill: var(--accent-soft); stroke: none; }
.chart .dot { fill: var(--accent); }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart-empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 26px 0; }
.chart-title { font-size: .75rem; color: var(--muted); margin-top: 12px; text-transform: uppercase; letter-spacing: .04em; }

.mbars { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.mbar { display: grid; grid-template-columns: 74px 1fr 58px; gap: 8px; align-items: center; font-size: .78rem; }
.mbar-label { color: var(--muted); }
.mbar-track { background: var(--card-2); border-radius: 999px; height: 8px; overflow: hidden; }
.mbar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.mbar-value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.pr-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pr-row[hidden] { display: none; }
.pr-values { text-align: right; display: flex; flex-direction: column; }
.pr-main { font-weight: 700; }

/* ---------- formularios -------------------------------------- */

.field-label { display: block; font-size: .75rem; color: var(--muted); margin: 12px 0 5px; }
.input, .select, .search {
  width: 100%; padding: 11px 12px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-s);
  color: var(--text); font-family: inherit; font-size: .95rem;
}
.input:focus, .select:focus, .search:focus { outline: none; border-color: var(--accent); }
.search { margin-bottom: 10px; }
textarea.input { resize: vertical; }
.range { width: 100%; accent-color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: .88rem; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.danger-zone { border-color: var(--danger); }

.routine-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.routine-fields label { font-size: .7rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.routine-fields input {
  padding: 8px 10px; background: var(--card-2); border: 1px solid var(--line);
  border-radius: 9px; color: var(--text); font-family: inherit; font-size: .95rem; text-align: center;
}
.routine-fields input:focus { outline: none; border-color: var(--accent); }

/* ---------- descanso ----------------------------------------- */

.rest-bar {
  position: fixed; left: 0; right: 0; z-index: 25;
  bottom: calc(62px + var(--safe-b));
  background: var(--card); border-top: 1px solid var(--line);
  overflow: hidden;
}
.rest-fill {
  position: absolute; top: 0; bottom: 0; left: 0;
  background: var(--accent-soft);
  transition: width .25s linear;
}
.rest-content {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; max-width: 640px; margin: 0 auto;
}
.rest-label { font-size: .78rem; color: var(--muted); }
.rest-time { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-right: auto; }
.rest-bar.done .rest-fill { background: var(--accent-mid); width: 100% !important; }

/* ---------- modal -------------------------------------------- */

.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 40; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.55); }
.modal-card {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding-bottom: calc(14px + var(--safe-b));
}
@media (min-width: 620px) {
  .modal-card { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 18px; }
}

.modal-head {
  position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--bg-soft); border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-body { padding: 14px; }
.modal-text { color: var(--muted); font-size: .92rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-actions.column { flex-direction: column; }
.modal-actions.column .btn { width: 100%; }

.chips-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.picker-list { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; }
.picker-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 4px; background: transparent; border: 0; border-bottom: 1px solid var(--line);
  color: var(--text); font-family: inherit; font-size: .93rem; text-align: left; cursor: pointer;
}
.picker-item:active { background: var(--card-2); }
.picker-item[hidden] { display: none; }

.menu-list { display: flex; flex-direction: column; margin-top: 14px; }
.menu-item {
  text-align: left; padding: 12px 4px; background: transparent; border: 0;
  border-top: 1px solid var(--line); color: var(--text);
  font-family: inherit; font-size: .93rem; cursor: pointer;
}

/* ---------- toast -------------------------------------------- */

.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(86px + var(--safe-b)); z-index: 50;
  max-width: calc(100% - 28px);
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 999px; padding: 10px 18px; font-size: .88rem;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }

/* ---------- sincronización ----------------------------------- */

.sync-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); margin-right: 8px; flex: 0 0 auto;
}
.sync-dot.ok { background: var(--ok); }
.sync-dot.pending { background: #e6a817; }
.sync-dot.error { background: var(--danger); }
.sync-dot.busy { background: var(--accent); animation: pulse 1.1s infinite; }

.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---------- ejercicios propios ------------------------------- */

.picker-row {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--line);
}
.picker-row[hidden] { display: none; }
.picker-row .picker-item { flex: 1; border-bottom: 0; }

.own-list { display: flex; flex-direction: column; margin: 8px 0 4px; }
.own-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 2px; background: transparent; border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text); font-family: inherit; font-size: .92rem;
  text-align: left; cursor: pointer;
}
.own-item:last-child { border-bottom: 0; }
.own-item:active { background: var(--card-2); }
