/* =========================================================================
   Serie · base.css — tokens, layout, navegación y componentes compartidos.
   Todo color sale de tokens. Tema: claro por defecto, oscuro con
   prefers-color-scheme (si data-theme no es "light") o data-theme="dark".
   ========================================================================= */

:root {
  color-scheme: light;
  --bg: #F4F5F1; --surface: #FFFFFF; --surface2: #EEF0EA; --line: #DFE3DC; --line-strong: #C9D0C5;
  --muted: #5C665F; --text: #18201C;
  --accent: #356F1F; --accent2: #5C8A3C; --accent-ink: #FFFFFF; --accent-soft: #E4EFD9; --accent-line: #A9C59A;
  --amber: #8F5C0E; --warn-soft: #FBF0DF; --warn-line: #E6CFA6;
  --danger: #B3261E; --danger-soft: #FCEDEA; --danger-line: #F0C4BD; --error: #B3261E;
  --input: #FAFBF8; --chip: #EEF2EA; --chip-text: #2A3A2C;
  --row: #F7F8F5; --row-done: #E8F2DE; --row-done-line: #A9C59A;
  --tint-push: #EAF2E2; --tint-pull: #E2EFEE; --tint-legs: #F3EEDF;
  --nav-bg: rgba(244, 245, 241, .94); --overlay: rgba(24, 32, 28, .42); --shadow: 0 10px 30px rgba(24, 32, 28, .12);
  /* Macros (módulo de comida) */
  --p: #C23B66; --c: #B97708; --f: #1B8585; --warn: #B4441F;

  --radius: 20px; --radius-sm: 12px;
  --tabbar-h: 64px; --sidebar-w: 232px; --content-max: 1100px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

/* Tokens del tema oscuro (se repiten para auto y para forzado). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101612; --surface: #19211b; --surface2: #202b23; --line: #2d3a30; --line-strong: #48563f;
    --muted: #9ba99b; --text: #f3f5ed;
    --accent: #d3f58b; --accent2: #9cbb6e; --accent-ink: #18240f; --accent-soft: #273322; --accent-line: #5b6c48;
    --amber: #edc48a; --warn-soft: #30291f; --warn-line: #584631;
    --danger: #f1a39a; --danger-soft: #2f211d; --danger-line: #573b35; --error: #ffc3b6;
    --input: #111813; --chip: #263229; --chip-text: #dbe8d3;
    --row: #202a21; --row-done: #263421; --row-done-line: #536d38;
    --tint-push: #263121; --tint-pull: #202e2d; --tint-legs: #302e23;
    --nav-bg: rgba(16, 22, 18, .95); --overlay: rgba(5, 10, 7, .79); --shadow: 0 10px 40px rgba(0, 0, 0, .4);
    --p: #EE7A9E; --c: #E9B04E; --f: #55C2C0; --warn: #F08A62;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101612; --surface: #19211b; --surface2: #202b23; --line: #2d3a30; --line-strong: #48563f;
  --muted: #9ba99b; --text: #f3f5ed;
  --accent: #d3f58b; --accent2: #9cbb6e; --accent-ink: #18240f; --accent-soft: #273322; --accent-line: #5b6c48;
  --amber: #edc48a; --warn-soft: #30291f; --warn-line: #584631;
  --danger: #f1a39a; --danger-soft: #2f211d; --danger-line: #573b35; --error: #ffc3b6;
  --input: #111813; --chip: #263229; --chip-text: #dbe8d3;
  --row: #202a21; --row-done: #263421; --row-done-line: #536d38;
  --tint-push: #263121; --tint-pull: #202e2d; --tint-legs: #302e23;
  --nav-bg: rgba(16, 22, 18, .95); --overlay: rgba(5, 10, 7, .79); --shadow: 0 10px 40px rgba(0, 0, 0, .4);
  --p: #EE7A9E; --c: #E9B04E; --f: #55C2C0; --warn: #F08A62;
}

/* ---------- Reset y base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 32px; line-height: 1.15; letter-spacing: -1px; font-weight: 650; }
h2 { font-size: 20px; line-height: 1.3; letter-spacing: -.3px; font-weight: 600; }
h3 { font-size: 16px; line-height: 1.4; font-weight: 600; }
small { font-size: 12px; }
a { color: var(--accent); }
svg { width: 20px; height: 20px; flex-shrink: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font-size: 16px; /* evita el zoom de iOS */
  color: var(--text); background: var(--input); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 12px; min-height: 44px; min-width: 0; max-width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input[type=checkbox] { accent-color: var(--accent); width: 22px; height: 22px; min-height: 22px; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Cifras: ancho fijo */
.num, input[inputmode=decimal], input[inputmode=numeric], input[type=number] { font-variant-numeric: tabular-nums; }

/* ---------- Utilidades ---------- */
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.accent-text { color: var(--accent); }
.warn-text { color: var(--amber); }
.error-text { color: var(--error); font-size: 14px; min-height: 1em; }
.eyebrow { font-size: 11px; font-weight: 650; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.note-block { padding: 12px 14px; border-left: 3px solid var(--accent2); background: var(--surface2); border-radius: 0 10px 10px 0; color: var(--muted); font-size: 14px; line-height: 1.6; margin: 16px 0; }
.callout { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; line-height: 1.55; }
.callout.warn { background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--amber); }
.checkfield { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.steps { margin: 8px 0; padding-left: 22px; line-height: 1.7; color: var(--muted); }
.inline-form { display: flex; gap: 10px; align-items: flex-end; }
.inline-form .field { margin: 0; }

/* ---------- Layout: barra superior (móvil), sidebar (escritorio), tab bar (móvil) ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-size: 28px; font-weight: 780; letter-spacing: -1.5px; }
.brand-dot { color: var(--accent); }
.mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); }
.mark svg { width: 22px; height: 22px; }
.topbar { display: none; }
.local-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
button.local-badge { min-height: 32px; padding: 0 4px; border-radius: 999px; }
.local-badge[data-state="syncing"] .dot { background: var(--amber); }
.local-badge[data-state="offline"] .dot { background: var(--muted); }
.local-badge[data-state="error"] { color: var(--danger); }
.local-badge[data-state="error"] .dot { background: var(--danger); }
.sync-code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 17px; letter-spacing: .06em; word-break: break-all; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); border: 1px solid var(--line); user-select: all; }
.callout.danger { background: var(--danger-soft); border: 1px solid var(--danger-line); color: var(--danger); }

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); max-width: calc(var(--sidebar-w) + var(--content-max) + 80px); margin: 0 auto; min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; padding: 28px 18px 24px 24px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 22px; }
.nav-items { display: flex; flex-direction: column; gap: 4px; }
.navbtn { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 14px; border-radius: var(--radius-sm); color: var(--muted); font-size: 15px; text-align: left; }
.navbtn:hover { background: var(--surface2); color: var(--text); }
.navbtn[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-note { margin-top: auto; font-size: 12px; color: var(--muted); line-height: 1.6; }
#view { padding: 36px 40px 64px; min-width: 0; width: 100%; max-width: calc(var(--content-max) + 80px); outline: none; }
.tabbar { display: none; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.pagehead h1 { margin-top: 6px; }
.pagehead p { color: var(--muted); font-size: 14px; margin-top: 6px; }
.back { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--muted); font-size: 14px; }

.boot { min-height: 70dvh; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; font-size: 56px; font-weight: 780; letter-spacing: -3px; }
.boot span { color: var(--accent); }
.boot small { width: 100%; text-align: center; font-size: 14px; letter-spacing: 0; font-weight: 400; color: var(--muted); margin-top: 12px; }
.error-card { max-width: 620px; margin: 40px auto; display: flex; flex-direction: column; gap: 14px; }

/* =========================================================================
   COMPONENTES COMPARTIDOS (reutilizables por cualquier módulo)
   .card            Tarjeta: superficie con borde y radio. h2/p dentro con espaciado.
   .btn             Botón base (≥44px). Variantes: .primary (acento), .secondary
                    (superficie), .ghost (solo texto acento), .danger. Tamaños: .small,
                    .full (ancho completo), .icon-only (cuadrado).
   .icon-btn        Botón de icono 44×44 sin fondo.
   .pill            Etiqueta de estado no interactiva (.warn, .ok).
   .chip            Etiqueta redondeada; si es <button>, seleccionable con aria-pressed.
   .field           <label class="field"><span>Etiqueta</span><input></label>.
   .seg             Control segmentado: botones hijos con aria-selected="true|false".
   .sheet           <dialog> modal: bottom-sheet en móvil, centrado en escritorio. Partes:
                    .sheet-head, .sheet-body (desplazable), .sheet-foot. Clase extra .small.
   .list / .list-row Filas de lista (≥48px). .list-row.as-button para filas pulsables.
   .progress        Barra: <div class="progress"><i style="width:40%"></i></div>.
                    Color con --bar (p. ej. style="--bar:var(--p)").
   .empty           Estado vacío centrado (.empty-icon, h3, p).
   .fab             Botón flotante principal (abajo a la derecha, sobre la tab bar).
   ========================================================================= */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card > h2 { margin-top: 2px; }
.card > p { line-height: 1.6; font-size: 15px; }
.card > .btn { align-self: flex-start; }
.card > .stack > .btn, .card .btn.full { align-self: stretch; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 550; line-height: 1.2; text-align: center; border: 1px solid transparent; transition: background-color .15s, border-color .15s; }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--surface2); border-color: var(--line); color: var(--text); }
.btn.secondary:hover { border-color: var(--line-strong); }
.btn.ghost { color: var(--accent); padding-left: 6px; padding-right: 6px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.btn.small { min-height: 44px; padding: 8px 12px; font-size: 14px; }
.btn.full { width: 100%; }
.btn.icon-only { padding: 0; width: 44px; flex-shrink: 0; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--muted); flex-shrink: 0; }
.icon-btn:hover { background: var(--surface2); color: var(--text); }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; color: var(--muted); white-space: nowrap; }
.pill.warn { color: var(--amber); background: var(--warn-soft); border-color: var(--warn-line); }
.pill.ok { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 10px; background: var(--chip); color: var(--chip-text); font-size: 14px; white-space: nowrap; }
button.chip { min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
button.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span:first-child { font-size: 13px; color: var(--muted); letter-spacing: .01em; }
.field input, .field select, .field textarea { width: 100%; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--surface2); border: 1px solid var(--line); border-radius: 14px; max-width: 100%; }
.seg > button { flex: 1; min-height: 44px; padding: 0 12px; border-radius: 10px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.seg > button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

dialog.sheet { padding: 0; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 24px; width: min(640px, calc(100% - 32px)); max-height: 90dvh; overscroll-behavior: contain; box-shadow: var(--shadow); }
dialog.sheet.small { width: min(440px, calc(100% - 32px)); }
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: var(--overlay); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 16px 14px 22px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin-top: 4px; }
.sheet-body { padding: 20px 22px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-body > p { margin-bottom: 12px; line-height: 1.6; }
.sheet-foot { display: flex; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
.sheet-foot .btn.icon-only { flex: 0 0 44px; }
.confirm-body p { font-size: 17px; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row > div { display: flex; flex-direction: column; gap: 3px; }
.list-row.as-button { width: 100%; text-align: left; border-bottom: 0; }
.list-row.as-button:hover { color: var(--accent); }

.progress { width: 100%; height: 6px; background: var(--surface2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--bar, var(--accent)); border-radius: inherit; transition: width .25s; }

.empty { padding: 36px 20px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty h3 { color: var(--text); font-size: 18px; font-weight: 550; }
.empty p { max-width: 340px; line-height: 1.6; }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 16px; }

.fab { position: fixed; right: max(24px, env(safe-area-inset-right)); bottom: 28px; z-index: 20; width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.fab svg { width: 26px; height: 26px; }

/* ---------- Avisos ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 28px; z-index: 60; display: none; align-items: center; gap: 18px; max-width: calc(100% - 32px); width: max-content; padding: 12px 18px; border-radius: 14px; background: var(--text); color: var(--bg); font-size: 15px; box-shadow: var(--shadow); }
.toast.show { display: flex; }
.toast-undo { color: inherit; text-decoration: underline; font-weight: 650; min-height: 44px; padding: 0 4px; }
.update-banner { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 70; display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--accent-line); box-shadow: var(--shadow); font-size: 15px; width: max-content; max-width: calc(100% - 32px); }

/* ---------- Móvil (≤760px): barra superior compacta + tab bar inferior ---------- */
@media (max-width: 760px) {
  .topbar { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 15; padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: var(--nav-bg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
  .topbar .brand { font-size: 24px; }
  .topbar .mark { width: 28px; height: 28px; border-radius: 8px; }
  .topbar .mark svg { width: 18px; height: 18px; }
  .shell { display: block; min-height: 0; }
  .sidebar { display: none; }
  #view { padding: 20px max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px) max(16px, env(safe-area-inset-left)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 4px max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left)); background: var(--nav-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
  .tabbtn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; font-size: 11px; color: var(--muted); position: relative; }
  .tabbtn svg { width: 23px; height: 23px; }
  .tabbtn[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .tabbtn[aria-current="page"]::before { content: ''; position: absolute; top: -4px; width: 22px; height: 3px; border-radius: 3px; background: var(--accent); }
  h1 { font-size: 28px; }
  .pagehead { margin-bottom: 18px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 18px 16px; }
  .fab { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
  .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
  dialog.sheet, dialog.sheet.small { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 92dvh; border-bottom: 0; }
  dialog.sheet[open] { animation: sheet-up .22s ease-out; }
  .sheet-head { padding: 14px 10px 12px 18px; }
  .sheet-body { padding: 18px; }
  .sheet-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

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