:root {
  --bg: #F2F4F3;
  --surface: #FFFFFF;
  --ink: #18201E;
  --ink2: #56625F;
  --line: #D6DDDA;
  --accent: #0E6E62;
  --accent-soft: #DCEFEA;
  --amber: #A45F00;
  --amber-soft: #FBEBCF;
  --red: #B3261E;
  --red-soft: #FBE2DF;
  --blue: #1D5FA8;
  --blue-soft: #DEEAF8;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: Consolas, "SFMono-Regular", "Roboto Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink2); }
.vacio { color: var(--ink2); padding: 24px 0; }
[hidden] { display: none !important; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-amber { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-danger { color: var(--red); border-color: var(--red); background: var(--surface); }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn-lg { min-height: 52px; font-size: 17px; width: 100%; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; }

/* ---------- Chips de estado ---------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1.5px solid transparent; white-space: nowrap; }
.chip-libre { color: var(--accent); border-color: var(--accent); }
.chip-ocupada { background: var(--accent); color: #fff; }
.chip-cuenta { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); }
.chip-pendiente { background: var(--blue-soft); color: var(--blue); }
.chip-preparando { background: var(--amber-soft); color: var(--amber); }
.chip-lista { background: var(--accent); color: #fff; }
.chip-entregada { color: var(--ink2); border-color: var(--line); }
.chip-cancelada { color: var(--red); border-color: var(--red); border-style: dashed; }

/* ---------- Mensajes ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 600; }
.flash-ok { background: var(--accent-soft); color: var(--accent); }
.flash-error { background: var(--red-soft); color: var(--red); }
.banner { padding: 12px 16px; border-radius: 8px; background: var(--amber-soft); color: var(--amber); margin-bottom: 16px; font-weight: 600; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); pointer-events: auto; }
.toast-lista { background: var(--accent); font-size: 17px; }
.toast-alerta, .toast-error { background: var(--red); }
.toast-ok { background: var(--accent); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: min(100%, 440px); display: flex; flex-direction: column; gap: 18px; }
.login-box h1 { font-size: 28px; }
.usuarios { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.usuarios label { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); cursor: pointer; }
.usuarios label small { color: var(--ink2); text-transform: capitalize; }
.usuarios input { position: absolute; opacity: 0; pointer-events: none; }
.usuarios label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.usuarios label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.pin-input { font: 600 28px var(--mono); letter-spacing: .4em; text-align: center; padding: 10px; border-radius: 8px; border: 2px solid var(--line); background: var(--surface); width: 100%; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { min-height: 56px; font-size: 22px; font-weight: 600; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); }

/* ---------- App (mozo / cocina) ---------- */
.appbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--accent); color: #fff; }
.appbar .back { color: #fff; text-decoration: none; font-size: 28px; line-height: 1; padding-right: 4px; }
.appbar-title { flex: 1; font-weight: 700; font-size: 18px; }
.appbar .quien { font-size: 13px; opacity: .85; }
.appbar form { margin: 0; }
.appbar .link { color: #fff; font-size: 14px; }
.conexion { width: 10px; height: 10px; border-radius: 50%; background: #9BE2C9; }
.conexion.off { background: #FF8A80; }
.app-main { padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.app-main.has-cart { padding-bottom: 110px; }

.tabs { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.tabs a { flex: 1; text-align: center; padding: 8px; border-radius: 7px; text-decoration: none; color: var(--ink2); font-weight: 600; }
.tabs a.on { background: var(--accent); color: #fff; }

.zona { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.zona h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink2); }
.mesas { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.mesa { position: relative; display: flex; flex-direction: column; gap: 4px; min-height: 96px; padding: 10px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); text-align: left; }
.mesa .n { font-size: 26px; font-weight: 800; line-height: 1; }
.mesa .info { font-size: 12.5px; color: var(--ink2); }
.mesa .total { font-weight: 700; font-size: 13.5px; margin-top: auto; }
.mesa.libre { border-color: var(--accent); }
.mesa.ocupada { background: var(--accent); border-color: var(--accent); color: #fff; }
.mesa.ocupada .info { color: #CFEDE6; }
.mesa.cuenta { background: var(--amber-soft); border-color: var(--amber); }
.mesa.ajena { opacity: .55; }
.mesa .badge { position: absolute; top: 8px; right: 8px; background: #fff; color: var(--accent); border-radius: 999px; padding: 1px 7px; font-size: 12px; font-weight: 800; }
.mesa.cuenta .badge, .mesa.libre .badge { background: var(--accent); color: #fff; }
.mesa form { margin-top: auto; }
.mesa form .btn { width: 100%; }

.cuenta-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.cuenta-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.comanda-mini { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.comanda-mini header { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--ink2); }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.items li { display: flex; gap: 8px; align-items: baseline; }
.items .cant { font-weight: 700; min-width: 2.2em; }
.items .nom { flex: 1; }
.items .nota { display: block; color: var(--amber); font-size: 13px; }
.items li.anulado .nom, .items li.anulado .cant, .items li.anulado .sub { text-decoration: line-through; color: var(--ink2); }
.items .motivo { display: block; color: var(--red); font-size: 12.5px; text-decoration: none; }
.total-row { display: flex; justify-content: space-between; font-size: 20px; font-weight: 800; border-top: 2px solid var(--ink); padding-top: 10px; }

/* Carta y pedido */
.cats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.cats button { flex: none; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; }
.cats button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.prod-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.prod { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; width: 100%; }
.prod:last-child { border-bottom: 0; }
.prod .nom { flex: 1; font-weight: 600; }
.prod .precio { color: var(--ink2); font-variant-numeric: tabular-nums; }
.prod .mas { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700; }
.prod .en-pedido { background: var(--amber); color: #fff; border-radius: 999px; padding: 0 8px; font-size: 13px; font-weight: 700; }
.prod:disabled { opacity: .45; }
.prod:disabled .mas { background: var(--ink2); }

.cart { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(0,0,0,.12); padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 10px; max-height: 80vh; }
.cart-bar { display: flex; align-items: center; gap: 10px; }
.cart-bar .resumen { flex: 1; font-weight: 700; background: none; border: 0; text-align: left; padding: 0; }
.cart-lines { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.cart-line .qty { display: flex; align-items: center; gap: 6px; }
.cart-line .qty button { width: 34px; height: 34px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); font-size: 18px; font-weight: 700; }
.cart-line input { grid-column: 1 / -1; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--line); }
.cart-extra { display: flex; align-items: center; gap: 10px; }
.cart-extra input { width: 70px; padding: 8px; border-radius: 8px; border: 1.5px solid var(--line); }

/* KDS: pantalla de cocina y bebidas en caja */
body.kds { background: #151A19; color: #E8EEEC; }
body.kds .vacio { color: #93A09C; }
.kds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.comanda { background: var(--surface); color: var(--ink); border-radius: var(--radius); border-top: 6px solid var(--blue); display: flex; flex-direction: column; }
.comanda.estado-preparando { border-top-color: var(--amber); }
.comanda.tarde { border-top-color: var(--red); box-shadow: 0 0 0 2px var(--red); }
.comanda > header { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px 0; }
.comanda > header strong { font-size: 22px; }
.comanda .since { font-weight: 700; font-variant-numeric: tabular-nums; }
.comanda.tarde .since { color: var(--red); }
.comanda .meta { padding: 0 12px 8px; font-size: 12.5px; color: var(--ink2); border-bottom: 1px dashed var(--line); }
.comanda .items { padding: 10px 12px; font-size: 16px; }
.comanda > footer { display: flex; gap: 8px; padding: 10px 12px 12px; margin-top: auto; }
.comanda > footer .btn { flex: 1; min-height: 48px; }
.listas-recientes { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.listas-recientes h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: #93A09C; }
.listas-recientes div { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel .listas-recientes h3 { color: var(--ink2); }

/* ---------- Panel de caja ---------- */
.topbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 24px; background: var(--ink); color: #fff; }
.topbar .brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 18px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: #C9D3D0; text-decoration: none; padding: 6px 12px; border-radius: 7px; font-weight: 600; }
.topbar nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.topbar .estado-caja { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--accent); color: #fff; text-decoration: none; }
.topbar .estado-caja.cerrada { background: var(--amber); }
.topbar .sim { font-size: 12px; padding: 3px 8px; border-radius: 4px; border: 1px dashed #F0AE4A; color: #F0AE4A; }
.topbar form { margin: 0; }
.topbar .link { color: #C9D3D0; }
.panel-main { padding: 20px 24px 48px; max-width: 1400px; margin: 0 auto; }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.panel-grid .kds-grid { grid-template-columns: 1fr; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.leyenda { display: flex; gap: 8px; flex-wrap: wrap; }
.barra-col { background: #1B2220; color: #E8EEEC; border-radius: 12px; padding: 16px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.barra-col h2 { margin-bottom: 12px; }
.barra-col .vacio { color: #93A09C; }
.barra-col .listas-recientes h3 { color: #93A09C; }

.volver { display: inline-block; margin-bottom: 10px; text-decoration: none; font-weight: 600; }
.mesa-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.mesa-head h1 { font-size: 30px; }
.mesa-head form { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.mesa-grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
.comanda-caja { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.comanda-caja header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink2); }
.comanda-caja header .btn { margin-left: auto; }
.items .sub { min-width: 90px; text-align: right; font-variant-numeric: tabular-nums; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 700; margin-bottom: 6px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .lbl { font-size: 13px; color: var(--ink2); font-weight: 600; }
input[type=text], input[type=number], input[type=password], select, textarea, .input { padding: 9px 10px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); min-width: 0; }
.pago-row { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; }
.pago-row input { text-align: right; font-variant-numeric: tabular-nums; }
.saldo { font-weight: 700; font-variant-numeric: tabular-nums; }
.saldo.falta { color: var(--red); }
.saldo.vuelto { color: var(--amber); }
.saldo.ok { color: var(--accent); }
.segmented { display: flex; gap: 6px; }
.segmented label { flex: 1; text-align: center; padding: 8px; border-radius: 8px; border: 1.5px solid var(--line); cursor: pointer; font-weight: 600; }
.segmented input { position: absolute; opacity: 0; }
.segmented label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.nota-sim { font-size: 12.5px; color: var(--amber); margin: 0; }

.tabla-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12.5px; color: var(--ink2); }
.dif-neg { color: var(--red); font-weight: 700; }
.dif-pos { color: var(--amber); font-weight: 700; }

/* Comprobante */
.ticket-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.ticket { position: relative; width: 340px; max-width: 100%; background: #FFFDF6; color: #222; font: 13px/1.5 var(--mono); padding: 20px; box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; }
.ticket .c { text-align: center; }
.ticket hr { border: 0; border-top: 1px dashed #999; margin: 8px 0; }
.ticket .fila { display: flex; justify-content: space-between; gap: 8px; }
.ticket .grande { font-size: 18px; font-weight: 700; }
.ticket .letra { display: inline-block; border: 2px solid #222; padding: 0 10px; font-size: 22px; font-weight: 700; }
.ticket .marca-sim { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.ticket .marca-sim span { transform: rotate(-30deg); font: 800 34px var(--font); color: rgba(179, 38, 30, .16); white-space: nowrap; }

@media (max-width: 1000px) {
  .panel-grid, .mesa-grid { grid-template-columns: 1fr; }
  .barra-col { position: static; max-height: none; }
}
@media (max-width: 600px) {
  .panel-main { padding: 16px; }
  .topbar { padding: 10px 16px; }
}
@media print {
  body { background: #fff; }
  .topbar, .no-print, #toasts { display: none !important; }
  .ticket { box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
