/* ===== Fuentes locales ===== */
@font-face { font-family: 'Lora'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('../assets/fuentes/lora.woff2') format('woff2'); }
@font-face { font-family: 'Lora'; font-style: italic; font-weight: 400 700; font-display: swap; src: url('../assets/fuentes/lora-italic.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 400; font-display: swap; src: url('../assets/fuentes/poppins-400.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 500; font-display: swap; src: url('../assets/fuentes/poppins-500.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 600; font-display: swap; src: url('../assets/fuentes/poppins-600.woff2') format('woff2'); }

/* ===== Tokens ===== */
:root {
  color-scheme: light;
  --fondo: #fbf6ee;
  --superficie: #ffffff;
  --superficie-2: #f4ece0;
  --borde: #e6dccd;
  --texto: #2a1a26;
  --texto-suave: #6b5866;
  --ciruela: #4a2545;
  --ciruela-suave: #efe3ec;
  --naranjo: #d9682a;
  --naranjo-texto: #a84a16;
  --naranjo-suave: #fbe6d8;
  --verde: #2f6b3b;
  --verde-suave: #e2f0dd;
  --aviso: #8a4b00;
  --aviso-fondo: #fff1d6;
  --error: #9b1c1c;
  --sombra: 0 1px 2px rgb(74 37 69 / 6%), 0 4px 14px rgb(74 37 69 / 7%);
  --radio: 16px;
  --radio-chico: 10px;
  --nav-alto: 68px;

  /* Grupos: fondo / texto */
  --c-f: #fcebc4; --c-t: #6e4600;
  --p-f: #f6d9de; --p-t: #7d1f35;
  --l-f: #dce8f7; --l-t: #1f4f86;
  --g-f: #dcefd8; --g-t: #2a6427;
  --a-f: #ebebc9; --a-t: #555512;
  --fr-f: #fcdfcc; --fr-t: #93400f;
  --v-f: #d2efe9; --v-t: #0f6457;
  --pl-f: #ece0f0; --pl-t: #5a2d6b;
  --corazon: #c2334d;

  --serif: 'Lora', Georgia, 'Times New Roman', serif;
  --sans: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Oscuro: automático según el sistema (salvo que se elija Claro) o forzado con data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fondo: #1b1418;
    --superficie: #261c22;
    --superficie-2: #2f242b;
    --borde: #44363f;
    --texto: #f4ebe2;
    --texto-suave: #c4b3be;
    --ciruela: #e4c4dc;
    --ciruela-suave: #3a2a36;
    --naranjo: #f08a4f;
    --naranjo-texto: #f6a676;
    --naranjo-suave: #3d2a1f;
    --verde: #9fd6a8;
    --verde-suave: #213226;
    --aviso: #ffd28a;
    --aviso-fondo: #3a2c14;
    --error: #ffaaaa;
    --sombra: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);

    --c-f: #4a3812; --c-t: #ffe1a0;
    --p-f: #4d2129; --p-t: #ffc7d1;
    --l-f: #1d3550; --l-t: #c3dcfb;
    --g-f: #213d22; --g-t: #bfe8b9;
    --a-f: #3a3a17; --a-t: #e6e6b0;
    --fr-f: #4b2a17; --fr-t: #ffcfae;
    --v-f: #133d37; --v-t: #b3ece2;
    --pl-f: #3b2545; --pl-t: #e8cdf2;
    --corazon: #ff8ea3;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fondo: #1b1418;
  --superficie: #261c22;
  --superficie-2: #2f242b;
  --borde: #44363f;
  --texto: #f4ebe2;
  --texto-suave: #c4b3be;
  --ciruela: #e4c4dc;
  --ciruela-suave: #3a2a36;
  --naranjo: #f08a4f;
  --naranjo-texto: #f6a676;
  --naranjo-suave: #3d2a1f;
  --verde: #9fd6a8;
  --verde-suave: #213226;
  --aviso: #ffd28a;
  --aviso-fondo: #3a2c14;
  --error: #ffaaaa;
  --sombra: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);

  --c-f: #4a3812; --c-t: #ffe1a0;
  --p-f: #4d2129; --p-t: #ffc7d1;
  --l-f: #1d3550; --l-t: #c3dcfb;
  --g-f: #213d22; --g-t: #bfe8b9;
  --a-f: #3a3a17; --a-t: #e6e6b0;
  --fr-f: #4b2a17; --fr-t: #ffcfae;
  --v-f: #133d37; --v-t: #b3ece2;
  --pl-f: #3b2545; --pl-t: #e8cdf2;
  --corazon: #ff8ea3;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 400 16px/1.5 var(--sans);
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding-bottom: calc(var(--nav-alto) + 2px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); color: var(--ciruela); line-height: 1.2; margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.75rem; }
h1 em, h2 em { font-style: italic; font-weight: 500; color: var(--naranjo-texto); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .75rem; }
a { color: var(--ciruela); }
small, .suave { color: var(--texto-suave); }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--naranjo); outline-offset: 2px; border-radius: 6px; }
.oculto-visual { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ===== Estructura ===== */
.encabezado {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--fondo) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--borde);
}
.marca { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-size: 1.2rem; font-weight: 600; color: var(--ciruela); text-decoration: none; }
.marca svg { width: 30px; height: 30px; }
.marca em { color: var(--naranjo-texto); font-weight: 500; }
.encabezado-acciones { display: flex; align-items: center; gap: 2px; }

