/* =========================================
   RADICAL THEME ENGINE (Variable Driven)
   ========================================= */

/* 1. Global Background & Font */
body.theme-active {
    background-image: var(--bg-main) !important;
    background-size: cover !important;
    background-position: center !important;
    background-attachment: fixed !important;
    color: var(--text-primary) !important;
    font-family: var(--font-family, 'Inter', sans-serif) !important;
    transition: background-image 0.5s ease, color 0.3s ease;
}

/* 2. Global Overlay (Pseudo-element for readability) */
body.theme-active::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay, rgba(0, 0, 0, 0.5)) !important;
    z-index: -1;
    pointer-events: none;
    transition: background 0.5s ease;
}

/* 3. Glass Panels & Containers */
body.theme-active .glass-nav,
body.theme-active #sidebar,
body.theme-active footer,
body.theme-active .service-card,
body.theme-active .theme-card,
body.theme-active .theme-search-bar,
body.theme-active .modal-content,
body.theme-active div[class*="bg-white"],
body.theme-active div[class*="bg-slate-"],
body.theme-active nav .absolute {
    background: var(--glass-bg, rgba(255, 255, 255, 0.1)) !important;
    border: var(--border-style, 1px solid rgba(255, 255, 255, 0.1)) !important;
    border-radius: var(--border-radius, 8px) !important;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

/* Make navbar solid (no transparency) for custom themes */
body.theme-active .glass-nav {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* 4. Text & Inputs */
body.theme-active h1,
body.theme-active h2,
body.theme-active h3,
body.theme-active h4,
body.theme-active h5,
body.theme-active h6,
body.theme-active p,
body.theme-active span,
body.theme-active a,
body.theme-active li,
body.theme-active button,
body.theme-active input {
    color: var(--text-primary) !important;
}

body.theme-active input:not(.input-reset),
body.theme-active select:not(.input-reset),
body.theme-active textarea:not(.input-reset) {
    background: rgba(0, 0, 0, 0.2) !important;
    border: 1px solid var(--accent-color) !important;
    color: var(--text-primary) !important;
}

body.theme-active input::placeholder {
    color: var(--text-primary) !important;
    opacity: 0.6;
}

/* 5. Accents & Interactive Elements */
body.theme-active .theme-btn,
body.theme-active button.primary,
body.theme-active .accent-element {
    background: var(--accent-color) !important;
    color: #000 !important;
    border: none !important;
    box-shadow: 0 0 10px var(--accent-color);
}

/* Links & Hovers */
body.theme-active a:hover {
    color: var(--accent-color) !important;
    text-shadow: 0 0 8px var(--accent-color);
}

/* 6. Scrollbar */
body.theme-active::-webkit-scrollbar {
    width: 8px;
}

body.theme-active::-webkit-scrollbar-track {
    background: var(--glass-bg);
}

body.theme-active::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 4px;
}

/* 7. Utilities (Scoped) */
body.theme-active .text-accent {
    color: var(--accent-color) !important;
}

body.theme-active .border-accent {
    border-color: var(--accent-color) !important;
}

/* HIDDEN ELEMENTS FIX (Scoped) */
body.theme-active .absolute.inset-0.bg-black\/50,
body.theme-active .absolute.inset-0.bg-gradient-to-t {
    display: none !important;
}

/* TOAST Z-INDEX FIX (Global is fine) */
#toast-container {
    z-index: 9999 !important;
}

/* HIDE DEFAULT IMG OVERLAYS */
body.theme-active img+div.absolute {
    display: none !important;
}

/* Global Transition Override (Scoped) */
body.theme-active * {
    transition-property: color, background-color, border-color, box-shadow;
    transition-timing-function: ease;
}

/* =========================================
   LOGGED-IN USER ELEMENTS (Antigravity)
   ========================================= */

/* Profile Widget Container */
.profile-widget {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    transition: all 0.3s ease;
}

.profile-widget:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.2);
    /* Soft purple glow */
}

/* Neon Avatar */
.neon-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid transparent;
    /* Fallback */
    background-image: linear-gradient(#111, #111), linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%);
    background-origin: border-box;
    background-clip: content-box, border-box;
    box-shadow: 0 0 10px rgba(124, 58, 237, 0.5);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.profile-widget:hover .neon-avatar {
    transform: scale(1.1) perspective(500px) translateZ(10px);
}

/* Glass Dropdown */
.glass-dropdown {
    background: rgba(17, 25, 40, 0.75) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.125);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.glass-dropdown a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Notification Badge */
.notification-bell {
    position: relative;
    cursor: pointer;
    color: #9ca3af;
    transition: color 0.3s;
}

.notification-bell:hover {
    color: white;
}

.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background-color: #ef4444;
    border-radius: 50%;
    border: 2px solid #111827;
    box-shadow: 0 0 8px #ef4444;
}

