/* PULSO — sistema monocromo. Dos temas conmutables (light/dark).
   Diseño editorial: veredicto en serif (la voz del coach), datos en sans. */

:root {
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #737373;
  --faint: #a3a3a3;
  --line: #e6e6e6;
  --panel: #fafafa;
  --invert-bg: #0a0a0a;
  --invert-fg: #ffffff;
  --maxw: 640px;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0a0a0a;
  --fg: #f5f5f5;
  --muted: #8f8f8f;
  --faint: #5c5c5c;
  --line: #232323;
  --panel: #131313;
  --invert-bg: #f5f5f5;
  --invert-fg: #0a0a0a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background .25s ease, color .25s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, body { transition: none !important; }
}

/* ---------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 20px 14px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.wordmark { font-weight: 700; letter-spacing: .28em; font-size: 15px; }
.mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 16%, transparent);
}
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  background: transparent; color: var(--fg);
  border: 1px solid transparent; border-radius: 10px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel); border-color: var(--line); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* icono de tema: muestra el opuesto al tema actual */
.ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: none; }
:root[data-theme="dark"] .ic-sun { display: block; }

/* ---------------------------------------------------------- layout */
.view {
  flex: 1;
  display: flex; flex-direction: column;
  width: 100%; max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px 20px 20px;
  /* Transición nativa entre secciones: fade + desplazamiento lateral. */
  transition: opacity .28s cubic-bezier(.4, 0, .2, 1), transform .28s cubic-bezier(.4, 0, .2, 1);
}
.view.is-exit  { opacity: 0; transform: translateX(-10px); }
.view.is-enter { opacity: 0; transform: translateX(12px); }

.eyebrow {
  font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 6px;
}
.section { margin-top: 34px; }
.section-title {
  font-size: 12px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
}

/* ---------------------------------------------------------- veredicto */
.verdict {
  font-family: var(--serif);
  font-size: clamp(24px, 6.4vw, 32px);
  line-height: 1.28;
  letter-spacing: -.01em;
  margin: 6px 0 0;
  font-weight: 500;
}
.reason {
  color: var(--fg);
  opacity: .82;
  font-size: 15.5px; line-height: 1.66;
  margin: 18px 0 0;
}

/* ---------------------------------------------------------- métricas */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1px; margin-top: 8px;
  background: var(--line);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
