:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafd;
  --sidebar-bg: #0f172a;
  --sidebar-ink: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --ink: #0f172a;
  --sub: #5b6b82;
  --line: #e2e8f0;
  --blue: #1d63dc;
  --blue-dark: #154eb3;
  --blue-soft: #eaf2ff;
  --green: #0b8765;
  --green-soft: #e7f8f2;
  --amber: #9a6700;
  --amber-soft: #fff8e6;
  --danger: #c92a2a;
  --danger-soft: #fff0f0;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #131c31;
  --surface-soft: #192540;
  --sidebar-bg: #070c17;
  --sidebar-ink: #f1f5f9;
  --sidebar-muted: #94a3b8;
  --ink: #f1f5f9;
  --sub: #94a3b8;
  --line: #24324d;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-soft: #1e3a5f;
  --green: #10b981;
  --green-soft: #0f382e;
  --amber: #f59e0b;
  --amber-soft: #36280d;
  --danger: #f87171;
  --danger-soft: #3b181b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
  border: 0;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.top-note {
  text-align: center;
  color: var(--amber);
  background: var(--amber-soft);
  border-bottom: 1px solid var(--line);
  padding: 8px 14px;
  font-size: 12px;
}

.app-frame {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: calc(100vh - 35px);
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #0d9488);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  flex-shrink: 0;
}

.brand strong {
  display: block;
  font-size: 14px;
  letter-spacing: -0.02em;
}

.brand small {
  display: block;
  color: var(--sidebar-muted);
  font-size: 11px;
}

.sidebar-nav {
  padding: 10px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--sidebar-muted);
  font-weight: 700;
  padding: 12px 10px 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  background: transparent;
  color: var(--sidebar-ink);
  text-align: left;
  font-size: 13px;
  font-weight: 550;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  background: var(--blue);
  color: #ffffff;
  font-weight: 700;
}

.nav-ico {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--sidebar-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.usb-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #6ee7b7;
  font-weight: 600;
}

.usb-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #10b981;
}

/* Workspace & Topbar */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 15;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-title {
  margin: 0;
  font-size: clamp(17px, 2.2vw, 21px);
  letter-spacing: -0.03em;
}

.topbar-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--sub);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--green);
  background: var(--green-soft);
  padding: 6px 11px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status i {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--green);
}

.content-area {
  padding: 22px 24px;
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* Buttons & Inputs */
.primary {
  border-radius: 10px;
  padding: 11px 16px;
  color: #fff;
  font-weight: 700;
  background: var(--blue);
  white-space: nowrap;
}

.primary:not(:disabled):hover {
  background: var(--blue-dark);
}

.secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 650;
  color: var(--ink);
}

.secondary:not(:disabled):hover {
  background: var(--surface-soft);
}

.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 7px 10px;
  font-weight: 700;
}

.icon-button {
  min-width: 38px;
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
}

input, select, textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
}

/* Panels & Layouts */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.p-body {
  padding: 20px 22px;
}

.p-body h2 {
  margin-top: 0;
  font-size: 18px;
}

