/* ------------------------------------------------------------------
   Entreno · hoja de estilo única
   Móvil primero. Sin dependencias externas (funciona sin conexión).
   ------------------------------------------------------------------ */

:root {
  --bg:        #0e1116;
  --bg-2:      #161b22;
  --bg-3:      #1c232d;
  --linea:     #2a3440;
  --texto:     #e7edf3;
  --suave:     #8b97a6;
  --acento:    #ff7a1a;
  --acento-2:  #ffa45c;
  --ok:        #2ecc71;
  --alerta:    #ffc53d;
  --mal:       #ff5a5a;
  --azul:      #4aa8ff;
  --radio:     14px;
  --nav-alto:  62px;
  font-size: 16px;
}

/* Los neutros van tirados hacia el azul a propósito, para que el naranja
   sea lo único cálido de la pantalla y el ojo vaya siempre ahí. */
@media (prefers-color-scheme: light) {
  :root {
    --bg:     #f4f6f9;
    --bg-2:   #ffffff;
    --bg-3:   #eceff4;
    --linea:  #dde3ea;
    --texto:  #14181d;
    --suave:  #5d6b7a;
  }
}

/* El interruptor de tema manda por encima de la preferencia del sistema. */
:root[data-theme="light"] {
  --bg:     #f4f6f9;
  --bg-2:   #ffffff;
  --bg-3:   #eceff4;
  --linea:  #dde3ea;
  --texto:  #14181d;
  --suave:  #5d6b7a;
}

:root[data-theme="dark"] {
  --bg:     #0e1116;
  --bg-2:   #161b22;
  --bg-3:   #1c232d;
  --linea:  #2a3440;
  --texto:  #e7edf3;
  --suave:  #8b97a6;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; border-radius: 6px; }

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(var(--nav-alto) + env(safe-area-inset-bottom) + 22px);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------- cabecera */

header.top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--linea);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

header.top h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: -0.02em;
  flex: 1;
}

header.top .fecha { color: var(--suave); font-size: .8rem; font-weight: 500; }

main { padding: 16px; max-width: 780px; margin: 0 auto; }

/* -------------------------------------------------------------- nav */

nav.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: color-mix(in srgb, var(--bg-2) 94%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom);
}

nav.tabs button {
  background: none;
  border: 0;
  color: var(--suave);
  font: inherit;
  font-size: .68rem;
  font-weight: 600;
  padding: 9px 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: color .15s;
}

nav.tabs button svg { width: 22px; height: 22px; stroke-width: 1.9; }

/* Seis pestañas caben, pero justas: en pantallas estrechas (un iPhone mini,
   por ejemplo) achico letra e iconos antes de que el texto se parta. */
@media (max-width: 400px) {
  nav.tabs button { font-size: .6rem; padding: 8px 1px 7px; gap: 2px; }
  nav.tabs button svg { width: 19px; height: 19px; }
}
@media (max-width: 340px) {
  nav.tabs button { font-size: .55rem; }
}
nav.tabs button[aria-current="page"] { color: var(--acento); }

/* ------------------------------------------------------------ piezas */

.tarjeta {
  background: var(--bg-2);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  padding: 14px;
  margin-bottom: 14px;
}

.tarjeta h2, .tarjeta h3 {
  margin: 0 0 10px;
  font-size: .95rem;
  letter-spacing: -0.01em;
}

h2.seccion {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--suave);
  margin: 22px 0 10px;
  font-weight: 700;
}
h2.seccion:first-child { margin-top: 4px; }

.fila { display: flex; align-items: center; gap: 10px; }
.entre { justify-content: space-between; }
.crece { flex: 1; min-width: 0; }
.envolver { flex-wrap: wrap; }