main { flex: 1 0 auto; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; }
.vista > * + * { margin-top: 16px; }

/* Barra inferior fija con las pestañas. */
.barra-inferior {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--superficie);
  border-top: 1px solid var(--borde);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 5%);
}
.navegacion {
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: var(--nav-alto);
}
.navegacion a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--texto-suave); text-decoration: none; font-size: .72rem; font-weight: 500;
  min-height: 44px;
}
.navegacion a svg { width: 24px; height: 24px; }
.navegacion a[aria-current="page"] { color: var(--ciruela); }
.navegacion a[aria-current="page"] svg { color: var(--naranjo); }

/* Pie de página: al final del contenido, fuera de la navegación. */
.pie {
  max-width: 760px; margin: 8px auto 0; padding: 12px 16px 16px;
  border-top: 1px solid var(--borde);
  text-align: center; font-size: .65rem; line-height: 1.4; color: var(--texto-suave);
}
.pie p { margin: 0; }

@media (min-width: 900px) {
  .barra-inferior { left: 50%; right: auto; transform: translateX(-50%); width: 560px; bottom: 16px; border-radius: 20px; border: 1px solid var(--borde); padding-bottom: 0; }
  body { padding-bottom: calc(var(--nav-alto) + 24px); }
}

/* ===== Componentes ===== */
.tarjeta {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 16px;
  box-shadow: var(--sombra);
}
.tarjeta.plana { box-shadow: none; }
.fila { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fila.entre { justify-content: space-between; }
.fila.nowrap { flex-wrap: nowrap; }
.pila > * + * { margin-top: 8px; }
.crece { flex: 1 1 auto; min-width: 0; }

.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px;
  border-radius: 999px; border: 1.5px solid var(--ciruela);
  background: var(--ciruela); color: var(--fondo);
  font: 500 .95rem/1.2 var(--sans); cursor: pointer; text-decoration: none;
  transition: transform .1s ease, background .15s ease;
}
.boton:active { transform: scale(.97); }
.boton.secundario { background: transparent; color: var(--ciruela); }
.boton.suave { background: var(--ciruela-suave); border-color: transparent; color: var(--ciruela); }
.boton.texto { background: transparent; border-color: transparent; color: var(--ciruela); padding-inline: 10px; }
.boton.peligro { background: transparent; border-color: var(--error); color: var(--error); }
.boton.chico { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.boton.ancho { width: 100%; }
.boton:disabled { opacity: .5; cursor: not-allowed; }
.boton svg { width: 18px; height: 18px; flex: none; }
.boton-icono {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--ciruela); cursor: pointer;
}
.boton-icono:hover { background: var(--ciruela-suave); }
.boton-icono svg { width: 22px; height: 22px; }
.corazon[aria-pressed="true"] { color: var(--corazon); }

/* Chips de grupo */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 500; line-height: 1.5; white-space: nowrap;
  background: var(--superficie-2); color: var(--texto);
}
.chip.g-C { background: var(--c-f); color: var(--c-t); }
.chip.g-P { background: var(--p-f); color: var(--p-t); }
.chip.g-L { background: var(--l-f); color: var(--l-t); }
.chip.g-G { background: var(--g-f); color: var(--g-t); }
.chip.g-A { background: var(--a-f); color: var(--a-t); }
.chip.g-F { background: var(--fr-f); color: var(--fr-t); }
.chip.g-V { background: var(--v-f); color: var(--v-t); }
.chip.g-PL { background: var(--pl-f); color: var(--pl-t); }
.chip.etiqueta { background: transparent; border: 1px solid var(--borde); color: var(--texto-suave); }
.chip.sodio { background: var(--aviso-fondo); color: var(--aviso); }

