:root {
  --bg: #0f1310;
  --bg2: #161c18;
  --card: #1b231e;
  --linea: #2a352d;
  --txt: #e9f0ea;
  --txt2: #9aa89e;
  --verde: #4ade80;
  --verde2: #22c55e;
  --naranja: #fbbf24;
  --rojo: #f87171;
  --azul: #60a5fa;
  --radio: 14px;
  --sombra: 0 2px 12px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7f4;
    --bg2: #ffffff;
    --card: #ffffff;
    --linea: #e2e8e3;
    --txt: #16211a;
    --txt2: #5f6f65;
    --verde: #16a34a;
    --verde2: #15803d;
    --naranja: #b45309;
    --rojo: #dc2626;
    --azul: #2563eb;
    --sombra: 0 1px 6px rgba(16, 33, 22, .08);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--txt);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ── estructura ── */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg2);
  border-bottom: 1px solid var(--linea);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
}
header.top h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
header.top .sub { font-size: 12px; color: var(--txt2); margin-left: auto; text-align: right; }

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

nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--bg2);
  border-top: 1px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom);
  /* Con siete pestañas, en pantallas muy angostas se desliza en vez de aplastarse. */
  overflow-x: auto;
  scrollbar-width: none;
}
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button {
  flex: 1 0 auto; min-width: 48px; background: none; border: 0; color: var(--txt2);
  padding: 9px 2px 8px; font-size: 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: inherit; white-space: nowrap;
}
nav.tabs button .ic { font-size: 19px; line-height: 1; }
nav.tabs button.on { color: var(--verde); font-weight: 600; }

.vista { display: none; }
.vista.on { display: block; animation: sube .18s ease; }
@keyframes sube { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── piezas ── */
.card {
  background: var(--card); border: 1px solid var(--linea);
  border-radius: var(--radio); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--sombra);
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--txt2); font-weight: 600; }
.nota { font-size: 12.5px; color: var(--txt2); margin: 6px 0 0; }

h2.seccion { font-size: 15px; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
h2.seccion:first-child { margin-top: 0; }

label { display: block; font-size: 12.5px; color: var(--txt2); margin: 0 0 5px; font-weight: 600; }
input, select {
  width: 100%; padding: 11px 12px; font-size: 15px; font-family: inherit;
  background: var(--bg); color: var(--txt);
  border: 1px solid var(--linea); border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--verde); }
.fila { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.fila.tres { grid-template-columns: 1fr 1fr 1fr; }
.campo { margin-bottom: 12px; }

button.btn {
  width: 100%; padding: 13px; font-size: 15px; font-weight: 700; font-family: inherit;
  background: var(--verde); color: #07130c; border: 0; border-radius: 11px; cursor: pointer;
}
button.btn:active { transform: scale(.99); }
button.btn.sec { background: transparent; color: var(--txt); border: 1px solid var(--linea); font-weight: 600; }

.pills { display: flex; flex-wrap: wrap; gap: 7px; }
.pill {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--linea);
  background: var(--bg); color: var(--txt2); font-size: 12.5px; cursor: pointer;
  font-family: inherit;
}
.pill.on { background: var(--verde); border-color: var(--verde); color: #07130c; font-weight: 700; }
.pill.mini { padding: 5px 10px; font-size: 11.5px; }

/* ── resultados de macros ── */
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.macro { background: var(--bg); border: 1px solid var(--linea); border-radius: 12px; padding: 11px 8px; text-align: center; }
.macro .v { font-size: 19px; font-weight: 800; letter-spacing: -.5px; }
.macro .l { font-size: 10.5px; color: var(--txt2); text-transform: uppercase; letter-spacing: .4px; }
.macro.kc .v { color: var(--verde); }
.macro.pr .v { color: var(--azul); }
.macro.ch .v { color: var(--naranja); }
.macro.gr .v { color: #e879f9; }

.datos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: 13px; }
.datos div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--linea); padding: 5px 0; }
.datos span:last-child { font-weight: 700; }

