:root {
  --primary: #0f3d5e;
  --primary-dark: #082438;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --danger: #dc2626;
  --success: #059669;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: Vazirmatn, Tahoma, 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
  body {
    padding-bottom: 24px;
  }
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font-family: inherit;
}

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 14px;
}

/* نوار نصب اپلیکیشن وب (PWA) */
.install-banner {
  background: linear-gradient(90deg, #082438, #0f3d5e);
  color: #fff;
  padding: 10px 14px;
  font-size: 0.88rem;
}

.install-banner-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.install-banner.hidden {
  display: none;
}

/* هدر */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-img {
  height: 44px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .brand-logo-img {
    height: 36px;
  }
}

.hero-brand-mark {
  height: 48px;
  width: auto;
  margin-bottom: 10px;
  opacity: 0.96;
}

.footer-logo-img {
  height: 38px;
  width: auto;
  object-fit: contain;
}

.sandbox-logo {
  height: 52px;
  width: auto;
  margin: 0 auto 12px;
  object-fit: contain;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.35rem;
  border: 2px solid var(--accent);
}

.brand strong {
  display: block;
  font-size: 1.05rem;
  color: var(--primary-dark);
}

.brand small {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.search-bar {
  flex: 1 1 280px;
  display: flex;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.search-bar:focus-within {
  border-color: var(--primary);
}

.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  font-size: 0.92rem;
  outline: none;
}

.search-bar button {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
}

.topbar-actions {
  display: none;
  align-items: center;
  gap: 8px;
}

@media (min-width: 768px) {
  .topbar-actions {
    display: flex;
  }
}

/* دکمه‌ها */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: center;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-dark);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-outline {
  background: #fff;
  color: var(--primary);
  border-color: var(--border);
}

.btn-outline:hover {
  border-color: var(--primary);
  background: #f8fafc;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 12px 20px;
  font-size: 1rem;
}

.cart-pill {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.78rem;
  font-weight: 700;
}

/* هیرو */
.hero {
  margin: 16px 0;
  background: linear-gradient(125deg, #082438 0%, #0f3d5e 65%, #164e63 100%);
  color: #fff;
  border-radius: 18px;
  padding: 22px 20px;
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow);
}

@media (min-width: 768px) {
  .hero {
    grid-template-columns: 1.4fr 1fr;
    align-items: center;
    padding: 30px 28px;
  }
}

.hero h1 {
  font-size: 1.4rem;
  line-height: 1.45;
  margin-bottom: 8px;
}

@media (min-width: 768px) {
  .hero h1 {
    font-size: 1.85rem;
  }
}

.hero p {
  color: #cbd5e1;
  font-size: 0.94rem;
  margin-bottom: 14px;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-badge {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
}

.hero-promo {
  background: rgba(249, 115, 22, 0.16);
  border: 1.5px dashed rgba(249, 115, 22, 0.7);
  border-radius: 14px;
  padding: 16px;
}

.hero-promo h3 {
  color: #fed7aa;
  margin-bottom: 6px;
  font-size: 1.05rem;
}

/* فیلترها */
.filters-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.category-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.filter-chip {
  white-space: nowrap;
  border: 1.5px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-chip.discount-chip.active {
  background: var(--danger);
  border-color: var(--danger);
}

.filter-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 640px) {
  .filter-controls {
    grid-template-columns: repeat(3, 1fr);
  }
}

.filter-controls select, .toggle-box {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 0.88rem;
}

.toggle-box {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
}

/* گرید محصولات رسپانسیو */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 768px) {
  .products-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 1080px) {
  .products-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
  }
}

.product-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.1);
}

.product-card.has-discount {
  border-color: #fecaca;
}

