*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  /* iOS Safari: prefer fill-available so 100vh/dvh don't overshoot the visual viewport */
  height: 100%;
  height: -webkit-fill-available;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--dz-background);
  color: var(--dz-text);
  font-family: var(--dz-font);
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
}

button, input, textarea, select {
  font-family: inherit;
}

/*
 * iOS Safari zooms the page when a focused text control is < 16px.
 * That zoom often sticks → shell looks clipped until the user resets zoom to 100%.
 * Apply on all widths (iPad landscape can be ≥900px). OTP overlay stays 2rem (higher specificity).
 */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="hidden"]):not(.dz-otp-hidden),
textarea,
select {
  font-size: 16px;
}

a {
  color: var(--dz-primary-dark);
}

#app {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
}

/**
 * Optional: vertical scrollbar on the physical left (nested list panes only).
 * Do NOT apply to .dz-app-shell__body — transform creates a containing block for
 * position:fixed and clips stage-edge scrollbar / full-screen modals.
 * Chrome/Edge on Windows keep the native bar on the right even with dir=rtl;
 * mirroring the scroller (and un-mirroring direct children) is the reliable fix.
 */
.dz-vscroll-left {
  transform: scaleX(-1);
}

.dz-vscroll-left > * {
  transform: scaleX(-1);
}

.dz-app-shell {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  background: var(--dz-background);
  position: relative;
  overflow-x: hidden;
  box-sizing: border-box;
  /* Notch / home indicator — keep shell inside the visible frame on iPhone */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.dz-app-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  /* Allow nested pages (e.g. purchase history) to size against stage height */
  height: 100%;
}

/* همان گرادیانت بالای صفحه — روی استیج (موبایل تمام‌عرض / دسکتاپ داخل قاب) */
.dz-app-stage::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  height: 220px;
  background: var(--dz-auth-haze);
  pointer-events: none;
  z-index: 0;
}

.dz-app-shell__body {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 32px;
}

/* کروم دسکتاپ (هدر/فوتر سایت) — موبایل مخفی */
.dz-desk-chrome {
  display: none;
}

.dz-app-mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

/* موبایل: استیج کل ارتفاع را پر کند */
.dz-app-mid > .dz-app-stage {
  flex: 1;
  min-height: 0;
}