/* ── plan ── */
.dias { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.dias button {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--linea);
  background: var(--card); color: var(--txt2); font-size: 13px; cursor: pointer; font-family: inherit;
}
.dias button.on { background: var(--verde); border-color: var(--verde); color: #07130c; font-weight: 700; }

.comida { background: var(--card); border: 1px solid var(--linea); border-radius: var(--radio); margin-bottom: 12px; overflow: hidden; }
.comida > .cab { padding: 12px 14px; border-bottom: 1px solid var(--linea); display: flex; align-items: baseline; gap: 8px; }
.comida > .cab .n { font-weight: 700; font-size: 14.5px; }
.comida > .cab .h { font-size: 11.5px; color: var(--txt2); }
.comida > .cab .k { margin-left: auto; font-size: 12.5px; color: var(--verde); font-weight: 700; }

.item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--linea); }
.item:last-child { border-bottom: 0; }
.item .txt { flex: 1; min-width: 0; }
.item .nom { font-size: 14px; }
.item .por { font-size: 12px; color: var(--txt2); }
.item .acc { display: flex; gap: 4px; }
.item .acc button {
  background: var(--bg); border: 1px solid var(--linea); color: var(--txt2);
  border-radius: 8px; padding: 5px 9px; font-size: 11.5px; cursor: pointer; font-family: inherit;
}
.item .acc button:hover { color: var(--verde); border-color: var(--verde); }
.rolico { width: 26px; text-align: center; font-size: 16px; flex: 0 0 auto; }

.barra { height: 7px; border-radius: 99px; background: var(--linea); overflow: hidden; margin: 5px 0 2px; position: relative; }
.barra i { display: block; height: 100%; background: var(--verde); border-radius: 99px; }
.barra i.alto { background: var(--naranja); }
/* Marca de lo que el menú planeaba, para comparar contra lo comido */
.barra em { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--txt2); opacity: .55; }

/* ── registro diario ── */
.chk {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px; cursor: pointer;
  border: 1.5px solid var(--linea); background: var(--bg); color: transparent;
  font-size: 13px; font-weight: 800; line-height: 1; font-family: inherit; padding: 0;
}
.chk.on { background: var(--verde); border-color: var(--verde); color: #07130c; }
.chk[disabled] { cursor: default; opacity: .8; }
.item.comido .nom { color: var(--txt2); }
.item.extra { background: color-mix(in srgb, var(--naranja) 7%, transparent); }
.etq { font-size: 10px; color: var(--naranja); border: 1px solid var(--naranja); border-radius: 5px; padding: 0 4px; margin-left: 4px; vertical-align: 1px; }

.cab-dia { display: flex; align-items: center; gap: 10px; padding: 12px 15px; }
.cab-dia .nota { display: block; margin: 2px 0 0; }
.cab-dia button { margin-left: auto; flex: 0 0 auto; }

.dias button { position: relative; }
.dias button.hoy { border-color: var(--verde); }
.dias .punto { position: absolute; top: 5px; right: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--verde); }
.dias button.on .punto { background: #07130c; }

/* ── tira de adherencia ── */
.tira { display: flex; gap: 3px; align-items: flex-end; height: 46px; margin-top: 10px; }
.tira div { flex: 1; background: var(--linea); border-radius: 3px 3px 0 0; min-height: 3px; position: relative; }
.tira div.ok { background: var(--verde); }
.tira div.alto { background: var(--naranja); }
.tira div.bajo { background: color-mix(in srgb, var(--verde) 45%, var(--linea)); }
.tira-pie { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--txt2); margin-top: 4px; }
.resumen-dia .lin { display: flex; justify-content: space-between; font-size: 12.5px; margin-top: 8px; }
.resumen-dia .lin b { font-weight: 700; }

/* ── explorador de alimentos ── */
.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th { text-align: right; font-size: 11px; color: var(--txt2); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--linea); }
.tabla th:first-child { text-align: left; }
.tabla td { padding: 8px 4px; border-bottom: 1px solid var(--linea); text-align: right; }
.tabla td:first-child { text-align: left; }
.tabla td .p2 { display: block; font-size: 11px; color: var(--txt2); }
.tabla tr.no { opacity: .38; }
.tabla .fav { color: var(--naranja); }

