/* ============================================================
   Mulanui — Design Tokens + Themes
   SINGLE SOURCE OF TRUTH for ALL CSS variables
   ⚠️ لازم يكون أول ملف CSS يتحمّل في كل صفحة
   ============================================================ */

/* ============================================================
   1. GLOBAL TOKENS (مشتركة بين كل الـ themes)
   ============================================================ */
:root {
    /* ---- Typography ---- */
    --font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Courier New', monospace;

    --fs-xs:   11px;
    --fs-sm:   12px;
    --fs-base: 14px;
    --fs-md:   15px;
    --fs-lg:   18px;
    --fs-xl:   22px;
    --fs-2xl:  28px;
    --fs-3xl:  38px;

    --fw-normal: 400;
    --fw-medium: 600;
    --fw-bold:   700;
    --fw-black:  900;

    /* ---- Spacing ---- */
    --space-1:  4px;
    --space-2:  8px;
    --space-3:  12px;
    --space-4:  16px;
    --space-5:  20px;
    --space-6:  25px;
    --space-8:  32px;
    --space-10: 40px;

    /* ---- Radius ---- */
    --radius-sm:   6px;
    --radius-md:   8px;
    --radius-lg:   12px;
    --radius-xl:   16px;
    --radius-2xl:  20px;
    --radius-full: 999px;

    /* ---- Z-index Scale (موحّد — متغيّرش القيم دي) ---- */
    --z-base:       1;
    --z-dropdown:   100;
    --z-sticky:     200;
    --z-navbar:     500;
    --z-sidebar:    600;
    --z-overlay:    700;
    --z-drawer:     800;
    --z-banner:     900;
    --z-modal:      1000;
    --z-modal-top:  1100;
    --z-toast:      1200;
    --z-tooltip:    1300;
    --z-max:        99999;

    /* ---- Transitions ---- */
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.35s ease;

    /* ---- Layout ---- */
    --container-max:  1280px;
    --container-pad:  5%;
    --navbar-height:  70px;
    --sidebar-width:  250px;

    /* ---- Legacy compatibility aliases ---- */
    --primary-hover:   var(--primary-color);
}

/* ============================================================
   2. 🌑 DARK THEME (Default)
   ============================================================ */
:root,
[data-theme="dark"] {
    --bg-main:      #0f111a;
    --bg-card:      #161925;
    --bg-elevated:  #1a1e2e;
    --bg-input:     #0d1117;
    --bg-hover:     #1f2433;
    --bg-overlay:   rgba(0, 0, 0, 0.75);

    --border-color:  #232738;
    --border-soft:   #30363d;
    --border-strong: #3a4048;

    --text-main:    #ffffff;
    --text-muted:   #a0aec0;
    --text-dim:     #6b7280;
    --text-inverse: #0f172a;

    --primary-color:  #5c80f6;
    --primary-hover:  #579af2;
    --primary-soft:   rgba(92, 128, 246, 0.15);
    --primary-border: rgba(92, 128, 246, 0.3);

    --secondary-color: #7c3aed;

    --success-color:  #3fb950;
    --success-soft:   rgba(63, 185, 80, 0.15);
    --success-border: rgba(63, 185, 80, 0.3);

    --danger-color:   #ef4444;
    --danger-soft:    rgba(239, 68, 68, 0.15);
    --danger-border:  rgba(239, 68, 68, 0.3);

    --warning-color:  #facc15;
    --warning-soft:   rgba(250, 204, 21, 0.15);
    --warning-border: rgba(250, 204, 21, 0.3);

    --info-color:     #38bdf8;
    --info-soft:      rgba(56, 189, 248, 0.15);
    --info-border:    rgba(56, 189, 248, 0.3);

    --shadow-card:  0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.6);

    --glow-color: transparent;
    --glow-size:  0;

    /* Semantic aliases */
    --navbar-bg:  var(--bg-card);
    --sidebar-bg: var(--bg-card);
    --card-bg:    var(--bg-card);

    /* Legacy inputs */
    --input-bg:     var(--bg-input);
    --input-border: var(--border-soft);

    /* Scrollbar */
    --scrollbar-thumb:       rgba(92, 128, 246, 0.35);
    --scrollbar-thumb-hover: rgba(92, 128, 246, 0.75);

    color-scheme: dark;
}

/* ============================================================
   3. ☀️ LIGHT THEME
   ============================================================ */
