/* CNP ERP POS — viewport-locked, touch + desktop modes */
:root {
  --pos-primary: #3b82f6;
  --pos-primary-dim: rgba(59, 130, 246, 0.12);
  --pos-success: #10b981;
  --pos-warning: #f59e0b;
  --pos-danger: #ef4444;
  --primary: var(--pos-primary);
  --success: var(--pos-success);
  --warning: var(--pos-warning);
  --danger: var(--pos-danger);
  --text-secondary: #cbd5e1;
  --border-light: #2a3f5f;
  --pos-bg: #0b1120;
  --pos-surface: #111827;
  --pos-panel: #1a2332;
  --pos-card: #152238;
  --pos-border: #2a3f5f;
  --pos-text: #f1f5f9;
  --pos-muted: #94a3b8;
  --pos-header-h: 52px;
  --pos-touch-min: 48px;
  --pos-radius: 10px;
  --pos-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

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

html, body.pos-app {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--pos-bg);
  color: var(--pos-text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.pos-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* ── Header ── */
.pos-header {
  flex: 0 0 var(--pos-header-h);
  min-height: var(--pos-header-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.85rem;
  background: linear-gradient(90deg, #111827 0%, #1a2332 100%);
  border-bottom: 1px solid var(--pos-border);
  z-index: 50;
}

.pos-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  color: var(--pos-text);
}
.pos-brand i { color: var(--pos-primary); font-size: 1.15rem; }

.pos-header-center {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.pos-mode-btn {
  border: 1px solid var(--pos-border);
  background: transparent;
  color: var(--pos-muted);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.pos-mode-btn.active-sales {
  background: var(--pos-success);
  border-color: var(--pos-success);
  color: #fff;
}
.pos-mode-btn.active-quote {
  background: var(--pos-warning);
  border-color: var(--pos-warning);
  color: #0b1120;
}

.pos-chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
  overflow: hidden;
}
.pos-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--pos-border);
  background: var(--pos-primary-dim);
  font-size: 0.72rem;
  color: var(--pos-muted);
  white-space: nowrap;
}
.pos-chip i { color: var(--pos-primary); }

.pos-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.pos-ui-toggle {
  display: inline-flex;
  border: 1px solid var(--pos-border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--pos-surface);
}
.pos-ui-toggle button {
  border: none;
  background: transparent;
  color: var(--pos-muted);
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.pos-ui-toggle button.active {
  background: var(--pos-primary);
  color: #fff;
}

.pos-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--pos-border);
  background: var(--pos-surface);
  color: var(--pos-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.pos-icon-btn:hover { background: var(--pos-panel); color: var(--pos-text); }

/* ── Main grid ── */
.pos-body {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 0.5rem;
  padding: 0.5rem;
}

.pos-mode-desktop .pos-body {
  grid-template-columns: 1fr minmax(320px, 34%);
  grid-template-rows: 1fr;
}

.pos-mode-touch .pos-body {
  grid-template-columns: 1fr minmax(300px, 32%) minmax(220px, 22%);
  grid-template-rows: 1fr;
}

.pos-panel {
  background: var(--pos-panel);
  border: 1px solid var(--pos-border);
  border-radius: var(--pos-radius);
  box-shadow: var(--pos-shadow);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pos-panel-head {
  flex: 0 0 auto;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--pos-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.pos-panel-head h6 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pos-muted);
}
.pos-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.55rem 0.75rem 0.65rem;
  gap: 0.45rem;
}

/* ── Catalog ── */
.pos-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
}
.pos-mode-touch .pos-search-row {
  grid-template-columns: 1fr;
}

.pos-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--pos-border);
  background: var(--pos-card);
  border-radius: 8px;
  color: var(--pos-text);
  font-size: 0.9rem;
}
.pos-mode-touch .pos-input {
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  min-height: var(--pos-touch-min);
}
.pos-input:focus {
  outline: none;
  border-color: var(--pos-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.pos-barcode-wrap {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.pos-barcode-wrap .pos-input { flex: 1; }

.pos-cat-row {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
  max-height: 2.6rem;
  overflow-y: auto;
}
.pos-mode-touch .pos-cat-row { max-height: 3.2rem; }

.pos-cat-btn {
  border: 1px solid var(--pos-border);
  background: var(--pos-card);
  color: var(--pos-muted);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pos-mode-touch .pos-cat-btn {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  min-height: 36px;
}
#catAll.pos-cat-active {
  background: var(--pos-primary);
  border-color: var(--pos-primary);
  color: #fff;
}

.pos-catalog-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.pos-hint {
  font-size: 0.72rem;
  color: var(--pos-muted);
  margin: 0;
}

.pos-check-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--pos-muted);
  cursor: pointer;
  user-select: none;
}
.pos-mode-touch .pos-check-inline { font-size: 0.82rem; min-height: 36px; }

#productsGrid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 0.5rem;
  align-content: start;
  padding-right: 2px;
}
.pos-mode-desktop #productsGrid {
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}
.pos-mode-touch #productsGrid {
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.65rem;
}

