/* =====================================================================
   بازارچه — سیستم طراحی (برگرفته از ظاهر قالب بازار 24)
   رنگ اصلی سرمه‌ای #002874، فونت IRANSansX، کارت‌های گرد، حالت شب
   ===================================================================== */
:root {
  --bg: #F9FAFB;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6B7280;
  --line: #E5E7EB;
  --line-2: #F3F4F6;
  --surface: #F9FAFB;
  --card: #FFFFFF;

  --brand: #002874;
  --brand-deep: #001D5A;
  --brand-ink: #00143F;
  --brand-tint: #E8ECF5;
  --brand-line: #C5CEE6;
  --btn: #002874;
  --btn-hover: #001D5A;

  --saffron: #F59E0B;
  --saffron-deep: #92400E;
  --saffron-tint: #FEF3C7;
  --saffron-line: #FCD34D;

  --ok: #047857; --ok-tint: #D1FAE5; --ok-line: #A7F3D0;
  --danger: #B91C1C; --danger-tint: #FEE2E2; --danger-line: #FECACA; --red: #EF4444;

  --r-sm: 12px; --r: 16px; --r-lg: 22px;
  --shadow-1: 0 1px 2px rgba(17,24,39,.05);
  --shadow-2: 0 10px 28px -10px rgba(0,40,116,.22);
  --font: "IRANSansX", "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
}
html.dark {
  --bg: #0A0A0A;
  --ink: #F3F4F6;
  --ink-2: #D1D5DB;
  --muted: #9CA3AF;
  --line: #1F2937;
  --line-2: #171F2B;
  --surface: #111827;
  --card: #111111;

  --brand: #4C6FB6;
  --brand-deep: #8FA8DB;
  --brand-ink: #0A1530;
  --brand-tint: rgba(76,111,182,.16);
  --brand-line: rgba(76,111,182,.38);
  --btn: #1E3F8C;
  --btn-hover: #2A4FA5;

  --saffron: #FBBF24;
  --saffron-deep: #FCD34D;
  --saffron-tint: rgba(251,191,36,.12);
  --saffron-line: rgba(251,191,36,.35);

  --ok: #34D399; --ok-tint: rgba(16,185,129,.14); --ok-line: rgba(16,185,129,.35);
  --danger: #F87171; --danger-tint: rgba(239,68,68,.14); --danger-line: rgba(239,68,68,.35);
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 12px 30px -10px rgba(0,0,0,.7);
  color-scheme: dark;
}
@font-face {
  font-family: "IRANSansX"; font-style: normal; font-weight: normal; font-display: swap;
  src: url("/static/fonts/IRANSansXNoEn-Regular.woff2") format("woff2"),
       url("/static/fonts/IRANSansXNoEn-Regular.woff") format("woff"),
       url("/static/fonts/IRANSansX-Regular.ttf") format("truetype");
}

* { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.9; direction: rtl; -webkit-font-smoothing: antialiased; transition: background .3s, color .3s; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-deep); }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { line-height: 1.5; margin: 0 0 .55em; color: var(--ink); font-weight: 700; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
b, strong { font-weight: 700; }
p { margin: 0 0 .8em; }
.container { width: min(1360px, 100% - 32px); margin-inline: auto; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.inline { display: inline; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; inset-inline-start: -999px; top: 8px; background: var(--card); padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { inset-inline-start: 8px; }

.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 16px; height: 16px; }
.i.lg { width: 28px; height: 28px; }

/* ---------- دکمه‌ها ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; cursor: pointer; font: inherit; font-weight: 700;
  background: var(--btn); color: #fff; padding: 9px 20px; border-radius: var(--r-sm); transition: background .2s, border-color .2s, box-shadow .2s, transform .2s; line-height: 1.7; }
.btn:hover { background: var(--btn-hover); color: #fff; }
.btn.alt { background: var(--saffron); color: #111827; }
.btn.alt:hover { background: #D97706; color: #111827; }
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--brand-line); }
.btn.ghost:hover { background: var(--brand-tint); border-color: var(--brand); color: var(--brand); }
.btn.danger { background: var(--red); color: #fff; } .btn.danger:hover { background: #DC2626; }
.btn.light { background: #fff; color: #001D5A; } .btn.light:hover { background: #E8ECF5; }
.btn.sm { padding: 5px 14px; font-size: .88rem; }
.btn.lg { padding: 12px 28px; font-size: 1.02rem; border-radius: var(--r); }
.btn.block { display: flex; width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.linkbtn:hover { color: var(--brand-deep); text-decoration: underline; }

/* ---------- اصلی ---------- */
main { padding: 26px 0 56px; min-height: 62vh; }
.messages { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 8px; }
.messages li { padding: 11px 16px; border-radius: var(--r-sm); background: var(--brand-tint); border: 1px solid var(--brand-line); color: var(--brand-ink); }
.messages li.success { background: var(--ok-tint); border-color: var(--ok-line); color: var(--ok); }
.messages li.error { background: var(--danger-tint); border-color: var(--danger-line); color: var(--danger); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow-1); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 20px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 34px 0 14px; }
.section-head h2 { margin: 0; font-size: 1.28rem; }
.section-head a { font-size: .92rem; font-weight: 600; }
.section-head:first-child { margin-top: 0; }

/* فرم‌ها */
label { display: block; font-weight: 700; margin-bottom: 5px; font-size: .9rem; color: var(--ink-2); }
input[type=text], input[type=number], input[type=password], input[type=email], input[type=tel], input[type=file], select, textarea {
  width: 100%; padding: 10px 13px; border: 1.5px solid var(--line); border-radius: var(--r-sm); font: inherit; background: var(--card); color: var(--ink);
  transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-tint); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 17px; height: 17px; }
