/* =====================================================================
   Default theme
   =====================================================================
   RTL rule: use logical properties everywhere (margin-inline-start, not
   margin-left). The layout then mirrors for Persian with no separate
   stylesheet and no [dir=rtl] override blocks.
   ===================================================================== */

/* ---------------------------------------------------------------------
   Fonts — self-hosted.
   Persian webfont CDNs are unreliable from Iran, and a VPN storefront
   that needs a VPN to render its own text is a bad joke.
   --------------------------------------------------------------------- */

@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

/* ---------------------------------------------------------------------
   Tokens
   --------------------------------------------------------------------- */

:root {
  /* Injected from settings by the layout — never hardcoded here. */
  --color-primary: #D4537E;
  --color-accent:  #5DCAA5;

  --color-bg:          #FFFFFF;
  --color-surface:     #FBEAF0;
  --color-surface-alt: #F7F5F2;
  --color-border:      #EDE4E7;
  --color-text:        #2B1E24;
  --color-text-muted:  #8A7A80;
  --color-text-invert: #FFFFFF;

  --color-success: #2E9E6B;
  --color-warning: #D99436;
  --color-danger:  #D14343;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --shadow-sm: 0 1px 2px rgba(43, 30, 36, 0.06);
  --shadow-md: 0 4px 16px rgba(43, 30, 36, 0.08);
  --shadow-lg: 0 12px 40px rgba(43, 30, 36, 0.12);

  --font-latin:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-persian: 'Vazirmatn', Tahoma, sans-serif;

  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  --container: 1120px;
}

[data-radius="sharp"] { --radius-sm: 2px; --radius-md: 4px;  --radius-lg: 6px; }
[data-radius="round"] { --radius-sm: 14px; --radius-md: 24px; --radius-lg: 36px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:          #171114;
    --color-surface:     #221A20;
    --color-surface-alt: #2C222A;
    --color-border:      #3A2E36;
    --color-text:        #F5EDF1;
    --color-text-muted:  #A8949E;
  }
}

:root[data-theme="dark"] {
  --color-bg:          #171114;
  --color-surface:     #221A20;
  --color-surface-alt: #2C222A;
  --color-border:      #3A2E36;
  --color-text:        #F5EDF1;
  --color-text-muted:  #A8949E;
}

/* ---------------------------------------------------------------------
   Reset
   --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-latin);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[dir="rtl"] body { font-family: var(--font-persian); }

h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 700; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
p  { margin: 0 0 var(--space-3); }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; height: auto; display: block; }

/* Latin digits inside Persian text: technical values stay scannable. */
.num, time, code, .mono {
  font-family: var(--font-latin);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: embed;
}

/* ---------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.page { min-height: 100vh; display: flex; flex-direction: column; }
.page__main { flex: 1; padding-block: var(--space-6); }

.stack > * + * { margin-block-start: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row--between { justify-content: space-between; }
.spacer { flex: 1; }

.grid { display: grid; gap: var(--space-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ---------------------------------------------------------------------
   Header
   --------------------------------------------------------------------- */

.header {
  border-block-end: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: 64px;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
}

.header__brand:hover { text-decoration: none; }
.header__logo { height: 28px; width: auto; }

.header__nav { display: flex; align-items: center; gap: var(--space-4); margin-inline-start: auto; }
.header__link { color: var(--color-text-muted); font-size: 0.95rem; }
.header__link:hover, .header__link[aria-current="page"] { color: var(--color-text); text-decoration: none; }

@media (max-width: 720px) {
  .header__nav { gap: var(--space-3); font-size: 0.9rem; }
  .header__link--optional { display: none; }
}

/* ---------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------- */

.footer {
  border-block-start: 1px solid var(--color-border);
  padding-block: var(--space-5);
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* ---------------------------------------------------------------------
   Cards
   --------------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}

.card--flat { background: var(--color-bg); }
.card--pad-sm { padding: var(--space-4); }

