:root {
  --bg: #faf7f2; --card: #ffffff; --ink: #1f1a17; --muted: #7a6f66; --line: #ece5dc;
  --accent: #d53633; --accent-ink: #ffffff; --accent-soft: #fde8e7; --sun: #f6e14b;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --info: #1d4ed8; --info-soft: #dbeafe; --bad: #b91c1c; --bad-soft: #fee2e2;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --tabs-h: 64px;
}
/* Theme: light by default. Más → Tema lets each phone pick Claro / Oscuro / Automático */
:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171412; --card: #221e1b; --ink: #f3ede7; --muted: #a89c91; --line: #342e29;
  --accent: #ef5b57; --accent-ink: #1a0605; --accent-soft: #3a1817; --sun: #f6e14b;
  --ok: #4ade80; --ok-soft: #173222; --warn: #fbbf24; --warn-soft: #3a2e12;
  --info: #93c5fd; --info-soft: #1b2a45; --bad: #f87171; --bad-soft: #3b1a1a;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #171412; --card: #221e1b; --ink: #f3ede7; --muted: #a89c91; --line: #342e29;
    --accent: #ef5b57; --accent-ink: #1a0605; --accent-soft: #3a1817; --sun: #f6e14b;
    --ok: #4ade80; --ok-soft: #173222; --warn: #fbbf24; --warn-soft: #3a2e12;
    --info: #93c5fd; --info-soft: #1b2a45; --bad: #f87171; --bad-soft: #3b1a1a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

header#topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 18px; }
.brand img { width: 38px; height: 38px; border-radius: 10px; }
header#topbar { border-bottom: 3px solid var(--sun); }
.top-actions { display: flex; gap: 8px; }

main { max-width: 820px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 40px 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card.tap { cursor: pointer; }
.list > .card { margin-bottom: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; min-height: 44px; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.b-pending { background: var(--warn-soft); color: var(--warn); }
.b-preparing { background: var(--info-soft); color: var(--info); }
.b-ready { background: var(--accent-soft); color: var(--accent); }
.b-delivered { background: var(--ok-soft); color: var(--ok); }
.b-cancelled { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; }
.b-paid { background: var(--ok-soft); color: var(--ok); }
.b-account { background: var(--info-soft); color: var(--info); }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; min-height: 44px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--card); padding: 10px 6px; font-weight: 600; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
@media (max-width: 380px) { .stat .v { font-size: 17px; } }

/* tally */
.tally { display: flex; flex-wrap: wrap; gap: 8px; }
.tally span { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 6px 10px; font-weight: 700; font-size: 14px; }

/* orders */
.order .head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.order .cname { font-weight: 700; font-size: 17px; }
.order ul { margin: 8px 0; padding: 0; list-style: none; }
.order li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.order li:last-child { border-bottom: 0; }
.order .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.order.cancelled { opacity: .6; }

/* menu grid */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
.dish { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.dish .ph { aspect-ratio: 4 / 3; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 34px; }
.dish .ph img { width: 100%; height: 100%; object-fit: cover; }
.dish .body { padding: 10px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.dish .nm { font-weight: 700; line-height: 1.2; }
.dish .ds { font-size: 12px; color: var(--muted); }
.dish .pr { font-weight: 800; color: var(--accent); margin-top: auto; }
.dish.off { opacity: .5; }
.qty { display: flex; align-items: center; justify-content: space-between; padding: 0 10px 10px; gap: 6px; }
.qty button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 20px; font-weight: 700; cursor: pointer; }
.qty button.plus { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.qty .n { font-weight: 800; font-size: 18px; min-width: 24px; text-align: center; }
.dish.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.cart-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); z-index: 15; padding: 10px 16px;
  background: var(--bg); border-top: 1px solid var(--line); }
.cart-bar .inner { max-width: 820px; margin: 0 auto; }
.has-cart main { padding-bottom: 90px; }

.thumb { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; background: var(--accent-soft); flex: none; display: flex; align-items: center; justify-content: center; font-size: 22px; }

/* tables */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 700; }
table.t td.r, table.t th.r { text-align: right; }
.scroll-x { overflow-x: auto; }

/* bottom tabs */
nav#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--card); border-top: 1px solid var(--line);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
nav#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none;
  color: var(--muted); font-size: 11px; font-weight: 600; }
nav#tabs a .ic { font-size: 22px; line-height: 1; }
nav#tabs a.on { color: var(--accent); }

/* modal sheet */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
#modal .sheet { background: var(--bg); width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { #modal { align-items: center; } #modal .sheet { border-radius: 20px; } }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 24px); z-index: 60; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