[data-theme="light"] {
    --bg-main:      #f8fafc;
    --bg-card:      #ffffff;
    --bg-elevated:  #f1f5f9;
    --bg-input:     #f8fafc;
    --bg-hover:     #f1f5f9;
    --bg-overlay:   rgba(15, 23, 42, 0.5);

    --border-color:  #e2e8f0;
    --border-soft:   #cbd5e1;
    --border-strong: #94a3b8;

    --text-main:    #0f172a;
    --text-muted:   #475569;
    --text-dim:     #94a3b8;
    --text-inverse: #ffffff;

    --primary-color:  #4f46e5;
    --primary-hover:  #4338ca;
    --primary-soft:   rgba(79, 70, 229, 0.1);
    --primary-border: rgba(79, 70, 229, 0.3);

    --secondary-color: #7c3aed;

    --success-color:  #16a34a;
    --success-soft:   rgba(22, 163, 74, 0.1);
    --success-border: rgba(22, 163, 74, 0.3);

    --danger-color:   #dc2626;
    --danger-soft:    rgba(220, 38, 38, 0.1);
    --danger-border:  rgba(220, 38, 38, 0.3);

    --warning-color:  #d97706;
    --warning-soft:   rgba(217, 119, 6, 0.1);
    --warning-border: rgba(217, 119, 6, 0.3);

    --info-color:     #0284c7;
    --info-soft:      rgba(2, 132, 199, 0.1);
    --info-border:    rgba(2, 132, 199, 0.3);

    --shadow-card:  0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-modal: 0 20px 60px rgba(15, 23, 42, 0.15);

    --glow-color: transparent;
    --glow-size:  0;

    --navbar-bg:  #ffffff;
    --sidebar-bg: #ffffff;
    --card-bg:    #ffffff;

    --input-bg:     var(--bg-input);
    --input-border: var(--border-soft);

    --scrollbar-thumb:       rgba(79, 70, 229, 0.3);
    --scrollbar-thumb-hover: rgba(79, 70, 229, 0.65);

    color-scheme: light;
}

/* ============================================================
   4. 🎮 GAMING THEME
   ============================================================ */
[data-theme="gaming"] {
    --bg-main:      #0a0612;
    --bg-card:      rgba(22, 12, 40, 0.65);
    --bg-elevated:  #1a0d2e;
    --bg-input:     rgba(15, 8, 26, 0.6);
    --bg-hover:     rgba(168, 85, 247, 0.08);
    --bg-overlay:   rgba(10, 6, 18, 0.85);

    --border-color:  rgba(168, 85, 247, 0.25);
    --border-soft:   rgba(168, 85, 247, 0.15);
    --border-strong: rgba(168, 85, 247, 0.5);

    --text-main:    #f0e7ff;
    --text-muted:   #c4b5fd;
    --text-dim:     #8b5cf6;
    --text-inverse: #0a0612;

    --primary-color:  #a855f7;
    --primary-hover:  #c084fc;
    --primary-soft:   rgba(168, 85, 247, 0.15);
    --primary-border: rgba(168, 85, 247, 0.4);

    --secondary-color: #06b6d4;

    --success-color:  #10b981;
    --success-soft:   rgba(16, 185, 129, 0.15);
    --success-border: rgba(16, 185, 129, 0.35);

    --danger-color:   #f43f5e;
    --danger-soft:    rgba(244, 63, 94, 0.15);
    --danger-border:  rgba(244, 63, 94, 0.35);

    --warning-color:  #fbbf24;
    --warning-soft:   rgba(251, 191, 36, 0.15);
    --warning-border: rgba(251, 191, 36, 0.35);

    --info-color:     #22d3ee;
    --info-soft:      rgba(34, 211, 238, 0.15);
    --info-border:    rgba(34, 211, 238, 0.35);

    --shadow-card:  0 2px 12px rgba(168, 85, 247, 0.15);
    --shadow-hover: 0 8px 32px rgba(168, 85, 247, 0.35);
    --shadow-modal: 0 0 40px rgba(168, 85, 247, 0.25);

    --glow-color: #a855f7;
    --glow-size:  20px;

    --navbar-bg:  rgba(22, 12, 40, 0.85);
    --sidebar-bg: rgba(22, 12, 40, 0.85);
    --card-bg:    rgba(22, 12, 40, 0.65);

    --input-bg:     var(--bg-input);
    --input-border: var(--border-color);

    --scrollbar-thumb:       rgba(168, 85, 247, 0.55);
    --scrollbar-thumb-hover: rgba(168, 85, 247, 0.95);

    color-scheme: dark;
}

/* ============================================================
   5. Gaming — Background (GPU accelerated)
   ============================================================ */