/* Filtros (chips seleccionables) */
.filtros { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.filtros::-webkit-scrollbar { display: none; }
.filtro {
  flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  border: 1.5px solid var(--borde); background: var(--superficie); color: var(--texto);
  font: 500 .85rem var(--sans); cursor: pointer;
}
.filtro[aria-pressed="true"] { background: var(--ciruela); border-color: var(--ciruela); color: var(--fondo); }

/* Formularios */
label { font-weight: 500; font-size: .9rem; }
.campo { display: flex; flex-direction: column; gap: 4px; }
input[type="search"], input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1.5px solid var(--borde); border-radius: var(--radio-chico);
  background: var(--superficie); color: var(--texto); font: 400 1rem var(--sans);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--ciruela); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--naranjo) 35%, transparent); }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--ciruela); flex: none; }
.buscador { position: relative; }
.buscador svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--texto-suave); pointer-events: none; }
.buscador input { padding-left: 40px; }

/* Avisos */
.aviso { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radio-chico); background: var(--aviso-fondo); color: var(--aviso); font-size: .92rem; }
.aviso.info { background: var(--ciruela-suave); color: var(--ciruela); }
.aviso.bien { background: var(--verde-suave); color: var(--verde); }
.aviso svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.aviso p { margin: 0; }

/* Progreso */
.progreso { display: grid; gap: 10px; }
.barra-fila { display: grid; grid-template-columns: 8.2rem 1fr 3rem; align-items: center; gap: 10px; font-size: .85rem; }
.barra-fila .valor { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.barra { height: 10px; border-radius: 999px; background: var(--superficie-2); overflow: hidden; }
.barra > span { display: block; height: 100%; border-radius: inherit; transition: width .3s ease; }
.barra.g-C > span { background: var(--c-t); }
.barra.g-PL > span { background: var(--pl-t); }
.barra.g-G > span { background: var(--g-t); }
.barra.g-A > span { background: var(--a-t); }
.barra.g-F > span { background: var(--fr-t); }
.barra.excede > span { background: var(--error); }

.vasos { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; margin-top: 4px; }
.vasos .boton-icono { width: 100%; height: 40px; border-radius: 8px; }
.vaso { width: 20px; height: 26px; color: var(--l-t); opacity: .3; }
.vaso.lleno { opacity: 1; }

/* Comidas */
.comida { position: relative; }
.comida-cabeza { display: flex; align-items: flex-start; gap: 12px; }
.hora { font-family: var(--serif); font-style: italic; color: var(--naranjo-texto); font-size: .95rem; min-width: 46px; padding-top: 2px; }
.comida-cabeza h3 { margin: 0; }
.comida .estado { font-size: .85rem; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.estado.completa { color: var(--verde); }
.estado.incompleta, .estado.excede { color: var(--aviso); }
.eleccion { margin-top: 12px; padding: 12px; border-radius: var(--radio-chico); background: var(--superficie-2); }
.eleccion strong { font-weight: 600; }
.eleccion ul { margin: 4px 0 0; padding-left: 18px; font-size: .92rem; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.acciones .boton { flex: 1 1 140px; }
.comida.hecha { border-color: color-mix(in srgb, var(--verde) 50%, var(--borde)); }

/* Check animado */
.marca-check { width: 22px; height: 22px; }
.marca-check path { stroke-dasharray: 24; stroke-dashoffset: 0; }
.hecha .check .marca-check path { animation: trazo .4s ease both; }
@keyframes trazo { from { stroke-dashoffset: 24; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
  .marca-check path { stroke-dashoffset: 0; }
}

/* Listas de recetas */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item-receta {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 14px; border-radius: var(--radio); border: 1px solid var(--borde);
  background: var(--superficie); color: var(--texto); text-align: left; text-decoration: none; font: inherit; cursor: pointer;
}
.item-receta:hover { border-color: var(--ciruela); }
.item-receta > svg { width: 20px; height: 20px; flex: none; color: var(--texto-suave); }
.aviso .boton-icono svg, .estado svg { width: 18px; height: 18px; }
summary svg { width: 20px; height: 20px; }
.item-receta .titulo { font-weight: 500; display: block; }
.item-receta .meta { font-size: .8rem; color: var(--texto-suave); }
.item-receta .chips { margin-top: 6px; }

/* Receta (detalle) */
.receta-detalle ol, .receta-detalle ul { padding-left: 20px; margin: 0; }
.receta-detalle ol li { margin-bottom: 10px; padding-left: 4px; }
.ingredientes { list-style: none; padding: 0 !important; }
.ingredientes li { border-bottom: 1px dashed var(--borde); }
.ingredientes li:last-child { border-bottom: 0; }
.ingredientes .check { font-weight: 400; width: 100%; }
.ingredientes input:checked + span { text-decoration: line-through; color: var(--texto-suave); }
.tip { padding: 12px 14px; border-left: 4px solid var(--naranjo); background: var(--naranjo-suave); border-radius: 0 var(--radio-chico) var(--radio-chico) 0; }
.tip strong { color: var(--naranjo-texto); }
body.cocinando { font-size: 20px; }
body.cocinando .receta-detalle { font-size: 1.15rem; }
body.cocinando .barra-inferior, body.cocinando .pie { display: none; }
body.cocinando { padding-bottom: 24px; }

/* Tablas */
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabla th, .tabla td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--borde); vertical-align: top; }
.tabla th { font-weight: 600; color: var(--ciruela); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.tabla-contenedor { overflow-x: auto; }

details.grupo { border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie); }
details.grupo + details.grupo { margin-top: 10px; }
details.grupo summary { cursor: pointer; padding: 14px 16px; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 500; list-style: none; }
details.grupo summary::-webkit-details-marker { display: none; }
details.grupo summary::after { content: '+'; font-size: 1.4rem; color: var(--texto-suave); }
details.grupo[open] summary::after { content: '–'; }
details.grupo .contenido { padding: 0 16px 14px; }
.alimento { padding: 8px 0; border-top: 1px dashed var(--borde); display: flex; justify-content: space-between; gap: 12px; }
.alimento .porcion { color: var(--texto-suave); text-align: right; font-size: .9rem; }

/* Diálogo tipo hoja */
dialog.hoja {
  width: min(640px, 100%); max-width: 100%; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--fondo); color: var(--texto);
  box-shadow: 0 -10px 40px rgb(0 0 0 / 25%);
}
dialog.hoja::backdrop { background: rgb(30 15 28 / 45%); }
dialog.hoja[open] { animation: subir .22s ease; }
@keyframes subir { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 700px) { dialog.hoja { margin: auto; border-radius: 22px; } }
.hoja-cabeza { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 12px 8px 12px 16px; background: var(--fondo); border-bottom: 1px solid var(--borde); }
.hoja-cabeza h2 { margin: 0; flex: 1; font-size: 1.15rem; }
.hoja-cuerpo { padding: 16px; overflow-y: auto; max-height: calc(92dvh - 70px); }
.hoja-cuerpo > * + * { margin-top: 14px; }
.hoja-pie { position: sticky; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--fondo); border-top: 1px solid var(--borde); display: flex; gap: 8px; }
.hoja-pie .boton { flex: 1; }

