:root {
  --brand-color: #7b2d8e;
  --brand-dark: #4a1a55;
  --brand-light: #f3e6f5;
}

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #faf7fb;
  color: #2b2b2b;
}

a { text-decoration: none; }

.btn-brand {
  background-color: var(--brand-color);
  border-color: var(--brand-color);
  color: #fff;
}
.btn-brand:hover, .btn-brand:focus {
  background-color: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}
.btn-outline-brand {
  color: var(--brand-color);
  border-color: var(--brand-color);
}
.btn-outline-brand:hover {
  background-color: var(--brand-color);
  color: #fff;
}
.text-brand { color: var(--brand-color); }
.bg-brand { background-color: var(--brand-color); }
.bg-brand-light { background-color: var(--brand-light); }

.brand-logo { height: 40px; width: auto; object-fit: contain; border-radius: 6px; }
.navbar .nav-link { font-weight: 500; color: #333; }
.navbar .nav-link.active { color: var(--brand-color); }
.cart-count-badge { font-size: 0.65rem; position: relative; top: -8px; left: -4px; }
.cart-count-badge-mobile {
  position: absolute;
  top: -4px;
  right: -6px;
  left: auto;
  font-size: 0.6rem;
  min-width: 16px;
  height: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- Hero ---------- */
.hero-section {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand-color));
  color: #fff;
  border-radius: 0 0 40px 40px;
  padding: 70px 0 90px;
}
.hero-section h1 { font-weight: 700; }

/* ---------- Product Cards ---------- */
.product-card {
  border: none;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  transition: transform .2s ease, box-shadow .2s ease;
  height: 100%;
}
.product-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 10px 24px rgba(0,0,0,0.12);
}
.product-card .product-img-wrap {
  aspect-ratio: 1/1;
  overflow: hidden;
  background: var(--brand-light);
  position: relative;
}
.product-card .product-img-wrap img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .3s;
}
.product-card:hover .product-img-wrap img { transform: scale(1.06); }
.product-badges { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 2;}
.product-badges .badge { font-size: 0.65rem; }
.price-old { text-decoration: line-through; color: #999; font-size: .85rem; }
.price-new { color: var(--brand-color); font-weight: 700; font-size: 1.05rem; }

.section-title {
  font-weight: 700;
  position: relative;
  padding-bottom: 10px;
  margin-bottom: 1.5rem;
}
.section-title::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 60px; height: 4px;
  background: var(--brand-color);
  border-radius: 2px;
}

