:root {
  --c0: #0E0B1D;   /* fondo */
  --c1: #2A1E4D;   /* superficies */
  --c2: #5A3B8C;   /* principal */
  --c3: #8B7CC7;   /* acento */
  --c4: #C9C2E3;   /* texto claro */
  --c5: #3A3A52;   /* neutro */
  --txt: #F1EEFA;
  --muted: #A49CC4;
  --line: rgba(201, 194, 227, .12);
  --card: rgba(42, 30, 77, .55);
  --ok: #7FD8B0;
  --warn: #F2C36B;
  --bad: #F28B9A;
  --r: 22px;
  --pill: 999px;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, .7);
  font-family: 'Manrope', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--c0);
  color: var(--txt);
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

.glow { position: fixed; z-index: -1; border-radius: 50%; filter: blur(90px); pointer-events: none; }
.glow-a { width: 520px; height: 520px; left: -220px; top: -160px; background: rgba(139, 124, 199, .28); }
.glow-b { width: 560px; height: 560px; right: -260px; bottom: -200px; background: rgba(90, 59, 140, .35); }

/* ---------- Header / navegación ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: rgba(14, 11, 29, .78);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.01em; font-size: 18px; }
.brand.big { font-size: 26px; justify-content: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--c3), var(--c2)); box-shadow: 0 0 14px var(--c3); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.chip { font-size: 12px; font-weight: 700; padding: 5px 12px; border-radius: var(--pill); background: var(--c5); color: var(--c4); white-space: nowrap; }
.chip.test { background: rgba(242, 195, 107, .15); color: var(--warn); }
.chip.live { background: rgba(127, 216, 176, .14); color: var(--ok); }

.tabs { display: flex; gap: 6px; background: rgba(42, 30, 77, .6); padding: 5px; border-radius: var(--pill); border: 1px solid var(--line); }
.tabs button {
  display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; cursor: pointer;
  padding: 9px 18px; border-radius: var(--pill);
  font-weight: 700; color: var(--muted);
  transition: background .2s, color .2s;
}
.tabs button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabs button.active { background: var(--c2); color: #fff; box-shadow: 0 6px 18px -6px var(--c2); }

main { max-width: 1040px; margin: 0 auto; padding: 24px 20px 120px; }

/* ---------- Elementos base ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 14px; }
.error { color: var(--bad); font-size: 14px; min-height: 1em; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--c5);
  padding: 12px 22px; border-radius: var(--pill);
  font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform .12s, background .2s, opacity .2s;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #6A49A0, var(--c2)); border-color: transparent; color: #fff; box-shadow: 0 10px 24px -10px var(--c2); }
.btn.accent { background: var(--c3); color: var(--c0); border-color: transparent; }
.btn.light { background: var(--c4); color: var(--c0); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--bad); border-color: rgba(242, 139, 154, .35); }
.btn.small { padding: 7px 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.huge { padding: 20px 26px; font-size: 18px; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.field { display: block; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 6px 6px; }
.input, .field input, .field select {
  width: 100%;
  background: rgba(14, 11, 29, .65);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 13px 18px;
  outline: none;
  font-size: 16px; /* evita zoom en iPhone */
  transition: border-color .2s, box-shadow .2s;
}
.input:focus, .field input:focus { border-color: var(--c3); box-shadow: 0 0 0 4px rgba(139, 124, 199, .2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Vender ---------- */
.sell-head { display: grid; gap: 14px; }
.code-form { display: flex; gap: 10px; }
.code-form .input { text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
#reader { border-radius: var(--r); overflow: hidden; background: #000; border: 1px solid var(--line); }
#reader video { border-radius: var(--r); }
.scan-wrap { position: relative; }
.scan-wrap .btn { position: absolute; right: 12px; top: 12px; z-index: 2; }

.product-hit { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 22px; align-items: start; }
.product-hit .ph { aspect-ratio: 3/4; border-radius: 18px; overflow: hidden; background: var(--c5); }
.ph img { width: 100%; height: 100%; object-fit: cover; }
.ph.empty { display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.price { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.code-tag { font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: .1em; background: var(--c5); padding: 3px 10px; border-radius: var(--pill); font-size: 13px; color: var(--c4); }
.stock-big { display: inline-flex; align-items: baseline; gap: 6px; padding: 8px 16px; border-radius: var(--pill); background: rgba(127, 216, 176, .12); color: var(--ok); font-weight: 800; }
.stock-big b { font-size: 24px; }
.stock-big.low { background: rgba(242, 195, 107, .14); color: var(--warn); }
.stock-big.zero { background: rgba(242, 139, 154, .14); color: var(--bad); }

.stepper { display: inline-flex; align-items: center; background: rgba(14, 11, 29, .6); border: 1px solid var(--line); border-radius: var(--pill); }
.stepper button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 22px; font-weight: 700; cursor: pointer; border-radius: 50%; }
.stepper span { min-width: 34px; text-align: center; font-weight: 800; font-size: 18px; }
.pay { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { background: rgba(14, 11, 29, .45); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.stat .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.stat.hero { background: linear-gradient(160deg, var(--c2), var(--c1)); border-color: transparent; }

/* ---------- Prendas ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .input { flex: 1; min-width: 180px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.item {
  text-align: left; cursor: pointer; padding: 0; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  transition: transform .15s, border-color .2s;
}
.item:hover { border-color: rgba(139, 124, 199, .5); }
.item:active { transform: scale(.98); }
.item .ph { aspect-ratio: 1; border-radius: 0; }
.item .info { padding: 12px 14px 14px; }
.item .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 6px; }
.badge { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: var(--pill); background: rgba(127, 216, 176, .14); color: var(--ok); white-space: nowrap; }
.badge.low { background: rgba(242, 195, 107, .15); color: var(--warn); }
.badge.zero { background: rgba(242, 139, 154, .15); color: var(--bad); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }

/* ---------- Caja ---------- */
.seg { display: inline-flex; background: rgba(42, 30, 77, .6); padding: 5px; border-radius: var(--pill); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 8px 18px; border-radius: var(--pill); font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--c4); color: var(--c0); }
.period { display: flex; align-items: center; gap: 8px; }
.period .lbl { font-weight: 700; min-width: 170px; text-align: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--c5); cursor: pointer; font-weight: 800; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.stats4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.void td { opacity: .4; text-decoration: line-through; }
.method { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: var(--pill); white-space: nowrap; }
.method.efectivo { background: rgba(127, 216, 176, .14); color: var(--ok); }
.method.transferencia { background: rgba(139, 124, 199, .2); color: var(--c4); }
.table-wrap { overflow-x: auto; }

/* ---------- Modal ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 28px; padding: 0;
  background: #17122C; color: var(--txt);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  box-shadow: 0 30px 80px -20px #000;
}
dialog::backdrop { background: rgba(8, 6, 18, .72); backdrop-filter: blur(4px); }
#modal-body { padding: 24px; overflow-y: auto; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h2 { margin: 0; }
.x { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--c5); cursor: pointer; font-size: 20px; line-height: 1; }

.photo-pick { display: grid; grid-template-columns: 130px 1fr; gap: 14px; align-items: center; }
.photo-pick .ph { aspect-ratio: 3/4; border-radius: 18px; overflow: hidden; background: var(--c5); }
.qr-box { background: #fff; border-radius: 18px; padding: 12px; width: 180px; }
.qr-box img { width: 100%; image-rendering: pixelated; }
.detail { display: grid; grid-template-columns: 1fr 180px; gap: 18px; align-items: start; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 14px 18px; border-radius: 18px; background: var(--c4); color: var(--c0); font-weight: 700; box-shadow: var(--shadow); animation: tin .25s ease-out; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); display: grid; gap: 14px; text-align: center; }
.login-card .field { text-align: left; }

/* ---------- Celular ---------- */
@media (max-width: 720px) {
  .top { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); backdrop-filter: none; background: rgba(14, 11, 29, .95); }
  .tabs {
    position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
    justify-content: space-around; padding: 6px; z-index: 30;
    background: rgba(23, 18, 44, .92); backdrop-filter: blur(16px);
    box-shadow: 0 10px 30px -8px #000;
  }
  .tabs button { flex: 1; flex-direction: column; gap: 2px; padding: 8px 4px; font-size: 12px; }
  main { padding: 16px 14px 120px; }
  h1 { font-size: 24px; }
  .card { padding: 18px; }
  .product-hit { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .product-hit .ph { aspect-ratio: auto; height: 240px; }
  .pay .btn.huge { padding: 18px 10px; font-size: 16px; }
  .price { font-size: 24px; }
  .stats4 { grid-template-columns: 1fr 1fr; }
  .mini-stats .stat .v { font-size: 17px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .detail { grid-template-columns: 1fr; }
  .detail .qr-box { justify-self: center; }
  .period .lbl { min-width: 0; flex: 1; font-size: 14px; }
  .hide-m { display: none; }
  #toasts { bottom: 104px; }
}

/* ---------- Impresión de etiquetas ---------- */
#print-area { display: none; }
@media print {
  @page { margin: 8mm; }
  body { background: #fff !important; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: flex !important; flex-wrap: wrap; gap: 3mm; }
  .label {
    width: 60mm; height: 32mm; border: 0.3mm dashed #999; border-radius: 2mm;
    display: flex; gap: 3mm; padding: 2.5mm; color: #000; font-family: Manrope, Arial, sans-serif;
    break-inside: avoid; page-break-inside: avoid;
  }
  .label img { width: 27mm; height: 27mm; }
  .label .t { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; }
  .label .store { font-size: 7pt; text-transform: uppercase; letter-spacing: .08em; }
  .label .n { font-size: 9pt; font-weight: 700; line-height: 1.15; overflow: hidden; max-height: 2.4em; }
  .label .s { font-size: 7.5pt; }
  .label .p { font-size: 13pt; font-weight: 800; }
  .label .c { font-family: monospace; font-size: 10pt; font-weight: 700; letter-spacing: .12em; }
}