.stat { background: var(--bg); padding: 16px 14px; }
.stat .label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .value .unit { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat .base { font-size: 11px; color: var(--faint); margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat.flag .value { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

/* --------------------------------------------------------- recomendaciones */
.recs { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.recs li {
  counter-increment: r;
  display: grid; grid-template-columns: 28px 1fr; gap: 14px;
  padding: 16px 0; border-top: 1px solid var(--line);
  font-size: 15.5px; line-height: 1.5;
}
.recs li:first-child { border-top: none; }
.recs li::before {
  content: counter(r, decimal-leading-zero);
  font-family: var(--mono); font-size: 13px; color: var(--muted);
  padding-top: 2px;
}

/* ---------------------------------------------------------- alertas */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; margin-top: 10px;
  border: 1px solid var(--fg); border-radius: 12px;
  font-size: 14px; line-height: 1.5;
}
.alert .bang { font-family: var(--serif); font-weight: 700; font-size: 18px; line-height: 1; }

/* ---------------------------------------------------------- semana */
.week { display: flex; flex-direction: column; }
.day {
  display: grid; grid-template-columns: 54px 1fr auto; align-items: center; gap: 14px;
  padding: 15px 2px; border-top: 1px solid var(--line);
}
.day:first-child { border-top: none; }
.day .dow { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.day .dnum { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.day .metrics { display: flex; gap: 16px; flex-wrap: wrap; }
.day .m { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.day .m b { color: var(--fg); font-weight: 600; }
.day .spark { justify-self: end; }

/* ---------------------------------------------------------- gym */
.field {
  width: 100%; padding: 13px 14px;
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 15px; font-family: var(--sans);
}
.field:focus { outline: none; border-color: var(--fg); }
.ex { padding: 16px 0; border-top: 1px solid var(--line); }
.ex:first-child { border-top: none; }
.ex .name { font-weight: 650; font-size: 15px; display: flex; justify-content: space-between; gap: 10px; }
.ex .name .now { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
.ex .trend { margin-top: 10px; }
.pill {
  display: inline-block; font-size: 11px; font-family: var(--mono);
  padding: 2px 7px; border: 1px solid var(--fg); border-radius: 999px;
  margin-left: 8px; vertical-align: middle;
}

/* ---------------------------------------------------------- ajustes */
.setting { padding: 18px 0; border-top: 1px solid var(--line); }
.setting:first-child { border-top: none; }
.setting label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.setting .hint { font-size: 13px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 12px; cursor: pointer;
  font-size: 15px; font-weight: 600; font-family: var(--sans);
  background: var(--invert-bg); color: var(--invert-fg); border: 1px solid var(--fg);
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; color: var(--fg); }

/* ---------------------------------------------------------- estados */
.center { min-height: 40vh; display: grid; place-items: center; text-align: center; }
.muted { color: var(--muted); font-size: 14.5px; line-height: 1.6; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--fg);
  animation: spin .7s linear infinite; margin: 0 auto 14px;
}
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: var(--invert-bg); color: var(--invert-fg);
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---------------------------------------------------------- tabbar */
.tabbar {
  position: sticky; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  padding: 14px 0; background: transparent; border: none; cursor: pointer;
  font-family: var(--sans); font-size: 12px; letter-spacing: .05em;
  color: var(--muted); position: relative;
  transition: color .25s ease;
}
.tab.is-active { color: var(--fg); font-weight: 650; }
/* Indicador único que se desliza entre pestañas (la barra no se mueve). */
.tab-indicator {
  position: absolute; top: 0; left: 0; width: 22px; height: 2px;
  background: var(--fg);
  transform: translateX(0);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}

/* ============================================================ PANTALLA HOY */
/* Colores semánticos: ÚNICO acento sobre el monocromo, solo para deltas. */
:root { --good: #15803d; --bad: #b91c1c; }
:root[data-theme="dark"] { --good: #4ade80; --bad: #f87171; }

.hoy {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0; gap: clamp(10px, 2.4vh, 22px);
}

/* --- bloque superior: anillo de recuperación + veredicto --- */
.hero { display: flex; align-items: center; gap: 18px; }
.hero-text { min-width: 0; }
.hero .titular {
  font-family: var(--serif); font-weight: 500;
  font-size: clamp(23px, 6.6vw, 30px); line-height: 1.12; letter-spacing: -.01em;
  margin: 0;
}
.hero .resumen { color: var(--muted); font-size: 13.5px; line-height: 1.45; margin: 8px 0 0; }

/* --- anillos (SVG) --- */
.ring-wrap { position: relative; flex: none; display: grid; place-items: center; }
.ring-wrap svg { display: block; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line); }
.ring-fg {
  fill: none; stroke: var(--fg); stroke-linecap: round;
  transition: stroke-dashoffset .85s cubic-bezier(.4, 0, .2, 1);
}
.ring-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center; line-height: 1;
}
.ring-label .pct { font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.ring-label .pct .u { font-size: .55em; font-weight: 600; color: var(--muted); }
.ring-empty .ring-fg { stroke: var(--line); }
.ring-wrap.big .pct { font-size: 26px; }

/* --- bloque medio: 4 métricas 2x2, sin anillos --- */
.metrics2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden;
}
.metric { background: var(--bg); padding: 13px 15px; }
.metric .label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.metric .row { display: flex; align-items: baseline; gap: 8px; margin-top: 5px; }
.metric .value { font-size: 25px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.metric .value .u { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.metric .delta { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .delta.up { color: var(--good); }
.metric .delta.down { color: var(--bad); }
.metric .delta.flat { color: var(--faint); }
.metric .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* --- bloque inferior: 3 anillos de nutrición en fila --- */
.nutri { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.nutri-item { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.nutri-item .pct { font-size: 15px; }
.nutri-item .cap { text-align: center; }
.nutri-item .cap .n { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.nutri-item .cap .v { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 1px; }

/* --- botón al pie --- */
.hoy .foot { margin-top: auto; }

/* ============================================================ MODAL comida */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, #000 45%, transparent);
  display: grid; place-items: end center;
  opacity: 0; transition: opacity .25s ease;
}
.modal-overlay.show { opacity: 1; }
.modal {
  width: 100%; max-width: var(--maxw);
  background: var(--bg); border-top-left-radius: 20px; border-top-right-radius: 20px;
  border: 1px solid var(--line); border-bottom: none;
  padding: 22px 20px calc(env(safe-area-inset-bottom) + 22px);
  transform: translateY(100%); transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal h3 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin: 0 0 4px; }
.modal p.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.modal textarea { min-height: 84px; resize: none; margin-bottom: 12px; }
.modal .actions { display: flex; gap: 10px; }
.modal .actions .btn { flex: 1; }

/* ============================================================ REGISTRAR COMIDA */
.modal.comida-sheet { max-height: 88vh; overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; }
.sheet-close {
  background: none; border: none; color: var(--muted); font-size: 18px;
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
}
.sheet-close:hover { background: var(--panel); color: var(--fg); }

.recientes { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.recientes:empty { display: none; }
.chip {
  flex: none; max-width: 200px;
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px;
  font-size: 13px; cursor: pointer; background: var(--panel); color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--sans);
}
.chip:active { transform: scale(.97); }
.chip .k { color: var(--muted); margin-left: 7px; font-variant-numeric: tabular-nums; }

.macro-card {
  margin-top: 16px; border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  animation: fade-up .28s cubic-bezier(.4, 0, .2, 1);
}
.macro-card.hidden { display: none; }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.macro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.macro-field label { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.macro-field input {
  width: 100%; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; color: var(--fg); font-family: var(--sans);
  -moz-appearance: textfield;
}
.macro-field input::-webkit-outer-spin-button,
.macro-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.macro-field input:focus { outline: none; border-color: var(--fg); }
.btn.calcular.loading { opacity: .7; }