.suave { color: var(--suave); }
.pequeno { font-size: .78rem; }
.mini { font-size: .7rem; }
.negrita { font-weight: 700; }
.centro { text-align: center; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

.ok   { color: var(--ok); }
.mala { color: var(--mal); }
.avi  { color: var(--alerta); }

/* --------------------------------------------------------- métricas */

.rejilla { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.metrica {
  background: var(--bg-2);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  padding: 12px 14px;
}
.metrica .et { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--suave); font-weight: 700; }
.metrica .val { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; margin-top: 2px; }
.metrica .val span { font-size: .85rem; font-weight: 600; color: var(--suave); margin-left: 2px; }
.metrica .pie { font-size: .74rem; color: var(--suave); margin-top: 2px; }

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

button.b, a.b {
  appearance: none;
  border: 1px solid var(--linea);
  background: var(--bg-3);
  color: var(--texto);
  border-radius: 11px;
  padding: 11px 15px;
  font: inherit;
  font-size: .87rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform .08s, filter .15s;
}
button.b:active, a.b:active { transform: scale(.975); }
button.b.pri { background: var(--acento); border-color: var(--acento); color: #17110b; }
button.b.fantasma { background: transparent; }
button.b.peligro { color: var(--mal); }
button.b.ancho { width: 100%; }
button.b:disabled { opacity: .45; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  background: var(--bg-3);
  border: 1px solid var(--linea);
  color: var(--suave);
}
.chip.sube  { background: color-mix(in srgb, var(--ok) 16%, transparent);   color: var(--ok);     border-color: transparent; }
.chip.baja  { background: color-mix(in srgb, var(--mal) 16%, transparent);  color: var(--mal);    border-color: transparent; }
.chip.man   { background: color-mix(in srgb, var(--azul) 14%, transparent); color: var(--azul);   border-color: transparent; }
.chip.stop  { background: color-mix(in srgb, var(--alerta) 16%, transparent); color: var(--alerta); border-color: transparent; }

/* --------------------------------------------------------- entradas */

input, select, textarea {
  font: inherit;
  color: var(--texto);
  background: var(--bg-3);
  border: 1px solid var(--linea);
  border-radius: 10px;
  padding: 10px 11px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acento); outline-offset: -1px; }
input[type="number"] { -moz-appearance: textfield; text-align: center; font-variant-numeric: tabular-nums; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
textarea { min-height: 76px; resize: vertical; }
label.et { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--suave); font-weight: 700; margin-bottom: 5px; }

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

.ejercicio { background: var(--bg-2); border: 1px solid var(--linea); border-radius: var(--radio); margin-bottom: 12px; overflow: hidden; }
.ejercicio > .cab { padding: 13px 14px; display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.ejercicio > .cab .n { font-weight: 700; font-size: .93rem; line-height: 1.25; }
.ejercicio > .cab .sub { font-size: .75rem; color: var(--suave); margin-top: 3px; }
.ejercicio .cuerpo { padding: 0 14px 14px; border-top: 1px solid var(--linea); padding-top: 12px; }
.ejercicio[data-hecho="1"] > .cab { background: color-mix(in srgb, var(--ok) 8%, transparent); }

.sugerencia {
  background: color-mix(in srgb, var(--acento) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--acento) 32%, transparent);
  border-radius: 11px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.sugerencia .obj { font-weight: 700; font-size: .95rem; letter-spacing: -0.01em; }
.sugerencia .por { font-size: .76rem; color: var(--suave); margin-top: 4px; line-height: 1.45; }

.serie { display: grid; grid-template-columns: 26px 1fr 1fr 1fr 34px; gap: 7px; align-items: center; margin-bottom: 7px; }
.serie .idx { font-size: .74rem; color: var(--suave); font-weight: 700; text-align: center; }
.serie .quitar { background: none; border: 0; color: var(--suave); font-size: 1.2rem; cursor: pointer; padding: 4px; }
.cabserie { display: grid; grid-template-columns: 26px 1fr 1fr 1fr 34px; gap: 7px; font-size: .63rem; text-transform: uppercase; letter-spacing: .06em; color: var(--suave); font-weight: 700; margin-bottom: 5px; text-align: center; }

.historial { font-size: .76rem; color: var(--suave); line-height: 1.6; }
.historial b { color: var(--texto); font-weight: 600; }

/* -------------------------------------------------------- dieta */

.comida { margin-bottom: 12px; }
.comida > h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--acento); margin: 0 0 6px; font-weight: 800; }
.alimento { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--linea); cursor: pointer; }
.alimento:last-child { border-bottom: 0; }
.alimento .caja { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--linea); flex: 0 0 auto; display: grid; place-items: center; transition: .15s; }
.alimento[data-ok="1"] .caja { background: var(--ok); border-color: var(--ok); }
.alimento[data-ok="1"] .caja::after { content: "✓"; color: #08130b; font-size: .8rem; font-weight: 900; }
.alimento[data-ok="1"] .txt { text-decoration: line-through; color: var(--suave); }
.alimento .cant { font-size: .78rem; color: var(--suave); font-weight: 600; white-space: nowrap; }

/* -------------------------------------------------------- tablas */

.scroll-x table { width: max-content; min-width: 100%; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: .8rem; }
th, td { padding: 7px 9px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--linea); font-variant-numeric: tabular-nums; }
th { font-size: .64rem; text-transform: uppercase; letter-spacing: .06em; color: var(--suave); font-weight: 700; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }

/* -------------------------------------------------------- gráficas */

