:root {
  --brand: #1a56db;
  --brand-dark: #143e9e;
  --bg: #f7f8fa;
  --card: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --whatsapp: #25d366;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Guarantee the `hidden` attribute always wins, even over classes further
   down this file that set `display: flex`/`display: block` directly on the
   same element (e.g. .modal-overlay, .cart-drawer). Without this, toggling
   `.hidden = true` in JS has no visual effect once those rules apply. */
[hidden] { display: none !important; }

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

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand { display: flex; flex-direction: column; margin-right: auto; }
.brand-name { font-size: 20px; font-weight: 800; color: var(--brand); }
.brand-tagline { font-size: 12px; color: var(--muted); }

.search-wrap { flex: 1 1 320px; max-width: 520px; }
#searchInput {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  outline: none;
}
#searchInput:focus { border-color: var(--brand); }

.cart-btn {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.cart-btn:hover { background: var(--brand-dark); }
.cart-count {
  background: rgba(255,255,255,.25);
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 4px;
  font-size: 12px;
}

.filter-bar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
}
.stock-toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.result-count { margin-left: auto; font-size: 13px; color: var(--muted); }

/* ---------- Main / grid ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 20px; min-height: 60vh; }

.loading { display: flex; flex-direction: column; align-items: center; padding: 80px 0; color: var(--muted); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite; margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
}
.product-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,.08); transform: translateY(-2px); }

.product-thumb {
  aspect-ratio: 1 / 1;
  background: #f1f2f4 url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="100" height="100" fill="%23f1f2f4"/><path d="M30 65 L45 45 L58 58 L70 40 L80 65 Z" fill="%23d1d5db"/><circle cx="38" cy="35" r="7" fill="%23d1d5db"/></svg>') center/50% no-repeat;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.product-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.product-info { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.product-source { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); font-weight: 700; }
.product-name { font-size: 13.5px; line-height: 1.35; font-weight: 600; flex: 1; }
.product-sku { font-size: 11px; color: var(--muted); }
.product-price-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 4px; }
.product-price { font-size: 16px; font-weight: 800; }
.stock-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.stock-badge.in { background: #dcfce7; color: var(--success); }
.stock-badge.out { background: #fee2e2; color: var(--danger); }

.add-to-cart-btn {
  margin: 0 14px 14px;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.add-to-cart-btn:disabled { background: #d1d5db; cursor: not-allowed; }
.add-to-cart-btn:hover:not(:disabled) { background: var(--brand-dark); }

.empty-state { text-align: center; padding: 60px 0; color: var(--muted); }

.pagination { display: flex; justify-content: center; gap: 8px; margin: 28px 0; flex-wrap: wrap; }
.pagination button {
  padding: 8px 14px; border: 1px solid var(--border); background: #fff;
  border-radius: 8px; cursor: pointer; font-size: 13px;
}
.pagination button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

.site-footer { text-align: center; padding: 30px 20px; color: var(--muted); font-size: 12px; }

/* ---------- Modal (product detail + checkout) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: var(--radius);
  max-width: 720px; width: 100%; max-height: 88vh; overflow-y: auto;
  padding: 24px; position: relative;
}
.modal-close { position: absolute; top: 14px; right: 14px; }

.product-modal .pm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.product-modal .pm-image {
  aspect-ratio: 1/1; background: #f1f2f4; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.product-modal .pm-image img { width: 100%; height: 100%; object-fit: contain; }
.product-modal h2 { margin-top: 0; font-size: 20px; }
.product-modal .pm-meta { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.product-modal .pm-price { font-size: 26px; font-weight: 800; margin: 12px 0; }
.product-modal .pm-desc { font-size: 13.5px; line-height: 1.6; white-space: pre-line; color: #374151; margin-top: 14px; }
@media (max-width: 640px) {
  .product-modal .pm-grid { grid-template-columns: 1fr; }
}

/* ---------- Cart drawer ---------- */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90;
}
.cart-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92vw;
  background: #fff; z-index: 95; display: flex; flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,.15);
}
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }

.cart-items { flex: 1; overflow-y: auto; padding: 10px 20px; }
.cart-item { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cart-item-thumb { width: 56px; height: 56px; border-radius: 6px; background: #f1f2f4; flex-shrink: 0; overflow: hidden; }
.cart-item-thumb img { width: 100%; height: 100%; object-fit: contain; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.cart-item-price { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.qty-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.qty-row button { width: 22px; height: 22px; border: 1px solid var(--border); background: #fff; border-radius: 4px; cursor: pointer; }
.qty-row .remove-link { margin-left: auto; font-size: 11px; color: var(--danger); cursor: pointer; text-decoration: underline; }
.cart-empty { text-align: center; color: var(--muted); padding: 40px 0; }

.cart-footer { padding: 16px 20px 20px; border-top: 1px solid var(--border); }
.cart-subtotal { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 12px; }

.btn { border: none; border-radius: 8px; padding: 11px 16px; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #d1d5db; cursor: not-allowed; }
.btn-secondary { background: #f1f2f4; color: var(--text); }
.btn-secondary:hover { background: #e5e7eb; }
.btn-whatsapp { background: var(--whatsapp); color: #fff; }
.btn-whatsapp:hover { background: #1fb455; }

/* ---------- Checkout ---------- */
.checkout-modal h2 { margin-top: 0; }
.checkout-sub { color: var(--muted); font-size: 13px; margin-top: -6px; }
#checkoutForm label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
#checkoutForm input, #checkoutForm textarea {
  width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: inherit;
}
.order-summary { background: var(--bg); border-radius: 8px; padding: 12px 14px; font-size: 13px; margin: 14px 0; max-height: 180px; overflow-y: auto; }
.order-summary-row { display: flex; justify-content: space-between; padding: 3px 0; }
.order-summary-total { display: flex; justify-content: space-between; font-weight: 800; border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
.checkout-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.checkout-note { font-size: 11.5px; color: var(--muted); margin-top: 12px; }
.btn-cancel { background: none; color: var(--muted); text-decoration: underline; padding: 6px; }
.btn-cancel:hover { color: var(--text); }
.checkout-banner {
  font-size: 13px; font-weight: 600; padding: 10px 14px; border-radius: 8px; margin: 4px 0 10px;
}
.checkout-banner.error { background: #fee2e2; color: var(--danger); }
.checkout-banner.success { background: #dcfce7; color: var(--success); }

@media (max-width: 640px) {
  .header-inner { gap: 10px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
}