/* دسکتاپ: هدر/فوتر جمع‌وجور + کل شل در یک ویوپورت (بدون اسکرول بیرونی روی FHD) */
@media (min-width: 900px) {
  .dz-app-shell {
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
    box-sizing: border-box;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background:
      radial-gradient(ellipse 90% 50% at 50% -5%, color-mix(in srgb, var(--dz-primary) 16%, transparent), transparent 55%),
      radial-gradient(ellipse 40% 35% at 8% 70%, color-mix(in srgb, var(--dz-primary) 7%, transparent), transparent 50%),
      radial-gradient(ellipse 35% 30% at 92% 80%, color-mix(in srgb, var(--dz-primary) 6%, transparent), transparent 50%),
      linear-gradient(180deg, #f7f5fb 0%, var(--dz-background) 28%, var(--dz-background) 100%);
  }

  .dz-desk-chrome {
    display: block;
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    z-index: 2;
    direction: rtl;
  }

  .dz-desk-chrome--top {
    padding: 12px 40px 10px;
    border-bottom: 1px solid color-mix(in srgb, var(--dz-primary) 12%, var(--dz-border));
    background:
      linear-gradient(180deg, color-mix(in srgb, #fff 70%, transparent) 0%, transparent 100%);
    backdrop-filter: blur(10px);
  }

  .dz-desk-chrome__glow {
    position: absolute;
    inset-inline: 10% 10%;
    bottom: -1px;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent 0%,
      color-mix(in srgb, var(--dz-primary-dark) 55%, transparent) 50%,
      transparent 100%
    );
    pointer-events: none;
  }

  .dz-desk-chrome__inner {
    max-width: 1120px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
  }

  .dz-desk-chrome__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }

  .dz-desk-chrome__logo {
    width: 44px;
    height: auto;
    flex-shrink: 0;
    filter: drop-shadow(0 4px 10px rgba(53, 0, 102, 0.16));
  }

  .dz-desk-chrome__logo--sm {
    width: 22px;
    filter: none;
    opacity: 0.9;
  }

  .dz-desk-chrome__titles {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
  }

  .dz-desk-chrome__name {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--dz-primary);
    letter-spacing: -0.01em;
    line-height: 1.25;
  }

  .dz-desk-chrome__tagline {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--dz-text-muted);
    line-height: 1.3;
  }

  .dz-desk-chrome__meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }

  .dz-desk-chrome__pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--dz-primary) 0%, var(--dz-primary-dark) 100%);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--dz-primary) 28%, transparent);
  }

  .dz-desk-chrome__sep {
    width: 1px;
    height: 18px;
    background: var(--dz-border);
  }

  .dz-desk-chrome__hint {
    font-size: 0.72rem;
    color: var(--dz-text-muted);
    font-weight: 400;
    max-width: 200px;
    line-height: 1.35;
  }

  .dz-app-mid {
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    min-height: 0;
    overflow: hidden;
  }

  .dz-app-stage {
    flex: 0 1 auto;
    width: min(440px, 100%);
    height: 100%;
    max-height: 100%;
    border-radius: 28px;
    overflow: hidden;
    background: var(--dz-background);
    border: 1px solid color-mix(in srgb, var(--dz-border) 80%, transparent);
    box-shadow:
      0 0 0 1px color-mix(in srgb, #000 4%, transparent),
      0 24px 60px rgba(25, 6, 73, 0.16),
      0 6px 18px rgba(0, 0, 0, 0.06);
  }

  .dz-desk-chrome--bottom {
    margin-top: 0;
    padding: 10px 40px 12px;
    border-top: 1px solid var(--dz-border);
    background:
      linear-gradient(0deg, color-mix(in srgb, var(--dz-primary) 5%, #fff) 0%, color-mix(in srgb, #fff 88%, transparent) 100%);
  }

  .dz-desk-chrome__inner--foot {
    flex-wrap: wrap;
    justify-content: space-between;
    row-gap: 6px;
  }

  .dz-desk-foot__brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--dz-primary-dark);
  }

  .dz-desk-foot__legal {
    margin: 0;
    font-size: 0.72rem;
    color: var(--dz-text-muted);
    text-align: center;
    flex: 1 1 auto;
  }

  .dz-desk-foot__note {
    margin: 0;
    font-size: 0.68rem;
    color: var(--dz-gray-400);
    flex-shrink: 0;
  }

  .dz-app-shell__body {
    max-width: none;
    width: 100%;
    margin: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--dz-primary-dark) 35%, transparent) transparent;
    /* فقط دسکتاپ: گرید محصولات نسبت به عرض قاب واکنش دهد */
    container-type: inline-size;
    container-name: dz-stage;
  }

  .dz-app-shell__body::-webkit-scrollbar {
    width: 6px;
  }

  .dz-app-shell__body::-webkit-scrollbar-track {
    background: transparent;
    margin: 10px 0 90px;
  }

  .dz-app-shell__body::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--dz-primary-dark) 28%, transparent);
    border-radius: 999px;
    border: 1px solid transparent;
    background-clip: padding-box;
  }

  .dz-app-shell__body::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--dz-primary-dark) 48%, transparent);
    background-clip: padding-box;
  }

  .dz-app-shell__body::-webkit-scrollbar-corner {
    background: transparent;
  }

  /* In-stage modals (buy/filter) can't cover desk chrome — dim chrome to match DialogHost. */
  html.dz-shell-scrim .dz-app-mid {
    position: relative;
    z-index: 3000;
  }

  html.dz-shell-scrim .dz-desk-chrome--top::before,
  html.dz-shell-scrim .dz-desk-chrome--bottom::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 5;
    background: rgba(0, 0, 0, 0.53);
    pointer-events: none;
  }
}

/* دسکتاپ متوسط/بزرگ: فقط عرض بیشتر — ارتفاع هدر/فوتر ثابت می‌ماند تا FHD اسکرول نخورد */
@media (min-width: 1100px) {
  .dz-desk-chrome--top {
    padding-inline: 56px;
  }

  .dz-desk-chrome__logo {
    width: 48px;
  }

  .dz-desk-chrome__name {
    font-size: 1.22rem;
  }

  .dz-desk-chrome__inner {
    max-width: 1200px;
  }

  .dz-app-stage {
    width: min(500px, 100%);
  }

  .dz-desk-chrome--bottom {
    padding-inline: 56px;
  }
}

