/* Calorías — sistema visual "Cumbre" (ver DESIGN.md de Cumbre). Móvil primero. */
:root {
  --bg: #F5F3EE;
  --paper: #EBE7DD;
  --paper2: #F0EAD8;
  --ink: #1C1C1A;
  --ink2: #5A574F;
  --ink3: #8A8478;
  --rule: #D6D2C4;
  --terra: #C2410C;
  --terra-bg: #FDE4D3;
  --on-terra: #FFFFFF;
  --moss: #5E6B4F;
  --ok: #3F6B4A;
  --warn: #B45309;
  --bad: #9A3412;
  --sp-xs: 4px; --sp-sm: 8px; --sp-md: 12px; --sp-lg: 16px; --sp-xl: 24px; --sp-xxl: 32px;
  --r-md: 2px; --r-lg: 4px;
  --serif: 'Source Serif 4', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140F; --paper: #1D1C17; --paper2: #211F19;
    --ink: #ECE7D8; --ink2: #A8A397; --ink3: #6E6A5F; --rule: #2A281F;
    --terra: #E0612B; --terra-bg: #3A1F12; --on-terra: #15140F;
    --moss: #7D8A6A; --ok: #7DA068; --warn: #D6904A; --bad: #C9543B;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; }

.serif { font-family: var(--serif); }
.eyebrow {
  font-family: var(--mono); font-weight: 700; font-size: 10px;
  letter-spacing: 1.8px; text-transform: uppercase; color: var(--ink3);
}
.muted { color: var(--ink2); font-size: 14px; }
.center-text { text-align: center; }
.big { font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }

/* ---------- Estructura ---------- */
.screen {
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: calc(var(--sp-lg) + env(safe-area-inset-top)) var(--sp-lg)
           calc(var(--tabbar-h) + var(--sp-xl) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--sp-lg);
}
.screen.center { min-height: 100dvh; justify-content: center; padding-bottom: var(--sp-xl); }
.head h1 { font-family: var(--serif); font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; }
.head.row { display: flex; align-items: center; gap: var(--sp-md); }
.stack { display: flex; flex-direction: column; gap: var(--sp-md); }
.section-title { margin-top: var(--sp-sm); }

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
}
.auth-card { display: flex; flex-direction: column; gap: var(--sp-lg); }
.auth-card h1 { font-size: 1.75rem; font-weight: 700; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-sm);
  min-height: 48px; padding: var(--sp-sm) var(--sp-lg);
  background: transparent; color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--r-md);
  font-weight: 600; cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--terra); border-color: var(--terra); color: var(--on-terra); }
.btn.ghost { border-color: transparent; color: var(--ink2); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn svg, .tab svg, .icon-btn svg {
  width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.actions { display: flex; flex-direction: column; gap: var(--sp-sm); }
.big-btn { min-height: 56px; font-size: 1rem; justify-content: flex-start; padding-inline: var(--sp-lg); }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--rule); border-radius: var(--r-md); cursor: pointer;
}
.field {
  width: 100%; min-height: 48px; padding: var(--sp-sm) var(--sp-md);
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--rule); border-radius: 0;
}
.field:focus { outline: 2px solid var(--terra); outline-offset: -1px; }
.field-label { display: flex; flex-direction: column; gap: var(--sp-xs); font-size: 14px; color: var(--ink2); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-sm); }

