:root {
  --brand: #4c1d95; --brand-2: #5b21b6; --brand-3: #6d28d9; --brand-soft: #ede9fe;
  --bg: #eef1f6; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb; --line-2: #f3f4f6;
  --ok: #059669; --ok-soft: #d1fae5; --warn: #d97706; --warn-soft: #fef3c7; --bad: #dc2626; --bad-soft: #fee2e2; --info: #0284c7; --info-soft: #e0f2fe;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --side: 210px; --top: 50px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-3); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
.hidden { display: none !important; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), var(--brand-3)); padding: 16px; }
.login form { background: #fff; padding: 32px; border-radius: 14px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 22px; color: var(--brand); }
.login p { margin: 0 0 20px; color: var(--muted); }

/* Estructura */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.app.collapsed { grid-template-columns: 0 1fr; }
.app.collapsed .side { visibility: hidden; }
.side { background: #fff; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { height: var(--top); display: flex; align-items: center; gap: 8px; padding: 0 16px; background: var(--brand); color: #fff; font-weight: 600; font-size: 16px; white-space: nowrap; position: sticky; top: 0; z-index: 2; }
.side .brand .dot { width: 9px; height: 9px; border-radius: 50%; background: #34d399; flex: none; }
.menu { list-style: none; margin: 0; padding: 8px; }
.menu > li > a, .menu > li > button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 8px; color: #374151; cursor: pointer; text-align: left; white-space: nowrap; }
.menu > li > a:hover, .menu > li > button:hover { background: var(--line-2); }
.menu > li > a.active, .menu > li.open > button { background: var(--brand-soft); color: var(--brand-2); }
.menu svg { width: 17px; height: 17px; flex: none; }
.menu .chev { margin-left: auto; width: 14px; height: 14px; transition: transform .15s; }
.menu li.open .chev { transform: rotate(-90deg); }
.menu ul { list-style: none; margin: 2px 0 6px; padding: 0 0 0 26px; display: none; }
.menu li.open ul { display: block; }
.menu ul a { display: block; padding: 6px 10px; border-radius: 6px; color: #4b5563; font-size: 13px; }
.menu ul a:hover { background: var(--line-2); }
.menu ul a.active { color: var(--brand-2); font-weight: 600; background: var(--brand-soft); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: var(--top); background: var(--brand); color: #fff; display: flex; align-items: center; gap: 8px; padding: 0 16px; position: sticky; top: 0; z-index: 20; }
.top .sp { flex: 1; }
.tbtn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tbtn:hover { background: rgba(255,255,255,.18); }
.tbtn svg { width: 16px; height: 16px; }
.drop { position: relative; }
.drop-menu { position: absolute; right: 0; top: 40px; background: #fff; color: var(--text); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 200px; padding: 6px; display: none; z-index: 50; }
.drop.open .drop-menu { display: block; }
.drop-menu a, .drop-menu button { display: flex; gap: 8px; align-items: center; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px; color: var(--text); cursor: pointer; text-align: left; }
.drop-menu a:hover, .drop-menu button:hover { background: var(--line-2); }

.page { padding: 20px; flex: 1; }
.band { background: linear-gradient(180deg, var(--brand-2), var(--brand-3)); margin: -20px -20px 0; padding: 20px 20px 80px; color: #fff; }
.band + .after-band { margin-top: -70px; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin: 0; font-size: 22px; font-weight: 600; }
.head small { color: var(--muted); font-size: 13px; }
.band .head h1 { font-size: 30px; }
.head .sp { flex: 1; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card > h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 16px; }
.card-head .sp { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; display: flex; gap: 14px; align-items: center; color: var(--text); }
.stat .ic { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.stat .ic svg { width: 21px; height: 21px; }
.stat small { color: var(--muted); display: block; margin-bottom: 4px; }
.stat b { font-size: 19px; font-family: "JetBrains Mono", ui-monospace, monospace; }
.c-info { background: var(--info-soft); color: var(--info); } .c-ok { background: var(--ok-soft); color: var(--ok); }
.c-warn { background: var(--warn-soft); color: var(--warn); } .c-bad { background: var(--bad-soft); color: var(--bad); }

/* Formularios */
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid .full { grid-column: 1 / -1; }
.f label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: #374151; }
.f label .req { color: var(--bad); }
.inp, .f input:not([type=checkbox]):not([type=radio]), .f select, .f textarea { width: 100%; height: 36px; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; }
.f textarea { height: auto; min-height: 70px; }
.inp:focus, .f input:focus, .f select:focus, .f textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-3); }
.f .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--brand-3); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; white-space: nowrap; font-weight: 500; }
.btn:hover { background: var(--line-2); }
.btn svg { width: 16px; height: 16px; }
.btn.pri { background: var(--brand-3); border-color: var(--brand-3); color: #fff; }
.btn.pri:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.info { background: var(--info); border-color: var(--info); color: #fff; }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn.lg { height: 46px; font-size: 15px; padding: 0 18px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

/* Tablas */
.tbl-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.tbl-tools .sp { flex: 1; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { background: #f9fafb; text-align: left; font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr:hover td { background: #fafaff; }
table.t td.n, table.t th.n { text-align: right; font-family: "JetBrains Mono", ui-monospace, monospace; white-space: nowrap; }
table.t tfoot td { font-weight: 600; background: #f9fafb; }
table.t .empty { text-align: center; color: var(--muted); padding: 24px; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.pager .btns { display: flex; gap: 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); } .b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); } .b-info { background: var(--info-soft); color: var(--info); } .b-mut { background: var(--line-2); color: var(--muted); }
.thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--line-2); display: inline-grid; place-items: center; color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal.lg { max-width: 980px; } .modal.xl { max-width: 1200px; } .modal.sm { max-width: 420px; }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 17px; flex: 1; }
.modal header button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal .body { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast div { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast div.err { background: var(--bad); }

/* Búsqueda de productos / contactos */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,.12); max-height: 320px; overflow-y: auto; z-index: 60; }
.ac-list div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.ac-list div:hover, .ac-list div.sel { background: var(--brand-soft); }
.ac-list small { color: var(--muted); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; }
.tabs button.on { color: var(--brand-2); border-color: var(--brand-3); }
.vtabs { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.vtabs nav { display: flex; flex-direction: column; gap: 2px; }
.vtabs nav button { text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.vtabs nav button.on { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.totals { margin-left: auto; max-width: 380px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals div.big { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; }
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; }

/* POS */
.pos { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; height: calc(100vh - var(--top) - 40px); }
.pos .left, .pos .right { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; }
.pos .left .bar { padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-bottom: 1px solid var(--line); }
.pos .cart { flex: 1; overflow-y: auto; }
.pos .cart table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pos .cart th { position: sticky; top: 0; background: #f9fafb; padding: 8px; text-align: left; font-weight: 600; }
.pos .cart td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); }
.pos .cart input { width: 76px; height: 30px; border: 1px solid #d1d5db; border-radius: 6px; padding: 0 6px; text-align: right; }
.pos .sum { border-top: 1px solid var(--line); padding: 10px 12px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 12px; font-size: 13px; }
.pos .sum b { display: block; font-size: 15px; }
.pos .paybar { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.pos .paybar .tot { margin-left: auto; font-size: 20px; font-weight: 700; color: var(--ok); }
.pos .right .bar { padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-bottom: 1px solid var(--line); }
.pos .prods { flex: 1; overflow-y: auto; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; align-content: start; }
.pos .prod { border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; text-align: center; background: #fff; display: flex; flex-direction: column; gap: 4px; }
.pos .prod:hover { border-color: var(--brand-3); box-shadow: var(--shadow); }
.pos .prod .img { height: 70px; border-radius: 6px; background: var(--line-2); display: grid; place-items: center; color: #9ca3af; overflow: hidden; }
.pos .prod .img img { width: 100%; height: 100%; object-fit: cover; }
.pos .prod .nm { font-size: 12px; font-weight: 600; line-height: 1.25; max-height: 3.75em; overflow: hidden; }
.pos .prod small { color: var(--muted); font-size: 11px; }

.calc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc input { grid-column: 1 / -1; height: 48px; font-size: 22px; text-align: right; }
.calc button { height: 46px; font-size: 17px; border: 1px solid var(--line); border-radius: 8px; background: #f9fafb; cursor: pointer; }

/* Factura / impresión */
.invoice { font-size: 13px; }
.invoice h2 { margin: 0; text-align: center; }
.invoice .c { text-align: center; }
@media print {
  body * { visibility: hidden; }
  #print, #print * { visibility: visible; }
  #print { position: absolute; left: 0; top: 0; width: 100%; }
  .no-print { display: none !important; }
}
.labels { display: flex; flex-wrap: wrap; gap: 0; }
.label { border: 1px dashed #ccc; padding: 4px; text-align: center; overflow: hidden; display: flex; flex-direction: column; justify-content: center; font-size: 11px; }
.label svg { max-width: 100%; height: 34px; }

@media (max-width: 1100px) { .stats, .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid, .grid.g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .pos { grid-template-columns: 1fr; height: auto; } .pos .prods { max-height: 60vh; } }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 90; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .app.mobile-open .side { transform: none; visibility: visible; }
  .app.collapsed .side { visibility: visible; }
  .stats, .filters, .grid, .grid.g2, .grid.g4 { grid-template-columns: 1fr; }
  .page { padding: 16px; } .band { margin: -16px -16px 0; padding: 16px 16px 80px; }
  .top .hide-m { display: none; }
  .vtabs { grid-template-columns: 1fr; }
  .pos .sum { grid-template-columns: repeat(2, 1fr); }
}
.band .inp, .band select, .band input { color: var(--text); }
