/* ==========================================================================
   Base stylesheet — shared across the whole POS
   Loaded on every page BEFORE any module's own styles/*.css file,
   so module CSS can rely on these variables and override where needed.
   ========================================================================== */

:root {
  /* Brand / semantic colors */
  --pos-primary: #2563eb;
  --pos-primary-dark: #1d4ed8;
  --pos-success: #16a34a;
  --pos-danger: #dc2626;
  --pos-warning: #d97706;
  --pos-info: #0891b2;

  /* Sidebar/topbar theme */
  --pos-nav-bg: #0f172a;
  --pos-nav-bg-active: #1e293b;
  --pos-nav-text: #94a3b8;
  --pos-nav-text-active: #ffffff;

  /* Status colors (credit, expiry, stock) */
  --pos-credit-owed: #dc2626;      /* customer owes us */
  --pos-credit-clear: #16a34a;     /* settled */
  --pos-payable: #d97706;          /* we owe supplier */
  --pos-expiry-soon: #d97706;
  --pos-expiry-expired: #dc2626;
  --pos-stock-low: #d97706;
  --pos-stock-out: #dc2626;

  /* Neutrals */
  --pos-bg: #f8fafc;
  --pos-surface: #ffffff;
  --pos-border: #e2e8f0;
  --pos-text: #0f172a;
  --pos-text-muted: #64748b;

  /* Layout */
  --pos-sidebar-width: 240px;
  --pos-sidebar-collapsed-width: 72px;
  --pos-topbar-height: 58px;
  --pos-radius: 10px;
  --pos-radius-sm: 6px;
  --pos-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --pos-transition: 0.15s ease;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  background: var(--pos-bg);
  color: var(--pos-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13.5px;
  letter-spacing: -0.01em;
}

a {
  text-decoration: none;
}

/* ---------- App shell layout ---------- */

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

.brand-badge-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
  flex-shrink: 0;
}

.app-topbar {
  height: var(--pos-topbar-height);
  background: #0f172a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}

.app-topbar .nav-link {
  font-size: 13px;
  font-weight: 500;
  color: #94a3b8 !important;
  transition: all 0.15s ease-in-out;
  border-radius: 6px;
  padding: 6px 10px !important;
}

.app-topbar .nav-link:hover {
  color: #f8fafc !important;
  background: rgba(255, 255, 255, 0.08);
}

.app-topbar .nav-link.active {
  color: #ffffff !important;
  background: #2563eb !important;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.app-topbar .dropdown-menu {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  padding: 6px;
}

.app-topbar .dropdown-item {
  color: #cbd5e1;
  font-size: 13px;
  border-radius: 6px;
  padding: 7px 12px;
  transition: all 0.15s ease;
}

.app-topbar .dropdown-item:hover {
  background: #334155;
  color: #ffffff;
}

.app-topbar .dropdown-item.active {
  background: #2563eb;
  color: #ffffff;
  font-weight: 600;
}

.app-topbar .btn-light {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  font-size: 13px;
  border-radius: 6px;
}

.app-topbar .btn-light:hover {
  background: #334155;
  color: #fff;
}

.app-content {
  padding: 22px;
  flex: 1;
}

/* ---------- Sidebar nav ---------- */

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 8px 0;
}

.sidebar-nav .nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.45);
  padding: 12px 16px 4px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--pos-nav-text);
  border-left: 3px solid transparent;
  transition: background var(--pos-transition), color var(--pos-transition);
  white-space: nowrap;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--pos-nav-text-active);
}

.sidebar-nav a.active {
  background: var(--pos-nav-bg-active);
  color: var(--pos-nav-text-active);
  border-left-color: #60a5fa;
}

.sidebar-nav i {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .nav-section-title {
  display: none;
}

/* ---------- Collapsible nav groups ---------- */

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--pos-nav-text);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background var(--pos-transition), color var(--pos-transition);
}

.nav-group-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--pos-nav-text-active);
}

.nav-group-toggle .chevron {
  margin-left: auto;
  transition: transform var(--pos-transition);
  font-size: 12px;
}

.nav-group.open .nav-group-toggle .chevron {
  transform: rotate(180deg);
}

.nav-group.open .nav-group-toggle {
  color: var(--pos-nav-text-active);
}

.nav-group-items {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--pos-transition);
}

.nav-group.open .nav-group-items {
  max-height: 500px;
}

