:root {
  --bg: #EEF2EC;
  --surface: #FFFFFF;
  --surface-2: #F6F8F4;
  --ink: #1E3B33;
  --ink-2: #4F675E;
  --line: #D5DED6;
  --accent: #8C2F5A;       /* remolacha */
  --accent-soft: #F5E4EC;
  --on-accent: #FFFFFF;
  --leaf: #3E7A5A;
  --leaf-soft: #E1EEE5;
  --warn: #B07A10;
  --warn-soft: #FBF0D6;
  --danger: #B4302A;
  --danger-soft: #F8E1DF;
  --protein: #8C2F5A;
  --carbs: #D49A2A;
  --fat: #3E7A5A;
  --radius-lg: 22px;
  --radius: 14px;
  --radius-sm: 9px;
  --tabbar-h: 68px;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12211D;
    --surface: #1A2E28;
    --surface-2: #213730;
    --ink: #E4EEE8;
    --ink-2: #A4B8AE;
    --line: #2E463E;
    --accent: #E07AA8;
    --on-accent: #2A0E1C;
    --accent-soft: #3A2230;
    --leaf: #7CC39B;
    --leaf-soft: #1F3A2E;
    --warn: #E9B44C;
    --warn-soft: #3A3018;
    --danger: #F07A72;
    --danger-soft: #3D211F;
    --protein: #E07AA8;
    --carbs: #E9B44C;
    --fat: #7CC39B;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .6em; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }

/* ---------- Estructura ---------- */
.shell { max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  max-width: 720px; margin: 0 auto;
}
.brand { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; flex: 1; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 26px; height: 26px; }
.profile-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: .9rem;
  font-family: var(--font-display);
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 12px 0 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar-h); }
.tabbar button {
  background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-2); font-size: .74rem;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* ---------- Bloques ---------- */
.panel { background: var(--surface); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 14px; border: 1px solid var(--line); }
.panel-flat { background: var(--surface-2); border-radius: var(--radius); padding: 14px; }
.panel h2 + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
.spacer { flex: 1; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; font-weight: 700;
  background: var(--accent); color: var(--on-accent); text-decoration: none;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.leaf { background: var(--leaf); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: progress; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }
.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 25;
  width: 60px; height: 60px; border-radius: 20px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent);
}
.fab svg { width: 28px; height: 28px; }

/* ---------- Formularios ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 700; margin-bottom: 4px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.seg { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 999px; min-height: 38px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.form-error { color: var(--danger); font-weight: 700; }

/* ---------- Anillo del día (el elemento protagonista) ---------- */
.day-hero { display: grid; grid-template-columns: 172px 1fr; gap: 18px; align-items: center; }
@media (max-width: 400px) { .day-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; } }
.ring { position: relative; width: 172px; height: 172px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-family: var(--font-display); font-weight: 800; font-size: 2.4rem; line-height: 1; }
.ring .sub { font-size: .8rem; color: var(--ink-2); }
.ring circle { transition: stroke-dashoffset .9s cubic-bezier(.2,.8,.2,1); }
@media (prefers-reduced-motion: reduce) { .ring circle { transition: none; } }
.macro { margin-bottom: 10px; }
.macro .row { font-size: .9rem; }
.macro b { font-family: var(--font-display); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; border-radius: 99px; }

.date-nav { display: flex; align-items: center; gap: 4px; }
.date-nav strong { font-family: var(--font-display); min-width: 110px; text-align: center; }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex: none; background: var(--surface-2); }
.meal-type { font-size: .8rem; color: var(--ink-2); }
.kcal { font-family: var(--font-display); font-weight: 700; white-space: nowrap; }
.clickable { cursor: pointer; }

.tag { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.tag.alergia, .tag.alta { background: var(--danger-soft); color: var(--danger); }
.tag.intolerancia, .tag.media { background: var(--warn-soft); color: var(--warn); }
.tag.sienta_mal, .tag.baja { background: var(--leaf-soft); color: var(--leaf); }
.tag.info { background: var(--surface-2); color: var(--ink-2); }
.tag.ok { background: var(--leaf-soft); color: var(--leaf); }

.alert { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; border-left: 4px solid; }
.alert.alta { background: var(--danger-soft); border-color: var(--danger); }
.alert.media { background: var(--warn-soft); border-color: var(--warn); }
.alert.baja { background: var(--leaf-soft); border-color: var(--leaf); }
.alert.info { background: var(--surface-2); border-color: var(--line); }
.alert strong { display: block; }
.alert .who { font-size: .8rem; color: var(--ink-2); margin-top: 4px; }

/* Suplementos: marcar toma */
.take {
  width: 44px; height: 44px; border-radius: 50%; flex: none; cursor: pointer;
  border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center; color: transparent;
}
.take[aria-pressed="true"] { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.take svg { width: 22px; height: 22px; }

/* ---------- Gráfico de peso ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-2); font-size: 11px; font-family: var(--font-body); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.35rem; }
.stat span { font-size: .8rem; color: var(--ink-2); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 130px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: .3em 0 .6em; padding-left: 1.2em; }
.msg h3, .msg h4 { font-family: var(--font-display); margin: .6em 0 .3em; font-size: 1rem; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 24;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
  padding: 10px 16px;
}
.composer form { max-width: 688px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 140px; border-radius: 22px; padding: 11px 16px; }
.suggestions { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.suggestions button { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: .875rem; }
.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); margin-right: 4px; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

/* ---------- Hoja inferior (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 25, 20, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto;
  border-radius: 24px 24px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  animation: up .22s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 24px; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
@keyframes up { from { transform: translateY(40px); opacity: .4 } to { transform: none; opacity: 1 } }
.sheet .grip { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

.photo-drop {
  display: grid; place-items: center; text-align: center; gap: 6px;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; cursor: pointer; background: var(--surface);
}
.photo-drop img { max-height: 220px; border-radius: 12px; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; }
.qty output { min-width: 34px; text-align: center; font-weight: 700; }

/* ---------- Acceso ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; }
.auth h1 { font-size: 2.6rem; margin-bottom: 6px; }
.auth .lead { color: var(--ink-2); margin-bottom: 22px; }

.empty { text-align: center; padding: 26px 10px; color: var(--ink-2); }
.empty svg { width: 44px; height: 44px; margin: 0 auto 8px; color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 80;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); font-weight: 700;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--danger); color: #fff; }

.spinner { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.disclaimer { font-size: .78rem; color: var(--ink-2); text-align: center; margin: 18px 8px 0; }

/* ---------- Instalación ---------- */
.install-banner { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 8px 12px 12px; margin-bottom: 14px; }
.install-banner img { border-radius: 11px; flex: none; }
.install-banner .grow { flex: 1; min-width: 0; }
.install-steps { list-style: none; counter-reset: s; padding: 0; margin: 0; }
.install-steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.install-steps li:first-child { border-top: 0; }
.install-steps li::before { content: counter(s); flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-family: var(--font-display); font-weight: 800; }
/* En modo app del iPhone no hay barra de Safari: respeta la muesca */
@media (display-mode: standalone) { .topbar { padding-top: calc(14px + env(safe-area-inset-top)); } }