.product-card {
  position: relative;
  background: var(--pos-card);
  border: 1px solid var(--pos-border);
  border-radius: var(--pos-radius);
  padding: 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  min-height: 118px;
}
.pos-mode-touch .product-card {
  min-height: 140px;
  padding: 0.75rem;
}
.product-card:hover {
  border-color: var(--pos-primary);
}
.product-card:active {
  transform: scale(0.98);
}
.product-name {
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}
.pos-mode-touch .product-name { font-size: 0.92rem; }
.product-price {
  color: var(--pos-success);
  font-weight: 800;
  font-size: 1.05rem;
  margin-top: auto;
}
.pos-mode-touch .product-price { font-size: 1.2rem; }
.product-sku, .product-stock {
  font-size: 0.7rem;
  color: var(--pos-muted);
}
.product-card .btn {
  margin-top: 0.35rem;
  font-weight: 600;
}
.pos-mode-touch .product-card .btn {
  min-height: 40px;
  font-size: 0.85rem;
}

/* ── Sidebar (cart / quote) ── */
.pos-sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pos-block {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--pos-border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
}
.pos-block-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pos-muted);
  margin-bottom: 0.35rem;
}

.pos-quote-picker .pos-input { font-size: 0.82rem; padding: 0.35rem 0.55rem; }

.pos-customer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.pos-customer-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.pos-cart-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--pos-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  position: relative;
}
#cartList, #quoteItemsList { padding: 0.35rem; }
#emptyCart, #emptyQuote {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--pos-muted);
  pointer-events: none;
}

.pos-totals {
  border-top: 1px solid var(--pos-border);
  padding-top: 0.4rem;
}
.pos-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 0.15rem 0;
  color: var(--pos-muted);
}
.pos-total-row.final {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--pos-text);
  border-top: 1px dashed var(--pos-border);
  margin-top: 0.25rem;
  padding-top: 0.4rem;
}
.pos-mode-touch .pos-total-row.final { font-size: 1.2rem; }

.pm-btn {
  flex: 1;
  border: 1px solid var(--pos-border);
  background: var(--pos-card);
  color: var(--pos-muted);
  border-radius: 8px;
  padding: 0.45rem 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}
.pos-mode-touch .pm-btn {
  min-height: var(--pos-touch-min);
  font-size: 0.85rem;
}
.pm-btn.active {
  background: var(--pos-primary);
  border-color: var(--pos-primary);
  color: #fff;
}
.pm-btn.disabled-credit {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

#cashControls {
  display: none;
  flex-direction: column;
  gap: 0.35rem;
}
#cashControls label { font-size: 0.72rem; color: var(--pos-muted); }

