/* ==========================================================================
   Food Tracker — Swiss / data-ledger UI (ui-ux-pro-max)
   Fira Sans for labels and prose; Fira Code for figures.
   ========================================================================== */

:root {
  color-scheme: light;
  --ground: #f7f9f8;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --border: #d9e3df;
  --rule: #e7eeea;
  --control: #c9d6d1;

  --green: #059669;
  --green-dark: #047857;
  --green-pale: #ecfdf5;
  --green-track: #d1fae5;

  --orange: #ea580c;
  --orange-dark: #c2410c;
  --orange-pale: #fff1e8;
  --orange-line: #fed7aa;

  --red: #dc2626;
  --red-dark: #b91c1c;

  --chart-line: #059669;

  --font-sans: "Fira Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Fira Code", ui-monospace, "Cascadia Code", monospace;

  --max: 1180px;
  --gap: 24px;
  --pad: 24px;
  --fs-small: 12px;
  --fs-body: 16px;
  --fs-title: 32px;
  --fs-figure: 48px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #0b0f0d;
  --surface: #121714;
  --ink: #f2f5f3;
  --muted: #a3aea8;
  --border: #28312c;
  --rule: #202823;
  --control: #3c4741;

  --green: #34d399;
  --green-dark: #6ee7b7;
  --green-pale: #0e231a;
  --green-track: #1d3a2b;

  --orange: #fb923c;
  --orange-dark: #fdba74;
  --orange-pale: #2a1a10;
  --orange-line: #7c3a12;

  --red: #f87171;
  --red-dark: #fca5a5;

  --chart-line: #0fa36b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.budget-figure,
.macro-value,
.split-value,
.kv-row dd,
.meal-row-kcal,
.meal-row-macros,
.meal-group-kcal,
.card-meta,
.track-ends,
.preview-total,
.preview-rows li span:last-child,
.result-figure,
.preview-figure,
.session-user,
.topbar-user #topUser {
  font-variant-numeric: tabular-nums;
}

/* ── Marca ─────────────────────────────────────────────────────────────── */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: left;
}

.brand .mark {
  width: 24px;
  height: 24px;
  flex: none;
}

.brand-lg {
  font-size: 18px;
}

.brand-lg .mark {
  width: 28px;
  height: 28px;
}

/* ── Arranque ───────────────────────────────────────────────────────────── */

.boot {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
}

.boot-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ── Registro e inicio de sesión ───────────────────────────────────────── */

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 20px 40px;
  background: var(--ground);
}

.gate-inner {
  width: 100%;
  max-width: 1120px;
  display: grid;
  gap: 32px;
}

