:root {
  --ink: #12262d;
  --muted: #5b707a;
  --line: #d9e2e6;
  --bg: #f4f7f8;
  --card: #ffffff;
  --brand: #0f4c5c;
  --brand-2: #1b7f8e;
  --brand-soft: #e3f1f3;
  --ok: #1f7a4d;
  --ok-soft: #e2f4ea;
  --warn: #9a6a00;
  --warn-soft: #fff3d6;
  --bad: #b3261e;
  --bad-soft: #fde8e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(18, 38, 45, .08), 0 4px 14px rgba(18, 38, 45, .06);
  --nav-w: 232px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
body.modal-open { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .4rem 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.icon { flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- estructura ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav {
  background: var(--brand); color: #fff; padding: 1rem .75rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: .25rem;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; font-weight: 700; line-height: 1.15; }
.brand small { display: block; font-weight: 400; opacity: .75; font-size: .75rem; }
.nav a {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .75rem; border-radius: 10px;
  color: #e8f3f5; text-decoration: none; min-height: 44px;
}
.nav a:hover { background: rgba(255, 255, 255, .1); }
.nav a[aria-current="page"] { background: #fff; color: var(--brand); font-weight: 600; }
.nav .spacer { flex: 1; }
.nav .who { padding: .5rem .75rem; font-size: .85rem; opacity: .85; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .75rem; padding: .75rem 1.25rem; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { flex: 1; font-size: 1.2rem; }
.icon-btn.menu-btn { display: none; }
.content { padding: 1.25rem; width: 100%; max-width: 1200px; margin: 0 auto; }
.banner { padding: .6rem 1.25rem; font-weight: 600; }
.banner-off { background: var(--bad); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(82vw, 290px); transform: translateX(-102%);
    transition: transform .2s ease;
  }
  .nav.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
  .icon-btn.menu-btn { display: inline-flex; }
  .content { padding: .9rem; }
  .topbar { padding: .6rem .9rem; }
}

/* ---------- componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 1rem; }
.grid > .card + .card, .grid > .card { margin-top: 0; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpi { padding: .9rem 1rem; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.kpi.good .value { color: var(--ok); }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0b3b48; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--bg); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-end { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
.row-between { display: flex; gap: .6rem; justify-content: space-between; align-items: center; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-help { font-size: .8rem; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .7rem; border: 1px solid #b9c7cd; border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, button:focus-visible {
  outline: 3px solid rgba(27, 127, 142, .45); outline-offset: 1px;
}
input[type=checkbox], input[type=radio] { width: 22px; min-height: 22px; }
textarea { min-height: 76px; resize: vertical; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.check { display: flex; gap: .6rem; align-items: center; margin-bottom: .8rem; }
.seg { display: inline-flex; border: 1px solid #b9c7cd; border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: .55rem 1rem; min-height: 44px; cursor: pointer; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .9rem; }
.tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .4rem .9rem; min-height: 40px; cursor: pointer; font-weight: 600; }
.tab[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .6rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-soft); }
tfoot td { font-weight: 700; border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }

.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-gris { background: #e8eef0; color: #42555d; }
.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-azul { background: var(--brand-soft); color: var(--brand); }

.empty { padding: 1.6rem 1rem; text-align: center; color: var(--muted); }
.loading { padding: 1.6rem 1rem; text-align: center; color: var(--muted); display: flex; gap: .6rem; justify-content: center; align-items: center; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand-2); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: var(--bad-soft); color: var(--bad); border: 1px solid #f0b8b3; border-radius: 10px; padding: .75rem 1rem; margin: .6rem 0; }
.warn-box { background: var(--warn-soft); color: #6b4a00; border: 1px solid #ecd28f; border-radius: 10px; padding: .75rem 1rem; margin: .6rem 0; }
.info-box { background: var(--brand-soft); color: var(--brand); border-radius: 10px; padding: .75rem 1rem; margin: .6rem 0; }

.toasts { position: fixed; z-index: 100; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; max-width: min(92vw, 420px); }
.toast { padding: .75rem 1rem; border-radius: 10px; color: #fff; box-shadow: var(--shadow); font-weight: 600; }
.toast-ok { background: var(--ok); }
.toast-error { background: var(--bad); }
.toast-aviso { background: var(--warn); }

.overlay { position: fixed; inset: 0; background: rgba(10, 25, 30, .5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 4vh .75rem; }
.modal { background: #fff; border-radius: 14px; width: min(100%, 520px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-wide { width: min(100%, 860px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .6rem .6rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-body { padding: 1rem 1.1rem 1.1rem; }
@media (max-width: 600px) { .overlay { padding: 0; align-items: stretch; } .modal, .modal-wide { width: 100%; border-radius: 0; min-height: 100vh; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #0f4c5c 0%, #1b7f8e 100%); }
.login-card { width: min(100%, 400px); background: #fff; border-radius: 16px; padding: 1.6rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.login-card h1 { margin: .6rem 0 .2rem; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center; }

/* ---------- venta ---------- */
.pos { display: grid; grid-template-columns: 1.15fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 960px) { .pos { grid-template-columns: 1fr; } }
.prod-list { display: grid; gap: .5rem; max-height: 58vh; overflow-y: auto; padding-right: .2rem; }
.prod { display: flex; justify-content: space-between; align-items: center; gap: .75rem; width: 100%; text-align: left; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; min-height: 56px; }
.prod:hover:not(:disabled) { border-color: var(--brand-2); background: var(--brand-soft); }
.prod:disabled { opacity: .5; cursor: not-allowed; }
.prod .t { font-weight: 600; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: .4rem .6rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.cart-line .ctrl { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.cart-line input { width: 92px; min-height: 40px; }
.cart-line input.qty { width: 64px; text-align: center; }
.totals { display: grid; gap: .3rem; margin-top: .6rem; }
.totals .line { display: flex; justify-content: space-between; }
.totals .grand { font-size: 1.35rem; font-weight: 800; border-top: 2px solid var(--ink); padding-top: .4rem; margin-top: .2rem; }

/* ---------- gráfico simple ---------- */
.bars { display: grid; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 92px; align-items: center; gap: .5rem; font-size: .85rem; }
.bar-track { background: #e8eef0; border-radius: 6px; height: 14px; position: relative; overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--brand-2); border-radius: 6px; }
.bar-fill.b2 { background: #d9a441; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .3rem; background: var(--brand-2); }
.dot.b2 { background: #d9a441; }

/* ---------- impresión (recibos) ---------- */
@media print {
  body > #app, .toasts { display: none !important; }
  .overlay { position: static; background: none; padding: 0; display: block; }
  .modal { box-shadow: none; width: 100%; border-radius: 0; min-height: 0; }
  .modal-head .icon-btn, .no-print { display: none !important; }
  body { background: #fff; }
}

/* Celular: las tablas se muestran como tarjetas (todo el contenido visible, sin desplazarse de lado) */
@media (max-width: 640px) {
  .table-wrap { overflow-x: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { position: absolute; left: -9999px; }
  .table-wrap tr { border: 1px solid var(--line); border-radius: 12px; padding: .35rem .8rem; margin-bottom: .65rem; background: #fff; }
  .table-wrap td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .3rem 0; border: 0; text-align: right; white-space: normal; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none; }
  .table-wrap td[data-label=""]::before { content: none; }
  .table-wrap td.actions { justify-content: flex-end; padding-top: .5rem; }
  .table-wrap tfoot tr { background: transparent; border: 0; }
}
