/* =========================================================================
   پیام‌بر — Design Tokens
   Single source of truth for all design decisions.
   Signal Grid Philosophy: Engineered precision, semantic color, modular scale.
   ========================================================================= */

:root {
  /* ─── Color Primitives ──────────────────────────────────────────────── */
  --color-bg: #070b16;
  --color-bg-soft: #0c1220;
  --color-surface: rgba(255, 255, 255, 0.035);
  --color-surface-strong: rgba(255, 255, 255, 0.06);
  --color-surface-elevated: rgba(255, 255, 255, 0.09);

  --color-border: rgba(148, 163, 184, 0.14);
  --color-border-strong: rgba(148, 163, 184, 0.28);
  --color-border-focus: rgba(34, 211, 238, 0.6);

  --color-text-primary: #e6ebf5;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
  --color-text-inverse: #070b16;
  --color-text-on-accent: #06111f;

  /* ─── Semantic Protocol Colors ──────────────────────────────────────── */
  /* Used ONLY where that protocol's data lives */
  --color-bale: #2dd4a5;
  --color-rubika: #8b7bf7;
  --color-eitaa: #f4b740;
  --color-telegram: #38bdf8;
  --color-soroush: #e85d75;

  /* ─── System Colors ─────────────────────────────────────────────────── */
  --color-cyan: #22d3ee;
  --color-indigo: #6366f1;
  --color-violet: #a78bfa;
  --color-green: #34d399;
  --color-gold: #ffb800;
  --color-orange: #fb923c;
  --color-red: #fb6a7a;
  --color-danger: #fb6a7a;
  --color-success: #34d399;

  /* ─── Gradients ─────────────────────────────────────────────────────── */
  --gradient-primary: linear-gradient(135deg, var(--color-cyan) 0%, var(--color-indigo) 100%);
  --gradient-primary-hover: linear-gradient(135deg, #3ae0fb 0%, #7c7aff 100%);
  --gradient-violet-cyan: linear-gradient(135deg, var(--color-violet) 0%, var(--color-cyan) 100%);
  --gradient-gold-orange: linear-gradient(135deg, var(--color-gold) 0%, var(--color-orange) 100%);
  --gradient-green-cyan: linear-gradient(135deg, var(--color-green) 0%, var(--color-cyan) 100%);
  --gradient-red-pink: linear-gradient(135deg, var(--color-red) 0%, #f472b6 100%);
  --gradient-surface: linear-gradient(180deg, var(--color-surface) 0%, var(--color-surface-strong) 100%);
  --gradient-glow-cyan: radial-gradient(ellipse, rgba(34, 211, 238, 0.18) 0%, transparent 70%);
  --gradient-glow-violet: radial-gradient(ellipse, rgba(167, 139, 250, 0.18) 0%, transparent 70%);
  --gradient-glow-bale: radial-gradient(ellipse, rgba(45, 212, 165, 0.15) 0%, transparent 70%);

  /* ─── Typography ────────────────────────────────────────────────────── */
  --font-sans: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-display: 'Tektur', 'Vazirmatn', sans-serif;

  --text-xs: 0.72rem;      /* 11.5px - micro labels, timestamps */
  --text-sm: 0.85rem;      /* 13.6px - UI labels, captions */
  --text-base: 1rem;       /* 16px - body text */
  --text-lg: 1.15rem;      /* 18.4px - emphasized body */
  --text-xl: 1.5rem;       /* 24px - small headings */
  --text-2xl: 2.25rem;     /* 36px - medium headings */
  --text-3xl: 3.5rem;      /* 56px - large headings */
  --text-4xl: clamp(2.5rem, 5vw, 5rem); /* 40-80px - hero */

  --leading-none: 1;
  --leading-tight: 1.15;
  --leading-snug: 1.375;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;
  --leading-loose: 2;

  --font-light: 300;
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;
  --font-black: 900;

  --tracking-tight: -0.03em;
  --tracking-normal: 0;
  --tracking-wide: 0.02em;
  --tracking-wider: 0.04em;
  --tracking-widest: 0.1em;

  /* ─── Spacing (4px base unit) ──────────────────────────────────────── */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 22px;
  --space-6: 28px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;
  --space-10: 56px;
  --space-11: 64px;
  --space-12: 80px;
  --space-13: 96px;
  --space-14: 128px;

  /* ─── Sizing ────────────────────────────────────────────────────────── */
  --size-xs: 20px;
  --size-sm: 28px;
  --size-md: 36px;
  --size-lg: 44px;
  --size-xl: 52px;
  --size-2xl: 64px;

  /* ─── Border Radius ─────────────────────────────────────────────────── */
  --radius-none: 0;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-2xl: 32px;
  --radius-full: 999px;

  /* ─── Shadows & Glows ───────────────────────────────────────────────── */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 4px 8px -4px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 40px -20px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 32px 64px -24px rgba(0, 0, 0, 0.7);

  --glow-cyan: 0 0 24px rgba(34, 211, 238, 0.35), 0 0 48px rgba(34, 211, 238, 0.15);
  --glow-violet: 0 0 24px rgba(167, 139, 250, 0.35), 0 0 48px rgba(167, 139, 250, 0.15);
  --glow-bale: 0 0 24px rgba(45, 212, 165, 0.3), 0 0 48px rgba(45, 212, 165, 0.12);
  --glow-gold: 0 0 24px rgba(255, 184, 0, 0.3), 0 0 48px rgba(255, 184, 0, 0.12);
  --glow-red: 0 0 24px rgba(251, 106, 122, 0.35), 0 0 48px rgba(251, 106, 122, 0.15);

  /* ─── Transitions ───────────────────────────────────────────────────── */
  --ease-linear: linear;
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);

  --duration-instant: 0ms;
  --duration-fast: 100ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
  --duration-slower: 500ms;

  /* ─── Z-Index ───────────────────────────────────────────────────────── */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-tooltip: 700;
  --z-toast: 800;
  --z-tour: 900;

  /* ─── Breakpoints ───────────────────────────────────────────────────── */
  --bp-sm: 480px;
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;
  --bp-2xl: 1536px;

  /* ─── Touch Targets ──────────────────────────────────────────────────── */
  --touch-min: 44px;

  /* ─── Container ─────────────────────────────────────────────────────── */
  --container-max: 1200px;
  --container-padding: var(--space-6);
  --container-padding-mobile: var(--space-4);
}

/* ─── RTL Logical Properties ──────────────────────────────────────────── */
:root {
  --inset-inline-start: right;
  --inset-inline-end: left;
  --margin-inline-start: margin-right;
  --margin-inline-end: margin-left;
  --padding-inline-start: padding-right;
  --padding-inline-end: padding-left;
  --border-inline-start: border-right;
  --border-inline-end: border-left;
}

/* ─── Safe Area ───────────────────────────────────────────────────────── */
:root {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ─── Reduced Motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-instant: 0ms;
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
    --duration-slower: 0ms;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── High Contrast ───────────────────────────────────────────────────── */
@media (prefers-contrast: high) {
  :root {
    --color-border: rgba(148, 163, 184, 0.4);
    --color-border-strong: rgba(148, 163, 184, 0.7);
    --color-text-secondary: #cbd5e1;
    --color-text-tertiary: #94a3b8;
  }
}

/* ─── Focus Visible ───────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-cyan);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ─── Selection ───────────────────────────────────────────────────────── */
::selection {
  background: rgba(34, 211, 238, 0.3);
  color: var(--color-text-primary);
}

/* ─── Scrollbar ───────────────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-tertiary);
  background-clip: padding-box;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* ─── Light Theme (Landing / Public Pages) ───────────────────────────── */
[data-theme="light"], .theme-light {
  --color-bg: #f8fafc;
  --color-bg-soft: #f1f5f9;
  --color-surface: rgba(255, 255, 255, 0.85);
  --color-surface-strong: rgba(255, 255, 255, 0.95);
  --color-surface-elevated: rgba(255, 255, 255, 1);

  --color-border: rgba(148, 163, 184, 0.25);
  --color-border-strong: rgba(148, 163, 184, 0.4);
  --color-border-focus: rgba(34, 211, 238, 0.5);

  --color-text-primary: #0f172a;
  --color-text-secondary: #475569;
  --color-text-tertiary: #64748b;
  --color-text-inverse: #f8fafc;
  --color-text-on-accent: #ffffff;

  --color-bale: #059669;
  --color-rubika: #6366f1;
  --color-eitaa: #d97706;
  --color-telegram: #0284c7;
  --color-soroush: #e11d48;

  --color-cyan: #0891b2;
  --color-indigo: #4f46e5;
  --color-violet: #7c3aed;
  --color-green: #16a34a;
  --color-gold: #d97706;
  --color-orange: #ea580c;
  --color-red: #dc2626;
  --color-danger: #dc2626;
  --color-success: #16a34a;

  --gradient-primary: linear-gradient(135deg, #0891b2 0%, #4f46e5 100%);
  --gradient-primary-hover: linear-gradient(135deg, #06b6d4 0%, #6366f1 100%);
  --gradient-violet-cyan: linear-gradient(135deg, #7c3aed 0%, #0891b2 100%);
  --gradient-gold-orange: linear-gradient(135deg, #d97706 0%, #ea580c 100%);
  --gradient-green-cyan: linear-gradient(135deg, #16a34a 0%, #0891b2 100%);
  --gradient-red-pink: linear-gradient(135deg, #dc2626 0%, #db2777 100%);
  --gradient-surface: linear-gradient(180deg, var(--color-surface) 0%, var(--color-surface-strong) 100%);
  --gradient-glow-cyan: radial-gradient(ellipse, rgba(8, 145, 178, 0.15) 0%, transparent 70%);
  --gradient-glow-violet: radial-gradient(ellipse, rgba(124, 58, 237, 0.15) 0%, transparent 70%);
  --gradient-glow-bale: radial-gradient(ellipse, rgba(5, 150, 105, 0.12) 0%, transparent 70%);
}

/* Light theme overrides for specific components */
[data-theme="light"] .surface,
.theme-light .surface {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .surface-elevated,
.theme-light .surface-elevated {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border-strong);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .stat-value,
.theme-light .stat-value {
  background: linear-gradient(135deg, var(--color-cyan), var(--color-indigo));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

[data-theme="light"] code,
.theme-light code {
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  color: var(--color-indigo);
}

[data-theme="light"] .table tbody tr:hover,
.theme-light .table tbody tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .tbl th,
.theme-light .tbl th {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .tbl td,
.theme-light .tbl td {
  border-bottom-color: var(--color-border);
}

[data-theme="light"] .confirm-overlay,
.theme-light .confirm-overlay {
  background: rgba(0, 0, 0, 0.5);
}