.corner-discount {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: linear-gradient(135deg, #dc2626, #ea580c);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 9px;
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(220, 38, 38, 0.3);
}

.product-thumb {
  display: block;
  background: #f8fafc;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

.product-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 6px;
}

.product-meta {
  font-size: 0.73rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.product-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-cars {
  font-size: 0.76rem;
  color: #334155;
  background: #f1f5f9;
  padding: 4px 8px;
  border-radius: 8px;
}

.price-section {
  margin-top: auto;
  padding-top: 6px;
}

.old-price {
  font-size: 0.82rem;
  color: #94a3b8;
  text-decoration: line-through;
}

.final-price {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.savings-tag {
  display: inline-block;
  margin-top: 3px;
  font-size: 0.73rem;
  font-weight: 700;
  color: #065f46;
  background: #d1fae5;
  padding: 2px 8px;
  border-radius: 6px;
}

.discount-label-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: #9a3412;
  background: #ffedd5;
  padding: 2px 7px;
  border-radius: 6px;
}

.card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.card-actions .btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 0.8rem;
}

@media (max-width: 480px) {
  .products-grid {
    gap: 9px;
  }
  .product-body {
    padding: 9px;
  }
  .product-title {
    font-size: 0.84rem;
  }
  .final-price {
    font-size: 0.94rem;
  }
}

/* نوار پایین موبایل */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: #fff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
}

@media (min-width: 768px) {
  .mobile-bottom-nav {
    display: none;
  }
}

.mobile-nav-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  position: relative;
}

.mobile-nav-btn.active {
  color: var(--primary);
}

.mobile-nav-badge {
  position: absolute;
  top: -2px;
  right: 22%;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  padding: 0 5px;
  border-radius: 999px;
}

/* کشو سبد خرید و مودال */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.backdrop.open {
  display: flex;
}

.drawer-backdrop {
  justify-content: flex-end;
  padding: 0;
}

.drawer {
  width: 100%;
  max-width: 440px;
  height: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.2);
}

.drawer-header, .modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}

.drawer-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}

.cart-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.modal-box {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.25);
}

.modal-body {
  padding: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 560px) {
  .form-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.field label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.summary-total {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary-dark);
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

/* صفحه جزئیات محصول SSR */
.product-detail-page {
  padding-top: 18px;
  padding-bottom: 36px;
}

.breadcrumb {
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.product-detail-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  display: grid;
  gap: 22px;
  box-shadow: var(--shadow);
}

@media (min-width: 768px) {
  .product-detail-card {
    grid-template-columns: 1fr 1.2fr;
    padding: 26px;
  }
}

.product-detail-media {
  position: relative;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: grid;
  place-items: center;
}

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  background: #f1f5f9;
  color: #334155;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.discount-banner {
  background: #fef2f2;
  border: 1.5px solid #fecaca;
  border-radius: 12px;
  padding: 10px 12px;
  margin: 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.badge-discount {
  background: var(--danger);
  color: #fff;
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.86rem;
}

.badge-label {
  background: #ffedd5;
  color: #9a3412;
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.82rem;
}

.savings-pill {
  color: #065f46;
  font-weight: 700;
  font-size: 0.86rem;
}

.stock-status {
  font-weight: 700;
  margin: 10px 0;
}
.stock-status.in { color: var(--success); }
.stock-status.out { color: var(--danger); }

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

/* شبیه‌ساز درگاه */
.sandbox-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.sandbox-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  max-width: 500px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.sandbox-badge {
  display: inline-block;
  background: #ffedd5;
  color: #9a3412;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 10px;
}

.sandbox-info {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin: 16px 0;
  display: grid;
  gap: 8px;
}

.sandbox-info > div {
  display: flex;
  justify-content: space-between;
}

.sandbox-actions {
  display: grid;
  gap: 10px;
}

/* پنل ادمین */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0;
}

@media (min-width: 768px) {
  .admin-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat-card small {
  color: var(--muted);
  display: block;
}

.stat-card strong {
  font-size: 1.25rem;
  color: var(--primary-dark);
}

.panel-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th, td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.footer {
  margin-top: 32px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  background: #fff;
  font-size: 0.86rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 90;
  font-size: 0.88rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  display: none;
}

.toast.show {
  display: block;
}
