:root {
  --surface-2: #f4f6f9;
  --card: #ffffff;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --border: #e1e0d9;
  --navy: #12233f;
  --blue: #2a78d6;
  --blue-dark: #1c5cab;
  --good: #0ca30c;
  --good-dark: #087a08;
  --critical: #d03b3b;
  --critical-dark: #a82e2e;
  --warn: #c7820c;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { min-height: 100vh; width: 100%; }

button { font-family: inherit; }

/* ----------------------------------------------------- Centered cards */
#screen-company, #screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.centerbox {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px 32px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(11,11,11,0.07);
  text-align: center;
}

.brand-icon { width: 56px; height: 56px; border-radius: 12px; margin-bottom: 8px; }

h1 { font-size: 21px; margin: 4px 0 10px; color: var(--navy); }

.centerbox input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  margin: 10px 0;
  text-align: center;
}
.centerbox input[type="text"]:focus { outline: 2px solid var(--blue); }

.company-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

.company-list button {
  padding: 14px 16px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.company-list button:active { background: #e8ebf0; }

.pin-dots { display: flex; justify-content: center; gap: 10px; margin: 6px 0 16px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); background: transparent; }
.pin-dot.filled { background: var(--navy); border-color: var(--navy); }

.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.pinpad button {
  padding: 16px 0;
  font-size: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.pinpad button:active { background: #e8ebf0; }
.pinpad-sub { font-size: 14px !important; color: var(--text-secondary); }

.error-text { color: var(--critical); font-size: 13px; margin: 0 0 12px; }

.btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
}
.btn-primary:disabled { background: var(--muted); cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.link-btn {
  display: inline-block;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}

/* --------------------------------------------------------- POS header */
.pos-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.pos-header-left { display: flex; flex-direction: column; line-height: 1.3; }
.pos-header-left .muted { color: rgba(255,255,255,0.7); font-size: 12px; }

.pos-header-right { display: flex; align-items: center; gap: 8px; }
.pos-header-right button {
  background: rgba(255,255,255,0.14);
  border: none;
  color: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.net-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.net-online { background: rgba(12,163,12,0.25); color: #baf0ba; }
.net-offline { background: rgba(208,59,59,0.3); color: #ffc9c9; }

.outbox-badge {
  background: rgba(199,130,12,0.35) !important;
  color: #ffe2a8 !important;
  font-weight: 700;
}

/* ----------------------------------------------------------- POS body */
.pos-body {
  display: flex;
  gap: 0;
  align-items: flex-start;
  min-height: calc(100vh - 56px);
}

.pos-catalog {
  flex: 1 1 auto;
  min-width: 0;
  padding: 14px;
}

.pos-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#product-search {
  flex: 1 1 auto;
  min-width: 0; /* without this, the input's intrinsic width stops it shrinking
                   to make room for the buttons beside it — overflows the row
                   instead of wrapping/shrinking, pushing them off-screen */
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}

.pos-search-row { flex-wrap: wrap; }

.scan-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.scanner-overlay.hidden {
  display: none;
}

.scanner-box {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

#scanner-viewport {
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  min-height: 260px;
}

.scanner-status {
  margin: 10px 0;
  font-size: 14px;
  color: var(--muted, #666);
}

/* ------------------------------------------------------------ Open Item */
.open-item-box { text-align: left; }
.open-item-box h3 { margin: 0 0 4px; }
.open-item-box label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 4px;
}
.open-item-box input[type="text"],
.open-item-box input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.open-item-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.open-item-actions button { flex: 1; }

/* Breadcrumb/back row shown only once drilled into a category — empty
   (and collapsed) at the top-level tile view and while searching. */
.category-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.category-row:empty { margin-bottom: 0; }

.back-row-btn {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--navy);
  cursor: pointer;
  white-space: nowrap;
}
.back-row-btn:active { background: #eef1f5; }

.back-row-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.category-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
}
.category-tile:active { background: #eef1f5; }
.category-tile .pname { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.category-tile .pstock { font-size: 12px; color: var(--muted); margin-top: 0; }

.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}
.product-card:active { background: #eef1f5; }

.product-card .pname {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-card .pprice { color: var(--navy); font-weight: 700; font-size: 15px; }
.product-card .pstock { font-size: 12px; color: var(--muted); margin-top: 4px; }
.product-card .pstock.low { color: var(--warn); }
.product-card .pstock.zero { color: var(--critical); }

.product-empty { padding: 30px; text-align: center; color: var(--muted); grid-column: 1 / -1; }

/* ------------------------------------------------------------- Cart */
.pos-cart {
  flex: 0 0 320px;
  max-width: 320px;
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 16px;
  position: sticky;
  top: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
}

.pos-cart h2 { font-size: 15px; margin: 0 0 10px; color: var(--text-secondary); }

.cart-lines { flex: 1; overflow-y: auto; margin-bottom: 10px; }

.cart-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.cart-line .cl-name { flex: 1; min-width: 0; }
.cart-line .cl-name .n { font-weight: 600; display: block; }
.cart-line .cl-name .p { color: var(--muted); font-size: 12px; }

.cl-price-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  text-decoration: underline dotted;
}
.cl-price-btn.custom { color: var(--blue-dark); font-weight: 600; text-decoration: none; }
.oi-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--navy, #12233f);
  border-radius: 999px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

.cl-price-edit { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.cl-price-edit .cl-price-input {
  width: 72px;
  padding: 4px 6px;
  font-size: 13px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}
.cl-price-edit button {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}
.cl-price-edit .cl-price-save { color: var(--good-dark); border-color: var(--good); }
.cl-price-edit .cl-price-cancel { color: var(--critical); }

.cart-qty { display: flex; align-items: center; gap: 4px; }
.cart-qty button {
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.cart-qty span { min-width: 20px; text-align: center; }

.cl-remove {
  background: none;
  border: none;
  color: var(--critical);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 4px;
}

.cart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.cart-total-row strong { font-size: 19px; color: var(--navy); }

.payment-methods {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.payment-methods button {
  padding: 10px 6px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}
.payment-methods button.selected {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.checkout-message { font-size: 13px; margin-top: 8px; text-align: center; color: var(--good-dark); }
.checkout-message.error { color: var(--critical); }

.adjust-total-link { width: 100%; text-align: center; font-size: 12px; margin-bottom: 4px; }

.adjust-total-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
}
.adjust-total-box input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  margin-bottom: 8px;
}
.adjust-total-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.adjust-total-actions .btn-secondary { padding: 9px; font-size: 13px; }
.adjust-total-hint { font-size: 11px; color: var(--muted); margin: 8px 0 0; }

/* ------------------------------------------------------- Sales report */
.report-body { max-width: 720px; margin: 0 auto; padding: 16px; }

.report-filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.report-range-presets, .report-scope {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.report-range-presets button, .report-scope button {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.report-range-presets button.selected, .report-scope button.selected {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.report-custom-range { display: flex; align-items: center; gap: 8px; }
.report-email-btn { align-self: flex-start; width: auto; padding: 8px 16px; font-size: 13px; }

.report-custom-range input[type="date"] {
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}

.report-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.report-stat {
  flex: 1 1 110px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.report-stat .rs-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.report-stat .rs-value { font-size: 17px; font-weight: 700; color: var(--navy); }
.report-stat-muted .rs-value { color: var(--muted); }

.report-subhead { font-size: 14px; color: var(--text-secondary); margin: 18px 0 8px; }

.report-items-table-wrap { overflow-x: auto; }
.report-items-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.report-items-table th, .report-items-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.report-items-table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.report-items-table td:nth-child(2), .report-items-table th:nth-child(2) { text-align: center; }
.report-items-table td:nth-child(3), .report-items-table th:nth-child(3) { text-align: right; }
.report-items-table tr:last-child td { border-bottom: none; }

.report-sales-list { display: flex; flex-direction: column; gap: 8px; }
.report-sale-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}
.report-sale-row.voided { opacity: 0.6; }
.rsr-top { display: flex; justify-content: space-between; font-weight: 600; }
.rsr-total { color: var(--navy); }
.rsr-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.rsr-flag { color: var(--warn); font-weight: 700; }
.rsr-items { color: var(--text-secondary); font-size: 12px; margin-top: 6px; }
.rsr-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }
.rsr-line.voided .rsr-line-text { text-decoration: line-through; opacity: 0.65; }
.rsr-line-text { flex: 1; }
.rsr-void-line {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--critical);
  color: var(--critical);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.rsr-void-line:hover { background: var(--critical); color: #fff; }
.rsr-void-sale {
  margin-top: 8px;
  background: none;
  border: 1px solid var(--critical);
  color: var(--critical);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.rsr-void-sale:hover { background: var(--critical); color: #fff; }

.report-empty { color: var(--muted); text-align: center; padding: 20px 0; font-size: 13px; }

/* ----------------------------------------------------------- Receipt */
.receipt-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.receipt {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  font-family: "Courier New", monospace;
  font-size: 13px;
}

.receipt h3 { text-align: center; margin: 0 0 2px; }
.receipt .rc-sub { text-align: center; color: var(--text-secondary); font-size: 12px; margin-bottom: 10px; }
.receipt hr { border: none; border-top: 1px dashed var(--border); margin: 10px 0; }
.receipt .rc-line { display: flex; justify-content: space-between; gap: 8px; margin: 3px 0; }
.receipt .rc-line .rc-l { flex: 1; }
.receipt .rc-total { display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; margin-top: 8px; }
.receipt .rc-flag { margin-top: 10px; padding: 8px; background: #fff3d6; color: var(--warn); border-radius: 6px; font-size: 12px; text-align: center; }

.receipt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 760px) {
  .pos-body { flex-direction: column; }
  .pos-cart {
    flex: none;
    max-width: none;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    position: static;
  }
}

@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: absolute; top: 0; left: 0; width: 100%; border: none; box-shadow: none; }
  .no-print { display: none !important; }
}