.gate-story h1 {
  margin: 20px 0 12px;
  max-width: 17ch;
  font-family: var(--font-sans);
  font-size: 28px;
  line-height: 1.08;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.gate-lede {
  margin: 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.gate-points {
  display: none;
  list-style: none;
  margin: 32px 0 0;
  padding: 0;
  gap: 14px;
}

.gate-points li {
  padding-left: 16px;
  border-left: 2px solid var(--green);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.gate-points strong {
  display: block;
  color: var(--ink);
  font-weight: 500;
}

.gate-foot {
  display: none;
  margin: 32px 0 0;
  max-width: 42ch;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.day-preview {
  display: none;
  max-width: 420px;
  margin: 28px 0 0;
  padding: 0;
}

.preview-caption {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.preview-card {
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.preview-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
}

.preview-total {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
}

.preview-total span {
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 400;
}

.preview-track {
  height: 8px;
  margin-top: 10px;
}

.preview-rows {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.preview-rows li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-size: 13px;
}

.preview-rows li:last-child {
  border-bottom: 0;
}

.preview-rows li span:last-child {
  color: var(--ink);
  font-family: var(--font-mono);
}

.preview-macros-line {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ── Tarjetas y formularios ───────────────────────────────────────────── */

.card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.auth-card {
  width: 100%;
  max-width: 480px;
  padding: 24px;
}

.auth-card h2 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 20px;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gate-restore {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.step-desc {
  margin: 6px 0 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.progress {
  height: 4px;
  margin-bottom: 24px;
  background: var(--rule);
}

.progress-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ink);
  transform: scaleX(var(--fill, 0.2));
  transform-origin: left;
  transition: transform 0.2s ease;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 18px;
  min-width: 0;
}

fieldset.field {
  border: 0;
  padding: 0;
}

.field:last-of-type {
  margin-bottom: 0;
}

.field label,
.field-label,
.field legend {
  padding: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--control);
  border-radius: 0;
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 16px;
}

input:disabled {
  background: var(--ground);
  color: var(--muted);
  cursor: not-allowed;
}

select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%23475569' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

input::placeholder {
  color: #64748b;
}

input:focus,
select:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}

.input-suffix {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.input-suffix input {
  padding-right: 44px;
}

.input-suffix > span {
  position: absolute;
  right: 12px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.input-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

/* Segmentado */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--control);
  background: var(--surface);
}

.seg label {
  position: relative;
  display: block;
  min-width: 0;
}

.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 6px;
  border-left: 1px solid var(--control);
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seg label:first-child span {
  border-left: 0;
}

.seg input:checked + span {
  background: var(--ink);
  color: #ffffff;
  font-weight: 500;
}

.seg input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

.seg-four span {
  font-size: 12px;
}

/* Opciones */
.choice-list {
  display: grid;
  border: 1px solid var(--control);
  background: var(--surface);
}

.choice {
  position: relative;
  display: block;
  min-width: 0;
  border-top: 1px solid var(--control);
}

.choice:first-child {
  border-top: 0;
}

.choice input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.choice > span {
  display: block;
  padding: 13px 16px;
  background: var(--surface);
}

.choice strong {
  display: block;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.choice em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  line-height: 1.4;
}

.choice input:checked + span {
  background: var(--green-pale);
  box-shadow: inset 4px 0 0 var(--green);
}

.choice input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn-primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #111111;
}

.btn-primary:hover {
  background: #f97316;
  border-color: #f97316;
}

.btn-primary:active {
  background: var(--orange-dark);
  border-color: var(--orange-dark);
  color: #ffffff;
}

.btn-primary:disabled {
  background: #e2e8e5;
  border-color: #e2e8e5;
  color: #64748b;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--control);
  color: var(--ink);
}

.btn-secondary:hover {
  background: var(--ground);
  border-color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--rule);
  color: var(--ink);
}

.btn-danger {
  background: var(--red-dark);
  border-color: var(--red-dark);
  color: #ffffff;
}

.btn-danger:hover {
  background: #991b1b;
  border-color: #991b1b;
}

.btn-full {
  width: 100%;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
}

.auth-actions .btn:not(.btn-ghost) {
  margin-left: auto;
}

.auth-actions .btn-full {
  margin-left: 0;
}

.text-btn {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: color 0.16s ease;
}

.text-btn:hover {
  color: var(--ink);
}

.text-btn.danger {
  color: var(--red-dark);
}

.text-btn.danger:hover {
  color: #7f1d1d;
}

.form-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #7f1d1d;
  font-size: 13px;
  line-height: 1.45;
}

/* ── Resultado del cálculo ─────────────────────────────────────────────── */

.result {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--green-track);
  background: var(--green-pale);
}

.result-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.result-figure {
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.macro-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--green-track);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.macro-summary strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 500;
}

.macro-empty {
  grid-column: 1 / -1;
}

/* ── Shell ─────────────────────────────────────────────────────────────── */

.shell {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 32px;
  width: 100%;
  max-width: var(--max);
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar .brand {
  font-size: 16px;
}

.topbar .mark {
  width: 22px;
  height: 22px;
}

.topnav {
  display: none;
  gap: 4px;
  margin-left: auto;
}

.theme-btn {
  margin-left: auto;
}

.topbar-user {
  display: none;
  align-items: center;
  gap: 16px;
  margin-left: 24px;
  color: var(--muted);
  font-size: 13px;
}

.topbar-user #topUser {
  font-family: var(--font-mono);
  font-size: 13px;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  text-align: left;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.nav-item:hover {
  background: var(--green-pale);
  color: var(--ink);
}

.topnav .nav-item.is-active {
  color: var(--ink);
  font-weight: 500;
  box-shadow: inset 0 -2px 0 var(--ink);
}

.canvas {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 20px 16px 96px;
}

.bottomnav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottomnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 60px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
}

.bottomnav-item svg {
  width: 20px;
  height: 20px;
}

.bottomnav-item.is-active {
  color: var(--ink);
}

.bottomnav-add {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 60px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
}

.bottomnav-add-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: var(--orange);
  color: #111111;
}

.bottomnav-add-icon svg {
  width: 22px;
  height: 22px;
}

/* ── Página ────────────────────────────────────────────────────────────── */

.page {
  max-width: var(--max);
}

.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.title-row h1 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 28px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.scope-inline {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
}

.title-row > .profile-meta {
  flex: none;
}

.profile-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.profile-meta .text-btn {
  font-size: 12px;
}

@media (min-width: 900px) {
  .profile-meta .text-btn {
    display: none;
  }
}

