/* Tokens from design/tokens.json */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #38bdf8;
  --indigo: #4f46e5;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --tint: #eff6ff;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 10px 25px rgba(37, 99, 235, 0.12);
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --font: "Tajawal", "Noto Sans Arabic", system-ui, sans-serif;
  color-scheme: light;
}
:root[lang="ku"] { --font: "Noto Sans Arabic", "Tajawal", system-ui, sans-serif; }
:root[lang="en"] { --font: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #3b82f6; --primary-hover: #60a5fa; --bg: #0f172a; --surface: #1e293b; --surface-2: #273449;
    --tint: #172554; --text: #f8fafc; --muted: #94a3b8; --faint: #64748b; --border: #334155;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --primary: #3b82f6; --primary-hover: #60a5fa; --bg: #0f172a; --surface: #1e293b; --surface-2: #273449;
  --tint: #172554; --text: #f8fafc; --muted: #94a3b8; --faint: #64748b; --border: #334155;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.35); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.6; min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { width: 100%; max-width: 1280px; margin-inline: auto; padding-inline: 16px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border); }
.topbar__inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo__mark { width: 38px; height: 38px; display: block; }
.logo__text { font-weight: 800; font-size: 22px; line-height: 1; }
.logo__text small { color: var(--primary); font-size: 13px; font-weight: 700; margin-inline-start: 4px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 12px; border-radius: var(--r-sm); color: var(--muted); font-weight: 500; font-size: 15px; }
.nav a:hover, .nav a.active { color: var(--text); background: var(--surface-2); }
.topsearch { flex: 1; max-width: 520px; }
.topsearch input { width: 100%; height: 42px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  padding-inline: 18px; outline: none; }
.topsearch input:focus { border-color: var(--primary); background: var(--surface); }
.actions { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 7px; font-size: 13px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.select { height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding-inline: 8px; }
.iconbtn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; color: var(--muted); }
.iconbtn:hover { color: var(--primary); }

/* Home hero (Torob-style centered search) */
.hero { text-align: center; padding: 64px 0 32px; }
.hero__brand { display: inline-flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.hero__brand img { height: 132px; width: auto; display: block; }
.hero h1 { font-size: clamp(24px, 4vw, 38px); margin: 0 0 6px; font-weight: 800; line-height: 1.35; }
.hero p { color: var(--muted); margin: 0 auto 28px; max-width: 640px; }

.searchbox { position: relative; max-width: 760px; margin-inline: auto; }
.searchbox form { display: flex; align-items: center; background: var(--surface); border: 2px solid var(--primary);
  border-radius: 999px; box-shadow: var(--shadow); padding: 6px; }
.searchbox input { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 48px; padding-inline: 20px; font-size: 17px; }
.searchbox button[type="submit"] { height: 48px; padding-inline: 28px; border: 0; border-radius: 999px; background: var(--primary);
  color: #fff; font-weight: 700; font-size: 15px; }
.searchbox button[type="submit"]:hover { background: var(--primary-hover); }
.suggest { position: absolute; inset-inline: 16px; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow); list-style: none; margin: 0; padding: 6px; z-index: 30; text-align: start; }
.suggest li a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 8px; }
.suggest li a:hover, .suggest li a[aria-selected="true"] { background: var(--tint); }
.suggest small { color: var(--faint); text-transform: capitalize; }
.suggest li a { align-items: center; }
.suggest img, .suggest__ph { width: 40px; height: 40px; flex-shrink: 0; border-radius: 8px; object-fit: contain; background: var(--surface-2); }
.suggest__name { flex: 1; min-width: 0; display: grid; }
.suggest__name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest__price { flex-shrink: 0; font-weight: 700; font-size: 14px; }
.topsearch { position: relative; }
.topsearch .suggest { inset-inline: 0; top: calc(100% + 8px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin-top: 18px; }
.chips > span { color: var(--muted); font-weight: 700; font-size: 14px; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 5px 14px; border-radius: 999px; font-size: 14px; font-weight: 500; }
.chip:hover, .chip.on { border-color: var(--primary); color: var(--primary); background: var(--tint); }

/* Sections */
.section { margin: 36px 0; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section__head h2 { font-size: 22px; margin: 0; font-weight: 800; }
.section__head a { color: var(--primary); font-weight: 700; font-size: 14px; }

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.cat { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px; transition: border-color .15s, transform .15s; }
.cat:hover { border-color: var(--primary); transform: translateY(-2px); }
.cat__icon { width: 48px; height: 48px; border-radius: 50%; background: var(--tint); display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.cat b { display: block; font-size: 15px; }
.cat small { color: var(--muted); font-size: 13px; }

/* Product cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; display: flex; flex-direction: column;
  gap: 10px; transition: border-color .15s, box-shadow .15s; }
.card:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); box-shadow: var(--shadow); }
.thumb { aspect-ratio: 4/3; border-radius: var(--r-md); background: linear-gradient(160deg, var(--tint), var(--surface-2));
  display: grid; place-items: center; font-size: 48px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.card h3 { font-size: 15px; margin: 0; font-weight: 700; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; min-height: 45px; }
.card__price { margin-top: auto; }
.card__price small { color: var(--muted); font-size: 12px; display: block; }
.card__price strong { color: var(--primary); font-size: 19px; font-weight: 800; }
.card__price em { color: var(--faint); font-size: 12px; font-style: normal; display: block; }
.card__foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--surface-2); padding-top: 10px;
  font-size: 13px; color: var(--muted); }
.pill { background: var(--tint); color: var(--primary); font-weight: 700; padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.unavailable { opacity: .6; }

/* Search page */
.searchpage { display: grid; grid-template-columns: 260px 1fr; gap: 24px; margin-top: 24px; align-items: start; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; position: sticky; top: 80px; }
.filters h4 { margin: 0 0 8px; font-size: 14px; }
.filters fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.filters label { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; cursor: pointer; text-transform: capitalize; }
.filters input[type="number"] { width: 100%; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding-inline: 10px; }
.range { display: flex; gap: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toolbar h1 { font-size: 20px; margin: 0; }
.sorts { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding-inline: 18px; border-radius: var(--r-md);
  border: 0; background: var(--primary); color: #fff; font-weight: 700; font-size: 15px; white-space: nowrap; }
.btn:hover { background: var(--primary-hover); }
.btn--soft { background: var(--tint); color: var(--primary); }
.btn--soft:hover { background: var(--primary); color: #fff; }
.btn--ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.pager { display: flex; justify-content: center; gap: 8px; margin: 28px 0; }
.filters-toggle { display: none; }

/* Product page */
.crumbs { font-size: 14px; color: var(--muted); margin: 20px 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a:hover { color: var(--primary); }
.summary { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px; display: flex; gap: 20px; }
.summary .thumb { width: 140px; flex-shrink: 0; aspect-ratio: 1; font-size: 64px; }
.summary h1 { font-size: 22px; margin: 0 0 6px; line-height: 1.45; }
.summary .alt { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.range-line { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; font-size: 15px; }
.range-line strong { color: var(--primary); font-size: 22px; font-weight: 800; }
.specs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.offers-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 28px 0 12px; }
.offers-head h2 { margin: 0; font-size: 20px; }
.offers { display: flex; flex-direction: column; gap: 12px; }
.offer { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 20px;
  display: grid; grid-template-columns: 44px 1fr auto auto; gap: 16px; align-items: center; }
.offer.top { border: 2px solid var(--primary); }
.offer.out { opacity: .55; }
.rank { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; color: var(--muted); }
.offer.top .rank { background: var(--primary); color: #fff; }
.offer__store b { font-size: 17px; }
.offer__store .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.offer__store .meta .good { color: var(--success); font-weight: 700; }
.offer__title { font-size: 12px; color: var(--faint); margin-top: 4px; display: block; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--muted); }
.badge--blue { background: var(--tint); color: var(--primary); }
.badge--green { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge--amber { background: color-mix(in srgb, var(--warning) 18%, transparent); color: #b45309; }
.offer__price { text-align: end; }
.offer__price strong { font-size: 21px; font-weight: 800; display: block; }
.offer.top .offer__price strong { color: var(--primary); }
.offer__price small { color: var(--faint); font-size: 13px; }
.score { display: grid; grid-template-columns: auto 64px; gap: 2px 8px; font-size: 11px; color: var(--muted); align-items: center; margin-top: 6px; }
.bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.explain { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--r-md); padding: 12px 16px; margin-top: 16px; font-size: 14px; color: var(--muted); }
.explain summary { cursor: pointer; font-weight: 700; color: var(--text); }

/* Stores page */
.stores { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.store { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; }
.store b { font-size: 17px; }
.store p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }

/* States */
.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty b { display: block; font-size: 20px; color: var(--text); margin-bottom: 6px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%;
  animation: shimmer 1.2s infinite; border-radius: 16px; min-height: 260px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 24px 0; font-size: 14px; }
.footer p { margin: 4px 0; }

/* Mobile-first adjustments */
@media (max-width: 900px) {
  .nav { display: none; }
  .searchpage { grid-template-columns: 1fr; }
  .filters { position: static; display: none; }
  .filters.open { display: block; }
  .filters-toggle { display: inline-flex; }
  .offer { grid-template-columns: 36px 1fr; gap: 10px 12px; padding: 14px; }
  .offer__price { grid-column: 2; text-align: start; }
  .offer .btn { grid-column: 1 / -1; width: 100%; }
}
@media (max-width: 640px) {
  .topbar__inner { gap: 8px; height: 58px; }
  .logo__text small { display: none; }
  /* Search stays available on phones: a full-width row under the header (not on home, which has its own box). */
  .topbar__inner { flex-wrap: wrap; height: auto; min-height: 58px; padding-block: 8px; }
  .topsearch { order: 10; flex-basis: 100%; max-width: none; }
  .topsearch .suggest { max-height: 70vh; overflow-y: auto; }
  .select { width: 72px; }
  .hero { padding: 36px 0 16px; }
  .hero__brand img { height: 104px; }
  .searchbox input { height: 42px; padding-inline: 12px; font-size: 16px; }
  .searchbox button[type="submit"] { height: 42px; padding-inline: 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 10px; border-radius: 14px; }
  .card h3 { font-size: 14px; }
  .card__price strong { font-size: 16px; }
  .summary { flex-direction: column; padding: 16px; }
  .summary .thumb { width: 100%; aspect-ratio: 16/9; }
  .cats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Long store titles / model codes must wrap instead of widening grid cells on phones. */
.offer > *, .summary > div, .searchpage > *, .card { min-width: 0; }
.offer__title, .summary h1, .summary .alt, .card h3, .crumbs b { overflow-wrap: anywhere; }
.crumbs b { font-weight: 700; color: var(--text); }
.score { width: max-content; margin-inline-start: auto; }
@media (max-width: 900px) { .score { margin-inline-start: 0; } }
@media (max-width: 640px) { .summary .thumb { aspect-ratio: 3/1; font-size: 48px; } }
