:root {
  --green: #3a9d4f;
  --dark-green: #1f6b33;
  --bg: #f4f6f5;
  --card: #ffffff;
  --border: #e0e4e2;
  --text: #1c1f1e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--dark-green);
  color: white;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand { font-size: 1.3em; font-weight: 700; }
.brand span { font-weight: 400; opacity: 0.85; }

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: rgba(0,0,0,0.12);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: rgba(255,255,255,0.75);
  padding: 10px 18px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 0.95em;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}
.tab-icon { font-size: 1.15em; }
.tab-btn:hover { background: rgba(255,255,255,0.08); color: white; }
.tab-btn.active {
  background: var(--card);
  color: var(--dark-green);
  border-bottom-color: var(--green);
}
.tab-btn.active:hover { background: var(--card); }

.today-summary { font-size: 0.9em; opacity: 0.9; }

.tab-panel { display: none; padding: 20px; }
.tab-panel.active { display: block; }

.pos-layout { display: flex; gap: 20px; align-items: flex-start; }
.pos-left { flex: 2; }
.pos-right {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  position: sticky;
  top: 20px;
}

#searchBox {
  width: 100%;
  padding: 10px 12px;
  font-size: 1em;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
}

/* ---- Category filter pills ---- */
.category-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.category-pill {
  background: white;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  color: #555;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.category-pill:hover { border-color: var(--green); }
.category-pill.active { background: var(--dark-green); border-color: var(--dark-green); color: white; }

.product-count { font-size: 0.82em; color: #888; margin-bottom: 10px; }

/* ---- Product grid & cards ---- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 14px;
}

.product-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s, border-color 0.15s;
  overflow: hidden;
}
.product-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--green);
  opacity: 0;
  transition: opacity 0.15s;
}
.product-card:hover {
  box-shadow: 0 8px 18px rgba(31,107,51,0.12);
  transform: translateY(-3px);
  border-color: var(--green);
}
.product-card:hover::before { opacity: 1; }

.product-card .card-icon {
  font-size: 1.8em;
  margin-bottom: 6px;
  display: block;
}
.product-card .name { font-weight: 700; margin-bottom: 2px; font-size: 0.98em; }
.product-card .meta { font-size: 0.78em; color: #888; margin-bottom: 10px; }
.product-card .price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.product-card .price { color: var(--dark-green); font-weight: 700; font-size: 1.05em; }

.stock-badge {
  font-size: 0.7em;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
}
.stock-badge.ok { background: #e7f6ea; color: var(--dark-green); }
.stock-badge.low { background: #fff4e5; color: #8a5a00; }
.stock-badge.out { background: #fbe9e7; color: #c0392b; }

.product-card.out-of-stock { opacity: 0.5; cursor: not-allowed; }
.product-card.out-of-stock:hover { transform: none; box-shadow: none; border-color: var(--border); }
.product-card.out-of-stock:hover::before { opacity: 0; }

.cart-qty-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--dark-green);
  color: white;
  font-size: 0.75em;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-items { max-height: 320px; overflow-y: auto; margin-bottom: 10px; }
.cart-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9em;
}
.cart-row .qty-controls button {
  width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--border);
  background: #f0f0f0; cursor: pointer;
}
.cart-row .remove-btn { color: #c0392b; cursor: pointer; margin-left: 8px; }

.cart-summary .row {
  display: flex; justify-content: space-between; margin: 8px 0; align-items: center;
}
.cart-summary .row.total { font-size: 1.2em; font-weight: 700; border-top: 1px solid var(--border); padding-top: 8px; }
.cart-summary input, .cart-summary select { padding: 6px; border-radius: 6px; border: 1px solid var(--border); width: 110px; }

.primary-btn {
  background: var(--green);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  width: 100%;
  margin-top: 10px;
}
.primary-btn:hover { background: var(--dark-green); }

.product-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: var(--card);
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.product-form input { padding: 8px; border-radius: 6px; border: 1px solid var(--border); }
.product-form button { grid-column: span 2; padding: 10px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
#resetFormBtn { background: #eee; }

.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.9em; }
.data-table th { background: #eef4ef; }
.data-table button { cursor: pointer; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-content { background: white; padding: 30px; border-radius: 12px; max-width: 360px; text-align: center; }

/* ---- Barcode scan input ---- */
#barcodeInput {
  width: 100%;
  padding: 12px 14px;
  font-size: 1em;
  border: 2px solid var(--green);
  border-radius: 8px;
  margin-bottom: 6px;
  background: #f3fbf4;
}
#barcodeInput:focus { outline: none; border-color: var(--dark-green); background: white; }
.barcode-status { min-height: 20px; font-size: 0.85em; margin-bottom: 10px; }
.barcode-status.ok { color: var(--dark-green); }
.barcode-status.err { color: #c0392b; }

.secondary-btn {
  background: #eee;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  width: 100%;
  margin-top: 8px;
}

/* ---- Settings form ---- */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  max-width: 420px;
}
.settings-form label { display: flex; flex-direction: column; font-size: 0.9em; gap: 4px; font-weight: 600; }
.settings-form input { padding: 8px; border-radius: 6px; border: 1px solid var(--border); font-weight: 400; }
.hint { color: #777; font-size: 0.9em; }

/* ---- Printable receipt ---- */
.print-only { display: none; }

@media print {
  body * { visibility: hidden; }

  body.printing-receipt #printReceipt,
  body.printing-receipt #printReceipt * { visibility: visible; }
  body.printing-receipt #printReceipt {
    display: block;
    position: absolute;
    top: 0; left: 0;
    width: 80mm;
    padding: 4mm;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #000;
  }

  body.printing-label #printLabel,
  body.printing-label #printLabel * { visibility: visible; }
  body.printing-label #printLabel {
    display: block;
    position: absolute;
    top: 0; left: 0;
    width: 50mm;
    padding: 2mm;
    font-family: Arial, sans-serif;
    color: #000;
  }

  body.printing-receipt { }
  body.printing-label { }
}

