:root {
  --bg: #f4f5f7; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-text: #fff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --cash: #16a34a; --bizum: #0ea5e9; --card-pay: #7c3aed;
  --radius: 14px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --card: #1a1d24; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f3a; --shadow: 0 1px 3px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 14px; background: var(--card); color: var(--text); box-shadow: var(--shadow); }
button:active { transform: scale(.97); }
button.primary { background: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; box-shadow: none; color: var(--accent); }
button.danger { background: var(--bad); color: #fff; }
button:disabled { opacity: .5; pointer-events: none; }
input, select, textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 40px 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin: 10px 0; }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 18px; } h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* Cabecera */
.top { position: sticky; top: 0; z-index: 5; background: var(--accent); color: #fff; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top button { background: rgba(255,255,255,.18); color: #fff; box-shadow: none; padding: 8px 12px; }
.top .stat { font-size: 13px; opacity: .95; text-align: right; line-height: 1.2; }
.top .stat b { font-size: 16px; display: block; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--text); }
.badge.off { background: var(--warn); color: #fff; }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; overflow-x: auto; background: var(--bg); position: sticky; top: 52px; z-index: 4; }
.tabs button { white-space: nowrap; border-radius: 10px 10px 0 0; box-shadow: none; background: transparent; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); background: var(--card); }
main { padding: 10px 12px 30px; max-width: 1100px; margin: 0 auto; }

/* Login */
.login { max-width: 360px; margin: 8vh auto; padding: 0 16px; }
.pin { font-size: 34px; letter-spacing: 12px; text-align: center; height: 56px; margin: 12px 0; font-variant-numeric: tabular-nums; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { font-size: 24px; padding: 16px 0; }

/* Rejilla productos */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.prod { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; position: relative; user-select: none; -webkit-user-select: none; }
.prod .img { aspect-ratio: 3/2; background: var(--line) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 30px; }
.prod .body { padding: 8px 10px; }
.prod .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prod .meta { display: flex; justify-content: space-between; font-size: 14px; margin-top: 2px; }
.prod .qty { font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--line); }
.prod .qty.low { background: var(--warn); color: #fff; } .prod .qty.zero { background: var(--bad); color: #fff; }
.prod .more { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.45); color: #fff; border-radius: 8px; padding: 2px 8px; font-size: 14px; box-shadow: none; }
.prod.inactive { opacity: .5; }

/* Modal */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
#modal[hidden] { display: none; }
.sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .18s ease-out; }
@media (min-width: 640px) { #modal { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .hero { display: flex; gap: 12px; align-items: center; }
.sheet .hero .img { width: 96px; height: 64px; border-radius: 10px; background: var(--line) center/cover no-repeat; flex: none; }
.price { font-size: 26px; font-weight: 700; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; font-size: 22px; padding: 0; }
.stepper span { min-width: 36px; text-align: center; font-size: 20px; font-weight: 700; }
.pay { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.pay button { color: #fff; padding: 18px 6px; font-size: 16px; font-weight: 600; }
.pay .cash { background: var(--cash); } .pay .bizum { background: var(--bizum); } .pay .card { background: var(--card-pay); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 12px; }
.pill.cash { background: var(--cash); } .pill.bizum { background: var(--bizum); } .pill.card { background: var(--card-pay); }

/* Listas */
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow); }
.item .img { width: 48px; height: 32px; border-radius: 6px; background: var(--line) center/cover no-repeat; flex: none; }
.item.undone { opacity: .45; text-decoration: line-through; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: 90vw; }
#toast.show { opacity: .95; }
#toast.err { background: var(--bad); }
.code { font-size: 40px; letter-spacing: 8px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.kpi .card { margin: 0; } .kpi b { font-size: 22px; display: block; }
.color-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; vertical-align: middle; margin-right: 6px; }
