/* =========================================================================
   FOCCO · Sistema visual "tiza y tinta"
   Fondo claro frío, tinta azul profunda y un color propio por hábito.
   El modo oscuro sigue la preferencia del sistema.
   ========================================================================= */
:root {
  --bg: #eceee8;
  --surface: #f9faf6;
  --surface-2: #e3e6de;
  --line: #d3d7cc;
  --ink: #17203a;
  --ink-2: #4b5368;
  --ink-3: #6f7689;
  --on-ink: #f9faf6;

  --train: #3346f0;
  --steps: #0e8f79;
  --kcal: #ec5a20;
  --prot: #3346f0;
  --carb: #d9a514;
  --fat: #b8487f;
  --danger: #c2363b;
  --miss: #c9ccc2;

  --r-xl: 28px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  --f-display: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
  --f-body: "Instrument Sans", system-ui, -apple-system, sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111522;
    --surface: #1a1f30;
    --surface-2: #242a3e;
    --line: #2e354b;
    --ink: #eef0f6;
    --ink-2: #b0b6c8;
    --ink-3: #8a91a6;
    --on-ink: #111522;
    --train: #7383ff;
    --steps: #2cc6a9;
    --kcal: #ff8350;
    --prot: #7383ff;
    --carb: #f1c043;
    --fat: #e07aad;
    --danger: #ff6b6f;
    --miss: #333a50;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  overflow-x: clip;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { opacity: .5; cursor: default; }
svg { display: block; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2.5px solid var(--train); outline-offset: 2px; border-radius: 6px; }

/* ---------- Estructura ---------- */
.main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(116px + env(safe-area-inset-bottom));
}

.nav {
  position: fixed; z-index: 40;
  left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 2px;
  padding: 6px;
  background: var(--ink);
  border-radius: 99px;
  box-shadow: 0 10px 30px -10px rgba(17, 21, 34, .45);
}
.nav-brand { display: none; }
.tab-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 66px; padding: 7px 10px 6px;
  border-radius: 99px;
  color: color-mix(in srgb, var(--on-ink) 62%, transparent);
  font-size: 11px; font-weight: 600;
  transition: background .2s, color .2s;
}
.tab-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-btn.active { background: var(--on-ink); color: var(--ink); }

@media (min-width: 960px) {
  .nav {
    left: 0; top: 0; bottom: 0; transform: none;
    width: 220px; border-radius: 0;
    flex-direction: column; align-items: stretch; gap: 4px;
    padding: 28px 16px;
    box-shadow: none;
  }
  .nav-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 0 10px 28px; color: var(--on-ink);
  }
  .tab-btn {
    flex-direction: row; gap: 12px; padding: 11px 14px;
    font-size: 15px; border-radius: var(--r-md);
  }
  .main { padding: 48px 32px 64px; margin-left: max(220px, calc(50vw - 280px + 110px)); margin-right: auto; max-width: 600px; }
}

.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--kcal);
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 7px var(--steps);
}
.brand-word { font-family: var(--f-display); font-weight: 800; font-size: 24px; letter-spacing: -.03em; }

/* ---------- Vistas ---------- */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: viewIn .28s ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } }

.view-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 20px;
}
.view-kicker { color: var(--ink-3); font-size: 14px; font-weight: 500; }
h1 {
  font-family: var(--f-display);
  font-size: clamp(40px, 11vw, 56px);
  line-height: .95; font-weight: 800; letter-spacing: -.04em;
}
h2 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 15px; font-weight: 600; }

.streak { text-align: right; line-height: 1.1; flex: none; }
.streak strong { display: block; font-family: var(--f-display); font-size: 30px; font-weight: 800; color: var(--kcal); }
.streak span { font-size: 12px; color: var(--ink-3); }

/* ---------- Navegación de fechas ---------- */
.date-nav { display: flex; align-items: center; gap: 2px; margin: 0 0 4px -8px; flex-wrap: wrap; }
.date-arrow {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-3);
}
.date-arrow:hover { background: var(--surface-2); color: var(--ink); }
.date-arrow svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.date-label {
  position: relative; display: inline-block;
  color: var(--ink-2); font-size: 14px; font-weight: 600; padding: 4px 6px; border-radius: var(--r-sm);
  cursor: pointer;
}
.date-label:hover { background: var(--surface-2); }
.date-input-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; border: 0; padding: 0;
}
.date-input-overlay::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.today-chip {
  margin-left: 6px; padding: 3px 10px; border-radius: 99px;
  background: var(--ink); color: var(--on-ink); font-size: 12px; font-weight: 600;
}
.today-chip.is-hidden { display: none; }