.grafica { width: 100%; height: 170px; display: block; }
.grafica .linea { fill: none; stroke: var(--acento); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.grafica .linea2 { fill: none; stroke: var(--azul); stroke-width: 1.4; opacity: .55; }
.grafica .area { fill: url(#degradado); }
.grafica .eje { stroke: var(--linea); stroke-width: 1; }
.grafica text { fill: var(--suave); font-size: 9px; font-family: inherit; }
.grafica .punto { fill: var(--acento); }

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

.crono {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-alto) + env(safe-area-inset-bottom) + 12px);
  z-index: 45;
  background: var(--acento);
  color: #17110b;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 22px rgba(0,0,0,.35);
  display: none;
  align-items: center;
  gap: 10px;
  border: 0;
  font-size: .95rem;
}
.crono.on { display: flex; }

/* ------------------------------------------------------------ misc */

.aviso {
  border-left: 3px solid var(--alerta);
  background: color-mix(in srgb, var(--alerta) 9%, transparent);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .8rem;
  line-height: 1.5;
  margin-bottom: 12px;
}
.aviso.info { border-color: var(--azul); background: color-mix(in srgb, var(--azul) 9%, transparent); }

.vacio { text-align: center; color: var(--suave); padding: 34px 16px; font-size: .87rem; line-height: 1.6; }

dialog {
  border: 1px solid var(--linea);
  background: var(--bg-2);
  color: var(--texto);
  border-radius: 16px;
  padding: 18px;
  width: min(92vw, 440px);
  max-height: 84vh;
  overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }

.oculto { display: none !important; }

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-alto) + env(safe-area-inset-bottom) + 64px);
  background: var(--texto);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s;
}
.toast.on { opacity: 1; }

/* --------------------------------------------------- rejilla histórica
   La tabla del Excel: semanas en columnas. La primera columna se queda
   fija al deslizar, que si no te pierdes en cuanto avanzas tres semanas. */

.rejilla-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -14px;
  padding: 0 14px;
  overscroll-behavior-x: contain;
}

.rejilla-hist {
  border-collapse: separate;
  border-spacing: 0;
  font-size: .78rem;
  white-space: nowrap;
}

.rejilla-hist th,
.rejilla-hist td {
  padding: 5px 9px;
  border-bottom: 1px solid var(--linea);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Primera columna: pegada a la izquierda y opaca, para que no se
   transparente lo que pasa por debajo. */
.rejilla-hist th[scope="row"],
.rejilla-hist thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-2);
  text-align: left;
  font-weight: 600;
  box-shadow: 1px 0 0 var(--linea);
}

.rejilla-hist thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-2);
  text-align: center;
  font-weight: 600;
  line-height: 1.25;
}
.rejilla-hist thead th:first-child { z-index: 3; }

.rejilla-hist .hgrupo th {
  background: var(--bg-3);
  color: var(--suave);
  text-align: left;
  font-size: .7rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  box-shadow: none;
}

.rejilla-hist .hfuerte td,
.rejilla-hist .hfuerte th[scope="row"] { font-weight: 700; }

/* ------------------------------------------------- informe para imprimir
   El informe vive oculto y solo aparece al imprimir. En papel mando yo:
   fondo blanco, tinta negra y nada de la interfaz. */

#informe { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }

  header.top, nav.tabs, .crono, .toast, #app, dialog { display: none !important; }

  body.imprimiendo #informe { display: block; }

  #informe {
    color: #000;
    background: #fff;
    font-size: 8pt;
    line-height: 1.3;
  }

  .pcab h1 { font-size: 15pt; margin: 0 0 2mm; }
  .pf { color: #555; font-size: 7pt; font-weight: 400; }
  .ppie { margin-top: 4mm; }

  .pres {
    width: 100%;
    border-collapse: collapse;
    margin: 3mm 0 5mm;
  }
  .pres th, .pres td { border: 1px solid #bbb; padding: 1.4mm 2mm; text-align: left; }
  .pres th { background: #f0f0f0; font-size: 7pt; text-transform: uppercase; letter-spacing: .04em; }
  .pres td { font-weight: 700; }

  .pt {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 6mm;
    /* Que un bloque de semanas no se parta entre dos hojas. */
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .pt th, .pt td {
    border: 1px solid #ccc;
    padding: .9mm 1.4mm;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  .pt thead th { background: #eee; text-align: center; font-size: 7pt; }
  .pt th[scope="row"] { text-align: left; font-weight: 400; white-space: nowrap; }
  .pt .pg th { background: #ddd; text-align: left; font-size: 7pt; letter-spacing: .06em; }
  .pt .pb th[scope="row"], .pt .pb td { font-weight: 700; }
}

/* ------------------------------------------------ calorías en la dieta */

.alimento .kcal {
  min-width: 42px;
  text-align: right;
  font-size: .74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--texto);
}
/* Genéricos ("fruta") y suplementos sin etiqueta: se ven, pero apagados,
   para que no los tomes por un dato exacto. */
.alimento .kcal.dudoso { color: var(--suave); font-weight: 600; }

.totales { width: 100%; border-collapse: collapse; }
.totales th {
  text-align: left;
  font-weight: 600;
  font-size: .74rem;
  color: var(--suave);
  padding: 3px 0;
}
.totales td {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: .78rem;
  padding: 3px 0 3px 10px;
  white-space: nowrap;
}
.totales td.grande { font-size: 1.15rem; font-weight: 800; }

/* El código de sincronización: monoespaciado y seleccionable de un toque,
   que la gente lo copia a mano y se equivoca. */
.codigo {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .04em;
  user-select: all;
  -webkit-user-select: all;
  word-break: break-all;
}
