:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --ink: #22302b;
  --muted: #69736e;
  --line: #e2ddd4;
  --primary: #2f5d50;
  --primary-ink: #ffffff;
  --primary-soft: #dfeae5;
  --evitar: #b3412e;
  --evitar-soft: #f8e3de;
  --moderar: #9a630f;
  --moderar-soft: #f7ecd6;
  --preferir: #3d7a46;
  --preferir-soft: #e2f0e0;
  --g-cereales: #c48a2c;
  --g-verduras: #4c8a49;
  --g-frutas: #cf5a3f;
  --g-proteicos: #8b4d6c;
  --g-lacteos: #477aa8;
  --g-grasas: #a9902a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(34, 48, 43, .06), 0 2px 8px rgba(34, 48, 43, .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161b19;
    --surface: #1f2623;
    --surface-2: #283130;
    --ink: #e8ece9;
    --muted: #9aa5a0;
    --line: #333d39;
    --primary: #7fb8a5;
    --primary-ink: #10201a;
    --primary-soft: #23382f;
    --evitar: #f08b78;
    --evitar-soft: #3a2420;
    --moderar: #e2b45f;
    --moderar-soft: #382c17;
    --preferir: #8cc794;
    --preferir-soft: #1f3322;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .6em; }
small, .nota { color: var(--muted); font-size: .86rem; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- estructura ---------- */
.app { max-width: 720px; margin: 0 auto; padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }
.cabecera { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0 12px; }
.cabecera .titulo { display: flex; flex-direction: column; }
.cabecera .titulo small { margin-top: 2px; }
.navfecha { display: flex; align-items: center; gap: 4px; }
.navfecha .fecha { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; text-transform: capitalize; }

nav.inferior {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
nav.inferior .items { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 720px; }
nav.inferior a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px; text-decoration: none; color: var(--muted); font-size: .74rem;
}
nav.inferior a svg { width: 24px; height: 24px; }
nav.inferior a.activo { color: var(--primary); font-weight: 600; }

.tarjeta { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.tarjeta > h2:first-child, .tarjeta > h3:first-child { margin-top: 0; }
.fila { display: flex; align-items: center; gap: 8px; }
.fila.entre { justify-content: space-between; }
.fila.envolver { flex-wrap: wrap; }
.pila > * + * { margin-top: 8px; }
.vacio { color: var(--muted); font-size: .92rem; padding: 4px 0; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer;
  text-decoration: none; font-weight: 500; font-size: .95rem;
}
.btn:active { transform: translateY(1px); }
.btn.primario { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.suave { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn.peligro { color: var(--evitar); }
.btn.ancho { width: 100%; }
.btn.chico { min-height: 32px; padding: 4px 10px; font-size: .86rem; }
.icono { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; }
.btn:disabled { opacity: .5; cursor: default; }
.enlace { background: none; border: 0; padding: 4px; color: var(--primary); cursor: pointer; font-weight: 500; }

/* ---------- progreso por grupo ---------- */
.grupos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 380px) { .grupos { grid-template-columns: repeat(2, 1fr); } }
.grupo {
  --c: var(--primary);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 10px 12px; text-align: center; box-shadow: var(--shadow);
}
.grupo .anillo { width: 64px; height: 64px; margin: 0 auto 4px; display: block; }
.grupo .anillo .fondo { stroke: var(--surface-2); }
.grupo .anillo .avance { stroke: var(--c); transition: stroke-dasharray .4s ease; }
.grupo .anillo text { font: 600 15px var(--sans); fill: var(--ink); }
.grupo .nombre { font-size: .84rem; font-weight: 600; }
.grupo .meta { font-size: .78rem; color: var(--muted); }
.grupo.listo .meta { color: var(--c); font-weight: 600; }
.g-cereales { --c: var(--g-cereales); }
.g-verduras { --c: var(--g-verduras); }
.g-frutas { --c: var(--g-frutas); }
.g-proteicos { --c: var(--g-proteicos); }
.g-lacteos { --c: var(--g-lacteos); }
.g-grasas { --c: var(--g-grasas); }

.chip {
  --c: var(--muted);
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c);
  white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- agua ---------- */
.agua .gotas { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.agua .gota { width: 22px; height: 28px; color: var(--surface-2); }
.agua .gota.llena { color: var(--g-lacteos); }

/* ---------- comidas ---------- */
.comida { padding: 12px 0; border-top: 1px solid var(--line); }
.comida:first-of-type { border-top: 0; padding-top: 4px; }
.comida .cab { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.comida .cab h3 { margin: 0; }
.comida .hora { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.registro { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; }
.registro .texto { flex: 1; min-width: 0; }
.registro .texto .desc { word-wrap: break-word; }
.registro.pendiente .desc::after { content: " · sin sincronizar"; color: var(--moderar); font-size: .78rem; }
.borrar { background: none; border: 0; color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 4px 6px; cursor: pointer; }
.sugerida { margin-top: 6px; }
.sugerida summary { cursor: pointer; color: var(--muted); font-size: .88rem; list-style: none; }
.sugerida summary::-webkit-details-marker { display: none; }
.sugerida summary::before { content: "▸ "; }
.sugerida[open] summary::before { content: "▾ "; }
.sugerida ul { list-style: none; margin: 6px 0 0; padding: 0; }
.sugerida li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; font-size: .93rem; }

.aviso { border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-size: .92rem; }
.aviso.evitar { background: var(--evitar-soft); color: var(--evitar); }
.aviso.moderar { background: var(--moderar-soft); color: var(--moderar); }
.aviso.preferir { background: var(--preferir-soft); color: var(--preferir); }
.aviso.info { background: var(--primary-soft); color: var(--primary); }
.aviso strong { display: block; margin-bottom: 2px; }

/* ---------- formularios ---------- */
label { display: block; font-size: .88rem; font-weight: 600; margin: 10px 0 4px; }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
textarea.codigo { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; min-height: 220px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.stepper { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.stepper:first-child { border-top: 0; }
.stepper .ctrl { display: flex; align-items: center; gap: 6px; }
.stepper .valor { min-width: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper .nombre { display: flex; align-items: center; gap: 8px; }
.punto { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }

.sugerencias { list-style: none; padding: 0; margin: 4px 0 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.sugerencias li button {
  width: 100%; text-align: left; background: var(--surface); border: 0; border-top: 1px solid var(--line);
  padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.sugerencias li:first-child button { border-top: 0; }
.sugerencias li button:hover { background: var(--surface-2); }
.sugerencias .porcion { color: var(--muted); font-size: .84rem; white-space: nowrap; }

/* ---------- hoja (dialog) ---------- */
dialog.hoja-modal {
  border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92vh;
  border-radius: 18px 18px 0 0; margin: auto auto 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 600px) { dialog.hoja-modal { border-radius: 18px; margin: auto; } }
dialog.hoja-modal::backdrop { background: rgba(20, 28, 25, .45); }
dialog .contenido { padding: 16px 18px 20px; overflow-y: auto; max-height: calc(92vh - 64px); }
dialog .pie { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 8px; }
dialog .pie .btn { flex: 1; }

/* ---------- consulta ---------- */
.veredicto { border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.veredicto h2 { margin: 0 0 4px; font-size: 1.15rem; }
.veredicto.evitar { background: var(--evitar-soft); color: var(--evitar); }
.veredicto.moderar { background: var(--moderar-soft); color: var(--moderar); }
.veredicto.si { background: var(--preferir-soft); color: var(--preferir); }
.veredicto.excluido { background: var(--evitar-soft); color: var(--evitar); }
.veredicto.nosabe { background: var(--surface-2); color: var(--ink); }
.veredicto p { color: inherit; }
.lista-simple { list-style: none; margin: 0; padding: 0; }
.lista-simple li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.lista-simple li:first-child { border-top: 0; }
.lista-simple .porcion { color: var(--muted); text-align: right; white-space: nowrap; }
.tachado { text-decoration: line-through; color: var(--muted); }
details.seccion { border-top: 1px solid var(--line); padding: 10px 0; }
details.seccion:first-of-type { border-top: 0; }
details.seccion summary { cursor: pointer; font-weight: 600; }
details.seccion ul { margin: 8px 0 0; padding-left: 20px; }
details.seccion li { margin: 4px 0; }
.nutriente { padding: 10px 0; border-top: 1px solid var(--line); }
.nutriente:first-of-type { border-top: 0; }

/* ---------- pestañas ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer;
  white-space: nowrap; font-size: .9rem; text-transform: capitalize;
}
.tabs button.activo { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.tabs button.hoy::after { content: " •"; }

/* ---------- peso ---------- */
.grafico { width: 100%; height: auto; display: block; }
.grafico .banda { fill: var(--primary-soft); }
.grafico .eje { stroke: var(--line); }
.grafico .linea { stroke: var(--primary); fill: none; stroke-width: 2; }
.grafico .pt { fill: var(--primary); }
.grafico text { fill: var(--muted); font: 10px var(--sans); }
.leyenda { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.leyenda span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; background: var(--c); }

/* ---------- tablas ---------- */
.tabla { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabla th, .tabla td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tabla th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla.compacta { font-size: .82rem; }
.tabla.compacta th, .tabla.compacta td { padding: 4px; }

.menu-lista a, .menu-lista button {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 14px 0; border: 0; border-top: 1px solid var(--line); background: none; text-decoration: none; color: var(--ink); cursor: pointer; text-align: left;
}
.menu-lista > :first-child { border-top: 0; }
.menu-lista .flecha { color: var(--muted); }
.badge { background: var(--primary); color: var(--primary-ink); border-radius: 999px; font-size: .75rem; padding: 1px 8px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 90vw; text-align: center;
}
.estado-red { font-size: .8rem; color: var(--moderar); }

/* ---------- login ---------- */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box form { text-align: left; margin-top: 16px; }
.login-box .error { color: var(--evitar); margin-top: 8px; }
.login-box .btn { margin-top: 14px; }
.sub { color: var(--muted); }

/* ---------- informe ---------- */
body.informe { background: var(--surface-2); }
.barra-informe { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; justify-content: space-between; max-width: 820px; margin: 0 auto; padding: 12px 16px; }
.barra-informe .rango { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.barra-informe label { margin: 0; font-weight: 500; }
.barra-informe input { min-height: 38px; padding: 6px 8px; width: auto; }
.hoja { background: #fff; color: #1d2622; max-width: 820px; margin: 0 auto 24px; padding: 32px 36px; border-radius: 6px; box-shadow: var(--shadow); }
.hoja section { margin-top: 22px; break-inside: avoid; }
.hoja h1 { font-size: 1.5rem; }
.hoja .tabla th, .hoja .tabla td { border-color: #ddd; }
.hoja .nota, .hoja .sub { color: #5d6762; }
.hoja footer { margin-top: 28px; }
@media (max-width: 600px) {
  .hoja { padding: 20px 14px; border-radius: 0; }
  .hoja .tabla { font-size: .82rem; }
  .hoja .tabla th, .hoja .tabla td { padding: 5px 3px; }
  .hoja .tabla.compacta { font-size: .72rem; }
}
@media print {
  @page { size: A4; margin: 14mm; }
  body.informe { background: #fff; }
  .no-print { display: none !important; }
  .hoja { box-shadow: none; padding: 0; margin: 0; max-width: none; }
}