input[type=file] { padding: 8px; background: var(--surface); }
textarea { resize: vertical; }
.field { margin-bottom: 16px; }
.help, .helptext { color: var(--muted); font-size: .82rem; display: block; margin-top: 4px; }
.errorlist { color: var(--danger); list-style: none; padding: 0; margin: 5px 0 0; font-size: .86rem; }
.form-narrow { max-width: 540px; margin-inline: auto; }
.form-card { padding: 28px; }
.form-card h1 { margin-bottom: 4px; }
#id_plan { display: grid; gap: 10px; }
#id_plan > div { border: 1.5px solid var(--line); border-radius: var(--r); padding: 12px 14px; background: var(--card); transition: border-color .15s, background .15s; }
#id_plan > div:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }
#id_plan label { display: flex; gap: 10px; align-items: center; font-weight: 700; margin: 0; color: var(--ink); }
#id_plan input { width: 17px; }

/* برچسب‌ها */
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--saffron-tint); color: var(--saffron-deep); border: 1px solid var(--saffron-line);
  border-radius: 6px; padding: 0 9px; font-size: .78rem; font-weight: 800; line-height: 1.7; white-space: nowrap; }
.tag.green { background: var(--ok-tint); color: var(--ok); border-color: var(--ok-line); }
.tag.brand { background: var(--brand-tint); color: var(--brand-deep); border-color: var(--brand-line); }
.tag.gray { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.price { font-weight: 800; color: var(--ink); white-space: nowrap; }
.price small { font-weight: 500; color: var(--muted); font-size: .78em; }
.price.big { font-size: 1.7rem; letter-spacing: -.5px; }

/* ---------- صفحه اصلی ---------- */
.hero { position: relative; overflow: hidden; border-radius: 22px; padding: 46px 46px 46px; margin-bottom: 30px;
  background: linear-gradient(135deg, #00143F 0%, #001D5A 55%, #002874 100%); color: #fff;
  display: grid; grid-template-columns: 1.15fr .85fr; gap: 36px; align-items: center; }
.hero::before { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; inset-inline-end: -140px; top: -220px;
  background: radial-gradient(circle, rgba(245,164,0,.28), transparent 65%); pointer-events: none; }
.hero::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: 22px 22px; pointer-events: none; mask-image: linear-gradient(90deg, transparent, #000 70%); }
.hero > * { position: relative; z-index: 1; }
.hero h1 { color: #fff; font-size: 2.15rem; line-height: 1.5; margin-bottom: 12px; }
.hero p.lead { color: #C9D4EC; font-size: 1.05rem; max-width: 52ch; margin-bottom: 22px; }
.hero .cta { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 28px; }
.hero .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.hero .btn.ghost:hover { background: rgba(255,255,255,.12); border-color: #fff; color: #fff; }
.hero-stats { display: flex; gap: 34px; flex-wrap: wrap; }
.hero-stats b { display: block; font-size: 1.55rem; font-weight: 900; color: #fff; line-height: 1.3; }
.hero-stats span { color: #9FB1D6; font-size: .86rem; }
.hero-panel { background: var(--card); color: var(--ink); border-radius: var(--r-lg); padding: 16px; box-shadow: 0 24px 50px -20px rgba(0,0,0,.5); }
.hero-panel h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: .95rem; }
.hp-item { display: flex; align-items: center; gap: 12px; padding: 9px 6px; border-top: 1px solid var(--line-2); color: var(--ink); }
.hp-item:hover { background: var(--surface); border-radius: 10px; color: var(--ink); }
.hp-thumb { width: 52px; height: 52px; border-radius: 10px; overflow: hidden; background: var(--brand-tint); flex: none; }
.hp-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.hp-name { flex: 1; font-size: .88rem; font-weight: 600; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hp-price { font-weight: 800; font-size: .92rem; white-space: nowrap; }

.trust { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 8px; }
.trust > div { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.trust .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-tint); color: var(--brand); display: grid; place-items: center; flex: none; }
.trust b { display: block; font-size: .95rem; }
.trust span { color: var(--muted); font-size: .82rem; }

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.cat-tile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 20px 12px; color: var(--ink); font-weight: 700; font-size: .95rem; transition: border-color .15s, transform .15s, box-shadow .15s; }
.cat-tile .ic { width: 54px; height: 54px; border-radius: 16px; background: var(--brand-tint); color: var(--brand); display: grid; place-items: center; }
.cat-tile:hover { border-color: var(--brand); box-shadow: var(--shadow-2); color: var(--brand-deep); transform: translateY(-2px); }

/* ---------- کارت کالا ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 16px; }
.pcard { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column;
  color: var(--ink); box-shadow: var(--shadow-1); transition: border-color .3s, box-shadow .3s, transform .3s; }
.pcard:hover { border-color: var(--brand-line); box-shadow: 0 12px 28px -10px rgba(0,40,116,.25); transform: translateY(-4px); color: var(--ink); }
.pcard:hover .name { color: var(--brand); }
.pcard .bagbtn { position: absolute; bottom: 12px; inset-inline-end: 12px; width: 36px; height: 36px; border-radius: 12px; background: var(--btn); color: #fff; display: grid; place-items: center;
  opacity: 0; transform: scale(.85); transition: opacity .3s, transform .3s; }
.pcard:hover .bagbtn { opacity: 1; transform: scale(1); }
.pcard .img { aspect-ratio: 1; background: var(--surface); display: grid; place-items: center; overflow: hidden; position: relative; }
.pcard .img img { width: 100%; height: 100%; object-fit: contain; padding: 14px; transition: transform .5s; }
.pcard:hover .img img { transform: scale(1.08); }
.pcard .img .tag { position: absolute; top: 10px; inset-inline-start: 10px; }
.pcard .body { padding: 13px 14px 15px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.pcard .brand { color: var(--muted); font-size: .8rem; }
.pcard .name { font-weight: 700; font-size: .94rem; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 3.3em; }
.pcard .foot { margin-top: auto; padding-top: 8px; display: flex; justify-content: space-between; align-items: end; gap: 6px; padding-inline-end: 44px; }
.pcard .price { font-size: 1.02rem; }
.noimg { color: var(--muted); font-size: .85rem; }

/* ---------- جستجو ---------- */
.layout { display: grid; grid-template-columns: 280px 1fr; gap: 24px; align-items: start; }
.sidebar { position: sticky; top: 150px; display: grid; gap: 14px; }
.sidebar .card { padding: 16px; }
.sidebar h3 { font-size: .95rem; padding-bottom: 8px; border-bottom: 1px solid var(--line-2); margin-bottom: 10px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-inline-start: 14px; border-inline-start: 2px solid var(--line-2); margin: 2px 4px 2px 0; }
.tree li { margin: 1px 0; }
.tree summary { cursor: pointer; padding: 3px 0; }
.tree a { color: var(--ink-2); font-size: .92rem; }
.tree a:hover { color: var(--brand); }
.tree a.active { font-weight: 800; color: var(--brand-deep); }
.crumbs { font-size: .86rem; color: var(--muted); margin-bottom: 14px; display: flex; gap: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); } .crumbs a:hover { color: var(--brand); }
.sortbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 10px 14px; }
.sortbar a { padding: 3px 14px; border-radius: 99px; color: var(--ink-2); font-size: .88rem; font-weight: 600; border: 1px solid transparent; }
.sortbar a:hover { background: var(--surface); }
.sortbar a.on { background: var(--brand-tint); color: var(--brand-deep); border-color: var(--brand-line); }
.sortbar .count { margin-inline-start: auto; }
.filter-toggle { display: none; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 26px; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 15px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--card); font-weight: 600; }
.pager span.cur { background: var(--btn); color: #fff; border-color: var(--btn); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ic { width: 64px; height: 64px; border-radius: 20px; background: var(--brand-tint); color: var(--brand); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { color: var(--ink); }

/* ---------- صفحه کالا ---------- */
.pdetail { display: grid; grid-template-columns: 420px 1fr 330px; gap: 26px; align-items: start; }
.gallery .main { aspect-ratio: 1; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; display: grid; place-items: center; }
.gallery .main img { width: 100%; height: 100%; object-fit: contain; padding: 18px; }
.gallery .thumbs { display: flex; gap: 8px; margin-top: 10px; }
.gallery .thumbs img { width: 68px; height: 68px; object-fit: contain; padding: 4px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); }
.gallery .thumbs a:hover img { border-color: var(--brand); }
.pinfo h1 { font-size: 1.4rem; }
.meta-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 14px; }
.buybox { position: sticky; top: 150px; padding: 0; overflow: hidden; }
.buybox .bb-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--line-2); }
.buybox .bb-body { padding: 16px 20px 20px; display: grid; gap: 14px; }
.bb-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bb-note { background: var(--surface); border-radius: var(--r-sm); padding: 10px 12px; font-size: .84rem; color: var(--ink-2); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
table.t th, table.t td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); text-align: right; vertical-align: middle; }
table.t th { background: var(--surface); font-size: .82rem; color: var(--muted); font-weight: 700; }
table.t tbody tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: var(--surface); }
table.t tr.best td { background: var(--saffron-tint); }
.scroll-x { overflow-x: auto; border-radius: var(--r); }
.specs td:first-child { width: 36%; color: var(--muted); background: var(--surface); font-weight: 600; }
.diff td { background: var(--saffron-tint); }
.store-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; background: var(--brand-tint); color: var(--brand-deep); font-weight: 900;
  display: grid; place-items: center; flex: none; }