.pos-change-box {
  padding: 0.4rem 0.55rem;
  background: rgba(16, 185, 129, 0.1);
  border-radius: 6px;
  border-left: 3px solid var(--pos-success);
}
.pos-change-box .label { font-size: 0.72rem; color: var(--pos-muted); }
.pos-change-box .value { font-weight: 800; color: var(--pos-success); font-size: 1rem; }

.pos-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.pos-checkout-btn {
  flex: 1;
  min-width: 120px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--pos-success), #059669);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}
.pos-mode-touch .pos-checkout-btn {
  min-height: 56px;
  font-size: 1.05rem;
}
.pos-checkout-btn:active { transform: scale(0.98); }

.pos-secondary-btn {
  width: 44px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--pos-border);
  background: var(--pos-card);
  color: var(--pos-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pos-mode-touch .pos-secondary-btn {
  width: 52px;
  min-height: 52px;
}

/* ── Touch dock ── */
.pos-touch-dock {
  display: none;
  min-height: 0;
}
.pos-mode-touch .pos-touch-dock {
  display: flex;
  flex-direction: column;
}

.pos-touch-dock-head {
  flex: 0 0 auto;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--pos-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pos-touch-dock-head span {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--pos-muted);
}

#touchPadGrid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  padding: 0.45rem;
  overflow-y: auto;
  align-content: start;
}

.touch-pad-key {
  min-height: 52px;
  border: 1px solid var(--pos-border);
  border-radius: 8px;
  background: var(--pos-card);
  color: var(--pos-text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.25rem;
}
.touch-pad-key:active { background: var(--pos-primary); }
.touch-pad-key .sub {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--pos-muted);
}
.touch-pad-key.action { background: rgba(59, 130, 246, 0.15); border-color: var(--pos-primary); }
.touch-pad-key.amount { background: rgba(16, 185, 129, 0.12); border-color: var(--pos-success); }
.touch-pad-key.wide { grid-column: span 2; }

.pos-touch-target-display {
  margin: 0 0.45rem;
  padding: 0.35rem 0.55rem;
  border: 1px dashed var(--pos-border);
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--pos-muted);
  text-align: center;
}
.pos-touch-target-display strong { color: var(--pos-primary); }

/* Hide native amount input keyboard on touch when pad visible */
.pos-mode-touch #amountTendered {
  font-size: 1.1rem;
  min-height: var(--pos-touch-min);
  text-align: right;
  font-weight: 700;
}

/* ── Quote panel accent ── */
#quotationModePanel .pos-checkout-btn {
  background: linear-gradient(135deg, var(--pos-warning), #d97706);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

/* ── Modals (dark) ── */
.pos-modal-dark .modal-content {
  background: #0b1220;
  color: #e2e8f0;
  border: 1px solid var(--pos-border);
}
.pos-modal-dark .modal-header,
.pos-modal-dark .modal-footer {
  border-color: #1f2937;
}

/* Touch pad config */
.touch-slot-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.35rem;
}
.touch-slot-row select,
.touch-slot-row input {
  font-size: 0.82rem;
  padding: 0.35rem 0.5rem;
  background: var(--pos-card);
  border: 1px solid var(--pos-border);
  color: var(--pos-text);
  border-radius: 6px;
}

/* ── Responsive: narrow screens stack sidebar below catalog ── */
@media (max-width: 1100px) {
  .pos-mode-touch .pos-body {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
  }
  .pos-mode-touch .pos-catalog { grid-column: 1 / -1; }
  .pos-mode-touch .pos-touch-dock {
    grid-column: 2;
    max-height: 220px;
  }
}

@media (max-width: 768px) {
  .pos-body,
  .pos-mode-desktop .pos-body,
  .pos-mode-touch .pos-body {
    grid-template-columns: 1fr;
    grid-template-rows: 55% 45%;
    overflow-y: auto;
  }
  .pos-shell { overflow: hidden; }
  .pos-mode-touch .pos-touch-dock { display: none; }
  .pos-chips { display: none; }
}
