@font-face { font-family: 'Barlow Condensed'; font-weight: 500; font-display: swap; src: url('../fonts/barlow-condensed-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url('../fonts/barlow-condensed-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-display: swap; src: url('../fonts/barlow-condensed-latin-700-normal.woff2') format('woff2'); }

:root {
  --fondo: #EEF2F0;
  --superficie: #FFFFFF;
  --hundido: #E3E9E6;
  --tinta: #18211E;
  --suave: #56645F;
  --linea: #CFD9D4;
  --z1: #5F84A0;
  --z2: #1F7D61;
  --z3: #B88A12;
  --z4: #CF4E26;
  --z5: #A3203A;
  --descanso: #7D8A85;
  --zona: var(--tinta);
  --peligro: #B42318;
  --ok: #1F7D61;
  --aviso: #A86A00;
  /* Gráficos (paleta validada para daltonismo; estados con etiqueta, nunca solo color) */
  --serie-1: #2a78d6;
  --serie-2: #eb6834;
  --estado-bien: #0ca30c;
  --estado-lento: #fab219;
  --estado-alza: #ec835a;
  --estado-mal: #d03b3b;

  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --texto: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radio: 14px;
  --radio-s: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #111715; --superficie: #1A221F; --hundido: #232D29; --tinta: #E4ECE8; --suave: #9AA9A3; --linea: #2E3A35;
    --z1: #86A9C4; --z2: #3FB58F; --z3: #E0B43C; --z4: #F07650; --z5: #E05570; --descanso: #8C9A95;
    --peligro: #F2705F; --ok: #3FB58F; --aviso: #E3A63A;
    --serie-1: #3987e5; --serie-2: #d95926;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fondo: #111715; --superficie: #1A221F; --hundido: #232D29; --tinta: #E4ECE8; --suave: #9AA9A3; --linea: #2E3A35;
  --z1: #86A9C4; --z2: #3FB58F; --z3: #E0B43C; --z4: #F07650; --z5: #E05570; --descanso: #8C9A95;
  --peligro: #F2705F; --ok: #3FB58F; --aviso: #E3A63A;
  --serie-1: #3987e5; --serie-2: #d95926;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo); color: var(--tinta);
  font: 16px/1.5 var(--texto);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--z1); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Estructura ---------- */
.cabecera {
  padding: calc(14px + env(safe-area-inset-top)) 16px 4px;
  max-width: 640px; margin: 0 auto;
  color: var(--suave); font-size: 0.95rem;
}
.cabecera strong { color: var(--tinta); font-weight: 600; }
main { max-width: 640px; margin: 0 auto; padding: 0 16px 24px; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.1; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 2.1rem; }
h2 { font-size: 1.5rem; margin: 28px 0 10px; }
h3 { font-size: 1.2rem; }
p { margin: 0 0 10px; }
.suave { color: var(--suave); }
.peq { font-size: 0.88rem; }

.pestanas {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--superficie); border-top: 1px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom);
}
.pestanas a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; text-decoration: none; color: var(--suave); font-size: 0.75rem;
}
.pestanas svg { width: 24px; height: 24px; }
.pestanas a[aria-current="page"] { color: var(--tinta); font-weight: 600; }
.pestanas a[aria-current="page"] svg { stroke-width: 2.4; }

/* ---------- Bloques ---------- */
.panel {
  background: var(--superficie); border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 16px; margin: 12px 0;
}
.fila { display: flex; gap: 10px; align-items: center; }
.fila > .crece { flex: 1; min-width: 0; }
.rejilla2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.rejilla2 > div { display: flex; flex-direction: column; justify-content: flex-end; }

/* ---------- Hoy: el pulso objetivo es el protagonista ---------- */
.hoy { margin-top: 6px; }
.hoy .tipo { font-family: var(--display); font-size: 1.05rem; font-weight: 600; color: var(--zona); }
.hoy h1 { font-size: 2.3rem; margin: 2px 0 14px; }
.pulso {
  display: grid; grid-template-columns: auto 1fr; align-items: end; column-gap: 12px;
  border-left: 6px solid var(--zona); padding: 2px 0 2px 14px; margin-bottom: 14px;
}
.pulso .ppm {
  font-family: var(--display); font-weight: 700; color: var(--zona);
  font-size: clamp(4rem, 22vw, 6.2rem); line-height: 0.85; font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.pulso .unidad { font-family: var(--display); font-size: 1.25rem; font-weight: 600; color: var(--suave); padding-bottom: 4px; }
.pulso .unidad b { display: block; color: var(--zona); font-size: 1.6rem; font-weight: 700; }

.banda { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; margin: 0 0 6px; }
.banda span {
  height: 10px; border-radius: 3px; background: var(--hundido); position: relative;
}
.banda span.activa { height: 14px; margin-top: -2px; }
.banda-etq { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; font-size: 0.75rem; color: var(--suave); font-variant-numeric: tabular-nums; }
.banda-etq span.activa { color: var(--tinta); font-weight: 600; }

.duracion { font-family: var(--display); font-size: 1.35rem; font-weight: 600; margin: 14px 0 4px; }
.pasos { list-style: none; margin: 8px 0 0; padding: 0; border-top: 1px solid var(--linea); }
.pasos li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--linea); }
.pasos .min { font-family: var(--display); font-weight: 600; font-size: 1.15rem; min-width: 52px; font-variant-numeric: tabular-nums; }
.pasos .marca { width: 6px; border-radius: 3px; flex: none; }

