:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec;
  --side: #141a26; --side-ink: #c9cfdb; --accent: #f5b800; --accent-ink: #1d2433;
  --ok: #1f9d55; --warn: #c27c0e; --bad: #d64545; --info: #2f6fdd;
  --r: 8px; font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--info); text-decoration: none; cursor: pointer; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 18px 0 10px; }
h3 { font-size: 14px; margin: 12px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.layout { display: flex; height: 100vh; }
.side { width: 230px; background: var(--side); color: var(--side-ink); overflow-y: auto; flex-shrink: 0; }
.side .brand { padding: 16px; font-weight: 700; color: #fff; font-size: 16px; border-bottom: 1px solid #232b3b; }
.side .brand small { display: block; color: var(--accent); font-weight: 500; font-size: 11px; margin-top: 2px; }
.side .grupo { padding: 12px 16px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7c869a; }
.side a { display: block; padding: 7px 16px 7px 22px; color: var(--side-ink); font-size: 13px; }
.side a:hover { background: #1e2636; color: #fff; }
.side a.act { background: #232c3f; color: #fff; border-left: 3px solid var(--accent); padding-left: 19px; }
.main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.top { background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 20px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; }
.top .sp { flex: 1; }
.contenido { padding: 20px; flex: 1; }
.menu-btn { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .sp { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 14px; }
.grid .full { grid-column: 1 / -1; }
.grid .dos { grid-column: span 2; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cfd4dd; border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f5b80055; border-color: var(--accent); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; }

button, .btn { font: inherit; border: 1px solid #cfd4dd; background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 6px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
button:hover { background: #f1f3f6; }
button.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.pri:hover { filter: brightness(.95); }
button.danger { color: var(--bad); border-color: #f0c4c4; }
button.sm { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
button.link { border: 0; background: none; color: var(--info); padding: 2px 4px; }

table.t { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; padding: 8px; border-bottom: 1px solid var(--line); background: #fafbfc; position: sticky; top: 0; }
table.t td { padding: 7px 8px; border-bottom: 1px solid #eef0f4; vertical-align: middle; }
table.t tr:hover td { background: #fbfaf4; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbfc; }
table.t tr.anulado td { color: #aab; text-decoration: line-through; }
table.t td input, table.t td select { width: 100%; padding: 5px 6px; }
.tabla-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); max-height: 65vh; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: #eef0f4; color: var(--muted); }
.tag.ok { background: #e3f5ea; color: var(--ok); }
.tag.warn { background: #fdf1dc; color: var(--warn); }
.tag.bad { background: #fbe5e5; color: var(--bad); }
.tag.info { background: #e4edfc; color: var(--info); }

.totales { margin-left: auto; width: 320px; }
.totales div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totales .gran { font-size: 18px; font-weight: 700; border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 6px; }

.modal-bg { position: fixed; inset: 0; background: #0b0f1880; display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 10px; width: 100%; max-width: 760px; box-shadow: 0 20px 60px #0004; }
.modal.xl { max-width: 1150px; }
.modal .mh { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .mh b { flex: 1; font-size: 15px; }
.modal .mb { padding: 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.buscador { position: relative; }
.buscador .res { position: absolute; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px #0002; max-height: 300px; overflow-y: auto; width: 100%; min-width: 380px; top: 100%; }
.buscador .res div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f2f3f6; font-size: 13px; }
.buscador .res div:hover, .buscador .res div.sel { background: #fff8de; }
.buscador .res small { color: var(--muted); }

.toast { position: fixed; bottom: 20px; right: 20px; z-index: 99; display: flex; flex-direction: column; gap: 8px; }
.toast div { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px #0003; max-width: 420px; }
.toast div.err { background: var(--bad); }
.toast div.ok { background: var(--ok); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #141a26, #232c3f); }
.login .card { width: 360px; padding: 28px; }
.login h1 { text-align: center; }
.login .marca { text-align: center; color: var(--muted); margin: -8px 0 20px; font-size: 12px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.act { color: var(--ink); border-color: var(--accent); font-weight: 600; }

.pos { display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
.pos .pago { position: sticky; top: 70px; align-self: start; }
.pos .total-pos { font-size: 34px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 12px; }
.err-box { background: #fbe5e5; color: #8a2020; border-radius: 6px; padding: 10px; font-size: 13px; margin: 8px 0; }
.ok-box { background: #e3f5ea; color: #145c33; border-radius: 6px; padding: 10px; font-size: 13px; margin: 8px 0; }
.nivel-1 td { font-weight: 700; } .nivel-2 td { font-weight: 600; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.chart div { flex: 1; max-width: 36px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.chart div:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

@media (max-width: 900px) {
  .side { position: fixed; left: -240px; top: 0; bottom: 0; z-index: 40; transition: left .2s; }
  .side.abierto { left: 0; }
  .menu-btn { display: inline-flex; }
  .pos { grid-template-columns: 1fr; }
  .totales { width: 100%; }
  .contenido { padding: 12px; }
}
@media print {
  .side, .top, .toolbar, button { display: none !important; }
  .contenido { padding: 0; }
  .tabla-wrap { max-height: none; border: 0; }
  .card { border: 0; }
}