#btnAddMeal,
#btnAddDayMeal {
  display: none;
  flex: none;
}

/* ── Presupuesto ───────────────────────────────────────────────────────── */

.budget-band {
  margin-bottom: var(--gap);
  padding: 24px;
  border: 1px solid var(--green-track);
  background: var(--green-pale);
}

.card-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
}

.budget-figure {
  margin: 8px 0 20px;
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.03em;
}

.budget-figure.is-over {
  color: var(--red-dark);
}

.unit {
  margin-left: 10px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0;
}

.track {
  height: 12px;
  background: var(--green-track);
  overflow: hidden;
}

.track-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--green);
  transform: scaleX(var(--fill, 0));
  transform-origin: left;
  transition: transform 0.35s ease;
}

.track-fill.is-over {
  background: var(--red);
}

.track-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.card-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.budget-split {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--green-track);
}

.split-cell {
  min-width: 0;
  padding-right: 10px;
}

.split-cell + .split-cell {
  padding-left: 14px;
  border-left: 1px solid var(--green-track);
}

.split-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.split-value {
  margin: 3px 0 0;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.1;
}

/* ── Grid del dashboard ────────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head .card-label {
  margin: 0;
}

.card-head .text-btn {
  font-size: 12px;
}

.card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* Macros */
.macro-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-top: 14px;
}

.macro-cell {
  padding: 12px 0;
  border-top: 1px solid var(--rule);
}

.macro-cell:first-child {
  border-top: 0;
  padding-top: 5px;
}

.macro-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.macro-label {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.macro-value {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.macro-value .unit {
  font-size: 12px;
  margin-left: 6px;
}

.macro-value.is-over {
  color: var(--orange-dark);
}

.macro-track {
  height: 2px;
  margin-top: 8px;
  background: var(--rule);
}

.macro-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--green);
  transform: scaleX(var(--fill, 0));
  transform-origin: left;
  transition: transform 0.35s ease;
}

.macro-fill.is-over {
  background: var(--orange);
}

/* Plan */
.kv {
  margin: 6px 0 0;
}

.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-height: 34px;
  padding: 6px 0;
  border-top: 1px solid var(--rule);
}

.kv-row:first-child {
  border-top: 0;
}

.kv-row dt {
  color: var(--muted);
  font-size: 13px;
}

.kv-row dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.kv-total {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--ink);
}

.kv-total dt {
  color: var(--ink);
  font-weight: 500;
}

.kv-total dd {
  font-weight: 500;
}

/* Comidas */
.meals-list {
  display: grid;
}

.meal-group + .meal-group {
  margin-top: 20px;
}

.meal-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
}

.meal-group-kcal {
  font-family: var(--font-mono);
  font-weight: 500;
}

.meal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 16px;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px 8px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  text-align: left;
  transition: background-color 0.16s ease;
}

.meal-row:hover {
  background: var(--green-pale);
}

.meal-row-name {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.meal-row-macros {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.meal-row-kcal {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 16px;
  white-space: nowrap;
}

.meal-row-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  justify-self: end;
}

/* Historial */

.history-list {
  display: grid;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 16px;
  column-gap: 12px;
  row-gap: 6px;
  align-items: center;
  width: 100%;
  padding: 14px 8px;
  border: 0;
  border-top: 1px solid var(--rule);
  background: transparent;
  text-align: left;
  transition: background-color 0.16s ease;
}

.history-row:first-child {
  border-top: 0;
}

.history-row:hover {
  background: var(--green-pale);
}

.history-main {
  display: block;
  min-width: 0;
}

.history-date {
  display: block;
  color: var(--ink);
  font-size: 16px;
  font-weight: 500;
}

.history-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.history-kcal {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-kcal.is-over {
  color: var(--red-dark);
}

.history-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  justify-self: end;
}

.history-track {
  grid-column: 1 / -1;
  height: 2px;
  background: var(--rule);
}

.history-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--green);
  transform: scaleX(var(--fill, 0));
  transform-origin: left;
}

.history-fill.is-over {
  background: var(--red);
}

.history-summary {
  margin-top: var(--gap);
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-top: 14px;
  background: var(--border);
}

