:root {
  --purple: #5B3DF0;
  --purple-dark: #4C31D6;
  --bg: #F7F7FB;
  --text: #17131F;
  --muted: #6E687C;
  --line: #ECE8F4;
  --card: #fff;
  --wa: #1FAA55;
  --shadow: 0 8px 24px rgba(23, 19, 31, 0.06);
  --radius: 18px;
  --sidebar: 248px;
  --nav-h: 64px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }

button, a, summary { -webkit-tap-highlight-color: transparent; }

img, svg { max-width: 100%; }

a { color: var(--purple); }

:focus-visible {
  outline: 3px solid rgba(91, 61, 240, 0.45);
  outline-offset: 2px;
}

h1, h2, p { overflow-wrap: break-word; }

.shell { min-height: 100vh; }

.sidebar {
  display: none;
}

.brand, .side-user { padding: 0 8px; }

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--purple);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex: 0 0 auto;
}

.brand-mark.brand-logo {
  background: #fff;
  object-fit: contain;
  padding: 4px;
  box-sizing: border-box;
  border: 1px solid #E3DEEE;
}

.logo-preview {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #E3DEEE;
  padding: 6px;
  box-sizing: border-box;
  display: block;
  margin-bottom: 12px;
}

.logo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 12px;
}

.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }

