/* GOING SHOP POS
   Layout: barra lateral fija (escritorio) / barra inferior (celular) + área de trabajo.
   Tipos: Archivo (marca y títulos), Atkinson Hyperlegible (lectura rápida en caja), IBM Plex Mono (precios, SKU, IMEI). */
:root {
  --bg: #F3F4F7;
  --surface: #FFFFFF;
  --surface-2: #ECEEF3;
  --ink: #141821;
  --ink-2: #4A5164;
  --ink-3: #7F879B;
  --line: #DCE0E8;
  --accent: #3043DB;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7EAFC;
  --ok: #10795A;      --ok-soft: #E2F3EB;
  --warn: #9A5800;    --warn-soft: #FCEFD9;
  --bad: #BF261C;     --bad-soft: #FBE6E3;
  --side: #121521;    --side-ink: #C9CEDD; --side-ink-on: #FFFFFF; --side-hi: #262B3D;
  --shadow: 0 1px 2px rgba(20,24,33,.06), 0 8px 24px rgba(20,24,33,.08);
  --f-brand: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1015; --surface: #171A21; --surface-2: #20242D; --ink: #ECEEF3; --ink-2: #AEB4C3; --ink-3: #757D8F;
    --line: #2A2F3A; --accent: #8090FF; --accent-ink: #0E1015; --accent-soft: #232A52;
    --ok: #4CC795; --ok-soft: #12271E; --warn: #E8A84C; --warn-soft: #2C2211; --bad: #FF7D72; --bad-soft: #321715;
    --side: #0A0C10; --side-ink: #9BA2B4; --side-ink-on: #FFFFFF; --side-hi: #1C2030;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1015; --surface: #171A21; --surface-2: #20242D; --ink: #ECEEF3; --ink-2: #AEB4C3; --ink-3: #757D8F;
  --line: #2A2F3A; --accent: #8090FF; --accent-ink: #0E1015; --accent-soft: #232A52;
  --ok: #4CC795; --ok-soft: #12271E; --warn: #E8A84C; --warn-soft: #2C2211; --bad: #FF7D72; --bad-soft: #321715;
  --side: #0A0C10; --side-ink: #9BA2B4; --side-ink-on: #FFFFFF; --side-hi: #1C2030;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-brand); font-weight: 700; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
.mono, .num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); }
.small { font-size: .85rem; } .tiny { font-size: .75rem; }
.right { text-align: right; } .center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; align-content: start; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden-mobile { }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0,1fr); min-height: 100%; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-family: var(--f-brand); font-stretch: 75%; font-weight: 800; font-size: 1.55rem; letter-spacing: .02em; color: var(--side-ink-on); padding: 4px 10px 2px; line-height: 1; }
.brand b { color: var(--accent); font-weight: 800; }
.brand-sub { font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; padding: 4px 10px 18px; color: var(--side-ink); }
.nav { display: grid; gap: 2px; }
.nav button { all: unset; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-ink); font-size: .95rem; }
.nav button:hover { background: var(--side-hi); color: var(--side-ink-on); }
.nav button.on { background: var(--side-hi); color: var(--side-ink-on); box-shadow: inset 3px 0 0 var(--accent); }
.nav button:focus-visible { outline: 2px solid var(--accent); }
.nav .ico { width: 20px; height: 20px; flex: none; }
.nav .pill { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: .7rem; padding: 1px 7px; font-family: var(--f-mono); }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--side-hi); font-size: .85rem; display: grid; gap: 8px; }
.side-foot .who { color: var(--side-ink-on); font-weight: 700; }
.side-foot button { all: unset; cursor: pointer; color: var(--side-ink); text-decoration: underline; font-size: .8rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px max(20px, env(safe-area-inset-right, 0px)) 14px max(20px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }
.topbar h1 { font-size: 1.25rem; }
.page { padding: 20px max(20px, env(safe-area-inset-right, 0px)) 40px max(20px, env(safe-area-inset-left, 0px)); display: grid; gap: 18px; align-content: start; }
.demo-band { background: var(--warn-soft); color: var(--warn); font-size: .85rem; padding: 7px max(20px, env(safe-area-inset-right, 0px)) 7px max(20px, env(safe-area-inset-left, 0px)); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.demo-band button { all: unset; cursor: pointer; text-decoration: underline; font-weight: 700; }

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.card > h2, .card > h3 { margin-bottom: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 700; line-height: 1.1; min-height: 40px; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.big { min-height: 56px; font-size: 1.1rem; padding: 12px 20px; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn .ico { width: 18px; height: 18px; }

.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .78rem; font-weight: 700; color: var(--ink-2); letter-spacing: .02em; }
.field input, .field select, .field textarea, .input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 11px; min-height: 42px; }
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field .err { color: var(--bad); font-size: .78rem; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .85rem; color: var(--ink-2); }
.check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--accent); }
.fgrid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: .74rem; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { all: unset; cursor: pointer; padding: 10px 14px; font-weight: 700; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline: 2px solid var(--accent); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { all: unset; cursor: pointer; padding: 6px 12px; border-radius: 7px; font-weight: 700; font-size: .88rem; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.tblwrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }

.empty { padding: 28px 16px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; font-family: var(--f-brand); }

.alertbar { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--r); background: var(--bad-soft); color: var(--bad); font-weight: 700; flex-wrap: wrap; }
.alertbar.warn { background: var(--warn-soft); color: var(--warn); }
.alertbar.ok { background: var(--ok-soft); color: var(--ok); }
.alertbar .btn { margin-left: auto; }