.history-stats > div {
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.stat-value {
  margin: 4px 0 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-value .unit {
  margin-left: 6px;
  font-size: 12px;
}

.day-back {
  margin-bottom: 10px;
}

.day-back .text-btn {
  font-size: 13px;
}

/* Peso */

.weight-summary {
  margin-bottom: var(--gap);
}

.weight-chart-card {
  margin-bottom: var(--gap);
}

.weight-current {
  margin: 4px 0 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.weight-current .unit {
  font-size: 14px;
}

.weight-change {
  margin: 10px 0 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.weight-last {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.weight-chart {
  position: relative;
  margin-top: 14px;
}

.weight-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}

.chart-tooltip-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-label {
  color: var(--muted);
  font-size: 11px;
}

.chart-grid {
  stroke: var(--rule);
  stroke-width: 1;
}

.chart-axis-label {
  fill: var(--muted);
  font-family: var(--font-sans);
  font-size: 11px;
}

.chart-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-area {
  fill: var(--chart-line);
  opacity: 0.1;
}

.chart-point {
  fill: var(--chart-line);
  stroke: var(--surface);
  stroke-width: 2;
}

.chart-crosshair {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.45;
}

.chart-hover-point {
  fill: var(--chart-line);
  stroke: var(--surface);
  stroke-width: 2;
}

.weight-list {
  display: grid;
}

.weight-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 16px;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 14px 8px;
  border: 0;
  border-top: 1px solid var(--rule);
  background: transparent;
  text-align: left;
  transition: background-color 0.16s ease;
}

.weight-row:first-child {
  border-top: 0;
}

.weight-row:hover {
  background: var(--green-pale);
}

.weight-date {
  color: var(--ink);
  font-size: 16px;
  font-weight: 500;
}

.weight-value {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.weight-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  justify-self: end;
}

/* Estadísticas */

.stats-kpis-card {
  margin-bottom: var(--gap);
}

.stats-chart-card {
  margin-bottom: var(--gap);
}

.stats-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-top: 14px;
  background: var(--border);
}

.stats-kpi {
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
}

.stats-kpi .stat-value {
  margin: 4px 0 0;
  font-size: 24px;
}

.stats-kpi .stat-delta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.stats-kpi .text-btn {
  margin-top: 2px;
  padding: 2px 0;
  font-size: 12px;
}

.stats-period {
  flex: none;
}

.card-head-actions {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.card-head-actions .text-btn {
  font-size: 12px;
}

.stats-bar {
  fill: var(--chart-line);
}

.stats-target {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

@media (min-width: 900px) {
  .stats-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .stats-chart-card .card-head {
    flex-wrap: wrap;
  }

  .stats-chart-card .card-head-actions {
    justify-content: flex-start;
  }
}

.empty-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 96px;
  margin-top: 16px;
  padding: 20px;
  border: 1px dashed var(--control);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.empty-box p {
  margin: 0;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--control);
  border-radius: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.pill-positive {
  border-color: var(--green);
  background: var(--green-pale);
  color: var(--green-dark);
}

/* ── Perfil ────────────────────────────────────────────────────────────── */

.settings-row {
  display: grid;
  gap: 16px;
  padding: 28px 0;
  border-top: 1px solid var(--border);
}

.settings-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.settings-label h2 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.settings-label p {
  margin: 6px 0 0;
  max-width: 42ch;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.settings-panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.save-status {
  margin: 0 auto 0 0;
  color: var(--green-dark);
  font-size: 12px;
}

.save-status.is-error {
  color: var(--red-dark);
}

.macro-mode {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.macro-percent-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.macro-percent-grid .field {
  margin: 0;
}

#macroSum {
  margin-top: 12px;
}

#macroSum.is-error {
  color: var(--red-dark);
}

#macroGramsPreview {
  margin-top: 6px;
}

#formPassword .field-pair {
  margin-bottom: 12px;
}

#formPassword .field-pair .field {
  margin-bottom: 0;
}

.plan-preview .preview-figure {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.settings-panel > .confirm-line {
  justify-content: flex-end;
  margin-top: 10px;
}

/* ── Diálogo de comida ─────────────────────────────────────────────────── */

.dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(92dvh, 900px);
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.dialog-body {
  display: flex;
  flex-direction: column;
  max-height: min(92dvh, 900px);
  padding: 0;
  overflow: hidden;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 0;
}

.dialog-head h2 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.dialog-head .icon-btn {
  margin-right: -8px;
}

.dialog-scroll {
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 20px 0;
  overflow-y: auto;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.delete-zone {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-right: auto;
}

.confirm-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.icon-btn:hover {
  background: var(--rule);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.mode-tabs {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.mode-tab {
  height: 40px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
}

.mode-tab:hover {
  color: var(--ink);
}

.mode-tab.is-active {
  border-bottom-color: var(--ink);
  color: var(--ink);
  font-weight: 500;
}

.mode-panel {
  display: grid;
  gap: 12px;
}

.mode-panel .btn {
  justify-self: start;
}

.photo-drop {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 16px;
  border: 1px dashed var(--control);
  border-radius: 0;
  background: var(--surface);
  text-align: left;
  transition: background-color 0.16s ease;
}

.photo-drop:hover {
  background: var(--green-pale);
}

.photo-title {
  font-size: 14px;
  font-weight: 500;
}

.photo-hint {
  color: var(--muted);
  font-size: 12px;
}

.photo-preview {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.photo-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
}

.ai-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.ai-status.is-error {
  color: var(--red-dark);
}

.ai-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--green-track);
  background: var(--green-pale);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.manual-hint {
  margin: 0 0 18px;
  padding: 12px;
  border: 1px solid var(--orange-line);
  background: var(--orange-pale);
}

.manual-hint p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.macro-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.macro-inputs .field {
  margin: 0;
}

.field-full {
  grid-column: 1 / -1;
}

/* ── Ajustes del tema oscuro ───────────────────────────────────────────── */

:root[data-theme="dark"] .btn-primary:active {
  color: #111111;
}

:root[data-theme="dark"] .btn-primary:disabled {
  background: #26302a;
  border-color: #26302a;
  color: #9aa69f;
}

:root[data-theme="dark"] .seg input:checked + span {
  background: var(--ink);
  color: var(--ground);
}

:root[data-theme="dark"] .btn-danger {
  background: #7f1d1d;
  border-color: #7f1d1d;
  color: #ffffff;
}

:root[data-theme="dark"] .btn-danger:hover {
  background: #991b1b;
  border-color: #991b1b;
}

:root[data-theme="dark"] .text-btn.danger:hover {
  color: #fecaca;
}

:root[data-theme="dark"] .form-error {
  background: #2a1416;
  border-color: #7f1d1d;
  color: #fca5a5;
}

:root[data-theme="dark"] input::placeholder {
  color: #8b9690;
}

:root[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%23a3aea8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] .dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

/* ── Escritorio ────────────────────────────────────────────────────────── */

@media (min-width: 640px) {
  .gate-points {
    display: grid;
  }

  .gate-foot {
    display: block;
  }

  .day-preview {
    display: block;
  }

  .auth-card {
    padding: 28px;
  }
}

@media (min-width: 900px) {
  .gate {
    align-items: center;
    padding: 32px;
  }

  .gate-inner {
    grid-template-columns: minmax(0, 1fr) 460px;
    gap: 64px;
    align-items: center;
    min-height: calc(100dvh - 64px);
  }

  .gate-story h1 {
    font-size: 32px;
  }

  .gate-lede {
    font-size: 16px;
  }

  .topbar {
    height: 64px;
  }

  .topbar-inner {
    gap: 40px;
    padding: 0 24px;
  }

  .topbar .brand {
    font-size: 16px;
  }

  .topbar .mark {
    width: 24px;
    height: 24px;
  }

  .topnav {
    display: flex;
  }

  .theme-btn {
    margin-left: 0;
  }

  .topbar-user {
    display: flex;
  }

  .bottomnav {
    display: none;
  }

  .canvas {
    padding: 40px 24px 64px;
  }

  .title-row {
    margin-bottom: 24px;
  }

  .title-row h1 {
    font-size: 32px;
  }

  #btnAddMeal {
    display: inline-flex;
  }

  #btnAddDayMeal {
    display: inline-flex;
  }

  .budget-band {
    padding: 28px;
  }

  .budget-figure {
    font-size: 44px;
  }

  .grid {
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  }

  .macro-card {
    grid-column: 1;
    grid-row: 1;
  }

  .plan-card {
    grid-column: 2;
    grid-row: 1;
  }

  .meals-card {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .settings-row {
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 40px;
    padding: 32px 0;
  }

  .settings-label h2 {
    margin-top: 4px;
  }

  .btn {
    min-height: 40px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  select {
    height: 40px;
    font-size: 16px;
  }

  .seg span {
    height: 38px;
  }
}

@media (min-width: 1120px) {
  .settings-row {
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 48px;
  }
}

@media (max-width: 480px) {
  .dialog {
    width: calc(100vw - 16px);
  }

  .dialog-head {
    padding: 16px 16px 0;
  }

  .dialog-scroll {
    padding: 14px 16px 0;
  }

  .dialog-actions {
    padding: 14px 16px 16px;
  }

  .dialog-actions .btn {
    flex: 1;
  }

  .delete-zone {
    order: -1;
    width: 100%;
    margin-right: 0;
  }
}

@media (max-width: 359px) {
  .field-pair {
    grid-template-columns: 1fr;
  }

  .seg-four span {
    font-size: 11px;
  }

  .budget-figure {
    font-size: 38px;
  }
}

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