.ajuste {
  border-radius: var(--radio-s); padding: 10px 12px; margin: 12px 0;
  background: color-mix(in srgb, var(--aviso) 14%, var(--superficie));
  border: 1px solid color-mix(in srgb, var(--aviso) 45%, transparent);
}
.ajuste.parar {
  background: color-mix(in srgb, var(--peligro) 14%, var(--superficie));
  border-color: var(--peligro);
}
.ajuste p { margin: 0; }
.ajuste details { margin-top: 6px; font-size: 0.92rem; }
.aviso-revision { color: inherit; text-decoration: none; border-color: var(--z2); }
.aviso-revision > span:last-child { font-size: 1.6rem; color: var(--suave); }
.nota { border-left: 3px solid var(--linea); padding-left: 10px; color: var(--suave); margin: 10px 0; }

details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
details > summary::marker { color: var(--suave); }

/* ---------- Formularios ---------- */
label { display: block; font-size: 0.9rem; font-weight: 600; margin: 12px 0 4px; }
label .suave { font-weight: 400; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: var(--radio-s);
  border: 1px solid var(--linea); background: var(--fondo); min-height: 46px;
}
textarea { min-height: 70px; resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--tinta); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 14px 0 4px; }
.check input { width: 22px; height: 22px; flex: none; margin: 1px 0 0; accent-color: var(--peligro); }
.segmentos { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--linea); border-radius: var(--radio-s); overflow: hidden; }
.segmentos input { position: absolute; opacity: 0; pointer-events: none; }
.segmentos label { margin: 0; text-align: center; padding: 10px 4px; font-weight: 500; cursor: pointer; border-right: 1px solid var(--linea); background: var(--fondo); }
.segmentos label:last-child { border-right: 0; }
.segmentos input:checked + span { font-weight: 700; }
.segmentos label:has(input:checked) { background: var(--tinta); color: var(--superficie); }
.segmentos label:has(input:focus-visible) { outline: 3px solid var(--z1); outline-offset: -3px; }
.error { color: var(--peligro); font-size: 0.9rem; margin-top: 8px; }

.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--tinta);
  background: var(--tinta); color: var(--superficie); font-weight: 600; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.boton.sec { background: transparent; color: var(--tinta); }
.boton.ancho { width: 100%; }
.boton.peligro { background: transparent; border-color: var(--peligro); color: var(--peligro); }
.botones { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.botones .boton { flex: 1 1 140px; }
.enlace { background: none; border: 0; padding: 4px 0; color: var(--tinta); text-decoration: underline; cursor: pointer; font-weight: 600; }

.hecho {
  display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--radio-s);
  background: color-mix(in srgb, var(--ok) 14%, var(--superficie)); border: 1px solid color-mix(in srgb, var(--ok) 50%, transparent);
  font-weight: 600; margin-top: 14px;
}
.hecho svg { color: var(--ok); flex: none; }

/* ---------- Plan ---------- */
.semana { border-top: 1px solid var(--linea); }
.semana > summary {
  list-style: none; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 14px 0 10px;
}
.semana > summary::-webkit-details-marker { display: none; }
.semana > summary h3 { font-size: 1.35rem; }
.semana > summary .suave { font-size: 0.85rem; text-align: right; }
.dia { display: grid; grid-template-columns: 46px 6px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; }
.dia .cuando { font-size: 0.82rem; color: var(--suave); line-height: 1.2; }
.dia .cuando b { display: block; color: var(--tinta); font-family: var(--display); font-size: 1.15rem; font-weight: 600; }
.dia .marca { align-self: stretch; border-radius: 3px; }
.dia .que { line-height: 1.3; }
.dia .estado { font-size: 0.8rem; color: var(--suave); text-align: right; }
.dia .estado.ok { color: var(--ok); font-weight: 600; }
.dia .estado.saltado { color: var(--peligro); }
.dia .estado.ajustado { color: var(--aviso); font-weight: 600; }
.titulo-bloque { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.etiqueta {
  font-size: 0.8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--linea); color: var(--tinta); background: var(--superficie);
}
.etiqueta.pendiente { border-color: var(--z2); color: var(--z2); }
.dia.es-hoy { background: var(--hundido); border-radius: var(--radio-s); margin: 0 -8px; padding: 8px; }
.dia.pasado .que { color: var(--suave); }