/* Recommended Badge */
.recommendation-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: linear-gradient(90deg, #7c3aed, #4f46e5);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 10px rgba(124, 58, 237, 0.4);
    z-index: 10;
    pointer-events: none;
}

/* =========================================
   GLOBAL LOADING SCREEN (Bouncing Balls)
   ========================================= */

/* Loading Screen Styles */
.loading-card {
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

/* Fade In Text Animation */
.fade-in {
    animation: fadeIn 0.8s ease-in forwards;
    opacity: 0;
}

.fade-in-delay {
    animation: fadeIn 0.8s ease-in 0.3s forwards;
    opacity: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Data Item Animations */
.data-item {
    transition: all 0.5s ease-in-out;
}

.data-item.moving-up {
    animation: moveUp 1s ease-in-out forwards;
}

@keyframes moveUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    50% {
        opacity: 0.3;
        transform: translateY(-100px) scale(0.9);
    }

    100% {
        opacity: 0;
        transform: translateY(-200px) scale(0.8);
    }
}

/* LoadingScreen fade transitions */
#loadingScreen {
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
    background-color: rgba(255, 255, 255, 0.7) !important;
    /* Light mode glass bg */
    backdrop-filter: blur(15px);
    /* Blur effect */
    -webkit-backdrop-filter: blur(15px);
}

html.dark #loadingScreen {
    background-color: rgba(17, 24, 39, 0.7) !important;
    /* Dark mode glass bg */
}

#loadingScreen.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Bouncing Balls - Optimized */
#loadingScreen .loader-balls {
    display: flex !important;
    opacity: 1;
    visibility: visible;
    transform: translateZ(0);
    will-change: transform, opacity;
    backface-visibility: hidden;
    padding: 0;
    margin: 0;
}

#loadingScreen .ball {
    list-style: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin: 0 4px;
    /* Added spacing */
    background-color: #9ca3af;
    /* Light mode base: Gray-400 */
    will-change: transform, background-color, opacity;
    backface-visibility: hidden;
    transform: translate3d(0, 0, 0) translateZ(0);
    transform-style: preserve-3d;
    background-clip: padding-box;
}

html.dark #loadingScreen .ball {
    background-color: #7c3aed;
    /* Dark mode base: Purple */
}

/* Light mode animations - 2 seconds */
#loadingScreen .ball:nth-child(1) {
    animation: bounceBall1 2s ease-in-out infinite;
}

#loadingScreen .ball:nth-child(2) {
    animation: bounceBall2 2s ease-in-out 0.3s infinite;
}

#loadingScreen .ball:nth-child(3) {
    animation: bounceBall3 2s ease-in-out 0.6s infinite;
}

/* Rank Animation - Subtle Glow Pulse */
.rank-animate {
    animation: rankGlow 3s ease-in-out infinite;
}

@keyframes rankGlow {

    0%,
    100% {
        text-shadow: 0 0 5px rgba(var(--accent-rgb), 0), 0 0 10px rgba(var(--accent-rgb), 0);
        opacity: 0.9;
    }

    50% {
        text-shadow: 0 0 10px rgba(var(--accent-rgb), 0.3), 0 0 20px rgba(var(--accent-rgb), 0.1);
        opacity: 1;
    }
}

/* Light mode keyframes (Purple Highlights) */
@keyframes bounceBall1 {

    0%,
    100% {
        transform: translate3d(0, 0, 0) translateZ(0) scale(1);
        background-color: #9ca3af;
        opacity: 1;
    }

    50% {
        transform: translate3d(0, -18px, 0) translateZ(0) scale(1);
        background-color: #7c3aed;
        /* Purple */
        box-shadow: 0 0 10px rgba(124, 58, 237, 0.5);
        opacity: 1;
    }
}

@keyframes bounceBall2 {

    0%,
    100% {
        transform: translate3d(0, 0, 0) translateZ(0) scale(1);
        background-color: #9ca3af;
        opacity: 1;
    }

    50% {
        transform: translate3d(0, -18px, 0) translateZ(0) scale(1);
        background-color: #7c3aed;
        /* Purple */
        box-shadow: 0 0 10px rgba(124, 58, 237, 0.5);
        opacity: 1;
    }
}

@keyframes bounceBall3 {

    0%,
    100% {
        transform: translate3d(0, 0, 0) translateZ(0) scale(1);
        background-color: #9ca3af;
        opacity: 1;
    }

    50% {
        transform: translate3d(0, -18px, 0) translateZ(0) scale(1);
        background-color: #7c3aed;
        /* Purple */
        box-shadow: 0 0 10px rgba(124, 58, 237, 0.5);
        opacity: 1;
    }
}