.sidebar nav, .mas-panel { display: flex; flex-direction: column; gap: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.nav-link.is-active { background: #F1ECFF; color: var(--purple); }
.nav-link:hover { background: #F7F5FC; text-decoration: none; }

.grow { flex: 1; }

.side-user { margin-top: 12px; }
.side-user strong, .side-user span { display: block; }
.side-user span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-form { margin: 8px 0 0; }

.count {
  margin-left: auto;
  background: var(--purple);
  color: #fff;
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  padding: 0 6px;
}

.emoji { font-size: 18px; line-height: 1; }

.frame { padding: 8px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 0 8px;
}

.eyebrow { margin: 0; color: var(--muted); font-size: 13px; font-weight: 700; }

.topbar h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.who { margin: 0; font-weight: 700; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
}

.bottom-nav a, .bottom-nav button {
  flex: 1;
  min-height: 52px;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  padding: 4px 2px;
}

.bottom-nav .label { font-size: 10px; font-weight: 700; }
.bottom-nav .is-active { color: var(--purple); }

.dot {
  width: 8px;
  height: 8px;
  background: var(--purple);
  border-radius: 50%;
  display: inline-block;
  margin-left: 3px;
}

.mas-sheet { position: fixed; inset: 0; z-index: 40; }
.mas-sheet[hidden] { display: none; }
.mas-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 19, 31, 0.45);
  border: 0;
  width: 100%;
}
.mas-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.card, .kpi, details.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card, .kpi { padding: 16px; min-width: 0; }

.card-head, .record-top, .toolbar, .search-row, .inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.card-head { margin-bottom: 8px; }
.card-head h2, .card > h2, details.panel > summary, .modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.kpi-label { margin: 0; font-size: 13px; font-weight: 700; }
.kpi-value, .total-vivo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.kpi-hero {
  background: linear-gradient(145deg, #5B3DF0 0%, #7C5CFF 100%);
  color: #fff;
}
.kpi-hero .kpi-value { font-size: 34px; }
.kpi-hero .hint, .kpi-hero .kpi-label { color: rgba(255, 255, 255, 0.92); }
.kpi-hero .link-more { color: #fff; }

.methods { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.method-chip { background: rgba(255, 255, 255, 0.16); border-radius: 12px; padding: 8px; }
.method-chip span { display: block; font-size: 12px; opacity: 0.85; }
.method-chip strong { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.dash { display: flex; flex-direction: column; gap: 12px; }
.dash .quick { order: 2; }
.dash .kpi { order: 3; }
.dash .kpi.kpi-hero { order: 1; }

.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.quick a {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-height: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
  text-align: center;
  padding: 8px 4px;
}
.quick a span { font-size: 22px; }
.quick a:hover { text-decoration: none; }

.link-more {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  color: var(--purple);
  text-decoration: none;
  white-space: nowrap;
}
.link-more .arrow { font-size: 24px; line-height: 1; }
.link-more:hover { text-decoration: none; }

.date-line { margin: 0; color: var(--muted); font-weight: 700; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; line-height: 1.45; }
.hint.is-bad { color: #C53434; }
.hint.is-ok { color: #1F7A45; }
.empty { margin: 8px 0; color: var(--muted); }
.is-neg { color: #C53434; }
.is-warn { color: #9A6700; }
.money, .kpi-value { font-variant-numeric: tabular-nums; }
.money { font-weight: 800; white-space: nowrap; }

.alert, .banner-warn { border-radius: 14px; padding: 12px 14px; margin: 0 0 12px; }
.alert-ok { background: #E8F8EF; color: #146C3A; }
.alert-error { background: #FDECEC; color: #9F2424; }
.alert ul { margin: 0; padding-left: 18px; }
.banner-warn { background: #FFF6E5; color: #8A5A00; }
.banner-warn a { color: #8A5A00; font-weight: 800; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-ok { background: #E8F8EF; color: #146C3A; }
.badge-warn { background: #FFF6E5; color: #8A5A00; }
.badge-info { background: #F1ECFF; color: var(--purple); }
.badge-off { background: #F1F1F4; color: #666; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 0;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  background: #EFEAFB;
  color: #3B2A86;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-dark); color: #fff; }
.btn-wa { background: var(--wa); color: #fff; }
.btn-wa:hover { background: #188E48; color: #fff; }
.btn-ghost { background: #F4F2F8; color: var(--text); }
.btn-danger { background: #FDECEC; color: #C53434; }
.btn[disabled], .btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-wa svg { width: 18px; height: 18px; display: block; }
.toolbar, .search-row, .acciones, .cobro-box { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar { margin-bottom: 12px; }

label, legend { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
fieldset { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #E3DEEE;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  margin-bottom: 12px;
}
textarea { min-height: 110px; resize: vertical; }
input[readonly] { background: #F7F5FC; }

.form-grid { display: grid; gap: 0 12px; }
.inline-form input, .search-row input { margin: 0; flex: 1; }
.inline-form .btn, .search-row .btn { flex: 0 0 auto; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.segmented.cols-3 { grid-template-columns: 1fr; }
.segment {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid #E3DEEE;
  background: #fff;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  padding: 8px;
}
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment.is-on, .segment:has(input:checked) {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
}
.segment:hover { text-decoration: none; }

.venta-form .bloque-credito { display: none; }
.venta-form.is-credito .bloque-credito,
.venta-form:has(input[value="credito"]:checked) .bloque-credito { display: block; }

.linea {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
}
.linea.is-invalid { border-color: #E5484D; }
.linea-grid { display: grid; gap: 8px; }
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 8px 0 12px;
}

details.panel { padding: 8px 16px 16px; }
details.panel > summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 800;
  list-style: none;
}
details.panel > summary::-webkit-details-marker { display: none; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.data-table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.data-table td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: 0; }
.is-inactivo { opacity: 0.62; }

.records { display: flex; flex-direction: column; gap: 10px; }
.record {
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.record-title { margin: 0; font-size: 16px; }
.record-top { align-items: flex-start; }

.stock-cell { display: flex; align-items: center; gap: 8px; }
.stock-bar {
  height: 8px;
  background: #EEEAF6;
  border-radius: 99px;
  overflow: hidden;
  width: 88px;
  flex: 0 0 auto;
}
.stock-bar > span { display: block; height: 100%; background: #1FAA55; }
.stock-bar.is-low > span { background: #E7A008; }
.stock-bar.is-out > span { background: #E5484D; }

ul.clean { list-style: none; padding: 0; margin: 8px 0 0; }
ul.clean li { padding: 6px 0; border-top: 1px solid var(--line); }

.chart { display: flex; align-items: stretch; gap: 8px; height: 220px; }
.chart-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; height: 100%; }
.chart-val {
  font-size: 11px;
  color: var(--muted);
  min-height: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.chart-track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  background: #F3F0FA;
  border-radius: 10px;
  overflow: hidden;
}
.chart-bar { display: block; width: 100%; background: var(--purple); border-radius: 10px 10px 4px 4px; }
.chart-lab { font-size: 12px; margin-top: 6px; color: var(--muted); }

.abono-form, .cobro-completo {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
}
.abono-form input, .abono-form select, .cobro-completo select { width: auto; min-width: 120px; flex: 1; margin: 0; }

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(23, 19, 31, 0.48); }
.modal-card {
  position: relative;
  background: #fff;
  width: min(520px, 100%);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: min(92vh, 720px);
  overflow: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  background: #F4F2F8;
  border-radius: 12px;
  font-size: 24px;
  cursor: pointer;
}
#escaner-video {
  width: 100%;
  border-radius: 14px;
  background: #17131F;
  max-height: 260px;
  object-fit: cover;
  margin-bottom: 10px;
}
body.modal-open { overflow: hidden; }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 22px;
}
.auth-card .brand-mark { margin: 0 auto 8px; }
.auth-card h1, .auth-card .hint { text-align: center; }
.auth-card h1 { margin: 8px 0 4px; }

.kpi-grid, .report-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }

@media (min-width: 480px) {
  .segmented.cols-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .only-desktop { display: none !important; }
  .kpi-hero { padding: 20px; }
  .kpi-hero .kpi-value { font-size: 40px; }
  .abono-form, .cobro-completo, .cobro-box .btn-wa { width: 100%; }
  .abono-form, .cobro-completo { flex-direction: column; align-items: stretch; }
  .abono-form input, .abono-form select, .cobro-completo select, .abono-form .btn, .cobro-completo .btn { width: 100%; }
}

@media (min-width: 769px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar);
    background: #fff;
    border-right: 1px solid var(--line);
    padding: 22px 14px;
    z-index: 20;
    overflow-y: auto;
  }
  .main { margin-left: var(--sidebar); }
  .frame {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 28px 48px;
  }
  .bottom-nav, .mas-sheet { display: none !important; }
  .only-mobile { display: none !important; }
  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .segmented.pay { grid-template-columns: repeat(4, 1fr); }
  .linea-grid { grid-template-columns: 1.6fr 0.6fr 0.7fr auto; align-items: end; }
  .linea-grid input, .linea-grid select { margin: 0; }
  .linea-accion { padding-bottom: 2px; }
  .dash {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
  .dash .kpi,
  .dash .kpi.kpi-hero,
  .dash .quick { order: 0; }
  .dash .quick { grid-column: 1 / -1; grid-template-columns: repeat(4, 148px); }
  .kpi-grid, .report-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .report-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .modal { place-items: center; }
  .modal-card { border-radius: 20px; }
  .topbar h1 { font-size: 32px; }
  .kpi-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.thumb {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #F1ECFF;
  display: grid;
  place-items: center;
  font-size: 26px;
  flex: 0 0 auto;
  border: 1px solid #E3DEEE;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.prod, .prod-mini { display: flex; gap: 12px; align-items: center; }
.prod-mini .thumb { width: 42px; height: 42px; font-size: 20px; }
.prod-mini select { margin: 0; }
.celda-prod { display: flex; gap: 10px; align-items: center; }
.photo-box {
  width: 96px;
  height: 96px;
  border: 2px dashed #C9C2D8;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  background: #FBFAFE;
  margin-bottom: 12px;
}
.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.catalog-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
  text-align: center;
}
.catalog-card .thumb { width: 100%; height: 110px; border-radius: 12px; margin: 0 auto 8px; font-size: 40px; }
.catalog-card .money { display: block; margin: 6px 0 10px; }
.rank { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.rank:first-of-type { border-top: 0; }
.meter { height: 10px; background: #EEEAF6; border-radius: 99px; overflow: hidden; margin: 6px 0 12px; }
.meter > span { display: block; height: 100%; background: var(--purple); }
.check-line { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.check-line input { width: auto; min-height: 0; margin: 0; }
.ticket {
  width: 80mm;
  max-width: 100%;
  margin: 0 auto;
  background: #fff;
  border: 1px dashed #C9C2D8;
  border-radius: 12px;
  padding: 16px;
  font-size: 14px;
}
.ticket.paper-58 { width: 58mm; }
.ticket.paper-carta { width: min(180mm, 100%); }
.ticket h3, .ticket p { margin: 0; text-align: center; }
.ticket hr { border: 0; border-top: 1px dashed #C9C2D8; margin: 10px 0; }
.ticket .row { display: flex; justify-content: space-between; gap: 8px; }
.ticket .brand-logo { margin: 0 auto 8px; }
.public-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
@media print {
  body { background: #fff; }
  .sidebar, .bottom-nav, .topbar, .no-print, .banner-warn { display: none !important; }
  .main { margin: 0 !important; }
  .frame, .content { padding: 0 !important; max-width: none; }
  .ticket { border: 0; width: 100%; }
  @page { margin: 4mm; }
}
@media (min-width: 769px) {
  .catalog-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