.app-sidebar.collapsed .nav-group-toggle .chevron,
.app-sidebar.collapsed .nav-group-toggle span:not(.chevron) {
  display: none;
}

/* ---------- Topbar feature search ---------- */

.topbar-search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.topbar-search-wrap input {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 8px 16px 8px 38px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.topbar-search-wrap input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.topbar-search-wrap input:focus {
  outline: none;
  background: #fff;
  color: var(--pos-text);
}

.topbar-search-wrap input:focus::placeholder {
  color: var(--pos-text-muted);
}

.topbar-search-wrap .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.75);
  pointer-events: none;
}

.topbar-search-wrap input:focus ~ .search-icon {
  color: var(--pos-text-muted);
}

.topbar-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  background: var(--pos-surface);
  border: 1px solid var(--pos-border);
  border-radius: var(--pos-radius-sm);
  box-shadow: var(--pos-shadow);
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
}

.topbar-search-results a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: var(--pos-text);
}

.topbar-search-results a:hover {
  background: #f1f5f9;
}

.topbar-search-results a.highlighted,
.topbar-search-results a.highlighted i {
  background: var(--pos-primary) !important;
  color: #ffffff !important;
}

@media (max-width: 768px) {
  .topbar-search-wrap {
    display: none;
  }
}

/* ---------- Cards / surfaces ---------- */

.pos-card {
  background: var(--pos-surface);
  border: 1px solid var(--pos-border);
  border-radius: var(--pos-radius);
  box-shadow: var(--pos-shadow);
}

.pos-card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--pos-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pos-card-body {
  padding: 18px;
}

/* ---------- Stat tiles (dashboard, reports) ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--pos-surface);
  border: 1px solid var(--pos-border);
  border-radius: var(--pos-radius);
  padding: 18px;
  box-shadow: var(--pos-shadow);
}

.stat-tile .stat-label {
  font-size: 12px;
  color: var(--pos-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.stat-tile .stat-value {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-tile .stat-sub {
  font-size: 12px;
  color: var(--pos-text-muted);
  margin-top: 4px;
}

.stat-tile.accent-primary { border-top: 3px solid var(--pos-primary); }
.stat-tile.accent-success { border-top: 3px solid var(--pos-success); }
.stat-tile.accent-danger  { border-top: 3px solid var(--pos-danger); }
.stat-tile.accent-warning { border-top: 3px solid var(--pos-warning); }

/* ---------- Tables ---------- */

.pos-table {
  width: 100%;
  border-collapse: collapse;
}

.pos-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--pos-text-muted);
  padding: 10px 14px;
  border-bottom: 2px solid var(--pos-border);
  white-space: nowrap;
}

.pos-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--pos-border);
  vertical-align: middle;
}

.pos-table tbody tr:hover {
  background: #f8fafc;
}

/* ---------- Status badges ---------- */

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-owed     { background: rgba(220, 38, 38, 0.1); color: var(--pos-credit-owed); }
.badge-clear    { background: rgba(22, 163, 74, 0.1); color: var(--pos-credit-clear); }
.badge-payable  { background: rgba(217, 119, 6, 0.1); color: var(--pos-payable); }
.badge-expiring { background: rgba(217, 119, 6, 0.1); color: var(--pos-expiry-soon); }
.badge-expired  { background: rgba(220, 38, 38, 0.1); color: var(--pos-expiry-expired); }
.badge-low      { background: rgba(217, 119, 6, 0.1); color: var(--pos-stock-low); }
.badge-out      { background: rgba(220, 38, 38, 0.1); color: var(--pos-stock-out); }

/* ---------- Forms ---------- */

.pos-form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--pos-text);
  margin-bottom: 4px;
  display: block;
}

.pos-required::after {
  content: " *";
  color: var(--pos-danger);
}

/* ---------- Buttons (complements Bootstrap, doesn't replace it) ---------- */

.btn-pos-primary {
  background: var(--pos-primary);
  border-color: var(--pos-primary);
  color: #fff;
}

.btn-pos-primary:hover {
  background: var(--pos-primary-dark);
  border-color: var(--pos-primary-dark);
  color: #fff;
}

/* Bootstrap's .btn:disabled has higher specificity (.btn + :disabled) than a
   single custom class, so without this it silently overrides background to
   transparent — the button goes invisible instead of looking muted. */