[data-theme="gaming"] body {
    background:
        radial-gradient(circle at 20% 20%, rgba(168, 85, 247, 0.15), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(6, 182, 212, 0.12), transparent 40%),
        #0a0612;
    background-attachment: fixed;
}

[data-theme="gaming"] body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 60% 40%, rgba(168, 85, 247, 0.08), transparent 50%),
        radial-gradient(circle at 30% 70%, rgba(6, 182, 212, 0.06), transparent 50%);
    animation: gamingBgShift 12s ease-in-out infinite alternate;
    will-change: transform, opacity;
    transform: translateZ(0);
    z-index: 0;
}

@keyframes gamingBgShift {
    0%   { opacity: 0.6; transform: translateZ(0) scale(1) rotate(0deg); }
    100% { opacity: 1;   transform: translateZ(0) scale(1.05) rotate(1deg); }
}

/* ============================================================
   6. Gaming — Reduced Effects (يدوي + نظام)
   ============================================================ */
[data-theme="gaming"][data-gaming-effects="reduced"] body::before {
    animation: none !important;
    opacity: 0.5;
}

[data-theme="gaming"][data-gaming-effects="reduced"] * {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
}

[data-theme="gaming"][data-gaming-effects="reduced"] h1,
[data-theme="gaming"][data-gaming-effects="reduced"] h2,
[data-theme="gaming"][data-gaming-effects="reduced"] .logo,
[data-theme="gaming"][data-gaming-effects="reduced"] .cms-section-title {
    text-shadow: none !important;
}

/* ============================================================
   7. Prefers-reduced-motion (يشتغل مع كل الـ themes)
   ============================================================ */
@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;
    }

    [data-theme="gaming"] body::before {
        animation: none !important;
        opacity: 0.5;
    }
}

/* ============================================================
   8. Theme Transition Animation
   ============================================================ */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
    transition:
        background-color var(--transition-slow),
        color            var(--transition-slow),
        border-color     var(--transition-slow),
        box-shadow       var(--transition-slow) !important;
}

/* ============================================================
   9. Theme Toggle Button
   ============================================================ */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    cursor: pointer;
    transition: all var(--transition-base);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.theme-toggle-btn:hover {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: #fff;
    transform: translateY(-2px);
}

.theme-toggle-btn i {
    font-size: 16px;
    transition: transform 0.4s ease;
}

.theme-toggle-btn:hover i {
    transform: rotate(20deg);
}

.theme-toggle-btn .icon-dark,
.theme-toggle-btn .icon-light,
.theme-toggle-btn .icon-gaming {
    display: none;
}

[data-theme="dark"]   .theme-toggle-btn .icon-dark   { display: inline-block; }
[data-theme="light"]  .theme-toggle-btn .icon-light  { display: inline-block; }
[data-theme="gaming"] .theme-toggle-btn .icon-gaming { display: inline-block; }

[data-theme="gaming"] .theme-toggle-btn {
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

@media (max-width: 768px) {
    .theme-toggle-btn {
        width: 36px;
        height: 36px;
    }
    .theme-toggle-btn i {
        font-size: 14px;
    }
}

/* ============================================================
   10. Global Scrollbar — Thin & Subtle
   ============================================================ */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    transition: background var(--transition-fast);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

::-webkit-scrollbar-thumb:active {
    background: var(--scrollbar-thumb-hover);
}

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

@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
}

body {
    overflow-x: hidden;
}

/* ============================================================
   11. Base Utility — Container
   ============================================================ */
.container {
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--container-pad);
}

/* ============================================================
   12. Table Design Tokens (Phase 1 — Table Visual Polish)
   ============================================================ */
:root {
    /* --- Density Scale --- */
    --table-density-compact:     6px 10px;
    --table-density-normal:      10px 14px;
    --table-density-comfortable: 15px 20px;

    /* Active density (يُبدَّل من JS في Phase 5) */
    --table-cell-pad: var(--table-density-normal);

    /* --- Header --- */
    --table-header-bg:     var(--bg-elevated);
    --table-header-color:  var(--text-muted);
    --table-header-weight: var(--fw-bold);

    /* --- Row --- */
    --table-row-hover-bg: var(--bg-hover);
    --table-row-accent:   var(--primary-color);
    --table-row-accent-w: 3px;

    /* --- Border --- */
    --table-border-color: var(--border-color);

    /* --- Fade-in Animation --- */
    --table-fade-duration:  0.35s;
    --table-fade-step:      0.03s;
    --table-fade-max-delay: 0.36s;

    /* --- Sticky Header --- */
    --table-sticky-top: var(--navbar-height);
    --table-sticky-z:   calc(var(--z-sticky) + 1);
}
