/* catalog.css — phone-first styles for the public catalog.
   No external fonts or images; system font stack only. */

:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1a2230;
  --muted: #5f6a79; /* darkened from #6b7484: >= 4.5:1 on both --card and --bg */
  --brand: #0f7a3d;
  --brand-ink: #ffffff;
  --in-stock: #0f7a3d;
  --out-stock: #b3261e;
  --chip-bg: #e9edf2;
  --line: #c9d2dd;
  --radius: 14px;
  --gap: 12px;
  /* Round 40: the real header height, measured by app.js (fitHeader) once
     the page runs. This default only covers the first paint before JS:
     roughly a one-row desktop header. */
  --header-h: 64px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* Round 40: focus/anchor jumps (search field, skip link) must land BELOW
     the fixed header, not under it. Tracks --header-h automatically. */
  scroll-padding-top: calc(var(--header-h) + 8px);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
               "Noto Naskh Arabic", "Noto Nastaliq Urdu", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Round 40: room for the fixed header (its measured height, --header-h). */
  padding-top: var(--header-h);
}

/* ---------- Header ---------- */
/* Round 43: the header's inner layout and colours live in the SHARED
   sheet (web/shared/header.css) — the same header the customer pages
   render. Only the catalog's positioning stays here: round 40's FIXED
   header (not sticky — as a sticky flex item it reserved no offset in
   the owner's browser, so content slid under it), with the measured
   --header-h offset on #app reserving exactly its real height in every
   browser, language and width. fitHeader() in app.js keeps --header-h
   equal to the header's height, search + chips rows included. */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

/* ---------- Content ---------- */
.content {
  padding: 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.search-label {
  font-weight: 600;
  white-space: nowrap;
}

.search-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: inherit;
}

.category-row { margin-bottom: 12px; }

.category-label {
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.chip-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 700;
}

/* ---------- Product grid: 1 column on phones, more when wider ---------- */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(20, 30, 50, 0.08);
  display: flex;
  flex-direction: column;
}

.card-media {
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #dfe7ef, #c6d3e1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.card-initial {
  font-size: 2.5rem;
  font-weight: 800;
  color: #5b6b7f;
}

/* Product picture (round 35): covers the media box over the initial-letter
   placeholder behind it. A load error adds .img-broken, which hides the
   img so the neutral placeholder shows — never a broken-image icon. */
.card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-broken {
  display: none;
}

.card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-name {
  margin: 0;
  font-size: 1rem;
}

.card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.card-price { margin: 4px 0 0; }

.card-price .price-label {
  color: var(--muted);
  font-weight: 400;
}

.card-barcode {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.badge {
  display: inline-block;
  align-self: flex-start;
  margin: 6px 0 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-in  { background: #e3f3e9; color: var(--in-stock); }
.badge-out { background: #fbe4e2; color: var(--out-stock); }

/* ---------- States ---------- */
.empty-wrap, .error-wrap {
  text-align: center;
  padding: 24px 12px;
}

.empty {
  color: var(--muted);
  margin: 0 0 12px;
}

.error-wrap .error {
  color: var(--out-stock);
  font-weight: 600;
  margin: 0 0 12px;
}

.btn-clear, .btn-retry {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-retry {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- Offline banner ---------- */
.offline-banner {
  background: #fff8e1;
  color: #6d5200;
  border-bottom: 1px solid #f0d97a;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---------- Loading skeleton ---------- */
.skeleton-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

@media (min-width: 560px) {
  .skeleton-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .skeleton-grid { grid-template-columns: repeat(3, 1fr); }
}

.skeleton-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(20, 30, 50, 0.08);
  padding-bottom: 12px;
}

.sk-media {
  aspect-ratio: 16 / 9;
  background: #e3e8ee;
}

.sk-line {
  height: 12px;
  border-radius: 6px;
  background: #e3e8ee;
  margin: 10px 14px 0;
}

.sk-w80 { width: 80%; }
.sk-w60 { width: 60%; }
.sk-w40 { width: 40%; }

@media (prefers-reduced-motion: no-preference) {
  .sk-media, .sk-line {
    animation: sk-pulse 1.4s ease-in-out infinite;
  }
}

@keyframes sk-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* ---------- Card actions ---------- */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn-share, .btn-wa {
  flex: 1;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

/* Contrast-checked pairs (>= 4.5:1, see test/catalog_test.mjs "color contrast"). */
.btn-share {
  border: 1px solid var(--line);
  background: #eef1f5;
  color: #1a2230;
}

.btn-wa {
  border: 1px solid #0d5c2e;
  background: #e7f6ec;
  color: #0d5c2e;
}

/* ---------- Cart (round 26) ---------- */
/* Round 43: the .cart-link / .account-link rules moved to the shared
   header sheet (web/shared/header.css), which keeps round 41's contrast
   fix — white var(--brand-ink) on the brand green = 5.42:1, WCAG AA;
   pinned in test/header_layout.test.mjs. */

.cart-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.qty-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eef1f5;
  color: #1a2230;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.qty-val {
  min-width: 20px;
  text-align: center;
  font-weight: 700;
}

.btn-add {
  flex: 1;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid #0d5c2e;
  background: #0d5c2e;
  color: #fff;
}

.btn-add:disabled {
  border-color: var(--line);
  background: #eef1f5;
  color: #5a6a7d;
  cursor: not-allowed;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2230;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

/* ---------- Accessibility: visible keyboard focus ---------- */
:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* Visually-hidden live-region text (still announced by screen readers). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link: hidden until it receives keyboard focus. */
.skip-link {
  position: absolute;
  top: -60px;
  inset-inline-start: 12px;
  z-index: 100;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
}

.skip-link:focus-visible {
  top: 8px;
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.site-footer {
  text-align: center;
  padding: 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- RTL: most layout flips automatically with dir="rtl";
   these rules fine-tune text alignment. The badge keeps align-self:
   flex-start from .badge, which already mirrors to the right in RTL —
   no override needed. ---------- */
[dir="rtl"] .search-input { text-align: right; }
[dir="rtl"] .card-body   { text-align: right; }