.chips { display: flex; gap: var(--sp-sm); flex-wrap: wrap; }
.chip {
  padding: var(--sp-xs) var(--sp-md); min-height: 36px;
  background: transparent; border: 1px solid var(--rule); border-radius: var(--r-md);
  font-weight: 500; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.toast {
  position: fixed; left: var(--sp-lg); right: var(--sp-lg);
  top: calc(var(--sp-md) + env(safe-area-inset-top)); z-index: 30;
  max-width: 528px; margin: 0 auto; padding: var(--sp-md) var(--sp-lg);
  background: var(--ink); color: var(--bg); border-radius: var(--r-lg); font-size: 14px;
}

/* ---------- Hoy ---------- */
.hero { display: flex; flex-direction: column; gap: var(--sp-md); align-items: center; }
.ring-wrap { position: relative; width: min(60vw, 220px); aspect-ratio: 1; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 9; }
.ring-bg { stroke: var(--rule); }
.ring-fg { stroke: var(--terra); stroke-linecap: butt; transition: stroke-dashoffset 0.5s ease; }
.ring-fg.over { stroke: var(--bad); }
.ring-text {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 2px;
}
.macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-sm); width: 100%; }
.macro { text-align: center; border-top: 1px solid var(--rule); padding-top: var(--sp-sm); }
.macro b { display: block; font-family: var(--serif); font-size: 1.25rem; }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-sm); }
.meal {
  display: flex; align-items: center; gap: var(--sp-md); width: 100%; text-align: left;
  padding: var(--sp-md); background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-lg); cursor: pointer;
}
.meal .thumb {
  width: 56px; height: 56px; flex: none; object-fit: cover; background: var(--paper2);
  border: 1px solid var(--rule); border-radius: var(--r-md);
  display: grid; place-items: center; color: var(--ink3); font-family: var(--serif); font-size: 1.25rem;
}
.meal .info { flex: 1; min-width: 0; }
.meal .names { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal .kcal { font-family: var(--serif); font-weight: 700; font-size: 1.125rem; white-space: nowrap; }
.empty { color: var(--ink3); text-align: center; padding: var(--sp-xl) 0; }

.day-group { display: flex; flex-direction: column; gap: var(--sp-sm); margin-bottom: var(--sp-lg); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-md); border-bottom: 2px solid var(--ink); padding-bottom: var(--sp-xs); }
.day-head .serif { font-size: 1.125rem; font-weight: 600; text-transform: capitalize; }

/* ---------- Revisar ---------- */
.review-photo { width: 100%; max-height: 40vh; object-fit: cover; border: 1px solid var(--rule); border-radius: var(--r-lg); }
.item { display: flex; flex-direction: column; gap: var(--sp-sm); }
.item-top { display: flex; gap: var(--sp-sm); align-items: center; }
.item-top .field { flex: 1; min-width: 0; font-weight: 600; }
.stepper { display: flex; align-items: center; gap: var(--sp-sm); }
.stepper .btn { min-height: 44px; min-width: 44px; padding: 0; font-size: 1.25rem; }
.stepper .field { text-align: center; flex: 1; min-width: 0; }
.item .muted { font-family: var(--mono); font-size: 12px; }
.total-card p:nth-child(2) { margin-top: var(--sp-xs); }

/* ---------- Resumen ---------- */
.chart { width: 100%; height: 180px; margin-top: var(--sp-md); display: block; }
.chart text { font-family: var(--mono); font-size: 9px; fill: var(--ink3); }
.chart .bar { fill: var(--terra); }
.chart .bar.over { fill: var(--bad); }
.chart .bar.zero { fill: var(--rule); }
.chart .goal { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }

/* ---------- Barra de pestañas ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--rule);
}
.tab {
  flex: 1; min-height: var(--tabbar-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: transparent; border: 0; color: var(--ink3); cursor: pointer;
  font-family: var(--mono); font-weight: 700; font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase;
}
.tab[aria-current="page"] { color: var(--terra); }
body.no-tabbar .tabbar { display: none; }

/* ---------- Escáner y hoja ---------- */
.scanner { position: fixed; inset: 0; z-index: 40; background: #000; color: #fff; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; left: 10%; right: 10%; top: 28%; height: 28%;
  border: 2px solid #fff; border-radius: var(--r-lg); box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
}
.scan-hint { position: absolute; left: 0; right: 0; top: 58%; text-align: center; color: #fff; }
.scan-close { position: absolute; right: var(--sp-lg); top: calc(var(--sp-lg) + env(safe-area-inset-top)); background: rgba(0, 0, 0, 0.55); color: #fff; border-color: #fff; }
.scan-manual {
  position: absolute; left: var(--sp-lg); right: var(--sp-lg);
  bottom: calc(var(--sp-lg) + env(safe-area-inset-bottom));
  display: flex; gap: var(--sp-sm);
}
.scan-manual .field { color: var(--ink); }
.sheet-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding-bottom: calc(var(--sp-lg) + env(safe-area-inset-bottom)); background: var(--bg);
}