.login-wrap { max-width: 380px; margin: 8vh auto 0; }
.login-wrap .logo { width: 220px; height: 220px; margin: 0 auto 4px; object-fit: contain; }
:root[data-theme="dark"] .login-wrap .logo { background: #fff; border-radius: 50%; padding: 10px; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .login-wrap .logo { background: #fff; border-radius: 50%; padding: 10px; } }
.photo-edit { display: flex; gap: 12px; align-items: center; }
.photo-edit .prev { width: 96px; height: 72px; border-radius: 10px; background: var(--accent-soft); overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 28px; flex: none; }
.photo-edit .prev img { width: 100%; height: 100%; object-fit: cover; }
.cat-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
.big-bal { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.owe { color: var(--bad); }
.clear { color: var(--ok); }

@media print {
  header#topbar, nav#tabs, .no-print, .cart-bar { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; }
}
a.chip { text-decoration: none; color: inherit; }
a.chip.on { color: var(--bg); }

/* new-order banner */
#banner { position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translate(-50%, -140%); z-index: 70;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); transition: transform .3s; max-width: 92vw; cursor: pointer; }
#banner.show { transform: translate(-50%, 0); }

/* kitchen */
.tally.big span { font-size: 18px; padding: 8px 12px; }
.korder .cname { font-weight: 800; font-size: 19px; }
.korder.preparing { border-left: 5px solid var(--info); }
.korder.pending { border-left: 5px solid var(--warn); }
.korder.ready { border-left: 5px solid var(--accent); }
.kitems { list-style: none; padding: 0; margin: 10px 0 4px; }
.kitems li { font-size: 19px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.kitems li:last-child { border-bottom: 0; }
.knote { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 10px; font-weight: 700; margin-top: 6px; }
a.btn { color: inherit; }

/* sizes / portions */
.qrow { border-top: 1px dashed var(--line); padding-top: 8px; }
.dish .body + .qrow { border-top: 0; }
.qrow .ol { display: flex; justify-content: space-between; gap: 6px; padding: 0 10px 6px; font-size: 14px; }
.qrow .ol .pr { color: var(--accent); font-weight: 800; }
.qty input.n { width: 52px; text-align: center; font-weight: 800; font-size: 18px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); min-height: 40px; padding: 0; -moz-appearance: textfield; }
.qty input.n::-webkit-outer-spin-button, .qty input.n::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.opts-card { background: var(--bg); box-shadow: none; }
.optrow { display: grid; grid-template-columns: 1fr 86px 58px 40px; gap: 6px; margin-bottom: 8px; align-items: center; }
.optrow input { min-height: 40px; padding: 8px; }
.optrow.head { margin-bottom: 4px; }
/* delivery time */
.dtime { display: inline-block; font-weight: 800; font-size: 14px; background: var(--info-soft); color: var(--info); border-radius: 8px; padding: 2px 8px; margin: 3px 0; }
.dtime.soon { background: var(--warn-soft); color: var(--warn); }
.dtime.late { background: var(--bad); color: #fff; }
.korder .dtime { font-size: 16px; }

/* iPhone / Safari: native date & select controls ignore sizing unless reset */
input[type=date], input[type=time], select {
  -webkit-appearance: none; appearance: none; display: block; line-height: 1.25; text-align: left;
}
input[type=date]::-webkit-date-and-time-value { text-align: left; margin: 0; }
#dpick::-webkit-date-and-time-value { text-align: center; }
select {
  padding-right: 36px; text-overflow: ellipsis;
  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 1l5 5 5-5' fill='none' stroke='%238a7f76' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.danger-zone { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }

/* opening hours */
.hours { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 14px; margin-bottom: 12px; background: var(--ok-soft); color: var(--ok); }
.hours.closed { background: var(--bad-soft); color: var(--bad); }
.hours .dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; flex: none; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 20%, transparent); }
.hours .btn { color: var(--ink); flex: none; }
.login-wrap .hours { text-align: left; }
.wrow { padding: 10px 0; border-bottom: 1px solid var(--line); }
.wrow.today b { color: var(--accent); }
.drow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; min-height: 56px; }
.drow select { width: auto; min-width: 116px; min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
/* dishes of the day */
.daychips { display: flex; gap: 6px; flex-wrap: wrap; }
.dchip input { position: absolute; opacity: 0; pointer-events: none; }
.dchip span { display: inline-block; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; font-weight: 700; font-size: 14px; cursor: pointer; background: var(--card); }
.dchip input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.dchip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.tagday { font-size: 11px; font-weight: 800; color: var(--warn); }
.specials .dish { border-color: var(--sun); box-shadow: 0 0 0 2px var(--sun); }
.specials .dish.sel { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
