:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1f26;
  --text-muted: #6b7280;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --primary-contrast: #ffffff;
  --accent: #2563eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --sidebar-w: 230px;
}

html[data-theme="dark"] {
  --bg: #0f1418;
  --surface: #171d23;
  --surface-alt: #1e252c;
  --border: #2a333c;
  --text: #e8ecef;
  --text-muted: #9aa5b1;
  --primary: #14b8a6;
  --primary-dark: #0d9488;
  --primary-contrast: #04211e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 700; font-size: 1.05rem; border-bottom: 1px solid var(--border); }
.brand-icon { font-size: 1.4rem; }
.nav { display: flex; flex-direction: column; padding: 10px; gap: 2px; overflow-y: auto; flex: 1; }
.nav-link { padding: 12px 14px; border-radius: var(--radius-sm); color: var(--text); font-weight: 500; font-size: 0.95rem; }
.nav-link:hover { background: var(--surface-alt); }
.nav-link.active { background: var(--primary); color: var(--primary-contrast); }
.nav-link-primary { border: 1px dashed var(--primary); }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 1.15rem; font-weight: 700; flex: 1; margin: 0; }
.hamburger { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 0.9rem; color: var(--text-muted); }
.role-badge { background: var(--surface-alt); padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; text-transform: capitalize; }

.page-content { padding: 20px; flex: 1; }