/* ---------- Tira de la semana ---------- */
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 8px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 0 10px; border-radius: var(--r-md);
  color: var(--ink-3); font-size: 12px; font-weight: 600;
}
.day:hover { background: var(--surface-2); }
.day b { font-family: var(--f-display); font-size: 18px; color: var(--ink); font-weight: 700; }
.day-dots { display: flex; gap: 3px; height: 5px; }
.day-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--miss); }
.day-dots i.t { background: var(--train); }
.day-dots i.s { background: var(--steps); }
.day-dots i.k { background: var(--kcal); }
.day.is-sel { background: var(--ink); color: color-mix(in srgb, var(--on-ink) 65%, transparent); }
.day.is-sel b { color: var(--on-ink); }
.day.is-today:not(.is-sel) b { color: var(--kcal); }
.day.is-future { opacity: .35; pointer-events: none; }

/* ---------- Anillo de foco ---------- */
.focus-block { display: flex; flex-direction: column; align-items: center; padding: 18px 0 26px; }
.focus-ring-wrap { position: relative; width: min(78vw, 280px); aspect-ratio: 1; }
.focus-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 14; }
.ring-arc {
  fill: none; stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 600; stroke-dashoffset: 600;
  transition: stroke-dashoffset .9s cubic-bezier(.2,.8,.2,1);
}
.arc-train { stroke: var(--train); }
.arc-steps { stroke: var(--steps); }
.arc-kcal  { stroke: var(--kcal); }
.arc-kcal.is-over { stroke: var(--fat); }
.focus-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.focus-center strong { font-family: var(--f-display); font-size: 64px; font-weight: 800; line-height: .9; letter-spacing: -.05em; }
.focus-center span { color: var(--ink-3); font-size: 14px; font-weight: 600; }
.focus-caption { margin-top: 14px; color: var(--ink-2); font-size: 15px; text-align: center; max-width: 32ch; }
.focus-block.is-closed .focus-center strong { color: var(--steps); }