@media (min-width: 1280px) {
  .dz-desk-chrome--top {
    padding-inline: 72px;
  }

  .dz-desk-chrome__logo {
    width: 52px;
  }

  .dz-desk-chrome__name {
    font-size: 1.28rem;
  }

  .dz-desk-chrome__inner {
    max-width: 1320px;
  }

  .dz-app-mid {
    padding-inline: 32px;
  }

  .dz-app-stage {
    width: min(560px, 100%);
    border-radius: 32px;
  }

  .dz-desk-chrome--bottom {
    padding-inline: 72px;
  }
}

@media (min-width: 900px) and (prefers-color-scheme: dark) {
  .dz-app-shell {
    background:
      radial-gradient(ellipse 90% 50% at 50% -5%, rgba(159, 88, 225, 0.22), transparent 55%),
      radial-gradient(ellipse 40% 35% at 8% 70%, rgba(159, 88, 225, 0.1), transparent 50%),
      radial-gradient(ellipse 35% 30% at 92% 80%, rgba(159, 88, 225, 0.08), transparent 50%),
      linear-gradient(180deg, #161018 0%, var(--dz-background) 30%, var(--dz-background) 100%);
  }

  .dz-desk-chrome--top {
    border-bottom-color: #333;
    background: linear-gradient(180deg, rgba(28, 28, 30, 0.92) 0%, rgba(18, 18, 18, 0.4) 100%);
  }

  .dz-desk-chrome__name {
    color: var(--dz-secondary-dark-text);
  }

  .dz-desk-chrome__pill {
    background: linear-gradient(135deg, #7b3fb0 0%, #9f58e1 100%);
    color: #1a1028;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  }

  .dz-desk-chrome__sep {
    background: #444;
  }

  .dz-desk-chrome__logo {
    filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45));
  }

  .dz-app-stage {
    border-color: #333;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.04),
      0 22px 56px rgba(0, 0, 0, 0.55),
      0 4px 16px rgba(0, 0, 0, 0.35);
  }

  .dz-desk-chrome--bottom {
    border-top-color: #333;
    background: linear-gradient(0deg, #141016 0%, rgba(28, 28, 30, 0.85) 100%);
  }

  .dz-desk-foot__brand {
    color: var(--dz-secondary-dark-text);
  }

  .dz-app-shell__body {
    scrollbar-color: rgba(225, 190, 231, 0.35) transparent;
  }

  .dz-app-shell__body::-webkit-scrollbar-thumb {
    background: rgba(225, 190, 231, 0.28);
    background-clip: padding-box;
  }

  .dz-app-shell__body::-webkit-scrollbar-thumb:hover {
    background: rgba(225, 190, 231, 0.45);
    background-clip: padding-box;
  }
}

/* Brand logo: swap by system theme */
.dz-logo {
  display: block;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.dz-logo--dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  .dz-logo--light {
    display: none;
  }
  .dz-logo--dark {
    display: block;
  }
}

.dz-ico {
  display: inline-flex;
  width: 1.25em;
  height: 1.25em;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dz-ico svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Boot splash — fixed full viewport so desktop/Android/iOS all center the same way */
.dz-boot {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--dz-boot-grad);
  font-family: var(--dz-font);
  padding:
    max(24px, env(safe-area-inset-top, 0px))
    max(24px, env(safe-area-inset-right, 0px))
    max(24px, env(safe-area-inset-bottom, 0px))
    max(24px, env(safe-area-inset-left, 0px));
  text-align: center;
  box-sizing: border-box;
}

/* While splash is in #app, keep html/body the same solid (no two-tone strip above). */
html:has(.dz-boot),
body:has(.dz-boot),
#app:has(.dz-boot) {
  background: var(--dz-boot-grad);
  min-height: 100%;
  min-height: 100dvh;
}

.dz-boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: min(280px, 100%);
}

.dz-boot-brand {
  position: relative;
  width: 168px;
  height: 168px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dz-boot-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--dz-primary-dark) 22%, transparent);
  border-top-color: var(--dz-primary-dark);
  animation: dz-boot-spin 0.9s linear infinite;
}