/* ---------- Footer ---------- */
.footer-brand { background: var(--brand-dark); color: #eee; }
.footer-link { color: #cbb8ce; }
.footer-link:hover { color: #fff; }

/* ---------- Cards / Forms ---------- */
.card-soft { border: none; border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.form-control:focus, .form-select:focus { border-color: var(--brand-color); box-shadow: 0 0 0 0.2rem rgba(123,45,142,0.15); }

/* ---------- Offline banner ---------- */
.offline-banner {
  background: #ffc107; color: #333; text-align: center; padding: 8px; font-size: .9rem; position: sticky; top: 0; z-index: 1100;
}

/* ---------- PWA install button ---------- */
.pwa-install-btn { position: fixed; bottom: 20px; right: 20px; z-index: 1200; }

/* ---------- Admin Layout ---------- */
.admin-sidebar {
  min-height: 100vh;
  background: var(--brand-dark);
  color: #fff;
  width: 240px;
}
.admin-sidebar .nav-link { color: #ddd; padding: 10px 18px; border-radius: 8px; margin: 2px 8px; }
.admin-sidebar .nav-link.active, .admin-sidebar .nav-link:hover { background: rgba(255,255,255,0.12); color: #fff; }
.admin-content { flex: 1; background: var(--brand-light); min-height: 100vh; }
.stat-card { border-radius: 16px; border: none; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.stat-card .stat-icon { width: 52px; height: 52px; border-radius: 12px; display:flex; align-items:center; justify-content:center; font-size:1.4rem; }

.thumb-60 { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; }
.img-preview-box { width: 90px; height: 90px; border: 2px dashed #ccc; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; background: #fafafa; }
.img-preview-box img { width: 100%; height: 100%; object-fit: cover; }
.img-preview-box .remove-img { position: absolute; top: 2px; right: 2px; background: #dc3545; color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* ---------- Star Rating ---------- */
.star-rating i { color: #ffc107; }
.rating-input i { cursor: pointer; color: #ddd; font-size: 1.4rem; }
.rating-input i.active { color: #ffc107; }

/* ---------- Responsive tweaks ---------- */
@media (max-width: 991px) {
  .admin-sidebar { position: fixed; left: -240px; top: 0; z-index: 1050; transition: left .25s ease; }
  .admin-sidebar.show { left: 0; }
}
@media (max-width: 576px) {
  .hero-section { padding: 40px 0 60px; border-radius: 0 0 24px 24px; }
  .brand-text { font-size: 1rem; }
}

.toast-container { z-index: 2000; }

/* The number field between the -/+ buttons was being squeezed to almost
   zero width because Bootstrap's input-group makes it flex-shrinkable by
   default, and the old fixed 110px on the whole group left barely any
   room for it once the two buttons took their share. Giving the input a
   guaranteed, non-shrinking width fixes that so the quantity is always
   fully visible (up to 3 digits) no matter how the group is laid out. */
.qty-box { width: auto; display: inline-flex; flex-wrap: nowrap; flex-shrink: 0; }
.qty-box input[type="number"] {
  flex: 0 0 56px;
  width: 56px;
  min-width: 56px;
  text-align: center;
}
.qty-box .btn { flex: 0 0 auto; }

/* The name/price column needs min-width:0 so it can actually shrink inside
   the flex row on narrow screens, instead of forcing everything else
   (including the qty-box) to be squeezed until it wraps. */
.cart-row .flex-grow-1 { min-width: 0; }

@media (max-width: 576px) {
  /* On phone widths there isn't room for image + name + qty box + total +
     delete all on one line. Instead of letting the qty-box get squeezed
     (which is what caused the -/number/+ to stack), wrap the row onto two
     clean lines: image+name on top, controls (qty, total, delete) below.
     The ::after acts as an invisible full-width "line break" so the two
     groups land on separate lines instead of splitting unpredictably. */
  .cart-row { flex-wrap: wrap; row-gap: 10px; }
  .cart-row::after { content: ""; flex-basis: 100%; width: 0; order: 2; }
  .cart-row .qty-box { order: 3; }
  .cart-row .line-total { order: 4; margin-left: auto; min-width: 0 !important; }
  .cart-row .btn-remove-cart { order: 5; }
}

.checkout-summary { position: sticky; top: 90px; }

.gcash-card { border: 2px dashed var(--brand-color); border-radius: 16px; background: var(--brand-light); }

.empty-state { padding: 60px 20px; text-align: center; color: #888; }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: .5; }

/* Long forms (e.g. Add/Edit Product) can be taller than the viewport.
   Bootstrap's own "modal-dialog-scrollable" class relies on 100vh math
   that behaves inconsistently across browsers/zoom levels/DevTools, so
   instead we force an explicit, guaranteed scroll area here: the header
   and footer always stay pinned in place, and only the body between them
   scrolls, no matter how tall the browser window is.
   Only applies at md and up — below that the modal is full-screen
   (modal-fullscreen-md-down in the markup) and already fills the
   viewport correctly on its own, so this must not interfere there. */
@media (min-width: 768px) {
  .modal-dialog-scrollable .modal-content {
    max-height: 80vh;
  }
  .modal-dialog-scrollable .modal-body {
    overflow-y: auto;
    max-height: calc(80vh - 65px); /* ~header height only, since the Save/Cancel buttons now live inside the scrollable body itself, not a separate footer */
  }
}
.modal-dialog-scrollable .modal-body {
  background:
    linear-gradient(#fff 30%, rgba(255,255,255,0)),
    linear-gradient(rgba(255,255,255,0), #fff 70%) 0 100%,
    radial-gradient(farthest-side at 50% 0, rgba(0,0,0,.12), rgba(0,0,0,0)),
    radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,.12), rgba(0,0,0,0)) 0 100%;
  background-repeat: no-repeat;
  background-size: 100% 40px, 100% 40px, 100% 14px, 100% 14px;
  background-attachment: local, local, scroll, scroll;
  padding: 1rem 1.25rem;
}
.modal-dialog-scrollable .modal-footer {
  box-shadow: 0 -2px 6px rgba(0,0,0,.06);
  padding: .85rem 1.25rem;
}

/* ============================================================
   PURCHASE ORDERS — spreadsheet-style editable tables
   ============================================================ */
.po-wrap { padding-bottom: 40px; }

.po-cat-block {
  margin-bottom: 24px; border: 1px solid #ececf1; border-radius: 14px; overflow: hidden;
  background: #fff; box-shadow: 0 1px 2px rgba(24,10,28,.04), 0 6px 16px rgba(74,26,85,.06);
  transition: box-shadow .2s ease;
}
.po-cat-block:hover { box-shadow: 0 2px 4px rgba(24,10,28,.05), 0 10px 22px rgba(74,26,85,.10); }

.po-cat-title-row {
  background: linear-gradient(135deg, var(--brand-color), var(--brand-dark));
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
}
.po-cat-title-row input.po-cat-name {
  background: rgba(255,255,255,0.12); border: 1px solid transparent; color: #fff; font-weight: 700; font-size: 1rem;
  flex: 1; padding: 6px 10px; border-radius: 8px; transition: background .15s ease, border-color .15s ease;
}
.po-cat-title-row input.po-cat-name:focus { background: rgba(255,255,255,0.22); outline: none; border-color: rgba(255,255,255,.4); }
.po-cat-name-label {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: .01em; padding: 6px 10px;
}
.po-cat-name-label i { font-size: .72rem; color: rgba(255,255,255,.75); flex-shrink: 0; }
.po-cat-name-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.po-cat-remove {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.14); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: background .18s ease, transform .12s ease;
}
.po-cat-remove:hover { background: rgba(255,255,255,0.30); transform: scale(1.08); }
.po-cat-remove:active { transform: scale(.94); }

table.po-table { border-collapse: collapse; width: 100%; }
table.po-table th {
  background: var(--brand-light); font-size: .78rem; text-transform: uppercase;
  letter-spacing: .03em; color: #555; font-weight: 700; padding: 10px 6px; border: 1px solid #f0eaf1; text-align: center;
}
table.po-table td { border: 1px solid #f0eaf1; padding: 3px; vertical-align: middle; }
table.po-table td input {
  width: 100%; border: none; background: transparent; padding: 7px 6px; text-align: center; font-size: .9rem; border-radius: 6px;
}
table.po-table td input.po-input-left { text-align: left; }
table.po-table td input:focus { background: #fff8e6; outline: 2px solid var(--brand-color); outline-offset: -1px; }

/* Order (category items) table + its Grand Total table share this class so
   a <colgroup> with matching widths lines up every column between the two
   separate <table> elements — otherwise each table auto-sizes its columns
   independently based on its own content and the totals drift out of
   alignment with the headers above them. */
table.po-order-table { table-layout: fixed; }
table.po-order-table .po-col-name { width: 20%; }
table.po-order-table .po-col-metric { width: 12%; }
table.po-order-table .po-col-end { width: 8%; }

/* Paired-field mismatch (Order per Pcs./Received, Free Tester/Free Tester
   Received, Order Tester/Order Tester Received) — flags a manual recount
   that came up short or over what was supposed to happen, so it's obvious
   at a glance instead of hiding in the numbers. Only the two involved
   cells go red, not the whole row, so it's clear which pair is off. */
table.po-table td.po-pair-mismatch-cell { background: #fdecea; }
table.po-table td input.po-pair-mismatch {
  background: #f8d7da; color: #842029; font-weight: 700;
  box-shadow: inset 0 0 0 1px #f1aeb5; border-radius: 6px;
}
table.po-table td input.po-pair-mismatch:focus { background: #fff3cd; }

.po-name-locked {
  display: flex; align-items: center; gap: 7px; padding: 7px 8px; font-size: .9rem; color: #333;
}
.po-name-locked i { font-size: .7rem; color: var(--brand-color); opacity: .7; flex-shrink: 0; }
.po-name-locked span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table.po-table .po-row-remove {
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: #fbe9e8; color: #c0392b; opacity: .8;
  display: inline-flex; align-items: center; justify-content: center; font-size: .8rem;
  transition: background .18s ease, opacity .18s ease, transform .12s ease;
}
table.po-table .po-row-remove:hover { background: #f6cbc7; opacity: 1; transform: scale(1.08); }
table.po-table .po-row-remove:active { transform: scale(.92); }

.po-cat-summary {
  display: flex; justify-content: flex-end; align-items: center; padding: 10px 14px; font-size: .85rem;
  color: #666; background: #faf7fb; border-top: 1px solid #f1e9f3;
}
.po-cat-summary b { color: var(--brand-dark); margin-left: 4px; font-size: .95rem; }

.po-add-row-bar { padding: 8px 12px; background: #fcfbfd; border-top: 1px solid #f4eef6; }

table.po-grand-total td { border: none; background: var(--brand-dark); color: #fff; font-weight: 700; padding: 10px 6px; text-align: center; }
table.po-grand-total .po-total-label { text-align: left; padding-left: 14px; }

.po-total-row td { background: var(--brand-light); font-weight: 700; border: 1px solid #eee; }
.po-total-row .po-total-label { text-align: left; padding-left: 10px; }
.po-subtle-row td { background: #fbfbfb; border: 1px solid #eee; }

.po-panel-header { font-weight: 700; color: var(--brand-dark); font-size: .95rem; }

.po-tabbar { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid #ddd; padding-top: 10px; }
.po-tab {
  padding: 6px 14px; border-radius: 8px 8px 0 0; background: #eee; color: #555; font-size: .85rem;
  cursor: pointer; border: 1px solid #ddd; border-bottom: none; user-select: none;
}
.po-tab.active { background: var(--brand-color); color: #fff; font-weight: 600; }
.po-tab-add {
  padding: 6px 12px; border-radius: 8px 8px 0 0; background: #fff; color: var(--brand-color);
  border: 1px dashed var(--brand-color); cursor: pointer; font-size: .85rem;
}

#poCategoryPickerList .list-group-item { cursor: pointer; }
#poCategoryPickerList .list-group-item:hover { background: var(--brand-light); }

/* Linked (auto-synced) inventory rows */
.text-brand { color: var(--brand-color); }
input.po-linked-input { background: #f3ecf8; font-weight: 600; }
input.po-linked-input:focus { background: #fff8e6; }