.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-weight: 500; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }
html[data-theme="dark"] .flash-success { background: #0f3d24; color: #86efac; }
html[data-theme="dark"] .flash-error { background: #4c1414; color: #fca5a5; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 0.95rem; font-weight: 600; cursor: pointer; background: var(--surface-alt); color: var(--text);
  transition: transform .05s ease, filter .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-small { padding: 8px 12px; font-size: 0.85rem; }
.btn-large { padding: 16px 22px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Cards / KPIs */
.grid { display: grid; gap: 14px; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 20px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.6rem; font-weight: 800; margin-top: 6px; }
.kpi-value.warn { color: var(--warning); }
.kpi-value.danger { color: var(--danger); }
.kpi-value.good { color: var(--success); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-title { font-weight: 700; margin: 0 0 12px; font-size: 1.02rem; }
.two-col { grid-template-columns: 2fr 1fr; }
.charts-grid { grid-template-columns: 1fr 1fr; margin-bottom: 20px; }

/* Tables */
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.data-table tr:hover td { background: var(--surface-alt); }
.badge { padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-muted { background: var(--surface-alt); color: var(--text-muted); }

/* Forms */
.form-group { margin-bottom: 14px; }
label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; color: var(--text-muted); }
input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.95rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.search-box { position: relative; }
.search-box input { padding-left: 38px; }
.search-box::before { content: "🔎"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 20, 25, 0.55); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.modal-wide { max-width: 820px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); }

/* Toast */
.toast-host { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-weight: 600; color: #fff; min-width: 220px; animation: toast-in .2s ease; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== POS / BILLING ===================== */
.pos-layout { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; min-height: 520px; height: calc(100vh - 128px); height: calc(100dvh - 128px); }
.pos-left { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.pos-right { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.pos-search-row { display: flex; gap: 8px; }
.pos-search-row input { font-size: 1.1rem; padding: 16px 16px 16px 42px; }
.pos-product-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; }
.pos-product-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
  cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 96px;
}
.pos-product-card:hover { border-color: var(--primary); }
.pos-product-card .pname { font-weight: 700; font-size: 0.9rem; line-height: 1.25; }
.pos-product-card .pprice { color: var(--primary); font-weight: 700; }
.pos-product-card .pstock { font-size: 0.75rem; color: var(--text-muted); }
.pos-product-card .pstock.low { color: var(--warning); font-weight: 700; }
.pos-product-card .pstock.out { color: var(--danger); font-weight: 700; }

.cart-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; flex: 1; min-height: 0; }
.cart-header { padding: 6px 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 0.92rem; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.cart-items { flex: 1; min-height: 220px; overflow-y: auto; padding: 0 10px; }
.cart-item { display: grid; grid-template-columns: 20px 1fr auto auto auto; gap: 6px; align-items: center; padding: 3px 4px; border-bottom: 1px solid var(--border); }
.cart-item .ci-num { color: var(--text-muted); font-weight: 700; font-size: 0.78rem; text-align: center; }
.cart-item .ci-name { font-weight: 600; font-size: 0.82rem; line-height: 1.15; }
.cart-item .ci-meta { font-size: 0.68rem; color: var(--text-muted); }
.qty-control { display: flex; align-items: center; gap: 3px; }
.qty-control button { width: 20px; height: 20px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface-alt); font-weight: 700; cursor: pointer; font-size: 0.78rem; line-height: 1; }
.qty-control input { width: 36px; text-align: center; padding: 3px; font-size: 0.78rem; }
.qty-control input.qty-whole { width: 44px; }
.qty-control input.qty-sub { width: 50px; }
.qty-control .qty-unit { font-size: 0.7rem; color: var(--text-muted); }
.ci-remove { background: none; border: none; color: var(--danger); font-size: 1rem; cursor: pointer; }
.ci-discount-btn { background: none; border: none; color: var(--accent); font-size: 0.72rem; cursor: pointer; text-decoration: underline; }

.cart-totals { padding: 6px 14px; border-top: 1px solid var(--border); font-size: 0.88rem; flex-shrink: 0; }
.totals-row { display: flex; justify-content: space-between; padding: 2px 0; }
.totals-row.grand { font-size: 1.15rem; font-weight: 800; border-top: 1px dashed var(--border); margin-top: 3px; padding-top: 6px; }
.pos-actions { padding: 8px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex-shrink: 0; }
.pos-actions .btn-checkout { grid-column: span 2; padding: 12px 22px; }
#paymentMethodChips.chip-row { gap: 6px; }
#paymentMethodChips .chip { padding: 6px 10px; font-size: 0.8rem; }

.scanner-modal-body { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#scannerRegion { width: 100%; }


/* Print-only invoice */
.invoice-sheet { max-width: 760px; margin: 0 auto; background: #fff; color: #111; padding: 28px; }
.invoice-sheet table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.invoice-sheet th, .invoice-sheet td { padding: 8px; border-bottom: 1px solid #ddd; font-size: 0.9rem; word-wrap: break-word; }
.invoice-head { display: flex; justify-content: space-between; margin-bottom: 20px; }

/* Thermal receipt (58mm / 80mm) — compact stacked layout, no wide table.
   Width matches the physical paper roll so nothing gets clipped or forced
   wider than the printer can render. */
.invoice-sheet.thermal-58,
.invoice-sheet.thermal-80 {
  max-width: none;
  margin: 0 auto; /* centred in the browser preview; reset to 0 when printing (see @media print) */
  padding: 2mm;
  box-sizing: border-box;
  font-family: 'Courier New', Courier, monospace;
  line-height: 1.35;
}
.invoice-sheet.thermal-58 { width: 58mm; font-size: 9px; }
.invoice-sheet.thermal-80 { width: 80mm; font-size: 10.5px; }
.th-center { text-align: center; }
.th-line { border-top: 1px dashed #333; margin: 4px 0; }
.th-item { margin-bottom: 3px; }
.th-item-name { font-weight: 700; word-break: break-word; }
.th-item-sub, .th-total-row { display: flex; justify-content: space-between; gap: 6px; }
.th-total-row span:last-child { white-space: nowrap; }
.th-grand { font-weight: 800; font-size: 1.15em; border-top: 1px dashed #333; margin-top: 4px; padding-top: 4px; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .invoice-sheet.thermal-58,
  .invoice-sheet.thermal-80 { margin: 0; }
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 0.85rem; }
.chip.active { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* Login page */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); padding: 16px; }
.login-card { background: var(--surface); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-title { text-align: center; font-size: 1.4rem; font-weight: 800; margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--text-muted); margin-bottom: 22px; font-size: 0.9rem; }

@media (max-width: 980px) and (min-height: 521px) {
  .pos-layout { grid-template-columns: 1fr; height: auto; }
  .pos-product-grid { max-height: 40vh; }
  .charts-grid, .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 860px) and (min-height: 521px) {
  .sidebar { position: fixed; left: -260px; top: 0; transition: left .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .hamburger { display: block; }
  .page-content { padding: 14px; }
}

/* ================= Offline status bar, scan read-out ================= */
.offline-bar { display: block; width: 100%; text-align: left; border: 1px solid transparent; border-radius: 10px; padding: 9px 14px; font-size: 0.85rem; font-weight: 600; cursor: pointer; margin-bottom: 10px; font-family: inherit; }
.offline-bar.online  { background: #dcfce7; color: #166534; }
.offline-bar.offline { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.offline-bar.warn    { background: #dbeafe; color: #1e40af; }
.offline-bar.danger  { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
html[data-theme="dark"] .offline-bar.online  { background: #0f3d24; color: #86efac; }
html[data-theme="dark"] .offline-bar.offline { background: #4a3408; color: #fcd34d; }
html[data-theme="dark"] .offline-bar.warn    { background: #172554; color: #93c5fd; }
html[data-theme="dark"] .offline-bar.danger  { background: #4c1414; color: #fca5a5; }

.ob-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.ob-row.failed { background: rgba(239, 68, 68, 0.06); }
.ob-error { color: var(--danger); font-size: 0.8rem; }

/* The complete barcode number, so it can be checked against the product label. */
.last-scan { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-alt); border: 1px dashed var(--border); border-radius: 10px; }
.last-scan .ls-label { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; font-weight: 700; }
.last-scan .ls-code { font-family: 'Courier New', monospace; font-weight: 800; font-size: 1.05rem; letter-spacing: 0.5px; word-break: break-all; }
.last-scan .ls-name { color: var(--text-muted); font-size: 0.85rem; }
.ci-barcode, .bc { font-family: 'Courier New', monospace; font-size: 0.72rem; color: var(--text-muted); word-break: break-all; white-space: normal; }

/* ================= Phones ================= */
@media (max-width: 700px) and (min-height: 521px) {
  /* 16px inputs stop iPhones zooming in when a field is tapped */
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .btn-small { min-height: 38px; }
  .chip { padding: 10px 14px; }
  .page-content { padding: 10px; }
  .card { padding: 12px; overflow-x: auto; }
  .data-table { min-width: 560px; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { padding: 8px 10px; }
  .page-title { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .user-chip { display: none; }

  /* a wide table inside a grid cell must scroll inside its card, not widen the whole page */
  .grid > *, .two-col > *, .main-area, .page-content { min-width: 0; }

  /* Billing screen: one column, big touch targets, checkout always in reach */
  .pos-layout { display: flex; flex-direction: column; height: auto; gap: 10px; }
  .pos-left, .pos-right { min-height: 0; }
  .pos-search-row { flex-wrap: wrap; }
  .pos-search-row .search-box { flex: 1 1 100% !important; }  /* beats the inline flex:1 in pos.php */
  .pos-search-row .btn { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .pos-search-row input { padding: 14px 14px 14px 40px; }
  .pos-product-grid { grid-template-columns: repeat(2, 1fr); max-height: 34vh; }
  .pos-product-card { min-height: 64px; }
  .cart-panel { min-height: 0; }
  .cart-items { max-height: none; overflow: visible; }

  .cart-item { grid-template-columns: 24px 1fr auto; row-gap: 8px; padding: 10px 2px; }
  .cart-item > :nth-child(1) { grid-row: 1; grid-column: 1; }
  .cart-item > :nth-child(2) { grid-row: 1; grid-column: 2; }
  .cart-item > :nth-child(5) { grid-row: 1; grid-column: 3; }
  .cart-item > :nth-child(3) { grid-row: 2; grid-column: 1 / span 2; }
  .cart-item > :nth-child(4) { grid-row: 2; grid-column: 3; font-weight: 700; }
  .cart-item .ci-name { font-size: 0.95rem; }
  .cart-item .ci-meta { font-size: 0.78rem; }
  .ci-remove { font-size: 1.3rem; min-width: 36px; min-height: 36px; }
  .qty-control { gap: 6px; flex-wrap: wrap; }
  .qty-control button { width: 38px; height: 38px; font-size: 1.1rem; }
  .qty-control input { width: 62px; height: 38px; }
  .qty-control input.qty-whole { width: 64px; }
  .qty-control input.qty-sub { width: 70px; }

  .pos-actions { position: sticky; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--border);
                 padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .pos-actions .btn-checkout { padding: 16px; font-size: 1.1rem; }

  /* Pop-ups slide up from the bottom like a phone sheet */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-overlay.open { align-items: flex-end; }
  .modal, .modal.modal-wide { max-width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; padding: 16px; }
  .modal-close { min-width: 40px; min-height: 40px; }
}

/* ================= Subscription lock + offline checklist ================= */
.license-lock { position: fixed; inset: 0; z-index: 300; background: rgba(15, 20, 25, 0.82); backdrop-filter: blur(3px);
                display: flex; align-items: center; justify-content: center; padding: 16px; }
.license-lock .ll-card { background: var(--surface); border-radius: 16px; padding: 26px; width: 100%; max-width: 420px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.rd-row { padding: 4px 0; font-size: 0.88rem; }
.rd-row.ok { color: var(--success); }
.rd-row.bad { color: var(--danger); font-weight: 600; }
.rd-fix { color: var(--text-muted); font-weight: 400; font-size: 0.8rem; }

.user-chip-mobile { display: none; }
@media (max-width: 700px) and (min-height: 521px) { .user-chip-mobile { display: inline-flex; } }

/* ================= Scan-first billing: camera, search results, popup ================= */
.scan-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px; }
.scan-panel.on { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.22); }
.scan-bar { display: flex; gap: 8px; }
.scan-bar #btnScan { flex: 1; justify-content: center; }
.scan-bar #btnTorch { min-width: 52px; justify-content: center; font-size: 1.2rem; }
/* The camera shows ONLY the scan strip. Phones hand over a tall portrait picture; it is centred inside a short
   fixed-height window and the rest is cut off, so nothing else is visible and the page never grows or scrolls. */
.scan-cam { position: relative; height: 112px; margin: 10px auto 0; border-radius: 10px; overflow: hidden; background: #000; max-width: 560px; }
.scan-cam > div { position: absolute !important; inset: 0; margin: 0 !important; padding: 0 !important; border: 0 !important; min-height: 0 !important; display: flex !important; align-items: center; justify-content: center; }
.scan-cam video { display: block; position: static !important; width: 100% !important; height: 100% !important; max-width: none !important; object-fit: cover; object-position: center center; margin: 0 auto !important; }
.scan-cam canvas, .scan-cam #qr-shaded-region { display: none !important; }      /* the library's own dimming overlay */
.scan-cam::after { content: ''; position: absolute; inset: 5px 4%; border: 3px solid #fff; border-radius: 8px; pointer-events: none; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.scan-cam::before { content: ''; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: rgba(239, 68, 68, .9); z-index: 2; pointer-events: none; animation: scanline 1.6s ease-in-out infinite; }
@keyframes scanline { 0%, 100% { transform: translateY(-34px); opacity: .35; } 50% { transform: translateY(34px); opacity: 1; } }

.search-results { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; max-height: 46vh; overflow-y: auto; box-shadow: var(--shadow); }
.sr-row { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px;
          background: none; border: none; border-bottom: 1px solid var(--border); text-align: left; cursor: pointer; font: inherit; color: inherit; }
.sr-row:last-child { border-bottom: none; }
.sr-row:hover, .sr-row:active { background: var(--surface-alt); }
.sr-name { display: block; font-weight: 700; }
.sr-sub { display: block; font-size: 0.78rem; color: var(--text-muted); }
.sr-price { font-weight: 800; color: var(--primary); white-space: nowrap; }
.sr-empty { padding: 16px; color: var(--text-muted); text-align: center; }
.pos-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.pos-tools .btn { flex: 1 1 auto; justify-content: center; }

/* shows what was just added; sits over everything, never blocks a tap */
.scan-popup { position: fixed; left: 50%; top: 76px; transform: translate(-50%, -16px); z-index: 260; min-width: 260px; max-width: 92vw;
              display: flex; gap: 12px; align-items: center; padding: 14px 18px; border-radius: 14px; color: #fff;
              box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; }
.scan-popup.show { opacity: 1; transform: translate(-50%, 0); }
.scan-popup.ok { background: #15803d; }
.scan-popup.error { background: #b91c1c; }
.sp-icon { font-size: 2.1rem; font-weight: 900; line-height: 1; }
.sp-name { font-size: 1.25rem; font-weight: 800; line-height: 1.2; word-break: break-word; }
.sp-sub { font-size: 0.92rem; opacity: 0.95; margin-top: 2px; }
.sp-code { font-family: 'Courier New', monospace; font-weight: 800; font-size: 1rem; letter-spacing: 0.5px; word-break: break-all; margin-top: 2px; }

@media (max-width: 700px) and (min-height: 521px) {
  .scan-popup { top: 58px; width: calc(100vw - 20px); }
  .scan-bar #btnScan { padding: 16px; font-size: 1.05rem; }
  .search-results { max-height: 40vh; }
}

/* ---- whole-site offline strip ---- */
.site-bar { padding: 8px 14px; font-size: 0.85rem; font-weight: 600; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; text-align: center; }
.site-bar.off { background: #fef3c7; color: #92400e; }
.site-bar.wait { background: #dbeafe; color: #1e40af; }
.site-bar.warn { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .site-bar.off { background: #422006; color: #fde68a; }
[data-theme="dark"] .site-bar.wait { background: #172554; color: #bfdbfe; }
[data-theme="dark"] .site-bar.warn { background: #450a0a; color: #fecaca; }

/* ---- Billing: customer card, taller cart, compact totals ---- */
.customer-pill { display: flex; align-items: center; gap: 12px; padding: 10px 12px; flex-shrink: 0;
  background: linear-gradient(135deg, rgba(15,118,110,.10), rgba(37,99,235,.08)); border: 1px solid rgba(15,118,110,.25); border-radius: 14px; }
.customer-pill .cp-avatar { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--primary), #2563eb); box-shadow: 0 3px 8px rgba(15,118,110,.35); }
.customer-pill .cp-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.customer-pill .cp-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.customer-pill .cp-name { font-size: 1.05rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-pill .cp-btn { border: 0; border-radius: 999px; padding: 9px 16px; font-weight: 800; font-size: 0.85rem; cursor: pointer; color: #fff;
  background: var(--primary); box-shadow: 0 2px 6px rgba(15,118,110,.3); white-space: nowrap; }
.customer-pill .cp-btn:active { transform: scale(.97); }
.customer-pill .cp-clear { border: 1px solid var(--border); background: var(--surface); color: var(--danger); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; align-items: center; justify-content: center; font-size: .95rem; }
.customer-pill.has-customer { background: linear-gradient(135deg, rgba(22,163,74,.14), rgba(15,118,110,.08)); border-color: rgba(22,163,74,.4); }
.customer-pill.has-customer .cp-avatar { background: linear-gradient(135deg, #16a34a, var(--primary)); }

/* totals in two columns so the item list gets the height */
.cart-totals { display: grid; grid-template-columns: 1fr 1fr; column-gap: 22px; }
.cart-totals > :nth-child(1) { order: 1; }
.cart-totals > :nth-child(3) { order: 2; }
.cart-totals > :nth-child(2) { order: 3; grid-column: 1 / -1; align-items: center; }
.cart-totals > :nth-child(4) { order: 4; }
.cart-totals > :nth-child(5) { order: 5; }
.cart-totals > :nth-child(6) { order: 6; grid-column: 1 / -1; }

@media (max-width: 860px) and (min-height: 521px) {
  .customer-pill { padding: 12px; }
  .customer-pill .cp-avatar { width: 46px; height: 46px; }
  .customer-pill .cp-btn { padding: 11px 18px; font-size: 0.95rem; }
  .cart-panel { min-height: 62vh; }
  .cart-items { min-height: 36vh; }
}

/* ---- Billing on a phone: the bill sits right under the scanner, newest item first ---- */
.cart-item.just-added { animation: cart-flash 1.4s ease-out; }
@keyframes cart-flash { 0% { background: rgba(37, 99, 235, .28); } 100% { background: transparent; } }

@media (max-width: 860px) and (min-height: 521px) {
  /* let the two columns dissolve so the pieces can be re-ordered: scanner, search, customer, BILL, then the extra buttons */
  .pos-left, .pos-right { display: contents; }
  .scan-panel { order: 1; }
  .pos-search-row { order: 2; }
  .search-results { order: 3; }
  .last-scan { order: 4; }
  .customer-pill { order: 5; padding: 8px 10px; gap: 10px; }
  .customer-pill .cp-avatar { width: 36px; height: 36px; font-size: 1rem; }
  .customer-pill .cp-name { font-size: 0.98rem; }
  .customer-pill .cp-btn { padding: 8px 14px; }
  .cart-panel { order: 6; min-height: 0; }
  .pos-tools { order: 7; }
  .cart-items { min-height: 18vh; }
}

/* ---- "Last added" strip (computer only): small, one block, name + price + stock ---- */
.last-scan { flex: none; align-self: stretch; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px; border-style: solid; border-color: rgba(15,118,110,.3);
  background: rgba(15,118,110,.07); border-radius: 10px; }
.last-scan .ls-label { font-size: 0.66rem; }
.last-scan .ls-big { font-size: 1rem; font-weight: 700; line-height: 1.25; }
.last-scan .ls-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
.last-scan .ls-stats .ls-code { font-size: 0.8rem; font-weight: 600; letter-spacing: 0; }
@media (max-width: 860px) and (min-height: 521px) {
  .last-scan { display: none !important; }          /* phones: the bill needs the room */
}

/* ---- Billing, computer screens: all products under the buttons, click to add ---- */
.pos-grid-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pos-grid-wrap .pos-product-grid { flex: 1; min-height: 0; max-height: none; padding-bottom: 4px; }
.pos-grid-wrap .pos-product-card { min-height: 78px; padding: 10px 12px; }
.pos-grid-wrap .pos-product-card:active { transform: scale(.98); }
@media (min-width: 861px), (max-height: 520px) {
  #searchResults { display: none !important; }      /* the grid below already follows what is typed */
}
@media (max-width: 860px) and (min-height: 521px) {
  .pos-grid-wrap { display: none !important; }       /* phones: scan or search; the bill needs the room */
}

/* ---- Product photos ---- */
.photo-row { display: flex; gap: 14px; align-items: center; }
.photo-box { width: 84px; height: 84px; flex: none; border: 2px dashed var(--border); border-radius: 12px; background: var(--surface-alt);
  display: flex; align-items: center; justify-content: center; font-size: 1.8rem; overflow: hidden; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { flex: 1; min-width: 0; }
.crop-view { position: relative; width: 260px; height: 260px; margin: 0 auto 12px; overflow: hidden; background: #111; border-radius: 10px;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.crop-view img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.crop-view::after { content: ''; position: absolute; inset: 0; border: 2px solid #fff; border-radius: 10px; pointer-events: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.35); }
.crop-zoom { display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 4px; }
.crop-zoom input[type=range] { width: 200px; padding: 0; }
.p-thumb { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; vertical-align: middle; margin-right: 6px; border: 1px solid var(--border); }

/* the grid cards: number badge, optional small picture */
.pos-grid-wrap .pos-product-card { position: relative; flex-direction: row; align-items: center; gap: 10px; }
.pos-grid-wrap .pos-product-card .pcard-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; text-align: left; }
.pos-grid-wrap .pos-product-card .pcard-text { padding-right: 16px; }
.pos-grid-wrap .pos-product-card .pname { overflow-wrap: anywhere; }
.pcard-img { width: 46px; height: 46px; flex: none; border-radius: 8px; object-fit: cover; background: var(--surface-alt); }
.pnum { position: absolute; top: 4px; right: 6px; font-size: 0.68rem; font-weight: 800; color: var(--text-muted); background: var(--surface-alt);
  border-radius: 999px; min-width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.pos-grid-wrap .pos-product-grid { grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); }

/* ================= Products & Inventory on a phone: one card per product ================= */
.p-row .c-name { font-weight: 600; }
.p-row .c-name .p-thumb { width: 34px; height: 34px; }
@media (max-width: 700px) and (min-height: 521px) {
  /* toolbar: search on its own line, then the buttons */
  .p-toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .p-toolbar .p-search { max-width: none !important; width: 100%; }
  .p-toolbar .p-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .p-toolbar .p-tools .btn { justify-content: center; width: 100%; }
  .p-toolbar .p-tools #btnAddProduct { grid-column: 1 / -1; order: -1; padding: 13px; font-size: 1rem; }

  /* the list: cards instead of a wide table */
  .p-list-card { background: transparent; border: 0; padding: 0; box-shadow: none; }
  #productsTable { min-width: 0 !important; display: block; font-size: 0.9rem; }
  #productsTable thead { display: none; }
  #productsTable tbody { display: block; }
  #productsTable tr.p-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start; padding: 12px 14px;
    margin-bottom: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
  #productsTable tr.p-row:hover td { background: transparent; }
  #productsTable td { display: block; padding: 0; border: 0; text-align: left !important; }
  #productsTable td.c-name { grid-column: 1; grid-row: 1; display: flex; align-items: center; gap: 10px; font-size: 1.02rem; font-weight: 700; line-height: 1.25; }
  #productsTable td.c-name .p-thumb { width: 44px; height: 44px; margin: 0; flex: none; }
  #productsTable td.c-status { grid-column: 2; grid-row: 1; }
  #productsTable td.c-code { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-muted); }
  #productsTable td.c-code .bc { font-family: 'Courier New', monospace; }
  #productsTable td.c-cat { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-muted); }
  #productsTable td.c-cat::before { content: '📁 '; }
  /* buy / sell / stock side by side as three small boxes */
  #productsTable td.c-buy, #productsTable td.c-sell, #productsTable td.c-stock { grid-column: auto; }
  #productsTable tr.p-row { grid-template-columns: 1fr 1fr 1fr; }
  #productsTable td.c-name { grid-column: 1 / span 2; }
  #productsTable td.c-status { grid-column: 3; justify-self: end; }
  #productsTable td.c-code, #productsTable td.c-cat { grid-column: 1 / -1; }
  #productsTable td.c-buy, #productsTable td.c-sell, #productsTable td.c-stock { background: var(--surface-alt); border-radius: 10px; padding: 7px 10px; margin-top: 4px; font-weight: 700; }
  #productsTable td[data-label].c-buy::before, #productsTable td[data-label].c-sell::before, #productsTable td[data-label].c-stock::before {
    content: attr(data-label); display: block; font-size: 0.66rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
  #productsTable td.c-act { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 6px; }
  #productsTable td.c-act .btn { flex: 1; justify-content: center; padding: 10px; }
  #productsTable td[colspan] { grid-column: 1 / -1; }
}
.p-row td.c-cat:empty::after { content: '—'; }
.p-row td.c-code:empty::after { content: ''; }
@media (max-width: 700px) and (min-height: 521px) {
  #productsTable td.c-cat:empty, #productsTable td.c-code:empty { display: none; }
  #productsTable td.c-cat:empty::after { content: none; }
}
@media (max-width: 860px) and (min-height: 521px) {
  .form-row > .form-group[style*="span 2"] { grid-column: 1 / -1 !important; }   /* wide fields must not make the other fields narrower */
}

/* product numbers in the Products list: a column on computers, a small badge on a phone */
.p-row td.c-num { color: var(--text-muted); font-weight: 700; width: 42px; }
@media (max-width: 700px) and (min-height: 521px) {
  #productsTable td.c-num { position: absolute; top: 10px; left: 10px; z-index: 1; width: auto; min-width: 22px; height: 22px; padding: 0 6px;
    display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.72rem; font-weight: 800; }
  #productsTable tr.p-row { position: relative; padding-top: 18px; }
  #productsTable td.c-name { padding-left: 22px; }
}

/* ---- shop logo ---- */
.brand .brand-logo { width: 34px; height: 34px; border-radius: 8px; object-fit: contain; background: #fff; flex: none; }
.inv-logo { max-height: 64px; max-width: 160px; object-fit: contain; display: block; margin-bottom: 6px; }
.inv-logo.th { max-height: 48px; margin: 0 auto 4px; }

/* ================= Billing on a phone: search + scan on one row, and a photo product picker ================= */
.pick-btn, .pick-overlay { display: none; }
@media (max-width: 860px) and (min-height: 521px) {
  /* one grid: search (75%) and the scan button (25%) share the first row; everything else is full width below */
  .pos-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: 0 10px; align-items: stretch; max-width: 100%; }
  .pos-layout > *, .cart-panel, .cart-items { min-width: 0; }
  .scan-panel, .scan-bar { display: contents; }
  .pos-search-row { grid-area: 1 / 1 / 2 / 2; margin-bottom: 10px; min-width: 0; }
  #btnScan { grid-area: 1 / 2 / 2 / 3; margin-bottom: 10px; }
  #scannerRegion { grid-area: 2 / 1 / 3 / -1; margin: 0 0 10px; max-width: none; }
  #btnTorch { grid-area: 2 / 1 / 3 / -1; justify-self: end; align-self: start; margin: 6px 6px 0 0; z-index: 4; min-width: 44px; }
  .pick-btn { display: flex; grid-area: 3 / 1 / 4 / -1; margin-bottom: 10px; justify-content: center; padding: 12px; font-weight: 700; }
  .pick-btn .pick-count { color: var(--primary); margin-left: 6px; }
  .search-results { grid-area: 4 / 1 / 5 / -1; margin-bottom: 10px; }
  .customer-pill { grid-area: 5 / 1 / 6 / -1; margin-bottom: 10px; }
  .cart-panel { grid-area: 6 / 1 / 7 / -1; margin-bottom: 10px; }
  .pos-tools { grid-area: 7 / 1 / 8 / -1; margin-bottom: 10px; }

  /* the scan button is a quarter of the row: just a camera and one short word */
  .scan-bar #btnScan { font-size: 0; padding: 0; min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; border-radius: 12px; }
  .scan-bar #btnScan::before { content: '📷'; font-size: 1.35rem; line-height: 1; }
  .scan-bar #btnScan::after { content: 'Scan'; font-size: 0.74rem; font-weight: 800; line-height: 1; }
  .scan-bar #btnScan[data-state="on"]::before { content: '⏹'; }
  .scan-bar #btnScan[data-state="on"]::after { content: 'Stop'; }
  .pos-search-row input { padding: 15px 10px 15px 38px; font-size: 1rem; }

  /* the photo product picker: full screen, stays open until Done */
  .pick-overlay { position: fixed; inset: 0; z-index: 240; background: var(--bg); flex-direction: column; }
  .pick-overlay.open { display: flex; }
  body.pick-open { overflow: hidden; }
  .pick-head { display: flex; gap: 8px; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 10px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .pick-hint { padding: 7px 12px; font-size: 0.78rem; color: var(--text-muted); }
  .pick-grid { flex: 1; overflow-y: auto; padding: 0 10px 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-content: start; -webkit-overflow-scrolling: touch; }
  .pick-card { position: relative; background: var(--surface); border: 2px solid var(--border); border-radius: 14px; padding: 12px 8px 10px; display: flex; flex-direction: column;
    align-items: center; text-align: center; gap: 2px; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .pick-card.in-bill { border-color: var(--primary); background: rgba(15, 118, 110, .08); }
  .pick-card.tapped { animation: pick-flash .35s ease-out; }
  .pick-img { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; background: var(--surface-alt); }
  .pick-initial { display: flex; align-items: center; justify-content: center; font-size: 1.9rem; font-weight: 800; color: var(--primary); }
  .pick-name { font-weight: 700; font-size: 0.92rem; line-height: 1.2; margin-top: 5px; overflow-wrap: anywhere; }
  .pick-price { color: var(--primary); font-weight: 800; }
  .pick-stock { font-size: 0.72rem; color: var(--text-muted); }
  .pick-stock.low { color: var(--warning); font-weight: 700; }
  .pick-stock.out { color: var(--danger); font-weight: 700; }
  .pick-qty { position: absolute; top: 6px; right: 6px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px; background: var(--primary); color: #fff;
    font-weight: 800; font-size: 0.8rem; align-items: center; justify-content: center; }
  .pick-minus { position: absolute; top: 6px; left: 6px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
    color: var(--danger); font-size: 1.4rem; font-weight: 800; line-height: 1; align-items: center; justify-content: center; padding: 0; }
  .pick-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); }
  .pick-foot .btn { padding: 13px 28px; }
}
@keyframes pick-flash { 0% { transform: scale(.95); background: rgba(37, 99, 235, .25); } 100% { transform: scale(1); } }

/* ---- "this barcode is already used" notice in the product form ---- */
.barcode-warn { margin-top: 6px; padding: 9px 11px; border-radius: 9px; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; font-size: 0.85rem; line-height: 1.5; }
.barcode-warn .btn { margin: 4px 4px 0 0; }
[data-theme="dark"] .barcode-warn { background: #450a0a; border-color: #7f1d1d; color: #fecaca; }

/* ================= Phone: customer card under the bill (slimmer), and a nicer "Choose products" button ================= */
@media (max-width: 860px) and (min-height: 521px) {
  .cart-panel { grid-area: 5 / 1 / 6 / -1; }
  .customer-pill { grid-area: 6 / 1 / 7 / -1; padding: 6px 10px; gap: 9px; border-radius: 12px; min-height: 0; }
  .customer-pill .cp-avatar { width: 30px; height: 30px; font-size: 0.9rem; box-shadow: none; }
  .customer-pill .cp-name { font-size: 0.92rem; }
  .customer-pill .cp-label { font-size: 0.62rem; }
  .customer-pill:not(.has-customer) .cp-label { display: none; }          /* "Walk-in Customer" says it all */
  .customer-pill .cp-btn { padding: 6px 12px; font-size: 0.8rem; }
  .customer-pill .cp-clear { width: 28px; height: 28px; font-size: 0.8rem; }

  .pick-btn { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; cursor: pointer; color: #fff; padding: 11px 14px; border-radius: 14px;
    background: linear-gradient(120deg, #0f766e 0%, #0e9aa7 55%, #2563eb 100%); box-shadow: 0 6px 16px rgba(15, 118, 110, .35); position: relative; overflow: hidden; }
  .pick-btn::after { content: ''; position: absolute; right: -30px; top: -30px; width: 100px; height: 100px; border-radius: 50%; background: rgba(255, 255, 255, .12); pointer-events: none; }
  .pick-btn:active { transform: scale(.985); }
  .pick-btn .pb-ic { width: 38px; height: 38px; border-radius: 12px; background: rgba(255, 255, 255, .22); display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex: none; }
  .pick-btn .pb-tx { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
  .pick-btn .pb-tx b { font-size: 1rem; }
  .pick-btn .pb-tx small { font-size: 0.74rem; opacity: .9; font-weight: 600; }
  .pick-btn .pick-count { margin: 0; background: #fff; color: #0f766e; font-weight: 800; font-size: 0.74rem; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
  .pick-btn .pick-count:empty { display: none; }
  .pick-btn .pb-go { font-size: 1.7rem; line-height: 1; opacity: .9; }
}

/* ---- kg / litre: add or change by AMOUNT ---- */
.amt { cursor: pointer; background: rgba(15, 118, 110, .12); border-radius: 999px; padding: 2px 9px; text-decoration: none; display: inline-block; }
.amt:hover { background: rgba(15, 118, 110, .22); }
.pick-price.amt { padding: 5px 12px; font-size: 0.9rem; }
.ci-amount { border: 1px dashed var(--primary); background: rgba(15, 118, 110, .08); color: inherit; font: inherit; font-weight: 700; border-radius: 8px; padding: 4px 8px; cursor: pointer; white-space: nowrap; }
.ci-amount:hover { background: rgba(15, 118, 110, .18); }
.amt-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.amt-preview { background: var(--surface-alt); border-radius: 10px; padding: 10px 12px; font-size: 1.02rem; min-height: 48px; }

/* phone: the customer card now lives inside the bill's button area, right above Checkout */
@media (max-width: 860px) and (min-height: 521px) {
  .pos-actions .customer-pill { grid-area: auto; grid-column: 1 / -1; margin: 0; order: 1; }
  .pos-actions .btn-checkout { order: 2; }
}

/* ---- Phone: bill rows. Name, amount and remove share the first line; the quantity controls get the whole second line,
        so kg / litre rows (kg + g boxes) never wrap and the amount lines up with the name ---- */
@media (max-width: 860px) and (min-height: 521px) {
  .cart-item { grid-template-columns: 24px minmax(0, 1fr) auto auto; row-gap: 8px; column-gap: 8px; align-items: start; }
  .cart-item > :nth-child(1) { grid-row: 1; grid-column: 1; }
  .cart-item > :nth-child(2) { grid-row: 1; grid-column: 2; min-width: 0; }
  .cart-item > :nth-child(4) { grid-row: 1; grid-column: 3; align-self: center; justify-self: end; text-align: right; font-weight: 700; }
  .cart-item > :nth-child(5) { grid-row: 1; grid-column: 4; align-self: center; }
  .cart-item > :nth-child(3) { grid-row: 2; grid-column: 1 / -1; }
  .cart-item .qty-control { flex-wrap: nowrap; gap: 6px; align-items: center; }
  .cart-item .ci-amount { padding: 5px 8px; font-size: 0.95rem; }
}

/* ================= Dashboard on a phone: a big "today" card, compact 2-column tiles, small charts, bills as cards ================= */
@media (max-width: 860px) and (min-height: 521px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .kpi-card { padding: 12px 14px; border-radius: 14px; position: relative; overflow: hidden; }
  .kpi-card .kpi-label { font-size: 0.66rem; line-height: 1.25; }
  .kpi-card .kpi-value { font-size: 1.2rem; margin-top: 4px; word-break: break-word; }

  /* today's sales: the big card at the top */
  .kpi-grid > .kpi-card:nth-child(1) { grid-column: 1 / -1; background: linear-gradient(135deg, #0f766e, #2563eb); color: #fff; border: 0; padding: 16px 18px; box-shadow: 0 8px 20px rgba(15, 118, 110, .3); }
  .kpi-grid > .kpi-card:nth-child(1) .kpi-label { color: rgba(255, 255, 255, .85); font-size: 0.74rem; }
  .kpi-grid > .kpi-card:nth-child(1) .kpi-value { font-size: 2rem; color: #fff; }
  /* money owed to the shop: also full width, warm */
  .kpi-grid > .kpi-card:nth-child(4) { grid-column: 1 / -1; border-left: 4px solid var(--warning); }
  /* a little colour stripe on the others */
  .kpi-grid > .kpi-card:nth-child(n+5):nth-child(-n+8) { border-top: 3px solid var(--border); }
  .kpi-grid > .kpi-card:nth-child(6) { border-top-color: var(--warning); }
  .kpi-grid > .kpi-card:nth-child(7) { border-top-color: var(--danger); }
  /* cash / UPI / credit: one tidy row of three */
  .kpi-grid > .kpi-card:nth-child(n+9) { padding: 10px 10px; }
  .kpi-grid > .kpi-card:nth-child(n+9) .kpi-value { font-size: 1rem; }

  .charts-grid { gap: 10px; margin-bottom: 14px; }
  .charts-grid .card { padding: 12px; }
  .charts-grid .card-title, .two-col .card-title { font-size: 0.95rem; margin-bottom: 8px; }
  .charts-grid canvas { max-height: 170px; }

  /* recent bills: one small card each */
  #recentTable { min-width: 0 !important; display: block; }
  #recentTable thead { display: none; }
  #recentTable tbody { display: block; }
  #recentTable tr.t-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 2px; border-bottom: 1px solid var(--border); align-items: center; }
  #recentTable tr.t-row:hover td { background: transparent; }
  #recentTable td { display: block; padding: 0; border: 0; text-align: left !important; }
  #recentTable td.c-inv { grid-column: 1; font-weight: 700; }
  #recentTable td.c-total { grid-column: 2; grid-row: 1; font-weight: 800; text-align: right !important; }
  #recentTable td.c-cust { grid-column: 1; font-size: 0.85rem; color: var(--text-muted); }
  #recentTable td.c-status { grid-column: 2; grid-row: 2; justify-self: end; }
  #recentTable td.c-date { grid-column: 1 / -1; font-size: 0.72rem; color: var(--text-muted); }
  #recentTable td[colspan] { grid-column: 1 / -1; }
  #topProductsTable { min-width: 0 !important; }
  .two-col .card { padding: 12px; }
}
@media (max-width: 860px) and (min-height: 521px) {
  .kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .kpi-grid > .kpi-card { grid-column: span 3; }
  .kpi-grid > .kpi-card:nth-child(1), .kpi-grid > .kpi-card:nth-child(4) { grid-column: 1 / -1; }
  .kpi-grid > .kpi-card:nth-child(n+9) { grid-column: span 2; }
  .kpi-grid > .kpi-card:nth-child(n+9) .kpi-label { font-size: 0.6rem; }
}

/* ---------- Hold / Held / Find-Edit Invoice: big, coloured, easy to spot ---------- */
.pos-tools { gap: 10px; }
.tool-btn { position: relative; flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 11px 14px; border: 0; border-radius: 14px;
  color: #fff; cursor: pointer; text-align: left; font-family: inherit; box-shadow: 0 4px 12px rgba(0,0,0,.18); transition: transform .12s, box-shadow .12s, filter .12s; }
.tool-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(0,0,0,.25); filter: brightness(1.06); }
.tool-btn:active { transform: scale(.97); }
.tool-ic { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.25); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.tool-tx { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.tool-tx b { font-size: 1rem; font-weight: 800; letter-spacing: .2px; }
.tool-tx small { font-size: .7rem; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-hold { background: linear-gradient(135deg, #ff9f1c, #f2561d); }
.tool-held { background: linear-gradient(135deg, #7b5cff, #3d4cff); }
.tool-find { background: linear-gradient(135deg, #12c2a0, #0a7fb5); flex-basis: 100%; }
.held-badge { position: absolute; top: -7px; right: -5px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; background: #ff2d55; color: #fff;
  font-weight: 800; font-size: .8rem; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); animation: heldPulse 1.8s infinite; }
@keyframes heldPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@media (min-width: 700px) { .tool-find { flex-basis: 0; } }
@media (max-width: 699px) and (min-height: 521px) { .tool-btn { padding: 9px 10px; gap: 8px; } .tool-ic { width: 32px; height: 32px; font-size: 1.1rem; } .tool-tx small { display: none; } .tool-find .tool-tx small { display: block; } }

/* ---------- Shop that does not track stock ---------- */
body.no-stock .stock-field, body.no-stock .stock-kpi, body.no-stock .th-stock,
body.no-stock #productsTable td.c-stock, body.no-stock .pstock, body.no-stock .pick-stock, body.no-stock #productsTable [data-stock] { display: none !important; }

/* =====================================================================
   Reports, Customers, Khata / Udhaar, Settings: a cleaner, friendlier look
   ===================================================================== */
.page-reports .card, .page-customers .card, .page-khata .card, .page-settings .card { border-radius: 16px; box-shadow: 0 2px 10px rgba(16,24,40,.07); }
.page-reports .card-title, .page-khata .card-title, .page-settings .card-title { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; font-weight: 800;
  padding-bottom: 10px; margin-bottom: 14px; border-bottom: 2px solid var(--border); position: relative; }
.page-reports .card-title::after, .page-khata .card-title::after, .page-settings .card-title::after { content: ''; position: absolute; left: 0; bottom: -2px; width: 56px; height: 2px; background: var(--primary); }
.page-reports .data-table th, .page-customers .data-table th, .page-khata .data-table th, .page-settings .data-table th { background: var(--surface-alt); font-size: .72rem; letter-spacing: .05em; padding: 9px 12px; }
.page-reports .data-table th:first-child, .page-customers .data-table th:first-child, .page-khata .data-table th:first-child { border-radius: 8px 0 0 8px; }
.page-reports .data-table th:last-child, .page-customers .data-table th:last-child, .page-khata .data-table th:last-child { border-radius: 0 8px 8px 0; }
.page-reports .data-table tbody tr:nth-child(even) td, .page-customers .data-table tbody tr:nth-child(even) td, .page-khata .data-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-alt) 45%, transparent); }
.page-reports .card, .page-khata .card, .page-customers .card { overflow-x: auto; }

/* Reports */
.page-reports .card.mb-12 form.form-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.page-reports .chip-row .chip { padding: 9px 18px; font-size: .9rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); transition: transform .12s; text-decoration: none; color: var(--text); }
.page-reports .chip-row .chip:hover { transform: translateY(-2px); }
.page-reports .chip-row .chip.active { background: linear-gradient(135deg, #0f766e, #2563eb); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(15,118,110,.35); }
.page-reports .kpi-card { border: 0; border-top: 4px solid var(--primary); border-radius: 16px; box-shadow: 0 2px 10px rgba(16,24,40,.08); }
.page-reports .kpi-card:nth-child(2) { border-top-color: #2563eb; }
.page-reports .kpi-card:nth-child(3) { border-top-color: var(--warning); }
.page-reports .kpi-card:nth-child(4) { border-top-color: #7c3aed; }
.page-reports .kpi-card:nth-child(5) { border-top-color: var(--danger); }
.page-reports .kpi-value { font-size: 1.5rem; }

/* Customers */
.page-customers .search-box input { border-radius: 999px; padding: 11px 18px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.page-customers #btnAddCustomer { border-radius: 999px; padding: 11px 20px; font-weight: 800; box-shadow: 0 4px 12px rgba(15,118,110,.35); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; margin-right: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, #0f766e, #2563eb); color: #fff; font-weight: 800; vertical-align: middle; }
.page-customers td.c-name a { font-weight: 700; color: var(--text); text-decoration: none; }
.page-customers td.c-name { white-space: nowrap; }

/* Khata */
.page-khata #khataTotal { font-size: 2rem; }
.page-khata .card.mb-12:first-of-type { background: linear-gradient(135deg, #f59e0b, #dc2626); color: #fff; border: 0; box-shadow: 0 8px 20px rgba(220,38,38,.3); }
.page-khata .card.mb-12:first-of-type .card-title { color: #fff; border-color: rgba(255,255,255,.3); }
.page-khata .card.mb-12:first-of-type .card-title::after { background: #fff; }
.page-khata .card.mb-12:first-of-type .kpi-value, .page-khata .card.mb-12:first-of-type .kpi-label, .page-khata .card.mb-12:first-of-type h2, .page-khata .card.mb-12:first-of-type .text-muted { color: #fff; }
.page-khata #khataRows .badge-warning { background: #fee2e2; color: #b91c1c; font-size: .85rem; padding: 4px 12px; }
.page-khata #btnRecordPayment { background: linear-gradient(135deg, #16a34a, #0f766e); border: 0; border-radius: 12px; font-weight: 800; box-shadow: 0 4px 12px rgba(22,163,74,.35); }
.page-khata #btnWhatsappReminder, .page-khata #btnStatement { border-radius: 12px; font-weight: 700; }
.page-khata #btnWhatsappReminder { background: #25d366; color: #fff; border-color: #25d366; }
.page-khata #ledgerTable td:nth-child(3) { color: var(--danger); font-weight: 600; }
.page-khata #ledgerTable td:nth-child(4) { color: var(--success); font-weight: 600; }

/* Settings */
.page-settings .two-col { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; gap: 16px; }
.page-settings .card { padding: 20px; }
.page-settings .totals-row { padding: 9px 0; border-bottom: 1px dashed var(--border); }
.page-settings .totals-row:last-of-type { border-bottom: 0; }
.page-settings .form-group label { font-weight: 700; font-size: .85rem; }
.page-settings input[type=text], .page-settings input[type=number], .page-settings input[type=email], .page-settings input[type=password], .page-settings select, .page-settings textarea {
  border-radius: 10px; padding: 10px 12px; }
.page-settings .card .btn-primary { border-radius: 10px; font-weight: 800; }

@media (max-width: 699px) and (min-height: 521px) {
  .page-reports .card.mb-12 form.form-row { grid-template-columns: 1fr 1fr; }
  .page-reports .chip-row { display: grid; grid-template-columns: 1fr 1fr; }
  .page-reports .chip-row .chip { text-align: center; }
  .page-reports .two-col { grid-template-columns: 1fr; }
  .page-settings .two-col { grid-template-columns: 1fr; }
  .page-settings .card { padding: 14px; }
  .page-khata #khataTotal { font-size: 1.7rem; }
  .page-khata .flex.gap-8.mt-12 { flex-wrap: wrap; }
  .page-khata .flex.gap-8.mt-12 > * { flex: 1 1 45%; justify-content: center; text-align: center; }
  .page-khata #btnRecordPayment { flex-basis: 100%; padding: 12px; }

  /* the lists become cards on a phone */
  #customersTable thead, .page-khata .card table:not(#ledgerTable) thead, #ledgerTable thead { display: none; }
  #customersTable, #customersTable tbody, .page-khata .card table:not(#ledgerTable), .page-khata .card table:not(#ledgerTable) tbody { display: block; width: 100%; }
  #customersTable tr, .page-khata #khataRows tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; padding: 12px; margin-bottom: 10px;
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
  #customersTable td, .page-khata #khataRows td { display: block; border: 0 !important; padding: 2px 0 !important; background: transparent !important; }
  #customersTable td:nth-child(1) { grid-column: 1; grid-row: 1; }
  #customersTable td:nth-child(2) { grid-column: 1; grid-row: 2; color: var(--text-muted); font-size: .85rem; }
  #customersTable td:nth-child(3) { grid-column: 1; grid-row: 3; color: var(--text-muted); font-size: .75rem; }
  #customersTable td:nth-child(4) { grid-column: 2; grid-row: 1; text-align: right; }
  #customersTable td:nth-child(5) { grid-column: 2; grid-row: 2 / 4; text-align: right; }
  #customersTable td:nth-child(5) .btn { padding: 6px 14px; border-radius: 10px; }
  #customersTable td[colspan], .page-khata #khataRows td[colspan] { grid-column: 1 / -1; }
  .page-khata #khataRows tr { border-left-color: var(--danger); }
  .page-khata #khataRows td:nth-child(1) { grid-column: 1; font-weight: 800; }
  .page-khata #khataRows td:nth-child(2) { grid-column: 1; color: var(--text-muted); font-size: .85rem; }
  .page-khata #khataRows td:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; }
  .page-khata #khataRows td:nth-child(4) { grid-column: 2; grid-row: 2; text-align: right; }
  .page-customers .card { background: transparent; border: 0; box-shadow: none; padding: 0; }

  #ledgerTable, #ledgerTable tbody { display: block; width: 100%; }
  #ledgerTable tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 2px 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface-alt); border-radius: 12px; }
  #ledgerTable td { display: block; border: 0 !important; padding: 1px 0 !important; background: transparent !important; text-align: left !important; font-size: .85rem; }
  #ledgerTable td:nth-child(1) { grid-column: 1 / 3; font-weight: 700; }
  #ledgerTable td:nth-child(2) { grid-column: 3; text-align: right !important; }
  #ledgerTable td:nth-child(3)::before { content: 'Debit '; color: var(--text-muted); font-weight: 400; }
  #ledgerTable td:nth-child(4)::before { content: 'Credit '; color: var(--text-muted); font-weight: 400; }
  #ledgerTable td:nth-child(5)::before { content: 'Bal '; color: var(--text-muted); font-weight: 400; }
  #ledgerTable td:nth-child(6) { grid-column: 1 / -1; font-size: .78rem; }
  #ledgerTable td[colspan] { grid-column: 1 / -1; }
  #ledgerTable td:nth-child(6):empty { display: none; }
}
@media (max-width: 699px) and (min-height: 521px) {
  #customersTable, #ledgerTable, .page-khata .card table.data-table { min-width: 0 !important; }
  .page-reports .data-table { min-width: 0; }
}
.page-settings .card { overflow-x: auto; }

/* full screen: keep clear of the camera notch */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.topbar { padding-top: calc(8px + env(safe-area-inset-top)); }


/* =====================================================================
   A phone held sideways shows the DESKTOP page, shrunk to fit (the script in includes/layout_top.php sets html.zd and
   --vh, the screen height in the page's own units: the vh unit does not follow a shrunk page).
   ===================================================================== */
html.zd .app-shell { min-height: var(--vh); }
html.zd .sidebar { height: var(--vh); }
html.zd .modal { max-height: calc(var(--vh) * .9); }
html.zd .pos-layout { height: calc(var(--vh) - 96px); min-height: 0; }
html.zd .page-content { padding: 14px; }
html.zd .pos-right { overflow-y: auto; }          /* the bill stays where it is; only its own list scrolls */
html.zd .pos-left { overflow: hidden; }

/* sideways phone: slimmer Hold / Held / Find-Edit buttons and customer card */
@media (max-height: 520px) {
  .pos-tools { gap: 6px; flex-wrap: nowrap; }
  .tool-btn { padding: 5px 9px; gap: 7px; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
  .tool-ic { width: 24px; height: 24px; font-size: .95rem; }
  .tool-tx b { font-size: .8rem; }
  .tool-tx small { display: none !important; }
  .tool-find { flex-basis: 0; }
  .tool-find .tool-tx b { white-space: nowrap; }
  .held-badge { min-width: 18px; height: 18px; font-size: .65rem; top: -5px; right: -3px; }
  .customer-pill { padding: 5px 9px; gap: 8px; }
  .customer-pill .cp-avatar { width: 28px; height: 28px; }
  .customer-pill .cp-label { font-size: .58rem; }
  .customer-pill .cp-name { font-size: .88rem; }
  .customer-pill .btn { padding: 5px 12px; font-size: .76rem; }
}

/* sideways phone: search takes 75% and Scan 25% of one row; the customer card is just the name and Select */
@media (max-height: 520px) {
  .pos-left { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); grid-template-rows: auto auto auto auto auto minmax(0, 1fr); gap: 0 8px; align-content: start; }
  .pos-left > * { grid-column: 1 / -1; min-width: 0; margin-bottom: 8px; }
  .scan-panel, .scan-bar { display: contents; }
  .pos-search-row { grid-area: 1 / 1 / 2 / 2; }
  #btnScan { grid-area: 1 / 2 / 2 / 3; margin-bottom: 8px; }
  #btnTorch { grid-area: 2 / 1 / 3 / -1; justify-self: end; margin: 0 0 6px; min-width: 44px; }
  #scannerRegion { grid-area: 3 / 1 / 4 / -1; margin: 0 0 8px; max-width: none; }
  .search-results { grid-area: 4 / 1 / 5 / -1; }
  .pos-tools { grid-area: 5 / 1 / 6 / -1; }
  .pos-grid-wrap { grid-area: 6 / 1 / 7 / -1; min-height: 0; margin-bottom: 0; }
  .scan-bar #btnScan { font-size: 0; padding: 0; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; border-radius: 12px; }
  .scan-bar #btnScan::before { content: '📷'; font-size: 1.15rem; line-height: 1; }
  .scan-bar #btnScan::after { content: 'Scan'; font-size: .72rem; font-weight: 800; line-height: 1; }
  .scan-bar #btnScan[data-state="on"]::before { content: '⏹'; }
  .scan-bar #btnScan[data-state="on"]::after { content: 'Stop'; }
  .pos-search-row input { padding: 11px 10px 11px 36px; font-size: .95rem; }
  .customer-pill .cp-label { display: none; }
}

/* =====================================================================
   Billing screen on a computer or a sideways phone: the page itself does not move. The menu, top bar, the bill and the
   buttons stay where they are; only the product list in the middle scrolls (and the bill's own list of items).
   ===================================================================== */
:root { --vh100: 100vh; }
@supports (height: 100dvh) { :root { --vh100: 100dvh; } }
html.zd { --vh100: var(--vh); }
@media (min-width: 861px), (max-height: 520px) {
  body.page-pos { height: var(--vh100); overflow: hidden; }
  body.page-pos .app-shell { height: var(--vh100); min-height: 0; }
  body.page-pos .sidebar { height: var(--vh100); }
  body.page-pos .main-area { height: var(--vh100); overflow: hidden; }
  body.page-pos .page-content { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  body.page-pos .page-content > * { flex-shrink: 0; }
  body.page-pos .page-content > .pos-layout { flex: 1 1 auto; height: auto; min-height: 0; }
  body.page-pos .pos-left, body.page-pos .pos-right { min-height: 0; }
  body.page-pos .cart-items { min-height: 48px; }
  body.page-pos .pos-grid-wrap { overflow: hidden; }
}
@media (max-height: 520px) {
  body.page-pos .topbar { padding-top: 3px; padding-bottom: 3px; }
  body.page-pos .page-title { font-size: .95rem; }
  body.page-pos .page-content { padding: 6px 10px; }
  body.page-pos .pos-right { overflow-y: auto; }
  body.page-pos .cart-header { padding: 3px 12px; }
  body.page-pos .cart-totals { padding: 3px 12px; font-size: .8rem; }
  body.page-pos .cart-totals .totals-row { padding: 0; }
  body.page-pos .cart-totals .totals-row.grand { font-size: 1rem; margin-top: 1px; padding-top: 2px; }
  body.page-pos .cart-totals select, body.page-pos .cart-totals input { padding: 1px 4px; font-size: .8rem; }
  body.page-pos .pos-actions { padding: 4px 10px 6px; gap: 4px; }
  body.page-pos #paymentMethodChips .chip { padding: 3px 9px; font-size: .74rem; }
  body.page-pos .pos-actions .btn-checkout { padding: 8px 18px; font-size: .95rem; }
}

/* The bill is a full-height column on the right edge (the top bar and the menu only span the part beside it). */
@media (min-width: 861px), (max-height: 520px) {
  body.page-pos .main-area { margin-right: 360px; }
  body.page-pos .pos-layout { grid-template-columns: minmax(0, 1fr); }
  body.page-pos .pos-right {
    position: fixed; top: 0; right: 0; width: 360px; height: var(--vh100); z-index: 12; box-sizing: border-box;
    padding: 8px 10px 8px 8px; padding-right: calc(10px + env(safe-area-inset-right)); background: var(--bg); border-left: 1px solid var(--border);
    overflow: hidden; display: flex; flex-direction: column; gap: 6px;
  }
  body.page-pos .pos-right .cart-panel { flex: 1 1 auto; min-height: 0; }
  body.page-pos .pos-right .customer-pill { flex-shrink: 0; margin: 0; }
}
@media (max-height: 520px) {
  body.page-pos .pos-right { overflow: hidden; padding-top: 6px; padding-bottom: 6px; }
  body.page-pos .user-chip .role-badge, body.page-pos .user-chip-mobile { display: none; }
}

/* computer screens: the customer card is just the name and Select */
@media (min-width: 861px) { .customer-pill .cp-label { display: none; } }

/* computer screens: search takes 75% and Scan 25% of one row */
@media (min-width: 861px) {
  .pos-left { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); grid-template-rows: auto auto auto auto auto minmax(0, 1fr); gap: 0 10px; align-content: start; }
  .pos-left > * { grid-column: 1 / -1; min-width: 0; margin-bottom: 10px; }
  .scan-panel, .scan-bar { display: contents; }
  .pos-search-row { grid-area: 1 / 1 / 2 / 2; }
  #btnScan { grid-area: 1 / 2 / 2 / 3; margin-bottom: 10px; }
  #btnTorch { grid-area: 2 / 1 / 3 / -1; justify-self: end; margin: 0 0 6px; min-width: 44px; }
  #scannerRegion { grid-area: 3 / 1 / 4 / -1; margin: 0 0 10px; max-width: none; }
  .search-results { grid-area: 4 / 1 / 5 / -1; }
  .pos-tools { grid-area: 5 / 1 / 6 / -1; }
  .pos-grid-wrap { grid-area: 6 / 1 / 7 / -1; min-height: 0; margin-bottom: 0; }
  .scan-bar #btnScan { padding: 0 8px; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 6px; border-radius: 12px; font-size: 1rem; font-weight: 800; }
  .pos-search-row input { padding: 15px 14px 15px 42px; font-size: 1rem; }
}
@media (min-width: 861px) { .scan-bar #btnScan { font-size: .9rem; white-space: nowrap; } }

/* the scanner view is taller, so a barcode is caught sooner */
.scan-cam { height: 190px; max-width: 640px; }
@media (min-width: 861px) { .scan-cam { height: 200px; } }
@media (max-height: 520px) { .scan-cam { height: 150px; } }

/* khata ledger: the products of each invoice, under the line */
.ledger-bill { margin-top: 6px; padding: 6px 8px; border-left: 3px solid var(--primary); background: var(--surface-alt); border-radius: 6px; color: var(--text); }
.ledger-bill .lb-head { font-weight: 800; font-size: .74rem; color: var(--primary); margin-bottom: 2px; }
.ledger-bill .lb-row { display: flex; justify-content: space-between; gap: 10px; font-size: .78rem; padding: 1px 0; }
.ledger-bill .lb-row small { color: var(--text-muted); }

/* suggested products while typing: a small photo on phones only */
.sr-img { display: none; }
@media (max-width: 860px) and (min-height: 521px) {
  .sr-row { justify-content: flex-start; padding: 8px 12px; }
  .sr-img { display: flex; width: 48px; height: 48px; flex: none; border-radius: 10px; object-fit: cover; background: var(--surface-alt); align-items: center; justify-content: center; font-size: 1.3rem; }
  .sr-main { flex: 1; min-width: 0; }
  .sr-name { overflow-wrap: anywhere; }
  .sr-price { margin-left: auto; }
}