.chart { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; max-width: 380px; }
.chart svg { width: 100%; height: auto; }

/* ---------- فروشگاه‌ها ---------- */
.store-card { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; color: var(--ink);
  transition: border-color .15s, box-shadow .15s; }
.store-card:hover { border-color: var(--brand-line); box-shadow: var(--shadow-2); color: var(--ink); }
.store-card .avatar { width: 52px; height: 52px; font-size: 1.2rem; }
.store-card .sname { font-weight: 800; }
.store-hero { display: flex; gap: 18px; align-items: center; }
.store-hero .avatar { width: 72px; height: 72px; font-size: 1.8rem; border-radius: 20px; }

/* ---------- پنل فروشنده ---------- */
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 22px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 6px; }
.subtabs a { padding: 7px 16px; border-radius: 9px; color: var(--ink-2); font-weight: 600; font-size: .9rem; }
.subtabs a:hover { background: var(--surface); }
.subtabs a.on { background: var(--btn); color: #fff; }
.stat { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.stat .card b { font-size: 1.5rem; display: block; line-height: 1.5; }
.stat .card .lbl { color: var(--muted); font-size: .84rem; font-weight: 600; }


/* ---------- واکنش‌گرا ---------- */
@media (max-width: 1100px) {
  .pdetail { grid-template-columns: 360px 1fr; }
  .buybox { grid-column: 1 / -1; position: static; }
  .hero { grid-template-columns: 1fr; padding: 34px 28px; }
  .hero-panel { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .filter-toggle { display: inline-flex; margin-bottom: 12px; }
  .sidebar .card { display: none; }
  .sidebar.show .card { display: block; }
  .pdetail { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  h1 { font-size: 1.3rem; } .hero h1 { font-size: 1.55rem; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .form-card { padding: 20px; }
  .pcard .bagbtn { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } .pcard:hover, .cat-tile:hover { transform: none; }  }

/* ---------- اصلاح نمای موبایل: جلوگیری از عرض اضافه و نمایش نیمه‌باز کشوها ---------- */
html { overflow-x: hidden; }
img, video, svg { max-width: 100%; }
.off.right, .off.left { visibility: hidden; transition: transform .3s ease, visibility .3s; }
body.open-menu .off.right, body.open-cart .off.left { visibility: visible; }