/* Componentes (armar comida) */
.espacio { padding: 12px; border-radius: var(--radio-chico); background: var(--superficie); border: 1px solid var(--borde); }
.espacio .equivale { font-size: .85rem; color: var(--texto-suave); margin-top: 6px; }

/* Otros */
.grilla-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.dato-grande { font-family: var(--serif); font-size: 2rem; color: var(--ciruela); font-weight: 600; line-height: 1; }
.segmentado { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--superficie-2); gap: 4px; }
.segmentado button { min-height: 40px; padding: 6px 16px; border: 0; border-radius: 999px; background: transparent; color: var(--texto-suave); font: 500 .9rem var(--sans); cursor: pointer; }
.segmentado button[aria-pressed="true"] { background: var(--superficie); color: var(--ciruela); box-shadow: var(--sombra); }
.vacio { text-align: center; padding: 24px 12px; color: var(--texto-suave); }
.ilustracion { width: 72px; height: 72px; color: var(--naranjo); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-alto) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; padding: 10px 18px; border-radius: 999px; background: var(--ciruela); color: var(--fondo);
  font-weight: 500; font-size: .9rem; box-shadow: var(--sombra); max-width: calc(100% - 32px);
  animation: subir .2s ease;
}
.compras-grupo h3 { font-family: var(--sans); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-suave); margin: 14px 0 4px; }
.compras-grupo .check { font-weight: 400; min-height: 40px; width: 100%; }
.compras-grupo input:checked + span { text-decoration: line-through; color: var(--texto-suave); }
.semana-dia { display: grid; gap: 8px; }
.semana-dia select { min-height: 40px; padding: 6px 10px; font-size: .9rem; }
.cambio-dia { display: flex; align-items: center; gap: 4px; }