/* ---------- Hábitos ---------- */
.habits { display: grid; gap: 10px; margin-bottom: 28px; }
.habit { background: var(--surface); border-radius: var(--r-lg); padding: 16px; display: grid; gap: 14px; }
.habit-row { display: flex; align-items: center; gap: 12px; }
.habit-swatch { width: 10px; align-self: stretch; border-radius: 99px; flex: none; }
.swatch-train { background: var(--train); }
.swatch-steps { background: var(--steps); }
.swatch-kcal  { background: var(--kcal); }
.habit-text { flex: 1; min-width: 0; }
.habit-text p, .habit-sub { color: var(--ink-3); font-size: 14px; }
.habit-sub { margin-top: -6px; }
.habit-status { font-size: 12px; font-weight: 600; color: var(--ink-3); white-space: nowrap; }
.habit.completed .habit-status { color: var(--steps); }
.habit-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: -4px; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: var(--r-md); }
.seg-btn {
  flex: 1; padding: 10px 6px; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600; color: var(--ink-2);
  transition: background .18s, color .18s, transform .1s;
}
.seg-btn:active { transform: scale(.97); }
.seg-btn.active { background: var(--ink); color: var(--on-ink); }
.seg-btn.seg-train.active { background: var(--train); color: #fff; }
.seg-btn.seg-steps.active { background: var(--steps); color: #fff; }
.seg-btn.seg-miss.active { background: var(--miss); color: var(--ink); }

.link-btn { font-size: 14px; font-weight: 600; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; padding: 2px 0; }
.link-btn:hover { color: var(--ink); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-thick { height: 10px; margin-bottom: 18px; }
.bar-fill { display: block; height: 100%; width: 0; border-radius: inherit; transition: width .7s cubic-bezier(.2,.8,.2,1); }
.fill-kcal { background: var(--kcal); }
.fill-prot { background: var(--prot); }
.fill-carb { background: var(--carb); }
.fill-fat  { background: var(--fat); }
.bar-fill.over-limit { background: repeating-linear-gradient(45deg, var(--fat) 0 6px, color-mix(in srgb, var(--fat) 70%, #000) 6px 12px); }

/* ---------- Inputs y botones ---------- */
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="password"], select {
  width: 100%; min-width: 0;
  padding: 12px 14px;
  background: var(--bg); border: 1.5px solid transparent;
  border-radius: var(--r-md);
  font-size: 16px;
  transition: border-color .15s;
}
input:focus, select:focus { outline: none; border-color: var(--ink); }
input::placeholder { color: var(--ink-3); }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

.quick-add { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: var(--r-md);
  font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-ink { background: var(--ink); color: var(--on-ink); }
.btn-soft { background: var(--surface-2); color: var(--ink); }
.btn-ghost { color: var(--ink-2); }
.btn-sm { padding: 8px 14px; font-size: 14px; }
.btn-wide { flex: 1; width: 100%; }
.icon-btn {
  flex: none; width: 46px; height: 46px; border-radius: var(--r-md);
  display: grid; place-items: center; background: var(--surface-2);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Desplegables personalizados (los arma app.js a partir de cada <select>) */
.custom-select-native-hidden { position: absolute !important; opacity: 0; pointer-events: none; width: 1px !important; height: 1px; }
.custom-select-wrapper { position: relative; }
.custom-select-trigger {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 14px; background: var(--bg); border: 1.5px solid transparent; border-radius: var(--r-md);
  text-align: left; font-size: 15px; font-weight: 500; color: var(--ink);
}
.custom-select-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-chevron { color: var(--ink-3); font-size: 12px; transition: transform .2s; }
.custom-select-wrapper.open .custom-select-trigger { border-color: var(--ink); }
.custom-select-wrapper.open .custom-select-chevron { transform: rotate(180deg); }
.custom-select-menu {
  display: none; position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 6px);
  min-width: 200px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 4px; max-height: 280px; overflow-y: auto;
  box-shadow: 0 16px 40px -12px rgba(17, 21, 34, .35);
}
.custom-select-wrapper.open .custom-select-menu { display: block; }
.custom-select-option {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 15px; font-weight: 500; color: var(--ink); cursor: pointer;
}
.custom-select-option:hover { background: var(--surface-2); }
.custom-select-check { opacity: 0; color: var(--steps); font-weight: 700; }
.custom-select-option.selected { background: var(--surface-2); }
.custom-select-option.selected .custom-select-check { opacity: 1; }

/* ---------- Paneles ---------- */
.panel { background: var(--surface); border-radius: var(--r-xl); padding: 20px; margin-bottom: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-foot { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 22px 4px 10px; }
.list-head-tight { margin: 16px 0 6px; }
.muted-s { font-size: 13px; color: var(--ink-3); }
.hint { font-size: 13px; color: var(--ink-3); margin: 8px 2px 0; }
.hint.is-ok { color: var(--steps); font-weight: 500; }
.hint.is-warn { color: var(--kcal); font-weight: 500; }
.hint.is-estimate { color: var(--ink-2); padding-left: 10px; border-left: 3px solid var(--carb); }
.hint.is-warn { padding-left: 10px; border-left: 3px solid var(--kcal); }
.hint.ai-loading { color: var(--ink-2); }

/* Etiqueta de valor estimado ("aprox." / "genérico") */
.est-tag {
  display: inline-block; vertical-align: 2px; margin-left: 6px;
  padding: 1px 7px; border-radius: 99px;
  font-size: 11px; font-weight: 600; line-height: 1.5;
  color: var(--ink-2); background: color-mix(in srgb, var(--carb) 28%, var(--surface));
}
.est-tag.is-rough { color: #fff; background: var(--kcal); }
.hint.ai-success { color: var(--steps); }

.legend { display: flex; gap: 12px; font-size: 12px; color: var(--ink-3); }
.legend span { display: flex; align-items: center; gap: 5px; }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.lg-3 { background: var(--ink); }
.lg-2 { background: color-mix(in srgb, var(--ink) 35%, var(--surface-2)); }
.lg-0 { background: var(--surface-2); }

.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.hm-h { font-size: 11px; color: var(--ink-3); text-align: center; font-weight: 600; }
.hm { aspect-ratio: 1; border-radius: 8px; background: var(--surface-2); position: relative; }
.hm.l1 { background: color-mix(in srgb, var(--ink) 20%, var(--surface-2)); }
.hm.l2 { background: color-mix(in srgb, var(--ink) 45%, var(--surface-2)); }
.hm.l3 { background: var(--ink); }
.hm.is-sel::after { content: ""; position: absolute; inset: -3px; border: 2px solid var(--kcal); border-radius: 10px; }
.hm-pad { aspect-ratio: 1; }

/* ---------- Comidas ---------- */
.kcal-hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 4px 2px 14px; }
.kcal-left { display: flex; flex-direction: column; min-width: 0; }
.kcal-num { font-family: var(--f-display); font-size: clamp(72px, 22vw, 104px); font-weight: 800; line-height: .85; letter-spacing: -.05em; color: var(--kcal); }
.kcal-num.is-over { color: var(--fat); }
.kcal-num.is-done { color: var(--steps); }
.kcal-unit { font-size: 15px; color: var(--ink-2); margin-top: 6px; font-weight: 500; }
.kcal-math { display: grid; gap: 6px; text-align: right; }
.kcal-math dt { font-size: 12px; color: var(--ink-3); }
.kcal-math dd { font-family: var(--f-display); font-size: 20px; font-weight: 700; }

.macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.macro { display: grid; gap: 8px; }
.macro-top { display: flex; flex-direction: column; font-size: 13px; color: var(--ink-3); }
.macro-top strong { font-family: var(--f-display); font-size: 19px; font-weight: 700; color: var(--ink); }

.add-big { display: flex; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 14px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 12px; border-radius: 99px; border: 1.5px solid var(--line); font-size: 14px; color: var(--ink-2); }
.chip:hover { border-color: var(--ink); color: var(--ink); }
.add-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.add-actions .btn { padding: 12px 6px; white-space: normal; }
.btn-stack { flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.2; text-align: center; }
.btn-stack svg { width: 22px; height: 22px; }

.meal-list { display: grid; gap: 14px; }
.meal { background: var(--surface); border-radius: var(--r-xl); padding: 8px 8px 8px 20px; }
.meal-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 12px 8px 0; }
.meal-head span { font-size: 13px; color: var(--ink-3); }
.food { display: flex; align-items: center; gap: 12px; padding: 12px 6px 12px 0; border-top: 1px solid var(--line); }
.food-main { flex: 1; min-width: 0; }
.food-name { font-weight: 500; }
.food-macro { font-size: 13px; color: var(--ink-3); }
.food-kcal { font-family: var(--f-display); font-weight: 700; font-size: 18px; white-space: nowrap; }
.food-del { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-3); flex: none; }
.food-del:hover { background: var(--surface-2); color: var(--danger); }
.food-del svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.empty { text-align: center; padding: 32px 20px; color: var(--ink-3); background: var(--surface); border-radius: var(--r-xl); }

/* ---------- Cuerpo ---------- */
.scale { background: var(--ink); color: var(--on-ink); border-radius: var(--r-xl); padding: 20px; margin-bottom: 14px; }
.scale-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; }
.scale-date { display: flex; align-items: center; gap: 6px; opacity: .9; }
.scale-date input {
  width: auto; padding: 4px 8px; font-size: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--on-ink) 10%, transparent); color: var(--on-ink);
  border-radius: var(--r-sm); color-scheme: dark;
}
@media (prefers-color-scheme: dark) { .scale-date input { color-scheme: light; } }
.delta-pill { padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: color-mix(in srgb, var(--on-ink) 14%, transparent); white-space: nowrap; }
.delta-pill.down { background: color-mix(in srgb, var(--steps) 40%, transparent); }
.delta-pill.up { background: color-mix(in srgb, var(--kcal) 45%, transparent); }
.scale-read { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 0 2px; }
.scale-num { display: flex; align-items: baseline; justify-content: center; min-width: 0; flex: 1; }
.scale-num input {
  width: 4.2ch; padding: 0; background: none; border: 0; border-radius: 0;
  color: var(--on-ink); text-align: right;
  font-family: var(--f-display); font-weight: 800; font-size: clamp(64px, 20vw, 92px); letter-spacing: -.05em; line-height: .95;
}
.scale-num input:focus { border: 0; text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 8px; }
.scale-num small { font-size: 22px; font-weight: 600; margin-left: 4px; opacity: .6; }
.scale-prev { text-align: center; font-size: 13px; opacity: .65; }
.step {
  flex: none; width: 52px; height: 52px; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--on-ink) 25%, transparent);
  font-size: 24px; font-weight: 500; color: var(--on-ink);
}
.step:active { background: color-mix(in srgb, var(--on-ink) 12%, transparent); }
.scale-chart { margin-top: 22px; }
.chart-plot { position: relative; height: 110px; touch-action: pan-y; cursor: crosshair; --chart-line: var(--on-ink); --chart-accent: var(--steps); }
.chart-plot.chart-light { --chart-line: var(--ink); --chart-accent: var(--fat); }
.chart-plot svg { width: 100%; height: 100%; overflow: visible; }
.chart-dot { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--chart-line); opacity: .45; transform: translate(-50%, -50%); pointer-events: none; }
.chart-dot.is-last { width: 10px; height: 10px; opacity: 1; background: var(--chart-accent); box-shadow: 0 0 0 2px var(--chart-line); }
.chart-dot.is-sel { width: 12px; height: 12px; opacity: 1; background: var(--chart-line); box-shadow: 0 0 0 3px var(--chart-accent); }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; opacity: .7; text-align: center; padding: 0 20px; }
.chart-tip {
  position: absolute; z-index: 2; transform: translate(-50%, calc(-100% - 14px));
  background: var(--chart-line); color: var(--surface);
  padding: 6px 10px; border-radius: var(--r-sm);
  display: grid; text-align: center; white-space: nowrap; pointer-events: none;
  box-shadow: 0 6px 16px -6px rgba(0,0,0,.4);
}
.scale .chart-tip { color: var(--ink); }
.chart-tip.edge-l { transform: translate(-12px, calc(-100% - 14px)); text-align: left; }
.chart-tip.edge-r { transform: translate(calc(-100% + 12px), calc(-100% - 14px)); text-align: right; }
.chart-tip.below { transform: translate(-50%, 14px); }
.chart-tip.below.edge-l { transform: translate(-12px, 14px); }
.chart-tip.below.edge-r { transform: translate(calc(-100% + 12px), 14px); }
.chart-tip b { font-family: var(--f-display); font-size: 18px; font-weight: 700; line-height: 1.1; }
.chart-tip span { font-size: 12px; opacity: .7; }
.chart-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; opacity: .65; margin-top: 8px; }

