/* ============================================
   Ejar Design System — Unified Design Tokens
   ============================================
   Single source of truth for all CSS variables.
   Override specific tokens via inline <style> for DB-driven colors.
   Supports Light Mode (:root) and Dark Mode (html[data-theme="dark"]).
   ============================================ */

:root {
  /* ---- Brand Colors (defaults; overridden inline from DB) ---- */
  --brand-primary: #0d2c52;
  --brand-primary-dark: #0d2c52;
  --brand-primary-light: #1a4b85;
  --brand-secondary: #06b6d4;
  --brand-accent: #c5a059;
  --brand-accent-hover: #d4b067;
  --brand-gradient: linear-gradient(135deg, #0d2c52 0%, #1a4b85 100%);
  --brand-gradient-hover: linear-gradient(135deg, #1a4b85 0%, #0d2c52 100%);

  /* ---- Brand RGB (for rgba(var(--brand-primary-rgb), X) overlays) ---- */
  --brand-primary-rgb: 13, 44, 82;
  --brand-accent-rgb: 197, 160, 89;
  --brand-secondary-rgb: 6, 182, 212;

  /* ---- Semantic Colors ---- */
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --info-color: #3b82f6;
  --success-color-rgb: 16, 185, 129;
  --warning-color-rgb: 245, 158, 11;
  --danger-color-rgb: 239, 68, 68;
  --info-color-rgb: 59, 130, 246;
  --purple-color: #8b5cf6;
  --purple-color-rgb: 139, 92, 246;

  /* ---- Background & Text ---- */
  --bg-body: #f1f5f9;
  --bg-subtle: #f8fafc;
  --surface-card: #ffffff;
  --surface-overlay: rgba(13, 44, 82, 0.08);
  --surface-overlay-hover: rgba(13, 44, 82, 0.12);
  --surface-overlay-subtle: rgba(13, 44, 82, 0.04);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-on-primary: #ffffff;
  --text-on-accent: #ffffff;

  /* ---- Sidebar ---- */
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 80px;
  --topbar-height: 65px;
  --sidebar-bg: #ffffff;
  --sidebar-border: rgba(226, 232, 240, 0.8);
  --sidebar-text: #475569;
  --sidebar-text-active: #0d2c52;

  /* ---- Glass Effects ---- */
  --glass-bg: rgba(255, 255, 255, 0.98);
  --glass-bg-solid: #ffffff;
  --glass-border: rgba(226, 232, 240, 0.8);

  /* ---- Shadows (unified) ---- */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
  --dropdown-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.15), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-color: rgba(0, 0, 0, 0.08);

  /* ---- Transitions ---- */
  --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* ---- Border Colors ---- */
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  --border-subtle: #f1f5f9;

  /* ---- Border Radius (unified) ---- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;
  --radius-circle: 50%;

  /* ---- Focus States ---- */
  --focus-ring: rgba(13, 44, 82, 0.25);
  --focus-ring-accent: rgba(197, 160, 89, 0.4);

  /* ---- Table ---- */
  --table-header-bg: #f8fafc;
  --table-row-hover: #f8fafc;
  --table-border: #f1f5f9;

  /* ---- Status Badges ---- */
  --badge-available-bg: #dcfce7;
  --badge-available-color: #166534;
  --badge-booked-bg: #fee2e2;
  --badge-booked-color: #991b1b;
  --badge-maintenance-bg: #fef9c3;
  --badge-maintenance-color: #854d0e;

  /* ---- Disabled States ---- */
  --disabled-opacity: 0.5;

  /* ---- Font Weights ---- */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* ---- Z-Index Layers ---- */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-toast: 9999;

  /* ---- Typography Fonts (Unified Architecture) ----
     SINGLE SOURCE OF TRUTH for ALL typography
     Language-specific stacks are derived from these tokens.

     Arabic-optimized primary: Tajawal (modern, readable, SaaS-grade)
     English/Latin complement: Inter (widely used, clean, professional)
     ============================================ */
  --font-family-ar: 'Tajawal', 'Cairo', 'Noto Sans Arabic', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-family-en: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  /* Dynamic main font: set per-language via inline style or attribute selector */
  --font-family-main: var(--font-family-ar);
  --font-family-headings: var(--font-family-main);
  --font-family-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  /* Font-face preload token (for font-display strategy) */
  --font-display-strategy: swap;

  /* ---- Typography Utilities ---- */
  --font-light: 300;
  --font-regular: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  /* ---- Legacy Mapping ---- */
  --dark-color: #1e293b;
  --light-color: #f8fafc;

  /* ---- Tooltip ---- */
  --tooltip-bg: #1e293b;
  --tooltip-text: #ffffff;

  /* ---- Card Shadows (default elevated) ---- */
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --card-border: none;

  /* ---- Semantic Dark Variants for Gradients ---- */
  --danger-color-dark: #dc2626;
  --warning-color-dark: #d97706;
  --success-color-dark: #059669;
  --brand-secondary-dark: #0891b2;

  /* ---- Theme-independent Semi-transparent Overlays ---- */
  --overlay-bg: rgba(0, 0, 0, 0.5);

  /* ---- Touch Targets (WCAG 2.5.5) ---- */
  --touch-target-min: 44px;

  /* ---- Typography Scale (unified) ---- */
  --text-xs: 0.7rem;
  --text-sm: 0.8rem;
  --text-base: 0.9rem;
  --text-lg: 1rem;
  --text-xl: 1.15rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.75rem;
  --text-4xl: 2.25rem;

  /* ---- Line Heights ---- */
  --leading-tight: 1.2;
  --leading-snug: 1.35;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* ---- Letter Spacing ---- */
  --tracking-tight: -0.025em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;
  --tracking-wider: 0.05em;

  /* ---- Spacing Scale ---- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* ---- Color Scheme (browser meta) ---- */
  color-scheme: light;
}

/* ============================================
   LANGUAGE-SPECIFIC FONT SWITCHING
   Automatically applies the correct font stack
   based on the html lang attribute.
   Pages do NOT need inline font-family overrides.
   ============================================ */
html[lang="ar"] {
  --font-family-main: var(--font-family-ar);
}
html[lang="en"] {
  --font-family-main: var(--font-family-en);
}
/* Fallback for pages without explicit lang */
html:not([lang="ar"]):not([lang="en"]) {
  --font-family-main: var(--font-family-ar);
}

/* ============================================
   DARK MODE — Override all structural tokens
   Note: Brand gradient (decorative) stays
   consistent; surfaces, text, borders, shadows,
   overlays, and brand-primary (for text
   readability) are adjusted for dark mode.
   ============================================ */
html[data-theme="dark"] {
  color-scheme: dark;

  /* ---- Brand Colors (lighter for readability on dark surfaces) ---- */
  --brand-primary: #60a5fa;
  --brand-primary-rgb: 96, 165, 250;

  /* ---- Background & Text ---- */
  --bg-body: #0b1120;
  --bg-subtle: #111827;
  --surface-card: #1a2332;
  --surface-overlay: rgba(255, 255, 255, 0.06);
  --surface-overlay-hover: rgba(255, 255, 255, 0.1);
  --surface-overlay-subtle: rgba(255, 255, 255, 0.03);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-primary: #e2e8f0;
  --text-secondary: #cbd5e1;
  --text-on-primary: #ffffff;
  --text-on-accent: #1e293b;

  /* ---- Sidebar ---- */
  --sidebar-bg: #111827;
  --sidebar-border: rgba(51, 65, 85, 0.8);
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f1f5f9;

  /* ---- Glass Effects ---- */
  --glass-bg: rgba(26, 35, 50, 0.98);
  --glass-bg-solid: #1a2332;
  --glass-border: rgba(51, 65, 85, 0.8);

  /* ---- Shadows (dark mode — more pronounced depth) ---- */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.45), 0 8px 10px -6px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
  --dropdown-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.4);

  /* ---- Border Colors ---- */
  --border-color: #293548;
  --border-light: #1e293b;
  --border-subtle: #1e293b;

  /* ---- Focus States ---- */
  --focus-ring: rgba(197, 160, 89, 0.35);
  --focus-ring-accent: rgba(197, 160, 89, 0.5);

  /* ---- Table ---- */
  --table-header-bg: #111827;
  --table-row-hover: #1e293b;
  --table-border: #293548;

  /* ---- Status Badges ---- */
  --badge-available-bg: rgba(16, 185, 129, 0.15);
  --badge-available-color: #6ee7b7;
  --badge-booked-bg: rgba(239, 68, 68, 0.15);
  --badge-booked-color: #fca5a5;
  --badge-maintenance-bg: rgba(245, 158, 11, 0.15);
  --badge-maintenance-color: #fcd34d;

  /* ---- Tooltip ---- */
  --tooltip-bg: #334155;
  --tooltip-text: #f1f5f9;

  /* ---- Card Shadows (dark mode — deeper) ---- */
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --card-border: none;

  /* ---- Semantic Dark Variants ---- */
  --danger-color-dark: #dc2626;
  --warning-color-dark: #d97706;
  --success-color-dark: #059669;
  --brand-secondary-dark: #0891b2;

  /* ---- Purple (theme-independent) ---- */
  --purple-color: #8b5cf6;
  --purple-color-rgb: 139, 92, 246;

  /* ---- Overlays (dark mode) ---- */
  --overlay-bg: rgba(0, 0, 0, 0.7);

  /* ---- Legacy ---- */
  --dark-color: #e2e8f0;
  --light-color: #111827;
}

/* ============================================
   Responsive Breakpoints (reference only)
   Desktop:   >= 992px
   Tablet:    768px - 991px
   Mobile:    < 768px
   Small:     < 576px
   ============================================ */

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
