:root {
  --fondo: #f4f6f5;
  --superficie: #ffffff;
  --texto: #15201d;
  --suave: #5c6b66;
  --borde: #e1e7e4;
  --marca: #0f6e56;
  --marca-texto: #ffffff;
  --marca-suave: #e3f2ec;
  --prot: #2f6fdb;
  --carb: #d98a1c;
  --gras: #b94f8a;
  --ok: #1f8a4c;
  --bien: #7ab648;
  --medio: #e3a21a;
  --mal: #d6453d;
  --sombra: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radio: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0d1513;
    --superficie: #16211e;
    --texto: #e8efec;
    --suave: #9aaba5;
    --borde: #26332f;
    --marca: #3fbf95;
    --marca-texto: #06140f;
    --marca-suave: #173a2f;
    --prot: #6c9cf0;
    --carb: #f0aa48;
    --gras: #e07fb5;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.sin-scroll { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--marca); }

.vista {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

.cabecera { margin: 8px 2px 14px; }
.cabecera h1 { font-size: 1.7rem; margin: 0; letter-spacing: -0.02em; }
.cabecera .sub { margin: 2px 0 0; color: var(--suave); }
.fila-fecha { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fila-fecha h1 { font-size: 1.35rem; text-align: center; flex: 1; }

.tarjeta {
  background: var(--superficie);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--sombra);
  border: 1px solid var(--borde);
}
.tarjeta h2 { font-size: 1.05rem; margin: 0 0 8px; }
.texto-suave { color: var(--suave); margin: 0 0 10px; font-size: 0.93rem; }
.nota { color: var(--suave); font-size: 0.82rem; margin: 10px 2px; }
.centrado { text-align: center; }
.alerta-texto { background: #fff4e0; color: #7a4b00; padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; }
@media (prefers-color-scheme: dark) { .alerta-texto { background: #3a2a0c; color: #f3cf8d; } }

/* Botones */
.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--borde);
  background: var(--superficie); font-weight: 600; cursor: pointer;
  text-align: center;
}
.boton:active { transform: scale(0.98); }
.boton.primario { background: var(--marca); color: var(--marca-texto); border-color: var(--marca); }
.boton.peligro { color: var(--mal); border-color: color-mix(in srgb, var(--mal) 40%, transparent); }
.boton.fantasma { background: transparent; border-style: dashed; color: var(--marca); }
.boton[disabled] { opacity: 0.5; }
.boton.ancho { width: 100%; margin-bottom: 12px; }
.icono {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent;
  font-size: 1.7rem; line-height: 1; cursor: pointer; color: var(--suave);
}
.icono[disabled] { opacity: 0.25; }
.enlace { background: none; border: 0; color: var(--marca); font-weight: 600; padding: 8px 0 0; cursor: pointer; }
.peligro-texto { color: var(--mal); font-weight: 500; padding: 0; }
.ico { width: 20px; height: 20px; }
.acciones-rapidas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.fila-botones { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.fila-botones .boton { flex: 1; }

/* Formularios */
.form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 0.88rem; color: var(--suave); font-weight: 500; }
input, select {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--borde); background: var(--fondo);
  font-size: 16px; color: var(--texto);
}
input:focus, select:focus { outline: 2px solid var(--marca); outline-offset: 1px; }
.fila2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details summary { cursor: pointer; color: var(--marca); font-weight: 600; padding: 6px 0; }
details .form, details label { margin-top: 8px; }

/* Resumen del día */
.resumen { display: grid; grid-template-columns: 132px 1fr; gap: 12px 16px; align-items: center; }
.anillo { position: relative; width: 132px; height: 132px; }
.anillo svg { width: 100%; height: 100%; }
.anillo .pista { fill: none; stroke: var(--borde); stroke-width: 11; }
.anillo .valor { fill: none; stroke: var(--marca); stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset 0.4s; }
.anillo.pasado .valor { stroke: var(--mal); }
.anillo-texto { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.anillo-texto strong { font-size: 1.6rem; line-height: 1.1; }
.anillo-texto span { font-size: 0.75rem; color: var(--suave); }
.resumen-datos { display: grid; gap: 8px; }
.dato { display: grid; }
.dato span { font-size: 0.8rem; color: var(--suave); }
.macros { grid-column: 1 / -1; display: grid; gap: 10px; margin-top: 4px; }
.macro-cab { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 4px; }
.macro-cab span:last-child { color: var(--suave); }
.barra { height: 8px; background: var(--borde); border-radius: 99px; overflow: hidden; }
.barra span { display: block; height: 100%; border-radius: 99px; }
.barra.prot span { background: var(--prot); }
.barra.carb span { background: var(--carb); }
.barra.gras span { background: var(--gras); }
.barra.pasado span { background: var(--mal); }

/* Listas de alimentos */
.comida-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.comida-cab .texto-suave { margin: 0; }
.lista { list-style: none; margin: 0; padding: 0; }
.fila-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border: 0; border-bottom: 1px solid var(--borde); background: none; text-align: left; cursor: pointer;
}
.lista li:last-child .fila-item { border-bottom: 0; }
.item-nombre { display: grid; min-width: 0; }
.item-nombre small { color: var(--suave); font-size: 0.8rem; }
.item-kcal { font-weight: 600; white-space: nowrap; }
.mas { font-size: 1.4rem; color: var(--marca); width: 32px; text-align: center; }
.etiqueta-lista { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--suave); margin: 14px 0 4px; }

/* Banner */
.banner { display: flex; gap: 8px; align-items: flex-start; }
.banner p { margin: 4px 0 0; font-size: 0.92rem; }
.banner.ok { background: var(--marca-suave); border-color: transparent; }
.banner.alerta { background: #fff4e0; border-color: transparent; }
@media (prefers-color-scheme: dark) { .banner.alerta { background: #3a2a0c; } }
.banner .icono { flex: none; width: 36px; height: 36px; font-size: 1.4rem; }

/* Hoja inferior */
.hoja-fondo {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  animation: aparecer 0.15s ease-out;
}
.hoja {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--superficie); border-radius: 20px 20px 0 0;
  padding: 22px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: subir 0.2s ease-out;
}
.hoja h2 { margin: 0 40px 6px 0; font-size: 1.2rem; }
.hoja .cerrar {
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--fondo); font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--suave);
}
@keyframes aparecer { from { opacity: 0; } }
@keyframes subir { from { transform: translateY(30px); } }
@media (prefers-reduced-motion: reduce) { .hoja-fondo, .hoja { animation: none; } }

.buscador { margin: 8px 0 12px; }
.cantidad-fila { display: flex; align-items: center; gap: 8px; }
.cantidad-fila input { font-size: 1.4rem; font-weight: 700; }
.cantidad-fila span { font-size: 1.1rem; color: var(--suave); }
.cantidad { margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip { border: 1px solid var(--borde); background: var(--fondo); border-radius: 99px; padding: 8px 12px; cursor: pointer; font-size: 0.88rem; }
.previa { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; padding: 12px; background: var(--marca-suave); border-radius: 12px; margin-bottom: 12px; }
.previa strong { font-size: 1.25rem; }
.previa span { color: var(--suave); font-size: 0.9rem; }
.cargando { padding: 40px 0; text-align: center; color: var(--suave); }

/* Escáner */
.lector { width: 100%; min-height: 240px; border-radius: 14px; overflow: hidden; background: #000; margin: 10px 0; }
.lector video { width: 100% !important; object-fit: cover; }
.codigo-manual { display: flex; gap: 8px; }
.codigo-manual .boton { flex: none; }

/* Ficha de producto */
.producto-cab { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.producto-img { width: 72px; height: 72px; object-fit: contain; border-radius: 10px; background: #fff; flex: none; }
.veredicto { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 99px; font-size: 1.05rem; margin-bottom: 8px; background: var(--fondo); }
.veredicto .punto { width: 14px; height: 14px; border-radius: 50%; background: var(--suave); }
.veredicto.excelente .punto { background: var(--ok); }
.veredicto.bueno .punto { background: var(--bien); }
.veredicto.mediocre .punto { background: var(--medio); }
.veredicto.malo .punto { background: var(--mal); }
.motivos { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.motivos li { font-size: 0.85rem; padding: 4px 10px; border-radius: 99px; }
.motivos.malos li { background: color-mix(in srgb, var(--mal) 14%, transparent); }
.motivos.buenos li { background: color-mix(in srgb, var(--ok) 14%, transparent); }
.tabla-nutri { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.92rem; }
.tabla-nutri caption { text-align: left; color: var(--suave); font-size: 0.8rem; padding-bottom: 4px; }
.tabla-nutri th { text-align: left; font-weight: 400; padding: 6px 0; border-bottom: 1px solid var(--borde); }
.tabla-nutri td { text-align: right; padding: 6px 0; border-bottom: 1px solid var(--borde); font-variant-numeric: tabular-nums; }
.ns { font-weight: 800; color: #fff; width: 30px; height: 30px; display: grid; place-content: center; border-radius: 8px; flex: none; }
.ns-a { background: #038141; } .ns-b { background: #85bb2f; } .ns-c { background: #fecb02; color: #222; }
.ns-d { background: #ee8100; } .ns-e { background: #e63e11; }

/* Progreso */
.peso-form { display: flex; gap: 10px; }
.peso-form input { font-size: 1.3rem; font-weight: 700; }
.peso-form .boton { flex: none; }
.grafica { width: 100%; height: auto; display: block; }
.grafica .eje { font-size: 9px; fill: var(--suave); }
.grafica .rejilla { stroke: var(--borde); stroke-dasharray: 3 3; }
.grafica .punto-peso { fill: var(--suave); opacity: 0.55; }
.grafica .linea-media { fill: none; stroke: var(--marca); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.leyenda { display: flex; gap: 16px; font-size: 0.8rem; color: var(--suave); margin-top: 6px; }
.leyenda i { display: inline-block; margin-right: 6px; vertical-align: middle; }
.l-punto { width: 8px; height: 8px; border-radius: 50%; background: var(--suave); opacity: 0.6; }
.l-linea { width: 16px; height: 3px; background: var(--marca); border-radius: 2px; }
.obj-actual { display: grid; background: var(--marca-suave); padding: 12px; border-radius: 12px; margin-bottom: 10px; }
.obj-actual span, .obj-actual small { color: var(--suave); font-size: 0.82rem; }
.obj-actual strong { font-size: 1.5rem; }
.explica { padding-left: 18px; margin: 6px 0 0; font-size: 0.9rem; color: var(--suave); }
.explica li { margin-bottom: 4px; }
.historial { list-style: none; padding: 0; margin: 0; }
.historial li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--borde); }
.historial li:last-child { border-bottom: 0; }
.historial small { grid-column: 1 / -1; color: var(--suave); font-size: 0.82rem; }
.fila-peso { grid-template-columns: 1fr auto auto !important; align-items: center; }

/* Navegación inferior */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--superficie) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--borde);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav[hidden] { display: none; }
.tab { border: 0; background: none; padding: 8px 0 10px; display: grid; justify-items: center; gap: 2px; font-size: 0.72rem; color: var(--suave); cursor: pointer; }
.tab svg { width: 24px; height: 24px; }
.tab.activa { color: var(--marca); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 20px);
  background: var(--texto); color: var(--fondo); padding: 10px 16px; border-radius: 12px; font-size: 0.92rem;
  opacity: 0; pointer-events: none; transition: 0.2s; z-index: 30; max-width: calc(100% - 32px); text-align: center;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.alerta { background: var(--mal); color: #fff; }

@media (max-width: 360px) {
  .resumen { grid-template-columns: 1fr; justify-items: center; }
  .resumen-datos { grid-template-columns: 1fr 1fr; width: 100%; text-align: center; }
}