.perims { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.perim { background: var(--bg); border-radius: var(--r-lg); padding: 12px 10px 10px; min-width: 0; }
.perim-top { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--ink-3); }
.perim-top b { color: var(--ink); font-weight: 600; font-size: 14px; }
.perim-ctl { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-top: 6px; }
.perim-ctl button { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--surface); font-size: 18px; }
.perim-val { display: flex; align-items: baseline; justify-content: center; min-width: 0; }
.perim-val input {
  width: 4.2ch; padding: 0; background: none; border: 0; border-radius: 0; text-align: right;
  font-family: var(--f-display); font-size: 24px; font-weight: 700; letter-spacing: -.02em;
}
.perim-val input:focus { border: 0; text-decoration: underline; text-underline-offset: 4px; }
.perim-val small { font-size: 12px; color: var(--ink-3); font-weight: 500; margin-left: 2px; }
@media (max-width: 400px) {
  .perim-val input { font-size: 21px; }
  .perim-ctl button { width: 28px; height: 28px; }
}

.history { display: grid; }
.h-item { border-top: 1px solid var(--line); }
.h-item:first-child { border-top: 0; }
.h-row {
  width: 100%; text-align: left;
  display: grid; grid-template-columns: 1fr auto auto 20px; gap: 14px; align-items: center;
  padding: 13px 0;
}
.h-item:first-child .h-row { padding-top: 2px; }
.h-date { font-weight: 500; }
.h-w { font-family: var(--f-display); font-weight: 700; font-size: 18px; }
.h-d { font-size: 13px; font-weight: 600; min-width: 44px; text-align: right; color: var(--ink-3); }
.h-d.down { color: var(--steps); }
.h-d.up { color: var(--kcal); }
.h-chev { width: 18px; height: 18px; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.h-item.is-open .h-chev { transform: rotate(180deg); }
.h-detail { padding: 0 0 14px; }
.h-perims { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.h-perims div { background: var(--bg); border-radius: var(--r-md); padding: 8px 10px; min-width: 0; }
.h-perims dt { font-size: 12px; color: var(--ink-3); }
.h-perims dd { font-family: var(--f-display); font-weight: 700; font-size: 17px; }
.h-perims small { font-family: var(--f-body); font-size: 12px; font-weight: 500; color: var(--ink-3); }
.h-perims em { display: block; font-family: var(--f-body); font-style: normal; font-size: 12px; font-weight: 600; }
.h-perims em.down { color: var(--steps); }
.h-perims em.up { color: var(--kcal); }
.h-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.h-del { font-size: 13px; font-weight: 600; color: var(--danger); padding: 6px 10px; border-radius: var(--r-sm); }
.h-del:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ---------- Perfil ---------- */
.comp-hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.comp-num { font-family: var(--f-display); font-size: 72px; font-weight: 800; letter-spacing: -.05em; line-height: .9; }
.comp-hero p { color: var(--ink-2); margin-top: 6px; }
.tag { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.bf-scale { margin: 22px 0 18px; }
.bf-track { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.bf-seg { padding-top: 14px; font-size: 12px; color: var(--ink-3); position: relative; }
.bf-seg::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 8px; border-radius: 99px; }
.bf-seg:nth-child(1)::before { background: color-mix(in srgb, var(--steps) 55%, var(--surface-2)); }
.bf-seg:nth-child(2)::before { background: var(--steps); }
.bf-seg:nth-child(3)::before { background: var(--carb); }
.bf-seg:nth-child(4)::before { background: var(--kcal); }
.bf-mark { position: absolute; top: -5px; width: 4px; height: 18px; border-radius: 4px; background: var(--ink); box-shadow: 0 0 0 3px var(--surface); transform: translateX(-50%); transition: left .6s; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: var(--r-lg); overflow: hidden; }
.stats div { background: var(--surface); padding: 12px 4px; }
.stats div:nth-child(odd) { padding-right: 12px; }
.stats div:nth-child(even) { padding-left: 14px; }
.stats dt { font-size: 13px; color: var(--ink-3); }
.stats dd { font-family: var(--f-display); font-size: 22px; font-weight: 700; }
.stats dd small { font-family: var(--f-body); font-size: 12px; font-weight: 500; color: var(--ink-3); display: block; }

.budget { display: grid; gap: 8px; }
.b-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.b-label { font-size: 14px; color: var(--ink-2); }
.b-val { font-family: var(--f-display); font-weight: 700; font-size: 16px; text-align: right; }
.b-track { grid-column: 1 / -1; height: 10px; position: relative; }
.b-bar { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: var(--ink); transition: left .5s, width .5s; }
.b-row.is-plus .b-bar { background: color-mix(in srgb, var(--ink) 40%, var(--surface-2)); }
.b-row.is-phase .b-bar { background: repeating-linear-gradient(45deg, var(--kcal) 0 4px, transparent 4px 8px); border: 1.5px solid var(--kcal); }
.b-row.is-phase.is-surplus .b-bar { background: repeating-linear-gradient(45deg, var(--steps) 0 4px, transparent 4px 8px); border-color: var(--steps); }
.b-row.is-total .b-label { color: var(--ink); font-weight: 600; }
.target-line { margin: 18px 0 16px; padding: 16px; border-radius: var(--r-lg); background: var(--kcal); color: #fff; }
.target-line strong { font-family: var(--f-display); font-size: 34px; font-weight: 800; letter-spacing: -.03em; display: block; line-height: 1; }
.target-line > span { font-size: 14px; opacity: .92; }
.macro-split { display: flex; gap: 4px; }
.ms { flex: 1; min-width: 0; padding: 12px 10px; border-radius: var(--r-md); display: grid; gap: 2px; color: #fff; transition: flex .5s; }
.ms b { font-family: var(--f-display); font-size: 22px; }
.ms span { font-size: 13px; font-weight: 600; }
.ms small { font-size: 12px; opacity: .85; }
.ms-prot { background: var(--prot); }
.ms-carb { background: var(--carb); color: #2a2205; }
.ms-fat  { background: var(--fat); }
@media (prefers-color-scheme: dark) { .ms-prot, .ms-fat { color: #111522; } }

.form { display: grid; gap: 18px; }
fieldset { border: 0; display: grid; gap: 10px; min-width: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--ink-3); margin-bottom: 10px; }
.form label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); min-width: 0; }
.custom-select-wrapper, .custom-select-trigger { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 520px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.phase-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.phase-pick button {
  display: flex; gap: 6px; align-items: baseline;
  padding: 8px 12px; border-radius: 99px; border: 1.5px solid var(--line);
  font-size: 14px; font-weight: 500;
}
.phase-pick button small { color: var(--ink-3); font-size: 12px; }
.phase-pick button.is-on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.phase-pick button.is-on small { color: inherit; opacity: .7; }

/* ---------- Hojas (bottom sheets) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(17, 21, 34, .45);
  display: none; align-items: flex-end; justify-content: center;
  animation: fadeIn .2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  animation: sheetUp .35s cubic-bezier(.2,.8,.2,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--r-xl); animation: sheetPop .3s cubic-bezier(.2,.8,.2,1); }
  @keyframes sheetPop { from { transform: translateY(24px) scale(.98); opacity: 0; } }
}
.sheet-grip { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.sheet-head h2 { font-family: var(--f-display); font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.ai-row { display: flex; gap: 8px; }

.scan-loading { flex-direction: column; }
.scan-photo { position: relative; height: 240px; border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2); }
.scan-photo img { width: 100%; height: 100%; object-fit: cover; }
.scan-line {
  position: absolute; left: 0; right: 0; height: 3px;
  background: var(--kcal); box-shadow: 0 0 18px 4px color-mix(in srgb, var(--kcal) 60%, transparent);
  animation: scan 1.6s ease-in-out infinite alternate;
}
@keyframes scan { from { top: 8%; } to { top: 92%; } }
.scan-status { text-align: center; margin-top: 16px; font-weight: 600; }
.scan-loading .hint { text-align: center; }

.scan-result { display: flex; flex-direction: column; }
.dish-head { display: flex; align-items: flex-end; gap: 10px; }
.dish-thumb { flex: none; width: 60px; height: 60px; border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.dish-thumb img { width: 100%; height: 100%; object-fit: cover; }
.dish-thumb svg { width: 26px; height: 26px; fill: none; stroke: var(--ink-3); stroke-width: 1.6; }
.dish-name { flex: 1; display: grid; gap: 4px; font-size: 12px; font-weight: 500; color: var(--ink-3); min-width: 0; }
.dish-name input { font-family: var(--f-display); font-weight: 700; font-size: 18px; padding: 10px 12px; }

.scan-items { display: grid; margin-bottom: 12px; }
.photo-scan-item-card { padding: 12px 0; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.scan-item-top-row { display: flex; gap: 8px; align-items: center; }
.scan-item-name-input { font-weight: 600; padding: 8px 10px !important; }
.scan-item-delete-btn { flex: none; width: 32px; height: 32px; border-radius: 50%; color: var(--ink-3); font-size: 14px; }
.scan-item-delete-btn:hover { background: var(--surface-2); color: var(--danger); }
.scan-item-controls-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.scan-item-qty-stepper { display: flex; align-items: center; gap: 4px; }
.scan-qty-btn { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); font-size: 16px; }
.scan-qty-input { width: 64px !important; padding: 6px 8px !important; text-align: right; }
.scan-qty-unit-badge { font-size: 13px; color: var(--ink-3); min-width: 20px; }
.scan-item-macros-right { display: flex; align-items: center; gap: 10px; }
.scan-item-macros-pills { font-size: 12px; color: var(--ink-3); }
.scan-item-kcal-wrap { display: flex; align-items: center; gap: 4px; }
.scan-item-kcal-input { width: 72px !important; padding: 6px 8px !important; text-align: right; font-family: var(--f-display); font-weight: 700; }
.scan-item-kcal-unit { font-size: 12px; color: var(--ink-3); }
.food-log-empty { color: var(--ink-3); font-size: 14px; text-align: center; padding: 18px 12px; }

.scan-total {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-top: 16px; padding: 16px; border-radius: var(--r-lg); background: var(--ink); color: var(--on-ink);
}
.scan-total strong { font-family: var(--f-display); font-size: 34px; font-weight: 800; letter-spacing: -.03em; }
.scan-total dl { display: flex; gap: 14px; }
.scan-total dt { font-size: 12px; opacity: .6; }
.scan-total dd { font-weight: 600; }

/* ---------- Sugerencias de alimentos ---------- */
.has-suggest { position: relative; }
.suggest {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 4px; max-height: 320px; overflow-y: auto;
  box-shadow: 0 16px 40px -12px rgba(17, 21, 34, .35);
}
.suggest-head { font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 8px 10px 4px; }
.suggest-opt {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm); text-align: left;
}
.suggest-opt:hover, .suggest-opt.is-active { background: var(--surface-2); }
.suggest-main { display: grid; min-width: 0; }
.suggest-main b { font-weight: 600; font-size: 15px; }
.suggest-main small { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-kcal { font-family: var(--f-display); font-weight: 700; white-space: nowrap; }
.suggest-tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }

/* ---------- Escáner: aceite, rango y origen de los valores ---------- */
.fat-q { margin: 4px 0 12px; display: grid; gap: 8px; }
.fat-q .hint { margin-top: 0; }
.scan-range { font-size: 13px; opacity: .75; margin-top: 2px; }
.scan-item-basis { flex-basis: 100%; font-size: 12px; color: var(--ink-3); }
.scan-item-basis.is-base { color: var(--steps); }
.scan-item-macros-right { flex-wrap: wrap; }

/* ---------- Producto envasado ---------- */
.pick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pick-btn {
  display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 20px 12px; border-radius: var(--r-lg); background: var(--bg); border: 2px dashed var(--line);
}
.pick-btn:hover { border-color: var(--ink-3); }
.pick-btn svg { width: 30px; height: 30px; fill: none; stroke: var(--kcal); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pick-btn strong { font-size: 15px; }
.pick-btn span { font-size: 13px; color: var(--ink-3); }
.barcode-manual { margin-top: 12px; }
.product-loading { display: grid; justify-items: center; gap: 14px; padding: 36px 0; color: var(--ink-2); font-weight: 500; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--kcal); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 420px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; color: var(--ink-2); }
.check-row input { width: 18px; height: 18px; accent-color: var(--ink); }
#productSheetBackdrop .scan-total span { font-size: 14px; opacity: .8; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 200;
  transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--on-ink);
  padding: 12px 18px; border-radius: 99px; font-weight: 500; font-size: 15px;
  transition: opacity .2s, transform .25s; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 960px) { .toast { bottom: 32px; left: calc(50% + 110px); } }

@media (max-width: 400px) {
  .macros { gap: 8px; }
  .macro-top strong { font-size: 17px; }
  .tab-btn { min-width: 58px; padding: 7px 6px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Inicio de sesión ---------- */
.auth-gate {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 360px;
  display: grid; gap: 14px;
  background: var(--surface); border-radius: var(--r-xl); padding: 28px 22px 18px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.auth-brand .brand-word { font-size: 30px; }
.auth-lead { color: var(--ink-2); font-size: 15px; margin: 0 0 4px; }
.auth-card label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.auth-error { min-height: 1.2em; margin: 0; font-size: 14px; color: var(--danger); }
.auth-error.is-ok { color: var(--steps); }
.auth-link {
  justify-self: center; padding: 8px; background: none; border: 0;
  color: var(--ink-2); font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer;
}
.account { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.account h2 { margin: 0 0 2px; }
.account-email { margin: 0; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }

/* ---------- Mantenimiento real ---------- */
.measured { margin-top: 16px; padding: 14px; border-radius: var(--r-lg); background: var(--bg); display: grid; gap: 8px; }
.measured-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.measured-head h3 { font-size: 15px; font-weight: 600; }
.measured-val { font-family: var(--f-display); font-weight: 800; font-size: 22px; letter-spacing: -.02em; white-space: nowrap; }
.measured-val.is-pending { font-size: 15px; font-weight: 600; color: var(--ink-3); }
.measured-note { font-size: 13px; line-height: 1.45; color: var(--ink-2); margin: 0; }
.measured-pick { background: var(--surface-2); }
.measured-pick[hidden] { display: none; }
.measured-meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.measured-meter i { display: block; height: 100%; background: var(--steps); border-radius: inherit; transition: width .5s; }
.chart-legend { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 12px; opacity: .7; }
.chart-legend[hidden] { display: none; }
.chart-legend i { flex: none; width: 18px; height: 3px; border-radius: 2px; background: currentColor; }

/* ---------- Plan semanal ---------- */
.plan-hint { font-size: 13px; color: var(--ink-3); margin: -6px 0 2px; }
.plan-week { display: grid; gap: 8px; }
.form .plan-week label { grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 10px; font-size: 14px; }
.day-plan { font-style: normal; font-size: 10px; font-weight: 600; letter-spacing: .01em; line-height: 1; height: 10px; color: var(--ink-3); max-width: 100%; overflow: hidden; }
.day.is-sel .day-plan { color: color-mix(in srgb, var(--on-ink) 75%, transparent); }
