@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #0a0f24;
  --panel: #12193a;
  --line: #2a3568;
  --text: #f3f5ff;
  --muted: #96a1c8;
  --blue: #3d6cf5;
  --blue2: #4f7cff;
  --green: #14b86a;
  --green2: #1ad07a;
  --danger: #ff7b7b;
  --shadow: 0 16px 36px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Vazirmatn, Tahoma, sans-serif;
  font-size: 14px;
  background:
    radial-gradient(900px 420px at 100% -8%, #1d2a6d 0%, transparent 55%),
    radial-gradient(700px 360px at 0% 100%, #15245f 0%, transparent 50%),
    linear-gradient(165deg, #171b45, #080b1d 48%, #0b1230);
}
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.app { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(9, 13, 32, .96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(42, 53, 104, .85);
}
.search-box {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 999px;
  background: #0d1430;
  border: 1px solid #2b3868;
}
.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  min-width: 0;
}
.search-ico { color: var(--muted); font-size: 18px; }
.brand-side { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #ff8a3d, #ff5a1f);
  font-weight: 800;
  flex-shrink: 0;
}
.brand-text strong { display: block; font-size: 14px; line-height: 1.1; }
.brand-text small { display: block; color: var(--muted); font-size: 11px; }
.cart-btn {
  position: relative;
  width: 42px;
  height: 42px;
  border: 1px solid #2d3b70;
  border-radius: 50%;
  background: #12193a;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.cart-btn b {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
}

.wrap {
  width: min(1180px, calc(100% - 16px));
  margin: 10px auto 40px;
}

.filter-panel {
  background: rgba(16, 22, 52, .72);
  border: 1px solid #27345f;
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 10px;
}
.stock-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.stock-tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #334275;
  background: #12193a;
  color: #d7dff8;
  font-size: 13px;
  white-space: nowrap;
}
.stock-tab.active {
  background: linear-gradient(120deg, var(--blue), var(--blue2));
  border-color: transparent;
  color: #fff;
  font-weight: 700;
}
.count-chip {
  margin-inline-start: auto;
  padding: 7px 12px;
  border-radius: 999px;
  background: #1a2348;
  border: 1px solid #334275;
  color: #c9d4f5;
  font-size: 12px;
}
.filters-form { display: grid; gap: 10px; }
.field { display: grid; gap: 6px; }
.field > span { color: #b8c4e6; font-size: 12px; }
.field select,
.field input,
.ghost-btn,
.checkout-form input,
.checkout-form textarea {
  width: 100%;
  background: #0d1430;
  border: 1px solid #30406c;
  border-radius: 14px;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  min-height: 46px;
}
.price-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #d5def7;
  background: #151d40;
  text-align: center;
}
.ghost-btn.apply {
  background: linear-gradient(120deg, var(--blue), var(--blue2));
  border-color: transparent;
  color: #fff;
  font-weight: 700;
}
.ghost-btn.full { width: 100%; margin-top: 8px; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  margin-top: 12px;
  font-size: 13px;
}
.stats b { color: #fff; }
.stats .ok b { color: #34d399; }
.stats .bad b { color: #fb7185; }

/* Sticky horizontal tags above product columns */
.tags-sticky {
  position: sticky;
  top: 66px;
  z-index: 20;
  margin: 0 -2px 12px;
  padding: 8px 0;
  background: linear-gradient(180deg, rgba(8, 11, 29, .96), rgba(8, 11, 29, .88));
  backdrop-filter: blur(8px);
}
.tag-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 4px 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tag-row::-webkit-scrollbar { display: none; }
.tag-pill {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #334275;
  background: #12193a;
  color: #d7dff8;
  white-space: nowrap;
  font-size: 13px;
}
.tag-pill.active {
  background: #111827;
  border-color: #111827;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 0 1px #93a4ff inset;
}

/* Products + side scroll progress rail */
.products-layout {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 12px;
  gap: 6px;
  align-items: start;
}
.list-rail {
  position: sticky;
  /* below topbar (~66px) + sticky tags (~56px) */
  top: 138px;
  height: min(58vh, 480px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 12;
  order: 2;
}
.list-progress-tag {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 1px;
  min-width: 40px;
  max-width: 46px;
  padding: 5px 3px;
  border-radius: 9px;
  background: #111827;
  border: 1px solid #3a4a84;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .24);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  writing-mode: horizontal-tb;
  flex-shrink: 0;
}
.list-progress-tag small {
  width: 100%;
  color: var(--muted);
  font-size: 8px;
  font-weight: 600;
  margin-top: 1px;
}
.list-progress-seen b { color: #7dd3fc; }
.list-progress-total b { color: #fff; }
.list-progress-sep { color: var(--muted); }
.list-rail-track {
  position: relative;
  flex: 1;
  width: 4px;
  border-radius: 999px;
  background: #1a2348;
  border: 1px solid #334675;
  overflow: hidden;
  cursor: pointer;
}
.list-rail-thumb {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 18%;
  min-height: 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, #4f7cff, #3d6cf5);
  box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset;
  transition: top .08s linear;
  pointer-events: none;
}

/* Snapp-like 2-column grid with large photos */
.products {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  order: 1;
  min-width: 0;
}
.product {
  background: #12193a;
  border: 1px solid #27345f;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.product.is-out { opacity: .7; }

.photo-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.05;
  background: #f4f6fb;
}
.photo-btn {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}
.photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
.empty-photo {
  display: grid;
  place-items: center;
  color: #6b7280;
  font-size: 12px;
  height: 100%;
}
.idx {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #5b4cff;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.quick-add {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  margin: 0;
}
.plus-fab {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #111827;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .22);
}

.p-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.p-body h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.45;
  font-weight: 800;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.9em;
}
.mini-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mini-tags a {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #1c2752;
  border: 1px solid #3a4a84;
  color: #b7c5ff;
}
.price-line {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 4px;
}
.price-line strong {
  font-size: 20px;
  font-weight: 800;
  direction: rtl;
  font-variant-numeric: normal;
  font-feature-settings: "ss01";
}
.price-line small { color: var(--muted); font-size: 12px; }
.code-line,
.carton-line {
  color: #c5d0ef;
  font-size: 12px;
  line-height: 1.4;
}
.code-line {
  direction: ltr;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.code-line b,
.carton-line b {
  color: #fff;
  font-weight: 700;
}

.buy { margin-top: auto; padding-top: 8px; position: relative; z-index: 5; }
.add-form { display: grid; gap: 6px; position: relative; z-index: 5; }
.btn.add { position: relative; z-index: 6; pointer-events: auto; touch-action: manipulation; }
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: #0d1430;
  border: 1px solid #334675;
}
.mode-opt {
  margin: 0;
  cursor: pointer;
}
.mode-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-opt span {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #c5d0ef;
}
.mode-opt input:checked + span {
  background: linear-gradient(120deg, var(--blue), var(--blue2));
  color: #fff;
}
.qty-bar {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 4px;
  background: #0d1430;
  border: 1px solid #334675;
  border-radius: 12px;
  padding: 4px;
  min-height: 40px;
}
.qty-bar form { margin: 0; }
.qty-bar input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  text-align: center;
  font-weight: 700;
}
.qty-bar button,
.qty-step {
  width: 36px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: #243b68;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}
.qty-bar strong { text-align: center; }
.qty-bar.blue button { background: #2b4a8a; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.btn.add,
.btn.primary {
  background: linear-gradient(120deg, var(--green), var(--green2));
  box-shadow: 0 8px 18px rgba(20, 184, 106, .25);
  min-height: 42px;
  width: 100%;
}
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.in-cart {
  background: #102d36;
  border: 1px solid #0f8a68;
  border-radius: 12px;
  padding: 6px;
  text-align: center;
}
.in-cart > span {
  display: block;
  color: #5de0a6;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
}
.out-badge {
  background: #3a1b28;
  color: #fb7185;
  border: 1px solid #7f2d44;
  border-radius: 12px;
  padding: 10px;
  font-weight: 700;
  text-align: center;
  font-size: 12px;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 42px 18px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.empty.soft { background: transparent; border: 0; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 20, .62);
  backdrop-filter: blur(3px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.overlay[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.cart-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(420px, 100%);
  height: 100%;
  background: #0e1430;
  border-left: 1px solid #27345f;
  z-index: 50;
  transform: translateX(-105%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.cart-drawer.open {
  transform: translateX(0);
  pointer-events: auto;
}
.drawer-head, .drawer-foot, .modal-head { padding: 16px; border-bottom: 1px solid #243156; }
.drawer-foot { border-bottom: 0; border-top: 1px solid #243156; margin-top: auto; }
.drawer-head { display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2, .modal-head h2 { margin: 0; font-size: 18px; }
.drawer-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.drawer-body { overflow: auto; padding: 12px 16px 20px; flex: 1; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #334675;
  background: #151d40;
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.cart-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #223057;
}
.cart-thumb {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  overflow: hidden;
  background: #e8ebf4;
}
.cart-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cart-info h3 { margin: 0 0 4px; font-size: 13px; line-height: 1.5; }
.cart-info .code, .cart-info .unit { color: var(--muted); font-size: 12px; }
.cart-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.cart-actions .qty-bar { min-width: 130px; }
.remove { background: none; border: 0; color: var(--danger); cursor: pointer; padding: 0; }
.line-total { margin-top: 8px; font-weight: 800; direction: rtl; text-align: right; }
.sum-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 15px;
}
.sum-row b { direction: rtl; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}
.modal.open { display: grid; pointer-events: auto; }
.modal[hidden] { display: none !important; pointer-events: none !important; }
.modal-card {
  width: min(560px, 100%);
  max-height: min(92vh, 860px);
  overflow: auto;
  background: #12193a;
  border: 1px solid #2c3a6d;
  border-radius: 20px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.checkout-form { padding: 8px 16px 16px; }
.checkout-form label {
  display: block;
  margin: 12px 0 6px;
  color: #c6d0ef;
  font-size: 13px;
}
.checkout-form input,
.checkout-form textarea { width: 100%; }
.checkout-summary {
  margin: 16px 0;
  padding: 12px;
  border-radius: 14px;
  background: #0d1430;
  border: 1px solid #2a3868;
}
.checkout-summary div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
}
.checkout-summary b { direction: ltr; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-actions .btn,
.modal-actions .ghost-btn { flex: 1; min-width: 140px; }

.toast-wrap {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  width: min(420px, calc(100% - 24px));
  transition: opacity .3s ease, transform .3s ease;
}
.toast-wrap.hide { opacity: 0; transform: translate(-50%, -12px); pointer-events: none; }
.toast {
  background: #1c3b58;
  border: 1px solid #355d83;
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}
.lightbox.open,
.lightbox:not([hidden]) {
  display: grid;
  pointer-events: auto;
}
.lightbox[hidden] { display: none !important; }
.lightbox img {
  max-width: min(920px, 92vw);
  max-height: min(82vh, 920px);
  object-fit: contain;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}
.lightbox-close {
  position: fixed;
  top: 18px;
  left: 18px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  z-index: 71;
}
.lightbox-caption {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90vw, 640px);
  text-align: center;
  color: #fff;
  font-size: 14px;
  background: rgba(8, 12, 28, .72);
  padding: 8px 14px;
  border-radius: 999px;
}

.success {
  width: min(520px, calc(100% - 24px));
  margin: 60px auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 20px;
}
.check {
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #164b40;
  color: #66e1b5;
  font-size: 28px;
}

@media (min-width: 760px) {
  .products-layout { grid-template-columns: 1fr 14px; gap: 8px; }
  .products { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .list-rail { top: 132px; height: min(64vh, 520px); }
  .list-progress-tag { min-width: 42px; max-width: 48px; font-size: 10px; }
  .list-rail-track { width: 5px; }
  .p-body h3 { font-size: 17px; }
  .price-line strong { font-size: 20px; }
  .brand-text { display: block; }
}

@media (min-width: 1100px) {
  .topbar {
    max-width: 1240px;
    margin: 8px auto 0;
    border: 1px solid #20294d;
    border-radius: 18px;
  }
  .products-layout { grid-template-columns: 1fr 14px; }
  .products { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-panel {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 12px 18px;
  }
  .stock-tabs, .stats { grid-column: 1 / -1; }
  .filter-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 759px) {
  .brand-text { display: none; }
  .cart-drawer { width: 100%; }
  .modal { padding: 0; align-items: end; }
  .modal.open { align-items: end; }
  .modal-card {
    width: 100%;
    max-height: 94vh;
    border-radius: 20px 20px 0 0;
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn,
  .modal-actions .ghost-btn { width: 100%; }
}

@media (max-width: 360px) {
  .products { gap: 8px; }
  .p-body { padding: 8px; }
  .price-line strong { font-size: 13px; }
}