.btn-pos-primary:disabled,
.btn-pos-primary.disabled {
  background: var(--pos-primary);
  border-color: var(--pos-primary);
  color: #fff;
  opacity: 0.5;
}

/* ---------- Utility ---------- */

.text-muted-sm {
  font-size: 12px;
  color: var(--pos-text-muted);
}

.scroll-x {
  overflow-x: auto;
}

/* ---------- Print (receipts / barcode labels) ----------
   Modules that print (pos/, barcode/) add their own print CSS file;
   this just hides the app shell so nothing but the printable node shows. */

@page {
  size: auto;
  margin: 0;
}

@media print {
  body {
    padding: 15mm 15mm 15mm 15mm !important;
  }

  /* Hide web app interactive elements, stat boxes, side buttons, back links */
  .badge,
  .btn,
  .no-print,
  a[href*="index.php"],
  .pos-card-header .text-muted-sm,
  .topbar-search-wrap,
  .app-sidebar,
  .app-topbar,
  header {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
    font-family: Arial, sans-serif !important;
  }

  .app-shell, .app-main, .app-content {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }

  .modal-header, .modal-footer, .btn-close, .modal-backdrop {
    display: none !important;
  }

  .scroll-x {
    overflow: visible !important;
  }

  .report-print-header {
    margin-bottom: 12px !important;
    padding-bottom: 8px !important;
    border-bottom: 1px solid #000000 !important;
  }

  .report-print-header h2 {
    font-size: 16pt !important;
    color: #000000 !important;
    margin-bottom: 2px !important;
  }

  .report-print-header h4 {
    font-size: 12pt !important;
    color: #000000 !important;
  }

  .pos-card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin-bottom: 15px !important;
    background: transparent !important;
  }

  .pos-card-header {
    padding: 4px 0 !important;
    margin-bottom: 4px !important;
    background: none !important;
    border: none !important;
    font-size: 11pt !important;
    font-weight: bold !important;
    color: #000000 !important;
  }

  .pos-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin-top: 4px !important;
    margin-bottom: 10px !important;
  }

  .pos-table th, .pos-table td {
    padding: 4px 8px !important;
    border: 1px solid #333333 !important;
    font-size: 9.5pt !important;
    color: #000000 !important;
    text-align: left;
  }

  .pos-table th {
    background-color: #f2f2f2 !important;
    color: #000000 !important;
    font-weight: bold !important;
    text-transform: uppercase;
    font-size: 8.5pt !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .report-print-footer {
    border-top: 1px solid #000000 !important;
    padding-top: 8px !important;
    margin-top: 25px !important;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .app-sidebar {
    position: fixed;
    left: -100%;
    z-index: 1000;
    transition: left var(--pos-transition);
  }

  .app-sidebar.mobile-open {
    left: 0;
  }
}

.topbar .nav-link {
  font-size: 13px !important;
  white-space: nowrap !important;
}

.topbar .dropdown-menu {
  font-size: 13px !important;
}

/* ---------- Search & scan boxes (assets/js/search-scan.js) ---------- */
.select-search-input {
  margin-bottom: 4px;
  min-width: 120px;
  font-size: 13px;
}
.select-search-input::placeholder { color: #94a3b8; }
select.product-select, select.batch-select { min-width: 210px; }
.table-quick-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  max-width: 420px;
}
.table-quick-search .bi-search { color: var(--pos-text-muted); }
.table-quick-search .tqs-input { flex: 1 1 auto; min-width: 0; }
.table-quick-search .tqs-count { font-size: 12px; color: var(--pos-text-muted); white-space: nowrap; }
@media print { .select-search-input, .table-quick-search { display: none !important; } }
.ss-suggest {
  position: fixed;
  z-index: 2000;
  background: #fff;
  border: 1px solid var(--pos-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  overflow-y: auto;
  font-size: 13px;
  padding: 4px 0;
}
.ss-suggest .ss-item { padding: 6px 10px; cursor: pointer; line-height: 1.3; }
.ss-suggest .ss-item:hover { background: #f1f5f9; }
.ss-suggest .ss-item.active { background: var(--pos-primary); color: #fff; }
.ss-suggest .ss-item mark { padding: 0; background: #fde68a; color: inherit; border-radius: 2px; }
.ss-suggest .ss-item.active mark { background: rgba(255, 255, 255, 0.35); }
.ss-suggest .ss-empty { padding: 8px 10px; color: var(--pos-text-muted); }

/* Ledger hubs: on screens narrower than ~1500px the row buttons show icons only
   (hover shows the name), so the Actions column is never cut off. */
@media (max-width: 1500px) {
  .pos-table .btn .btn-lbl { display: none; }
}

/* Safety net for every page and screen size: nothing (an open menu, a wide
   element) may make the whole page scroll sideways and shift it left.
   Wide tables still scroll inside their own box (.scroll-x). */
body { overflow-x: clip; }
@supports not (overflow-x: clip) { body { overflow-x: hidden; } }

/* Customer Ledgers hub on small screens: hide "Credit limit & usage"
   (still shown on each customer's ledger page) so the table fits. */
@media (max-width: 1150px) {
  .ledger-hub-table > thead > tr > th:nth-child(3), .ledger-hub-table > tbody > tr > td:nth-child(3) { display: none; }
  /* total bought / total paid history (on the customer's ledger page) — Current Baqaya stays */
  .ledger-hub-table > thead > tr > th:nth-child(4), .ledger-hub-table > tbody > tr > td:nth-child(4),
  .ledger-hub-table > thead > tr > th:nth-child(5), .ledger-hub-table > tbody > tr > td:nth-child(5) { display: none; }
}

/* Tables fit the screen on every page (no sideways scrolling):
   column headings wrap onto two lines, cells are tighter, and the big
   total figures shrink a little. Money values stay on one line. */
@media screen {
  .pos-table th, .table th { white-space: normal !important; vertical-align: middle; }
  .pos-table th, .pos-table td { padding-left: 8px; padding-right: 8px; }
  .pos-table .fs-5, .pos-table .fs-4 { font-size: 1rem !important; }
  .pos-table .fs-6 { font-size: 0.9rem !important; }
}
@media screen and (max-width: 1400px) {
  .pos-table, .table { font-size: 13px; }
  .pos-table th, .table th { font-size: 10.5px !important; letter-spacing: 0.02em !important; }
  .pos-table th, .pos-table td { padding-left: 6px; padding-right: 6px; }
}

/* Summary cards always fill the whole row (no empty gap on the right),
   even where a page set a fixed card width. */
.stat-grid[style] { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important; }

/* Search / filter bars sit on one line instead of stacking down the side */
.filter-bar { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; }
@media (max-width: 700px) { .filter-bar { flex-wrap: wrap; } }
.filter-bar > .form-control, .filter-bar > .form-select { width: auto; min-width: 220px; flex: 0 1 260px; }
.filter-bar > .btn, .filter-bar > label { flex: 0 0 auto; white-space: nowrap; }

/* ---- Live search suggestions (assets/js/live-suggest.js) ---- */
.ls-wrap { position: relative; display: inline-block; min-width: 220px; }
.filter-bar > .ls-wrap { flex: 0 1 300px; }
.ls-wrap > .form-control { width: 100% !important; }
.ls-box {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 1050;
  width: max(100%, 380px); max-width: calc(100vw - 32px); max-height: 420px; overflow-y: auto;
  background: var(--pos-surface, #fff); border: 1px solid var(--pos-border, #e2e8f0);
  border-radius: var(--pos-radius, 6px); box-shadow: var(--pos-shadow, 0 8px 24px rgba(0,0,0,.12));
}
.ls-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; color: var(--pos-text, #1e293b); border-bottom: 1px solid var(--pos-border, #e2e8f0); cursor: pointer; }
.ls-item:last-child { border-bottom: 0; }
.ls-item.active, .ls-item:hover { background: var(--pos-bg, #f1f5f9); }
.ls-main { flex: 1; min-width: 0; }
.ls-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-name mark, .ls-sub mark { padding: 0; background: rgba(255, 196, 0, .35); color: inherit; }
.ls-sub { font-size: 12px; color: var(--pos-text-muted, #64748b); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-right { text-align: right; font-size: 12px; white-space: nowrap; }
.ls-edit { color: var(--pos-text-muted, #64748b); padding: 4px; }
.ls-empty { padding: 12px; color: var(--pos-text-muted, #64748b); font-size: 13px; }
@media (max-width: 700px) { .ls-wrap, .filter-bar > .ls-wrap { flex: 1 1 100%; width: 100%; } }