.card__title { font-size: 1rem; font-weight: 700; margin-block-end: var(--space-2); }
.card__meta  { color: var(--color-text-muted); font-size: 0.875rem; }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform var(--transition), filter var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; filter: brightness(0.94); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary { background: var(--color-primary); color: #fff; }
.btn--accent  { background: var(--color-accent);  color: #06251B; }
.btn--ghost   { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn--danger  { background: var(--color-danger); color: #fff; }
.btn--block   { width: 100%; }
.btn--sm      { padding: 6px 14px; font-size: 0.85rem; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */

.field { margin-block-end: var(--space-4); }

.field__label {
  display: block;
  margin-block-end: var(--space-2);
  font-size: 0.875rem;
  font-weight: 600;
}

.field__input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field__input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent);
}

.field__input--error { border-color: var(--color-danger); }

/* Email and password are always LTR even in a Persian form — an RTL
   password field puts the caret on the wrong side and confuses typing. */
.field__input[type="email"],
.field__input[type="password"],
.field__input[type="url"] {
  direction: ltr;
  text-align: start;
}

[dir="rtl"] .field__input[type="email"],
[dir="rtl"] .field__input[type="password"],
[dir="rtl"] .field__input[type="url"] {
  text-align: right;
}

.field__error { margin-block-start: var(--space-2); color: var(--color-danger); font-size: 0.8rem; }
.field__hint  { margin-block-start: var(--space-2); color: var(--color-text-muted); font-size: 0.8rem; }

.field__password { position: relative; }

.field__toggle {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
  line-height: 0;
}

.checkbox { display: flex; align-items: center; gap: var(--space-2); font-size: 0.9rem; cursor: pointer; }

/* ---------------------------------------------------------------------
   Alerts
   --------------------------------------------------------------------- */

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border-inline-start: 3px solid;
  font-size: 0.9rem;
  margin-block-end: var(--space-4);
}

.alert--info    { background: color-mix(in srgb, var(--color-accent) 12%, transparent);  border-color: var(--color-accent); }
.alert--success { background: color-mix(in srgb, var(--color-success) 12%, transparent); border-color: var(--color-success); }
.alert--warning { background: color-mix(in srgb, var(--color-warning) 12%, transparent); border-color: var(--color-warning); }
.alert--danger  { background: color-mix(in srgb, var(--color-danger) 12%, transparent);  border-color: var(--color-danger); }

/* ---------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
}

.badge--active    { background: color-mix(in srgb, var(--color-success) 16%, transparent); color: var(--color-success); }
.badge--warning   { background: color-mix(in srgb, var(--color-warning) 16%, transparent); color: var(--color-warning); }
.badge--danger    { background: color-mix(in srgb, var(--color-danger) 16%, transparent);  color: var(--color-danger); }

/* ---------------------------------------------------------------------
   Progress
   --------------------------------------------------------------------- */

.progress {
  height: 6px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width 400ms ease;
}

.progress__bar--warning { background: var(--color-warning); }
.progress__bar--danger  { background: var(--color-danger); }

/* ---------------------------------------------------------------------
   Auth pages
   --------------------------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-4);
}

.auth__card {
  width: 100%;
  max-width: 400px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

.auth__mascot { display: grid; place-items: center; margin-block-end: var(--space-4); }
.auth__title { text-align: center; margin-block-end: var(--space-1); }
.auth__subtitle { text-align: center; color: var(--color-text-muted); font-size: 0.9rem; margin-block-end: var(--space-5); }
.auth__footer { margin-block-start: var(--space-5); text-align: center; font-size: 0.875rem; color: var(--color-text-muted); }

/* ---------------------------------------------------------------------
   Hero
   --------------------------------------------------------------------- */

.hero { padding-block: var(--space-8); text-align: center; }

.hero--gradient {
  background:
    radial-gradient(ellipse at top, color-mix(in srgb, var(--color-primary) 12%, transparent), transparent 60%),
    radial-gradient(ellipse at bottom, color-mix(in srgb, var(--color-accent) 10%, transparent), transparent 60%);
}

.hero__title { font-size: clamp(2rem, 5vw, 3rem); }
.hero__tagline { color: var(--color-text-muted); font-size: 1.1rem; max-width: 40ch; margin-inline: auto; }
.hero__actions { display: flex; gap: var(--space-3); justify-content: center; margin-block-start: var(--space-5); flex-wrap: wrap; }

/* ---------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------- */

.empty { text-align: center; padding: var(--space-7) var(--space-4); color: var(--color-text-muted); }
.empty__icon { font-size: 2.5rem; margin-block-end: var(--space-3); opacity: 0.5; }

/* ---------------------------------------------------------------------
   Error page
   --------------------------------------------------------------------- */

.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: var(--space-4); }
.error-page__code { font-size: 4rem; font-weight: 700; color: var(--color-primary); line-height: 1; }

/* ---------------------------------------------------------------------
   Mascot
   --------------------------------------------------------------------- */

.mascot { width: 120px; height: 120px; user-select: none; }
.mascot svg { overflow: visible; }

/* ---------------------------------------------------------------------
   Utilities
   --------------------------------------------------------------------- */

.text-muted  { color: var(--color-text-muted); }
.text-center { text-align: center; }
.text-sm     { font-size: 0.875rem; }
.text-xs     { font-size: 0.75rem; }
.mt-0 { margin-block-start: 0; }
.mb-0 { margin-block-end: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