/* ---------- KPIs and charts ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi .l { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700; }
.kpi .v { font-family: var(--f-mono); font-size: 1.45rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .8rem; color: var(--ink-2); }
.kpi.hi { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kpi.hi .l, .kpi.hi .s { color: var(--accent-ink); opacity: .85; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-3); font-family: var(--f-mono); font-size: 10px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; font-size: .88rem; }
.hbar .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.cols-2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-2 > * { min-width: 0; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.pos-search { position: relative; }
.pos-search input { width: 100%; font-size: 1.1rem; padding: 14px 14px 14px 46px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); min-height: 56px; }
.pos-search input:focus { border-color: var(--accent); outline: none; }
.pos-search .ico { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--ink-3); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip { all: unset; cursor: pointer; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .85rem; font-weight: 700; white-space: nowrap; color: var(--ink-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip:focus-visible { outline: 2px solid var(--accent); }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
.tile { all: unset; cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: grid; gap: 6px; align-content: start; min-height: 112px; position: relative; }
.tile:hover { border-color: var(--accent); }
.tile:focus-visible { outline: 2px solid var(--accent); }
.tile .n { font-weight: 700; line-height: 1.25; }
.tile .m { padding-right: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .74rem; color: var(--ink-3); font-family: var(--f-mono); }
.tile .p { font-family: var(--f-mono); font-weight: 600; font-size: 1.05rem; margin-top: auto; }
.tile .st { position: absolute; top: 10px; right: 10px; }
.tile.off { opacity: .45; cursor: not-allowed; }
.cart { position: sticky; top: 84px; display: grid; gap: 0; padding: 0; overflow: hidden; }
.cart-h { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.cart-list { max-height: 46vh; overflow-y: auto; }
.cl { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 4px 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.cl .n { font-weight: 700; font-size: .92rem; }
.cl .imei { font-family: var(--f-mono); font-size: .75rem; color: var(--accent); }
.cl .pr { font-family: var(--f-mono); font-weight: 600; text-align: right; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.qty button { all: unset; cursor: pointer; width: 32px; height: 30px; text-align: center; font-weight: 700; }
.qty button:hover { background: var(--surface-2); }
.qty span { min-width: 28px; text-align: center; font-family: var(--f-mono); }
.cart-f { padding: 14px 16px; display: grid; gap: 10px; background: var(--surface-2); }
.tot { display: flex; justify-content: space-between; font-family: var(--f-mono); }
.tot.big { font-size: 1.5rem; font-weight: 700; }
.mode-g { background: var(--warn-soft); color: var(--warn); padding: 10px 16px; font-size: .85rem; font-weight: 700; }

/* ---------- Payment ---------- */
.paygrid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
.paybtn { all: unset; cursor: pointer; border: 1px solid var(--line); border-radius: 10px; padding: 12px 10px; text-align: center; font-weight: 700; background: var(--surface); font-size: .92rem; }
.paybtn:hover { border-color: var(--accent); }
.paybtn.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.paybtn:focus-visible { outline: 2px solid var(--accent); }
.payline { display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: .9rem; }
.restante { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 10px; font-family: var(--f-mono); font-weight: 700; font-size: 1.1rem; }
.restante.pend { background: var(--warn-soft); color: var(--warn); }
.restante.done { background: var(--ok-soft); color: var(--ok); }