/* Dark mode keyframes (White Highlights) */
@keyframes bounceBall1Dark {

    0%,
    100% {
        transform: translate3d(0, 0, 0) translateZ(0) scale(1);
        background-color: #7c3aed;
        /* Purple Base */
        opacity: 1;
    }

    50% {
        transform: translate3d(0, -18px, 0) translateZ(0) scale(1);
        background-color: #ffffff;
        /* White Highlight */
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
        opacity: 1;
    }
}

@keyframes bounceBall2Dark {

    0%,
    100% {
        transform: translate3d(0, 0, 0) translateZ(0) scale(1);
        background-color: #7c3aed;
        /* Purple Base */
        opacity: 1;
    }

    50% {
        transform: translate3d(0, -18px, 0) translateZ(0) scale(1);
        background-color: #ffffff;
        /* White Highlight */
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
        opacity: 1;
    }
}

@keyframes bounceBall3Dark {

    0%,
    100% {
        transform: translate3d(0, 0, 0) translateZ(0) scale(1);
        background-color: #7c3aed;
        /* Purple Base */
        opacity: 1;
    }

    50% {
        transform: translate3d(0, -18px, 0) translateZ(0) scale(1);
        background-color: #ffffff;
        /* White Highlight */
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
        opacity: 1;
    }

}

/* Global Notification Bell - Animated */
.notification-bell-animated {
    width: fit-content;
    height: fit-content;
    background-color: transparent;
    border-radius: 9px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: 0.2s;
}

.notification-bell-animated:active {
    transform: scale(0.95);
}

.notification-bell-animated .notification-icon {
    width: 20px;
    height: 20px;
    color: rgb(156, 163, 175);
    /* gray-400 */
    transition: color 0.3s;
}

.notification-bell-animated:hover .notification-icon {
    color: #4F46E5;
    /* Indigo/Accent */
}

.dark .notification-bell-animated:hover .notification-icon {
    color: #818cf8;
    /* Light Indigo for dark mode */
}

.notification-bell-animated .notification-point {
    position: absolute;
    top: 10px;
    right: 17px;
    width: 4px;
    height: 4px;
    background-color: #4F46E5;
    border-radius: 50%;
}

.dark .notification-bell-animated .notification-point {
    background-color: #818cf8;
}

.notification-bell-animated .notification-point::after {
    content: "";
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: inherit;
    border-radius: inherit;
    animation: notification-pulse-loop 10s infinite;
}

@keyframes notification-pulse-loop {
    0% {
        width: 100%;
        height: 100%;
        opacity: 1;
        transform: scale(1);
    }

    5% {
        width: 300%;
        height: 300%;
        opacity: 0;
        transform: scale(3);
    }

    10% {
        width: 300%;
        height: 300%;
        opacity: 0;
        transform: scale(3);
    }

    100% {
        width: 100%;
        height: 100%;
        opacity: 0;
        transform: scale(1);
    }
}

/* =========================================
   CHAT RICH TEXT STYLES (Markdown)
   ========================================= */
.text-markdown p {
    margin-bottom: 0.75em;
}

.text-markdown p:last-child {
    margin-bottom: 0;
}

.text-markdown ul {
    list-style-type: disc;
    margin-left: 1.5em;
    margin-bottom: 0.75em;
}

.text-markdown ol {
    list-style-type: decimal;
    margin-left: 1.5em;
    margin-bottom: 0.75em;
}

.text-markdown li {
    margin-bottom: 0.25em;
}

.text-markdown pre {
    background-color: #1e1e1e !important;
    color: #d4d4d4;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.75em 0;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85em;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.text-markdown code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.2em 0.4em;
    border-radius: 0.25em;
    font-size: 0.9em;
}

.text-markdown pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 1em;
    color: inherit;
}

.text-markdown blockquote {
    border-left: 4px solid #7c3aed;
    padding-left: 1em;
    margin: 0.75em 0;
    font-style: italic;
    opacity: 0.8;
}

.text-markdown h1,
.text-markdown h2,
.text-markdown h3 {
    font-weight: 700;
    margin-top: 1em;
    margin-bottom: 0.5em;
    line-height: 1.2;
}

.text-markdown h1 {
    font-size: 1.5em;
}

.text-markdown h2 {
    font-size: 1.25em;
}

.text-markdown h3 {
    font-size: 1.1em;
}

.text-markdown strong {
    font-weight: 700;
    color: inherit;
}

.text-markdown a {
    color: #a78bfa;
    text-decoration: underline;
}

/* Specific bubble adjustments for rich text */
.fade-message .bg-gray-100.text-markdown pre {
    background-color: #2d2d2d !important;
    /* Slightly lighter for light mode bubbles */
}

/* Code block scrollbar */
.text-markdown pre::-webkit-scrollbar {
    height: 6px;
}

.text-markdown pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.text-markdown pre::-webkit-scrollbar-thumb {
    background: rgba(124, 58, 237, 0.5);
    border-radius: 3px;
}