/* ---------- Listas ---------- */
.lista { list-style: none; padding: 0; margin: 0; }
.lista li { display: flex; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--linea); }
.lista li:last-child { border-bottom: 0; }
.lista .crece { flex: 1; min-width: 0; }
.panel.lista { padding: 2px 16px; }
.lista .valor { font-family: var(--display); font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.icono-btn { background: none; border: 0; padding: 8px; color: var(--suave); cursor: pointer; border-radius: 8px; min-width: 40px; min-height: 40px; }

.cifras { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--linea); border: 1px solid var(--linea); border-radius: var(--radio); overflow: hidden; margin: 12px 0; }
.cifras div { background: var(--superficie); padding: 12px 14px; }
.cifras b { display: block; font-family: var(--display); font-size: 1.75rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.cifras span { font-size: 0.85rem; color: var(--suave); }

.alerta { padding: 10px 12px; border-radius: var(--radio-s); border-left: 6px solid; background: var(--superficie); margin: 12px 0; }
.alerta.verde { border-color: var(--ok); }
.alerta.amarillo { border-color: var(--z3); }
.alerta.naranja { border-color: var(--z4); }
.alerta.rojo { border-color: var(--peligro); }
.alerta.sin_datos { border-color: var(--linea); color: var(--suave); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--linea); }
th { font-size: 0.82rem; color: var(--suave); font-weight: 600; }
td { white-space: nowrap; }
td.peq { white-space: normal; }
td.zona-nombre { font-family: var(--display); font-weight: 700; font-size: 1.15rem; }

.aviso-toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--tinta); color: var(--superficie); padding: 10px 16px; border-radius: 999px;
  font-weight: 600; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.vacio { text-align: center; padding: 26px 10px; color: var(--suave); }

/* ---------- Revisión de bloque ---------- */
.indicadores { list-style: none; padding: 4px 16px; }
.indicadores li {
  display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: baseline;
  padding: 10px 0 10px 12px; border-bottom: 1px solid var(--linea); position: relative;
}
.indicadores li:last-child { border-bottom: 0; }
.indicadores li::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 2px; background: var(--descanso); }
.indicadores li.ok::before { background: var(--ok); }
.indicadores li.aviso::before { background: var(--aviso); }
.indicadores li.mal::before { background: var(--peligro); }
.indicadores .nombre { font-weight: 600; }
.indicadores .valor { font-family: var(--display); font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.indicadores .detalle { grid-column: 1 / -1; font-size: 0.85rem; color: var(--suave); }
.decision { border-left: 6px solid var(--z2); }
.decision.consolidar { border-left-color: var(--aviso); }
.decision.retroceder { border-left-color: var(--peligro); }
.decision .tipo { font-family: var(--display); font-weight: 600; color: var(--suave); }
.decision h2 { margin: 0 0 6px; }
.decision ul { margin: 0 0 10px; padding-left: 20px; }
.semanas-previa .cifra-sem { text-align: right; white-space: nowrap; }
.semanas-previa .cifra-sem b { display: block; font-family: var(--display); font-size: 1.2rem; font-weight: 600; }

/* ---------- Gráficos ---------- */
.grafico { position: relative; margin: 6px 0 2px; outline-offset: 4px; touch-action: pan-y; }
.grafico svg { display: block; overflow: visible; }
.grafico .ejes text { fill: var(--suave); font-size: 11px; font-variant-numeric: tabular-nums; }
.grafico .rejilla { stroke: var(--linea); stroke-width: 1; }
.grafico .base { stroke: var(--suave); stroke-width: 1; }
.grafico .cruz { stroke: var(--suave); stroke-width: 1; }
.grafico .col.activa { filter: brightness(1.15); }
.grafico-tip {
  position: absolute; top: -8px; transform: translateY(-100%); z-index: 2; pointer-events: none;
  background: var(--superficie); border: 1px solid var(--linea); border-radius: var(--radio-s);
  padding: 6px 10px; font-size: 0.82rem; box-shadow: 0 4px 14px rgb(0 0 0 / 0.12); white-space: nowrap;
}
.grafico-tip .tit { color: var(--suave); margin-bottom: 2px; }
.fila-tip { display: flex; align-items: center; gap: 6px; }
.fila-tip b { font-variant-numeric: tabular-nums; }
.fila-tip span:last-child { color: var(--suave); }
.llave { display: inline-block; flex: none; width: 14px; height: 2px; border-radius: 1px; background: var(--c); vertical-align: middle; }
.llave.punto { width: 8px; height: 8px; border-radius: 50%; }
.llave.rect { width: 10px; height: 10px; border-radius: 2px; }
.llave.marca { width: 14px; height: 2px; background: var(--c); }
.llave.banda { width: 14px; height: 10px; border-radius: 2px; background: color-mix(in srgb, var(--c) 18%, transparent); }
.leyenda { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82rem; color: var(--suave); margin: 4px 0 2px; }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.datos-grafico { margin-top: 6px; }
.datos-grafico table { font-size: 0.85rem; margin-top: 4px; }
.subtitulo-grafico { margin: 0 0 4px; }