.panel-heading {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.wrap-heading {
  flex-wrap: wrap;
}

.no-border-pad {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 16px;
  margin: 0 0 3px;
}

.panel-heading p {
  color: var(--sub);
  font-size: 12px;
  margin: 0;
}

.soft-tag {
  padding: 6px 11px;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* POS Grid */
.pos-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.38fr) minmax(330px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.messages {
  padding: 20px 22px;
  min-height: 310px;
  max-height: 460px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 13px;
  background: var(--surface-soft);
}

.message {
  padding: 12px 15px;
  max-width: 92%;
  border-radius: 12px;
  word-break: break-word;
  border: 1px solid transparent;
}

.assistant {
  background: var(--surface);
  border-color: var(--line);
  border-top-left-radius: 4px;
}

.user {
  background: var(--blue);
  color: #fff;
  margin-left: auto;
  border-top-right-radius: 4px;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.options button, .quick-commands button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 650;
  color: var(--blue);
}

.options button:hover, .quick-commands button:hover {
  background: var(--blue-soft);
}

.quick-commands {
  padding: 12px 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  border-top: 1px solid var(--line);
}

.composer {
  display: flex;
  gap: 10px;
  padding: 0 22px;
}

.composer input {
  flex: 1;
  padding: 12px 14px;
}

.no-pad-composer {
  padding: 0;
  margin: 14px 0;
}

.tools {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  padding: 14px 22px 20px;
}

.tools button {
  border-radius: 9px;
  border: 1px solid var(--line);
  padding: 9px 12px;
  background: var(--surface-soft);
  font-weight: 650;
  font-size: 12px;
}

.tools button:hover {
  background: var(--blue-soft);
}

/* Cart */
.cart-panel {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 78px;
}

.customer-box {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.customer-box label {
  font-size: 11px;
  font-weight: 700;
  color: var(--sub);
  text-transform: uppercase;
}

.count {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
  padding: 6px 11px;
  border-radius: 8px;
}

.cart-lines {
  padding: 16px 20px;
  min-height: 240px;
  max-height: 370px;
  overflow-y: auto;
}

.empty {
  text-align: center;
  color: var(--sub);
  padding: 36px 8px;
}

.empty span {
  font-size: 38px;
  opacity: 0.6;
}

.line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.line-name {
  font-size: 13px;
  font-weight: 750;
}

.line-meta {
  color: var(--sub);
  font-size: 11px;
  margin: 3px 0 6px;
}

.line-controls {
  display: flex;
  gap: 7px;
  align-items: center;
}

.line-controls input {
  width: 74px;
  padding: 6px;
  text-align: center;
}

.line-right {
  text-align: right;
  white-space: nowrap;
}

.line-right strong {
  display: block;
}

.line-right small {
  color: var(--sub);
  font-size: 11px;
}

.cart-footer {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

.totals-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.tot-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--sub);
}

.amount {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}

.amount strong {
  font-size: 26px;
  letter-spacing: -0.03em;
}

.cart-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.full {
  flex: 1;
  width: 100%;
}

.tax-note {
  font-size: 11px;
  color: var(--sub);
  margin: 6px 0;
}

.blocked {
  text-align: center;
  color: var(--amber);
  font-size: 11px;
  margin-top: 10px;
  font-weight: 600;
}

/* Catalog Cards */
.filter-inline, .action-bar, .filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.filter-bar input {
  flex: 1;
  min-width: 190px;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  padding: 20px 22px;
}

.product {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--surface-soft);
}

.product .sku {
  font-size: 11px;
  color: var(--sub);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.product-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.badge.high {
  background: var(--danger-soft);
  color: var(--danger);
}

.product-meta-list {
  font-size: 12px;
  color: var(--sub);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.product .price {
  font-size: 17px;
  font-weight: 800;
  color: var(--blue);
}

.product button {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 8px;
}

/* Tables & KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  padding: 16px 22px;
}

.p-body .kpi-grid {
  padding: 8px 0 20px;
}

.kpi-card {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 14px 16px;
}

.kpi-card span {
  display: block;
  font-size: 11px;
  color: var(--sub);
  text-transform: uppercase;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  font-size: 24px;
  margin-top: 4px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 680px;
}

.data-table th, .data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sub);
  background: var(--surface-soft);
}

.data-table td input {
  width: 100%;
  min-width: 170px;
  padding: 7px 9px;
}

.center-cell {
  text-align: center !important;
  padding: 26px !important;
}

/* Scanner, Purchases & Misc Grids */
.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.scanner-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.scanner-box, #scanner-video {
  width: 100%;
  max-height: 280px;
  background: #0f172a;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 12px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-card {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 14px 16px;
}

.compact-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}

.list-item {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 12px;
}

.notice {
  border: 1px solid var(--amber);
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.setting-card {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-card h3 {
  margin: 0;
  font-size: 15px;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  cursor: pointer;
}

.bars-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 50px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 99px;
}

.clean-list {
  padding-left: 20px;
  color: var(--sub);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mt-lg {
  margin-top: 22px;
}

.muted {
  color: var(--sub);
}

.search-sm {
  width: 280px;
  max-width: 100%;
}

footer {
  color: var(--sub);
  font-size: 11px;
  text-align: center;
  padding: 20px 16px;
  border-top: 1px solid var(--line);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 30, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-top {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-top h2 {
  font-size: 17px;
  margin: 0;
}

.modal-content {
  padding: 20px;
  overflow-x: auto;
}

.preview {
  max-height: 240px;
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin: 10px auto;
  border-radius: 8px;
}

.mobile-only {
  display: none;
}

/* =========================================================
   RESPONSIVE BREAKPOINTS (Tablet <= 1040px, Mobile <= 680px)
   ========================================================= */
@media (max-width: 1040px) {
  .app-frame {
    grid-template-columns: 1fr;
  }

  .mobile-only {
    display: inline-grid;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 278px;
    transform: translateX(-104%);
    transition: transform 0.22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 15, 30, 0.55);
    z-index: 25;
  }

  .pos-layout, .split-grid {
    grid-template-columns: 1fr;
  }

  .cart-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .hide-xs {
    display: none;
  }

  .topbar {
    padding: 12px 14px;
  }

  .topbar-sub {
    display: none;
  }

  .content-area {
    padding: 14px 12px;
  }

  .panel-heading, .p-body {
    padding: 14px;
  }

  .messages {
    padding: 14px;
    min-height: 250px;
    max-height: 360px;
  }

  .quick-commands, .tools {
    padding: 10px 14px;
  }

  .composer {
    padding: 0 14px;
    flex-direction: column;
  }

  .composer input, input, select {
    font-size: 16px; /* Previene zoom automático en iOS / Android */
  }

  .composer button {
    width: 100%;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }

  .catalog-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .bar-row {
    grid-template-columns: 110px minmax(0, 1fr) 38px;
    font-size: 12px;
  }

  .search-sm {
    width: 100%;
  }
}