.dz-boot-brand .dz-logo {
  width: 118px;
  height: 118px;
  position: relative;
  z-index: 1;
}

.dz-boot-progress {
  width: min(220px, 100%);
  margin: 14px auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.dz-boot-progress[hidden] {
  display: none !important;
}

.dz-boot-progress__track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--dz-primary-dark) 16%, transparent);
}

.dz-boot-progress__bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--dz-primary-dark), var(--dz-primary));
  transition: width 0.18s ease-out;
}

.dz-boot-progress__pct {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--dz-text-muted, #666);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.dz-boot-sub {
  margin-top: 18px;
  max-width: 18.5rem;
  padding-inline: 12px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--dz-text-muted);
  line-height: 1.55;
  text-align: center;
}

.dz-boot-retry {
  margin-top: 18px;
  max-width: 220px;
}

@keyframes dz-boot-spin {
  to { transform: rotate(360deg); }
}

.dz-ready-card {
  background: var(--dz-surface);
  border-radius: var(--dz-radius-lg);
  box-shadow: var(--dz-shadow-soft);
  padding: 22px 18px;
  border: 1px solid var(--dz-border);
}

.dz-ready-card h1 {
  margin: 0 0 8px;
  font-size: 1.25rem;
  color: var(--dz-primary);
  font-weight: 700;
}

.dz-ready-card p {
  margin: 0 0 12px;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--dz-text-muted);
}

.dz-ready-meta {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
  color: var(--dz-text-muted);
}

.dz-ready-meta li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--dz-border);
}

.dz-ready-meta strong {
  color: var(--dz-midnight-blue);
  font-weight: 700;
  word-break: break-all;
  text-align: left;
  direction: ltr;
}

.dz-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--dz-status-buy-light);
  color: var(--dz-primary);
}

.dz-pill--ok {
  background: var(--dz-status-ready-light);
  color: var(--dz-status-ready);
}

.dz-pill--warn {
  background: var(--dz-status-download-light);
  color: var(--dz-status-download);
}

/* Blazor framework error UI — keep #blazor-error-ui, .reload, .dismiss hooks */
#blazor-error-ui {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 4000;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  font-family: var(--dz-font);
  direction: rtl;
  align-items: center;
  justify-content: center;
}

#blazor-error-ui.blazor-error-boundary,
#blazor-error-ui[style*="display: block"],
#blazor-error-ui.show {
  display: flex !important;
}

.dz-blazor-error {
  width: min(100%, 360px);
  margin: 0 auto;
  padding: 22px 18px 16px;
  border-radius: 16px;
  background: var(--dz-surface, #fff);
  color: var(--dz-text, #242424);
  box-shadow: 0 18px 48px rgba(25, 6, 73, 0.28);
  text-align: center;
  animation: dz-blazor-error-in 0.28s ease both;
}

@keyframes dz-blazor-error-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.dz-blazor-error__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  background: var(--dz-red, #ed1c24);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--dz-red, #ed1c24) 35%, transparent);
}

.dz-blazor-error__title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--dz-primary, #350066);
}

.dz-blazor-error__msg {
  margin: 0 0 16px;
  font-size: 0.86rem;
  line-height: 1.65;
  color: var(--dz-text-muted, #6E6E6E);
}

.dz-blazor-error__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#blazor-error-ui .reload,
.dz-blazor-error__reload {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--dz-primary, #350066);
  color: #fff !important;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none !important;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--dz-primary, #350066) 35%, transparent);
}

#blazor-error-ui .dismiss,
.dz-blazor-error__dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 999px;
  background: transparent;
  color: var(--dz-text-muted, #6E6E6E) !important;
  font-weight: 700;
  font-size: 0.88rem;
  text-decoration: none !important;
  cursor: pointer;
  position: static;
}

@media (prefers-color-scheme: dark) {
  .dz-blazor-error {
    background: var(--dz-surface, #1c1230);
    color: var(--dz-text, #f2f2f2);
  }

  #blazor-error-ui .reload,
  .dz-blazor-error__reload {
    background: var(--dz-primary-dark, #9f58e1);
  }
}

.validation-message {
  color: var(--dz-red);
}
