:root {
  --bg: #f4f2ef;
  --panel: #ffffff;
  --ink: #1d1b19;
  --muted: #6b655e;
  --line: #e2ddd6;
  --brand: #7a1f2b;
  --brand-ink: #ffffff;
  --brand-soft: #f6e8ea;
  --ok: #1e7a46;
  --ok-soft: #e3f3ea;
  --warn: #9a6400;
  --warn-soft: #fff3d6;
  --bad: #b3261e;
  --bad-soft: #fde7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: #2a1418; color: #f3e9ea; display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { font-weight: 800; font-size: 20px; letter-spacing: .5px; padding: 6px 10px 14px; }
.side .logo span { color: #e6a5ae; }
.side a { color: #f3e9ea; text-decoration: none; padding: 10px 12px; border-radius: 8px; display: block; }
.side a:hover { background: rgba(255,255,255,.08); }
.side a.active { background: var(--brand); }
.side .branch-box { margin: auto 0 0; padding: 10px 12px; font-size: 13px; border-top: 1px solid rgba(255,255,255,.12); }
.side .branch-box label { display: block; opacity: .8; margin-bottom: 4px; color: inherit; }
.side .branch-box select { width: 100%; color: var(--ink); }
.side .branch-box .muted { color: inherit; opacity: .7; }
.side .who { margin-top: 0; padding: 10px 12px; font-size: 13px; opacity: .85; border-top: 1px solid rgba(255,255,255,.12); }
.side .who button { margin-top: 8px; width: 100%; color: var(--ink); }
.main { padding: 18px 22px; min-width: 0; }
.topbar { display: none; }

.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }

/* Controls */
.btn { border: 1px solid var(--line); background: #fff; padding: 9px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9c1b7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); border-color: #efc2be; }
.btn.big { padding: 14px 18px; font-size: 17px; }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #d9a3ab; border-color: var(--brand); }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 10px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 15px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; border-bottom: 3px solid transparent; color: var(--muted); }
.tabs button.active { border-color: var(--brand); color: var(--ink); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; } tr.click:hover td { background: #faf8f5; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: #eee; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 420px; gap: 16px; height: calc(100vh - 36px); }
.pos-left { display: flex; flex-direction: column; min-height: 0; }
.pos-right { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.scan { font-size: 20px; padding: 14px; }
.cats { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.cats button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.cats button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; overflow-y: auto; padding-bottom: 8px; align-content: start; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 92px; }
.tile:hover { border-color: var(--brand); }
.tile .n { font-weight: 600; font-size: 14px; line-height: 1.2; }
.tile .p { font-weight: 700; color: var(--brand); margin-top: auto; }
.tile .s { font-size: 12px; color: var(--muted); }
.tile.low .s { color: var(--bad); }
.cart { flex: 1; overflow-y: auto; padding: 4px 12px; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cart-line .d { font-weight: 600; font-size: 14px; }
.cart-line .m { font-size: 12px; color: var(--muted); }
.cart-line .t { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 18px; line-height: 1; }
.qty input { width: 56px; text-align: center; padding: 5px; }
.cart-empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.totals { border-top: 1px solid var(--line); padding: 12px 14px; }
.totals .line { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 30px; font-weight: 800; margin: 6px 0 10px; }
.pos-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.pos-actions .btn { padding: 8px 6px; font-size: 13px; }
kbd { font-size: 11px; background: #eee; border-radius: 4px; padding: 1px 4px; color: var(--muted); }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(20,10,12,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 4vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal header { padding: 16px 18px 6px; display: flex; align-items: center; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 8px 18px 14px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.x { border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }

.pay-total { font-size: 38px; font-weight: 800; text-align: center; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.pay-methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.pay-methods button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.bills { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.change { font-size: 44px; font-weight: 800; color: var(--ok); text-align: center; font-variant-numeric: tabular-nums; }
.age-box { border: 2px solid var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 12px; margin: 10px 0; }
.age-box .check { font-weight: 600; font-size: 16px; }
.denoms { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.denoms .d { display: flex; align-items: center; gap: 6px; }
.denoms .d span { width: 64px; text-align: right; font-weight: 600; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #222; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #2a1418, #7a1f2b); }
.login .card { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login .logo { font-size: 30px; font-weight: 800; text-align: center; color: var(--brand); margin-bottom: 4px; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.pinpad button { padding: 14px; font-size: 20px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.bar { height: 8px; background: var(--brand); border-radius: 4px; min-width: 2px; }
.bars td { padding: 4px 8px; }

@media (max-width: 1000px) {
  .pos { grid-template-columns: 1fr; height: auto; }
  .pos-right { min-height: 60vh; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #2a1418; color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; }
  .main { padding: 12px 16px; }
  .pay-methods { grid-template-columns: repeat(2, 1fr); }
  .bills { grid-template-columns: repeat(3, 1fr); }
}

/* Ticket impreso */
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; left: 0; top: 0; }
}
#print-area { display: none; }
@media print { #print-area { display: block; } }
.ticket { width: 72mm; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
.ticket .c { text-align: center; }
.ticket table td { padding: 1px 0; border: 0; }
.ticket hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
