:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d211f;
  --muted: #6a706b;
  --line: #e2ded4;
  --accent: #1f7a5a;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe6;
  --warn: #a8640c;
  --warn-soft: #fbecd3;
  --danger: #b4342b;
  --danger-soft: #f8e0dd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1e2220;
    --surface-2: #272c29;
    --text: #e9ece9;
    --muted: #9aa29c;
    --line: #313733;
    --accent: #4fbf8f;
    --accent-ink: #0d1f17;
    --accent-soft: #1f3a2e;
    --warn: #f0b45a;
    --warn-soft: #3a2d17;
    --danger: #f08a80;
    --danger-soft: #3d201d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button, a, .chip, .tabs a { touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
a { color: inherit; text-decoration: none; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Estructura ---------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.topbar h1 { flex: 1; margin: 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; display: grid; place-items: center; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.view { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 4px 16px calc(96px + var(--safe-bottom)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
  position: relative;
}
.tabs a.on { color: var(--accent); }
.tabs .badge { position: absolute; top: 2px; left: calc(50% + 6px); }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.section-title:first-child { margin-top: 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); min-height: 56px; }
.list > li:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; }
.row-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); margin-top: 1px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.badge { display: inline-flex; align-items: center; min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px; font-size: 11px; font-weight: 700; background: var(--danger); color: #fff; justify-content: center; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.ok { background: var(--accent-soft); color: var(--accent); }

.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); display: grid; place-items: center; }
.stepper button:active { transform: scale(.94); }
.stepper .qty { min-width: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.quick button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); text-align: left; font-weight: 600;
}
.quick button .i { color: var(--accent); width: 26px; height: 26px; }
.quick button small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 12px; text-align: left; border: 1px solid var(--line); }
.stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.warn b { color: var(--warn); }
.stat.danger b { color: var(--danger); }

/* ---------- Formularios ---------- */
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 16px; /* evita el zoom en iPhone */
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; font-weight: 600; }
.switch input { width: 48px; height: 28px; appearance: none; -webkit-appearance: none; border-radius: 14px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }

.search { position: relative; margin: 6px 0 10px; }
.search .i { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.search input { padding-left: 42px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; color: var(--muted); }
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }

.check {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); background: transparent; flex: none; position: relative;
  display: grid; place-items: center; color: var(--accent-ink);
}
.check:active { background: var(--accent); border-color: var(--accent); }

.addbar { display: flex; gap: 8px; margin: 6px 0 4px; }
.addbar .input { flex: 1; }
.addbar .btn { flex: none; width: 46px; padding: 0; }

.fab {
  position: fixed; right: 16px; bottom: calc(80px + var(--safe-bottom)); z-index: 4;
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
@media (min-width: 672px) { .fab { right: calc(50% - 304px); } }

/* ---------- Ficha de producto ---------- */
.hero { padding: 18px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.hero .big { font-size: 40px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hero .unit { font-size: 16px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; font-weight: 600; }
.actions button .i { color: var(--accent); }
.hist-undone { text-decoration: line-through; opacity: .55; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px; }

/* ---------- Hoja inferior ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .15s; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  animation: up .2s ease-out;
}
.sheet h2 { margin: 6px 0 4px; font-size: 20px; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 8px; }
.picker { max-height: 50vh; overflow-y: auto; margin-top: 8px; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-bottom)); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; width: calc(100% - 32px); max-width: 480px;
  padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast button { border: 0; background: none; color: var(--accent-soft); font-weight: 700; padding: 0; text-transform: uppercase; font-size: 13px; letter-spacing: .03em; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--accent-ink); } }

/* ---------- Acceso ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-logo { width: 64px; height: 64px; margin-bottom: 14px; }
.auth h1 { margin: 0 0 4px; font-size: 26px; }
.auth p { color: var(--muted); margin: 0 0 8px; }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: 200px; margin: 12px auto; display: block; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; text-align: center; color: var(--muted); }

/* ---------- Utilidades ---------- */
.mt { margin-top: 14px; }
.mt-lg { margin-top: 24px; }
.pad { padding: 14px; }
.note { padding: 12px 14px; white-space: pre-wrap; }

/* ---------- Ticket ---------- */
.quick button.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; }
.ticket-list > li.ticket-line { display: block; padding: 12px 14px; margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ticket-line.off { opacity: .45; }
.ticket-line.off .field, .ticket-line.off .new-box { display: none; }
.ticket-head { display: flex; gap: 12px; align-items: flex-start; }
.ticket-head input[type=checkbox] { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.new-box { padding-left: 10px; border-left: 3px solid var(--accent-soft); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.ocr-text { background: var(--surface-2); padding: 10px; border-radius: 10px; overflow-x: auto; }
.sticky-bottom { position: sticky; bottom: calc(76px + var(--safe-bottom)); padding-top: 10px; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- iPhone ---------- */
/* Título grande en las pestañas principales, como en las apps de iOS. */
.topbar h1.large { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
/* La casilla de "comprado" se ve de 30 px pero se puede tocar en 44 px. */
.check::after { content: ""; position: absolute; inset: -9px; }
.chip { min-height: 38px; }
.tabs a { font-size: 11px; padding: 4px 0; }
.tabs .i { width: 26px; height: 26px; }

/* ---------- Escáner ---------- */
.scan-box { position: relative; margin-top: 8px; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 12%; right: 12%; top: 32%; bottom: 32%; border: 2px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }

/* ---------- Ficha: ritmo y precios ---------- */
.facts > div { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.facts > div + div { margin-top: 8px; }
.facts .i { color: var(--accent); width: 20px; height: 20px; }

/* ---------- Gasto ---------- */
.spend-link { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.spend-link span { flex: 1; color: var(--muted); font-weight: 600; }
.spend-link b { font-size: 20px; font-variant-numeric: tabular-nums; }
.spend-link .i { color: var(--accent); }
.big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.month-cols { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; margin-top: 14px; }
.month-col { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 4px 0; border-radius: 10px; min-height: 44px; }
.month-col.on { color: var(--text); font-weight: 700; background: var(--surface-2); }
.month-bar-wrap { height: 72px; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.month-bar { width: 14px; background: color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 4px 4px 0 0; min-height: 0; }
.month-col.on .month-bar { background: var(--accent); }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li + li { margin-top: 12px; }
.bar-label { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.bar-label b { font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; margin-top: 4px; border-radius: 4px; background: var(--surface-2); }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }

/* ---------- Tareas ---------- */
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekdays .chip { padding: 0; min-height: 44px; font-size: 15px; }

/* Con botón flotante, el aviso sale por encima para no taparlo. */
body:has(.fab) .toast { bottom: calc(152px + var(--safe-bottom)); }

/* ---------- Comidas ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 10px; font-weight: 600; }
.icon-btn.flip .i { transform: scaleX(-1); }
.section-title.today { color: var(--accent); }
.meal-empty .hint { margin-top: 2px; color: var(--accent); font-weight: 600; }
.meal-done .row-name { text-decoration: line-through; opacity: .6; }
.actions.three { grid-template-columns: repeat(3, 1fr); }
.hero .stepper { margin-top: 6px; }
.ing-row { align-items: flex-start; }
.ing-fields { flex: 1; min-width: 0; display: grid; gap: 8px; }
.ing-fields .grid2 { gap: 8px; }
.name-serv { grid-template-columns: 2fr 1fr; }
textarea.input.tall { min-height: 160px; }

/* Pedido online */
.order-box { margin-bottom: 8px; }
.order-box .bar-track { margin: 6px 0 4px; }
