:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f9fafb; --text: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1f6feb; --accent-ink: #ffffff; --ok: #1a7f37; --warn: #b45309; --bad: #c62828;
  --ok-bg: #e7f5ec; --warn-bg: #fdf3e2; --bad-bg: #fde8e8; --info-bg: #e8f0fe;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  /* Paleta categórica para sucursales (orden fijo, validada para daltonismo) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --grid: #e1e0d9; --axis: #c3c2b7; --up: #006300;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --panel-2: #1d2129; --text: #e7e9ee; --muted: #9aa3b2; --line: #2a2f3a;
    --accent: #4c8dff; --ok: #4ac26b; --warn: #e3a341; --bad: #ff6b6b;
    --ok-bg: #16301f; --warn-bg: #33270f; --bad-bg: #3a1818; --info-bg: #182540; color-scheme: dark;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --grid: #2c2c2a; --axis: #383835; --up: #0ca30c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-size: 14px; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.big { padding: 14px 18px; font-size: 18px; width: 100%; }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: not-allowed; }
h1, h2, h3 { margin: 0 0 12px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--info-bg); color: var(--accent); border-color: transparent; }

/* Shell */
#app { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }
nav.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 12px 8px; gap: 2px; overflow: auto; }
nav.side .brand { font-weight: 800; font-size: 17px; padding: 6px 10px 14px; letter-spacing: -.2px; }
/* Logotipo del negocio: sobre fondo blanco para que se vea igual en modo oscuro */
.brand-logo { display: block; width: 100%; max-height: 64px; object-fit: contain; background: #fff; border-radius: 8px; padding: 4px; }
.login-logo { display: block; width: 100%; max-width: 320px; max-height: 110px; object-fit: contain; margin: 0 auto 6px; background: #fff; border-radius: 10px; }
.ticket-logo { display: block; width: 100%; max-width: 260px; max-height: 80px; object-fit: contain; margin: 0 auto 6px; }
.logo-prev { width: 260px; height: 84px; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
nav.side .brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
nav.side a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
nav.side a:hover { background: var(--panel-2); }
nav.side a.on { background: var(--info-bg); color: var(--accent); font-weight: 600; }
nav.side .sp { flex: 1; }
main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
header.top { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
header.top select { width: auto; }
#view { padding: 18px; overflow: auto; flex: 1; }

/* Tablas */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel-2); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* POS */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; height: 100%; }
.cart select { max-width: 100%; }
.cart td:first-child { min-width: 180px; }
.pos .scan { position: relative; }
.pos .scan input { font-size: 18px; padding: 12px 14px; }
.results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 340px; overflow: auto; }
.results div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.results div:hover, .results div.sel { background: var(--info-bg); }
.cart { margin-top: 12px; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line); flex: none; display: inline-grid; place-items: center; font-size: 18px; color: var(--muted); }
.thumb.lg { width: 160px; height: 160px; border-radius: 14px; font-size: 48px; }
.with-thumb { display: flex; gap: 10px; align-items: center; min-width: 0; }
.with-thumb > div { min-width: 0; }
td > .with-thumb { min-width: 230px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 10px; }
.chips button { border-radius: 99px; padding: 5px 12px; font-size: 13px; }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
/* Caja rápida táctil (sin catálogo): renglones y botones grandes para el dedo */
.pos.reg { grid-template-columns: minmax(0, 1fr) clamp(270px, 32%, 380px); }
.pos.reg .tx { display: none; }
.pos.reg .cart td:first-child { min-width: 140px; }
.pos.reg .cart td > .with-thumb { min-width: 0; }
.pos.reg .cart select { width: 100% !important; min-width: 0; }
.pos.reg .cart .with-thumb > div { flex: 1; overflow-wrap: anywhere; }
.pos.reg .cart .sub { font-size: 13px; }
.pos.reg .cart .thumb { width: 34px; height: 34px; }
.pos.reg .scan input { font-size: 20px; padding: 16px 18px; }
.pos.reg #layout { padding: 14px 16px; white-space: nowrap; }
.pos.reg .cart { min-height: 52vh; background: var(--panel); }
.pos.reg .cart td { padding: 12px 6px; font-size: 16px; }
.pos.reg .cart th { padding-left: 6px; padding-right: 6px; }
.pos.reg .results div { padding: 14px 16px; font-size: 16px; }
.qtybox { display: inline-flex; align-items: center; gap: 4px; }
.qtybox button { width: 40px; height: 42px; padding: 0; font-size: 22px; line-height: 1; border-radius: 10px; }
.qtybox input { width: 52px !important; height: 42px; font-size: 16px; text-align: center !important; }
.pos.reg .cart [data-del] { font-size: 20px; padding: 8px 10px; }
.pos.reg .totals .big { font-size: 46px; }
.pos.reg #pickCust { padding: 12px 14px; }
.paybtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.paybtns button { padding: 18px 8px; font-size: 17px; font-weight: 600; border-radius: 12px; }
.paybtns [data-pay=mixto] { grid-column: 1 / -1; padding: 14px 8px; }
.paybtns button.primary { grid-column: 1 / -1; padding: 22px 8px; font-size: 21px; }
button.danger-soft { color: var(--bad); padding: 14px; }
.cashbtns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cashbtns button { flex: 1 1 90px; padding: 14px 8px; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.paybig input { font-size: 20px; padding: 12px; }
.branch-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.branch-pick button { display: grid; gap: 4px; text-align: left; padding: 18px 16px; border-radius: 12px; font-size: 15px; }
.branch-pick button strong { font-size: 20px; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.tile { display: grid; gap: 4px; text-align: left; padding: 8px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.tile:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.tile img, .tile .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--panel-2); display: grid; place-items: center; font-size: 34px; color: var(--muted); }
.tile .n { font-size: 12px; line-height: 1.25; height: 2.5em; overflow: hidden; }
.tile .p { font-weight: 700; font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; align-items: baseline; }
.tile .p small { font-weight: 400; color: var(--muted); font-size: 11px; }
.tile.out { opacity: .55; }
.rank td { border-bottom: 0; padding: 6px 4px; }
.rank td.pos { width: 22px; color: var(--muted); font-weight: 700; text-align: center; }
.hbar { height: 6px; border-radius: 3px; background: var(--panel-2); margin-top: 4px; overflow: hidden; }
.hbar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.printdoc { background: #fff; color: #000; padding: 8px; }
.printdoc th { background: #f2f2f2; color: #000; }
/* Panel general */
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--up); } .delta.down { color: var(--bad); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; margin-bottom: 8px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--text); font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; min-width: 150px; z-index: 5; }
.tip div { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.share { display: flex; gap: 2px; height: 28px; border-radius: 6px; overflow: hidden; background: var(--panel); }
.share span { display: block; min-width: 2px; }
.bcard h3 { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.bcard .alerts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; font-size: 13px; }
.bcard .alerts div { background: var(--panel-2); border-radius: 8px; padding: 6px 8px; }
.bcard .alerts strong { display: block; font-size: 16px; }
.panel2 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .panel2 { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .g5 { grid-template-columns: 1fr 1fr; } }
/* Control de la Jefatura */
.tx { display: flex; gap: 6px; justify-content: flex-end; align-items: center; margin: 4px 0; font-size: 12px; color: var(--muted); }
.tx button { padding: 2px 8px; font-size: 12px; }
.badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.crumbs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.alert-strip { display: flex; gap: 10px; align-items: center; background: var(--bad-bg); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.alert-strip ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
/* Contabilidad */
tr.lvl1 td { font-weight: 700; } tr.lvl2 td { font-weight: 600; }
tr.sub td { color: var(--muted); font-size: 13px; }
tr.acc-tot td { font-weight: 700; border-top: 2px solid var(--line); }
table.acc td, table.acc th { padding-top: 5px; padding-bottom: 5px; }
.pol-ed td { padding: 4px; } .pol-ed input, .pol-ed select { padding: 5px 6px; }
.pol-ed input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.pnl { position: relative; height: 8px; background: var(--panel-2); border-radius: 4px; }
.pnl span { position: absolute; top: 0; bottom: 0; background: var(--up); border-radius: 4px; }
.pnl::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; border-left: 1px solid var(--axis); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: none; } .seg button.on { background: var(--accent); color: var(--accent-ink); }
.printdoc tr.sub td { color: #444; }
.photo-field { grid-column: 1/-1; display: flex; gap: 14px; align-items: center; }
.cart td input { width: 72px; padding: 4px 6px; text-align: right; }
.cart .sub { font-size: 12px; color: var(--muted); }
.totals { font-variant-numeric: tabular-nums; }
.totals .big { font-size: 34px; font-weight: 800; letter-spacing: -1px; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.bars div { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars div span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Modal y avisos */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(980px, 100%); }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; bottom: 18px; right: 18px; z-index: 60; display: grid; gap: 8px; }
#toast div { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: var(--shadow); }
#toast div.err { background: var(--bad); color: #fff; }
.login { display: grid; place-items: center; height: 100vh; padding: 16px; }
.login .card { width: min(360px, 100%); display: grid; gap: 12px; }
.serial-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 300px; overflow: auto; }
.serial-grid label { flex-direction: row; display: flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; color: var(--text); font-size: 13px; }
.serial-grid input { width: auto; }
.ticket { font-family: ui-monospace, Consolas, monospace; font-size: 12px; width: 300px; margin: 0 auto; background: #fff; color: #000; padding: 12px; }
.ticket table td, .ticket table th { padding: 2px 0; border: 0; background: none; color: #000; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  nav.side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  nav.side .brand, nav.side .sp { display: none; }
  nav.side a { white-space: nowrap; }
  main { height: auto; min-height: calc(100vh - 50px); }
  .pos, .pos.reg { grid-template-columns: 1fr; }
  .pos.reg .cart { min-height: 0; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  #view { padding: 16px; }
}
@media print {
  body * { visibility: hidden; }
  .ticket, .ticket *, .printdoc, .printdoc * { visibility: visible; }
  .ticket, .printdoc { position: absolute; left: 0; top: 0; width: 100%; }
  .ticket { width: 300px; }
}

/* Recargas y paquetes (TAE) */
.topup-hero { background: linear-gradient(120deg, var(--info-bg), var(--panel) 70%); }
.topup-ico { font-size: 46px; width: 74px; height: 74px; display: grid; place-items: center; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.topup-bal { font-size: 40px; font-weight: 800; letter-spacing: -.5px; color: var(--accent); font-variant-numeric: tabular-nums; }
.topup-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.topup-cat { display: grid; gap: 6px; justify-items: center; text-align: center; padding: 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.topup-cat:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.topup-cat .n { font-weight: 700; font-size: 14px; }
.topup-img { width: 100%; max-width: 128px; aspect-ratio: 1; object-fit: contain; border-radius: 22px; background: #fff; }
.topup-noimg { display: grid; place-items: center; color: #fff; font-weight: 800; padding: 10px; text-align: center; font-size: 15px; line-height: 1.2; }
.topup-img.mini { width: 56px; height: 56px; border-radius: 12px; font-size: 8px; padding: 4px; flex: none; }
.topup-head { gap: 12px; align-items: center; }
.topup-pkgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 16px; }
.topup-pkg { display: grid; gap: 6px; align-content: start; justify-items: center; text-align: center; padding: 14px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.topup-pkg .t { font-size: 20px; font-weight: 800; }
.topup-pkg .d { color: var(--muted); font-size: 13px; }
.topup-pkg .b, .topup-badge { font-size: 12px; font-weight: 700; color: #0b84c6; }
.topup-pkg .pr { color: var(--accent); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.topup-pkg .pr small { font-size: 11px; font-weight: 400; color: var(--muted); }
.topup-pkg button.primary { width: 100%; letter-spacing: .5px; }
.topup-pkg.off { opacity: .55; }
input[type=color] { height: 38px; padding: 3px; cursor: pointer; }