@page { margin: 0; }

.pr-shop-name { font-size: 16px; font-weight: 700; text-align: center; }
.pr-line { text-align: center; }
#printReceipt hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
.pr-items { width: 100%; border-collapse: collapse; }
.pr-items th, .pr-items td { text-align: left; padding: 2px 0; font-size: 11px; }
.pr-items th:nth-child(2), .pr-items td:nth-child(2) { text-align: center; }
.pr-items th:nth-child(3), .pr-items td:nth-child(3),
.pr-items th:nth-child(4), .pr-items td:nth-child(4) { text-align: right; }
.pr-row { display: flex; justify-content: space-between; }
.pr-row.pr-total { font-weight: 700; font-size: 13px; }
.pr-footer { text-align: center; margin-top: 8px; font-style: italic; }

/* ================= LOGIN SCREEN ================= */
.login-screen {
  position: fixed; inset: 0; background: linear-gradient(135deg, var(--dark-green), var(--green));
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: white; padding: 36px; border-radius: 14px; width: 300px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-box .brand { font-size: 1.5em; font-weight: 700; color: var(--dark-green); }
.login-box .brand span { font-weight: 400; color: #666; }
.login-box input { padding: 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 1em; }
.login-error { color: #c0392b; font-size: 0.85em; min-height: 18px; }
.login-hint { font-size: 0.75em; color: #999; }
.hidden { display: none !important; }
.admin-only { display: none; }
body.role-admin .tab-btn.admin-only { display: flex; }
/* Audit accounts: Reports is the only menu item */
body.role-auditor .tab-btn { display: none; }
body.role-auditor .tab-btn[data-tab="reports"] { display: flex; }
body.role-admin .tile.admin-only { display: flex; }
body.role-admin .stat-card.admin-only { display: block; }
body.role-admin button.admin-only#createPoFromLowStockBtn { display: inline-block; }

/* ================= TOPBAR EXTRAS ================= */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-pill { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.15); padding: 6px 10px; border-radius: 20px; font-size: 0.85em; }
.user-pill button { background: transparent; border: 1px solid rgba(255,255,255,0.5); color: white; border-radius: 12px; padding: 3px 10px; cursor: pointer; font-size: 0.85em; }

/* ================= LOW STOCK BANNER ================= */
.low-stock-banner {
  background: #fff4e5; border: 1px solid #f0b969; color: #8a5a00;
  padding: 10px 16px; border-radius: 8px; margin-bottom: 14px; font-size: 0.9em;
}

/* ================= CUSTOMER PICKER (POS) ================= */
.customer-picker { position: relative; margin-bottom: 12px; }
.customer-picker input { width: 100%; padding: 8px; border-radius: 6px; border: 1px solid var(--border); }
.customer-results {
  position: absolute; z-index: 5; background: white; border: 1px solid var(--border);
  border-radius: 6px; width: 100%; max-height: 160px; overflow-y: auto; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.customer-results div { padding: 8px 10px; cursor: pointer; font-size: 0.9em; }
.customer-results div:hover { background: #f0f4f1; }
.selected-customer {
  margin-top: 6px; background: #eef7ee; border: 1px solid var(--green); border-radius: 6px;
  padding: 6px 10px; font-size: 0.85em; display: flex; justify-content: space-between; align-items: center;
}
.selected-customer button { background: none; border: none; color: #c0392b; cursor: pointer; font-size: 0.9em; }

/* ================= FORMS (products/customers) ================= */
.customer-form { display: flex; gap: 10px; margin-bottom: 18px; }
.customer-form input { padding: 8px; border-radius: 6px; border: 1px solid var(--border); flex: 1; }

.customer-history { margin-top: 20px; }

/* ================= RETURNS TAB ================= */
.returns-search { display: flex; gap: 10px; margin-bottom: 18px; max-width: 500px; }
.returns-search input { flex: 1; padding: 10px; border-radius: 6px; border: 1px solid var(--border); }
.return-result { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.return-result input[type="number"] { width: 70px; padding: 4px; border-radius: 4px; border: 1px solid var(--border); }

/* ================= REPORTS TAB ================= */
.report-range { display: flex; gap: 8px; margin-bottom: 16px; }
.range-btn { padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: white; cursor: pointer; }
.range-btn.active { background: var(--green); color: white; border-color: var(--green); }
.report-cards { display: flex; gap: 14px; margin-bottom: 20px; }
.report-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px 22px; min-width: 140px; }
.report-card .label { font-size: 0.8em; color: #777; }
.report-card .value { font-size: 1.4em; font-weight: 700; color: var(--dark-green); }
#revenueChart { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 24px; max-width: 700px; }

/* ================= BARCODE LABEL PRINT ================= */
.label-print { text-align: center; }
.label-name { font-size: 11px; font-weight: 700; margin-bottom: 2px; }
.label-price { font-size: 13px; font-weight: 700; margin-top: 2px; }

.print-label-btn { font-size: 0.75em; padding: 4px 8px; }

/* ================= LOW STOCK BANNER (updated layout) ================= */
.low-stock-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.low-stock-banner button {
  background: #8a5a00; color: white; border: none; padding: 6px 12px;
  border-radius: 6px; cursor: pointer; font-size: 0.85em; white-space: nowrap;
}

/* ================= SUPPLIERS & PO ================= */
.supplier-form { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.supplier-form input { padding: 8px; border-radius: 6px; border: 1px solid var(--border); flex: 1; min-width: 140px; }

.po-builder {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin-bottom: 24px; max-width: 700px;
}
.po-builder select { padding: 8px; border-radius: 6px; border: 1px solid var(--border); margin-bottom: 10px; width: 100%; }
.po-line-builder { display: flex; gap: 8px; margin-bottom: 12px; }
.po-line-builder select { flex: 2; margin-bottom: 0; }
.po-line-builder input { flex: 1; padding: 8px; border-radius: 6px; border: 1px solid var(--border); }
.po-line-builder button { padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border); background: #eee; cursor: pointer; white-space: nowrap; }
.po-total { font-weight: 700; margin: 10px 0; text-align: right; }
.remove-line-btn { color: #c0392b; cursor: pointer; background: none; border: none; }

.status-pill { padding: 3px 10px; border-radius: 12px; font-size: 0.8em; }
.status-pending { background: #fff4e5; color: #8a5a00; }
.status-received { background: #e7f6ea; color: var(--dark-green); }

/* ================= HOME DASHBOARD ================= */
.home-greeting { margin-bottom: 22px; }
.home-greeting h1 { font-size: 1.8em; margin: 0 0 4px 0; color: var(--text); }
.home-greeting p { margin: 0; color: #777; font-size: 0.95em; }

.home-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-card.stat-warning { border-left-color: #d98c1f; }
.stat-value { font-size: 1.7em; font-weight: 700; color: var(--dark-green); line-height: 1.1; }
.stat-warning .stat-value { color: #8a5a00; }
.stat-label { font-size: 0.85em; color: #777; margin-top: 4px; }

.hero-action {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(120deg, var(--dark-green), var(--green));
  color: white;
  border: none;
  border-radius: 14px;
  padding: 22px 26px;
  cursor: pointer;
  margin-bottom: 24px;
  text-align: left;
  transition: transform 0.08s ease;
}
.hero-action:hover { transform: translateY(-1px); }
.hero-action:active { transform: translateY(0); }
.hero-icon { font-size: 2.4em; }
.hero-text { display: flex; flex-direction: column; gap: 2px; }
.hero-title { font-size: 1.25em; font-weight: 700; }
.hero-sub { font-size: 0.9em; opacity: 0.85; }

.home-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 10px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.1s, transform 0.08s;
}
.tile:hover { border-color: var(--green); transform: translateY(-2px); }
.tile-icon { font-size: 1.8em; }

.home-recent h3 { margin-bottom: 10px; }
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 0.9em;
}
.recent-row .recent-meta { color: #888; font-size: 0.85em; }
.recent-empty { color: #999; font-size: 0.9em; padding: 10px 0; }