/* ── ejercicio ── */
.ej { padding: 11px 0; border-bottom: 1px solid var(--linea); }
.ej:last-child { border-bottom: 0; }
.ej .n { font-weight: 600; font-size: 14px; }
.ej .d { font-size: 12.5px; color: var(--verde); margin-top: 1px; }
.ej .t { font-size: 12px; color: var(--txt2); margin-top: 3px; }
.dia-ej .cab { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.dia-ej .cab .dd { font-weight: 700; font-size: 14.5px; }
.dia-ej .cab .ff { font-size: 12px; color: var(--txt2); }

/* ── modal ── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55); display: none; align-items: flex-end; }
.modal.on { display: flex; }
.modal .caja {
  background: var(--bg2); width: 100%; max-height: 82vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px 28px; margin: 0 auto; max-width: 780px;
}
.modal .caja h3 { margin: 0 0 2px; font-size: 16px; color: var(--txt); }
.modal .op { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--linea); cursor: pointer; }
.modal .op:hover { background: var(--card); }
.modal .op .txt { flex: 1; }
.modal .op .nom { font-size: 14px; }
.modal .op .por { font-size: 11.5px; color: var(--txt2); }
.modal .op .kc { font-size: 12px; color: var(--txt2); text-align: right; }

/* ── progreso ── */
.gr { width: 100%; height: auto; display: block; margin-top: 6px; }
.gr-eje { font-size: 9px; fill: var(--txt2); font-family: inherit; }

.cifras { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cifra { background: var(--bg); border: 1px solid var(--linea); border-radius: 12px; padding: 10px 8px; text-align: center; }
.cifra .v { font-size: 17px; font-weight: 800; letter-spacing: -.4px; }
.cifra .l { font-size: 10px; color: var(--txt2); text-transform: uppercase; letter-spacing: .3px; margin-top: 2px; }
.cifra .v.baja { color: var(--verde); }
.cifra .v.sube { color: var(--naranja); }

.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
.hist th { text-align: right; font-size: 10.5px; color: var(--txt2); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--linea); }
.hist th:first-child { text-align: left; }
.hist td { padding: 8px 4px; border-bottom: 1px solid var(--linea); text-align: right; }
.hist td:first-child { text-align: left; }
.hist button { background: none; border: 0; color: var(--txt2); cursor: pointer; font-size: 13px; padding: 2px 4px; font-family: inherit; }
.hist button:hover { color: var(--rojo); }

/* ── productos empaquetados ── */
.prod { border: 1px solid var(--linea); border-radius: 12px; padding: 12px; margin-top: 10px; }
.prod .cab { display: flex; align-items: flex-start; gap: 8px; }
.prod .nom { font-size: 14px; font-weight: 600; flex: 1; }
.prod .macros-min { font-size: 12px; color: var(--txt2); margin-top: 4px; }
.prod .porque { font-size: 12px; color: var(--txt2); margin-top: 6px; }
.prod .porque li { margin-left: 14px; }
.prod .ingr { font-size: 11.5px; color: var(--txt2); margin-top: 6px; max-height: 3.6em; overflow: hidden; }

.luz { flex: 0 0 auto; width: 11px; height: 11px; border-radius: 50%; margin-top: 5px; }
.luz.verde { background: var(--verde); }
.luz.amarillo { background: var(--naranja); }
.luz.rojo { background: var(--rojo); }

/* Octágonos de la NOM-051: negros y en mayúsculas, como en el empaque. */
.sellos { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.sello {
  background: #111; color: #fff; border: 2px solid #fff; border-radius: 4px;
  font-size: 9.5px; font-weight: 800; letter-spacing: .2px; padding: 4px 7px;
  text-transform: uppercase; line-height: 1.15; text-align: center; max-width: 96px;
}
@media (prefers-color-scheme: light) { .sello { border-color: #111; } }

.dudoso { font-size: 11.5px; color: var(--naranja); margin-top: 6px; }
.cargando { text-align: center; color: var(--txt2); font-size: 13px; padding: 18px; }

.aviso { background: color-mix(in srgb, var(--naranja) 12%, transparent); border: 1px solid var(--naranja); border-radius: 12px; padding: 11px 13px; font-size: 12.5px; }
.vacio { text-align: center; color: var(--txt2); padding: 40px 20px; font-size: 14px; }

@media (min-width: 640px) {
  .macros { grid-template-columns: repeat(4, 1fr); }
  nav.tabs button { font-size: 12px; }
}
@media print {
  nav.tabs, header.top, .item .acc, .dias, button { display: none !important; }
  .vista { display: block !important; }
  body { background: #fff; color: #000; }
}