/* ---------- Modal / toast ---------- */
.ov { position: fixed; inset: 0; background: rgba(10,12,18,.55); display: flex; align-items: flex-start; justify-content: center; padding: max(24px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 24px max(12px, env(safe-area-inset-left, 0px)); overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: min(640px, 100%); box-shadow: var(--shadow); display: grid; margin: auto 0; }
.modal.wide { width: min(960px, 100%); }
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-h h2 { flex: 1; }
.modal-b { padding: 18px; display: grid; gap: 14px; min-width: 0; }
.modal-f { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.x { all: unset; cursor: pointer; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; color: var(--ink-2); }
.x:hover { background: var(--surface-2); }
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-weight: 700; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---------- Receipt ---------- */
.receipt { background: #fff; color: #111; font-family: var(--f-mono); font-size: 12px; width: 300px; max-width: 100%; margin: 0 auto; padding: 16px; border: 1px dashed #bbb; }
.receipt .c { text-align: center; } .receipt .b { font-weight: 700; }
.receipt .r { display: flex; justify-content: space-between; gap: 8px; }
.receipt hr { border: 0; border-top: 1px dashed #999; margin: 8px 0; }
.imgprev { display: grid; place-items: center; background: var(--surface-2); border-radius: 12px; padding: 16px; }
.imgprev img { width: 340px; max-width: 100%; border-radius: 6px; box-shadow: var(--shadow); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); background: var(--side); }
.login-card { width: min(400px, 100%); background: var(--surface); border-radius: 16px; padding: 28px; display: grid; gap: 16px; }
.login-brand { font-family: var(--f-brand); font-stretch: 75%; font-weight: 800; font-size: 2.6rem; line-height: .9; letter-spacing: .01em; }
.login-brand b { color: var(--accent); }
.rolepick { display: grid; gap: 10px; }
.rolepick button { all: unset; cursor: pointer; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 2px; }
.rolepick button:hover { border-color: var(--accent); background: var(--accent-soft); }
.rolepick b { font-family: var(--f-brand); font-size: 1.05rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .pos { grid-template-columns: minmax(0,1fr) 330px; } }
.mbar { display: none; }
@media (max-width: 860px) {
  .mbar:not([hidden]) { display: flex; position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom, 0px)); z-index: 15; gap: 8px; align-items: center; background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow); padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); font-family: var(--f-mono); }
  .main { padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px)) !important; }
  .shell { grid-template-columns: minmax(0,1fr); }
  .side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); z-index: 20; overflow-x: auto; overflow-y: hidden; }
  .brand, .brand-sub, .side-foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav button { flex-direction: column; gap: 3px; font-size: .68rem; padding: 6px 9px; min-width: 64px; justify-content: center; white-space: nowrap; }
  .nav button.on { box-shadow: inset 0 -3px 0 var(--accent); }
  .nav .pill { position: absolute; margin: -4px 0 0 22px; }
  .main { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .pos { grid-template-columns: minmax(0,1fr); }
  .cart { position: static; }
  .cart-list { max-height: none; }
  .hidden-mobile { display: none; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: tin .2s ease-out; }
  @keyframes tin { from { transform: translateY(8px); opacity: 0; } }
}
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; left: 0; top: 0; }
  #print-area .receipt { border: 0; width: 72mm; padding: 0; }
}
