/* Enhanced Scrollbar dengan efek animasi petir/kilat */

/* Base styling untuk scrollbar */
::-webkit-scrollbar {
    width: var(--scrollbar-width, 12px) !important;
    background-color: rgba(0, 0, 0, 0.05) !important;
    position: relative !important;
    z-index: 100 !important;
}

::-webkit-scrollbar-track {
    background-color: rgba(0, 0, 0, 0.05) !important;
    border-radius: 10px !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Track dengan efek kilatan listrik saat scroll */
::-webkit-scrollbar-track::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, 
        rgba(83, 109, 254, 0) 0%,
        rgba(83, 109, 254, 0.2) 30%,
        rgba(83, 109, 254, 0.5) 50%,
        rgba(83, 109, 254, 0.2) 70%,
        rgba(83, 109, 254, 0) 100%);
    opacity: 0;
    z-index: -1;
    background-size: 100% 200px;
    background-repeat: no-repeat;
    background-position: 0 -200px;
    transition: opacity 0.3s ease;
}

/* Active track lightning effect */
::-webkit-scrollbar-track::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 50% var(--lightning-pos, 50%), rgba(131, 156, 255, 0.7) 0%, rgba(131, 156, 255, 0) 70%);
    opacity: 0;
    z-index: 1;
    background-size: 150% 100px;
    background-repeat: no-repeat;
    transition: opacity 0.2s ease;
}

/* Extra lightning bolt effect for scrollbar track */
::-webkit-scrollbar-track::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(0deg, 
            transparent 0px, 
            rgba(83, 109, 254, 0.1) 1px, 
            transparent 2px, 
            transparent 10px);
    background-size: 100% 10px;
    opacity: 0;
    z-index: 1;
    animation: track-bolt-move 10s linear infinite;
}

/* Scrollbar thumb styling with lightning effect */
::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, var(--primary-color), #4361ee) !important;
    border-radius: 10px !important;
    position: relative !important;
    overflow: hidden !important;
    box-shadow: 
        inset 0 0 6px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(83, 109, 254, 0.3) !important;
    z-index: 101 !important;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #536dfe, #3f51b5) !important;
}

/* Direction-aware electricity effects on thumb */
::-webkit-scrollbar-thumb::before,
::-webkit-scrollbar-thumb::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Zigzag lightning effect pattern */
::-webkit-scrollbar-thumb::before {
    background-image: 
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255, 255, 255, 0.8) 2px, transparent 4px),
        repeating-linear-gradient(-90deg, transparent, transparent 2px, rgba(255, 255, 255, 0.8) 2px, transparent 5px);
    background-size: 7px 100%, 7px 100%;
    background-position: 0 0, 3px 0;
    opacity: 0;
    animation: lightning-flicker 0.3s infinite;
}

/* Glowing electric trail effect */
::-webkit-scrollbar-thumb::after {
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(83, 109, 254, 0.7) 20%, transparent 70%);
    background-size: 200% 200%;
    background-position: center;
    filter: blur(1px);
    opacity: 0;
}

/* Electricity trail for scrollbar */
.electricity-trail {
    position: fixed;
    right: 0;
    top: 0;
    width: 12px; /* Same as scrollbar width */
    height: 100%; /* Don't use vh to avoid overflow */
    pointer-events: none;
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow: hidden; /* Prevent content from spilling */
}

/* Direction-based scroll effects */
.scroll-up ::-webkit-scrollbar-thumb {
    box-shadow: 
        inset 0 0 6px rgba(0, 0, 0, 0.1),
        0 -3px 5px -2px rgba(83, 109, 254, 0.5);
}

.scroll-down ::-webkit-scrollbar-thumb {
    box-shadow: 
        inset 0 0 6px rgba(0, 0, 0, 0.1),
        0 3px 5px -2px rgba(83, 109, 254, 0.5);
}

/* Lightning trail animations based on direction */
.scroll-up .electricity-trail {
    background: linear-gradient(to top, 
        transparent, 
        rgba(83, 109, 254, 0.2) 20%, 
        rgba(131, 156, 255, 0.6) 50%,
        rgba(83, 109, 254, 0.2) 80%, 
        transparent);
    transform: translateY(0); /* Removed translateY to fix positioning */
}

.scroll-down .electricity-trail {
    background: linear-gradient(to bottom, 
        transparent, 
        rgba(83, 109, 254, 0.2) 20%, 
        rgba(131, 156, 255, 0.6) 50%,
        rgba(83, 109, 254, 0.2) 80%, 
        transparent);
    top: 0;
}

/* Active scrolling effects */
.scrolling.active-scroll .electricity-trail {
    opacity: 1;
    height: var(--trail-height, 100px);
}

.scrolling.active-scroll ::-webkit-scrollbar-thumb::before {
    opacity: 0.8;
}

.scrolling.active-scroll ::-webkit-scrollbar-thumb::after {
    opacity: 0.7;
    animation: pulse 1s infinite alternate;
}

.scrolling.active-scroll ::-webkit-scrollbar-track::before {
    opacity: 0.6;
}

.scrolling.active-scroll ::-webkit-scrollbar-track::after {
    opacity: 0.7;
}

/* Animation keyframes */
@keyframes lightning-scroll {
    0% {
        background-position: 0 calc(50% - 3px), 0 calc(50% + 3px);
    }
    100% {
        background-position: 10px calc(50% - 3px), -10px calc(50% + 3px);
    }
}

@keyframes lightning-flicker {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 0.3; }
}

@keyframes pulse {
    0% { opacity: 0.3; transform: scale(0.8); }
    100% { opacity: 0.7; transform: scale(1.2); }
}

@keyframes track-lightning {
    0% { background-position: 0 -200px; opacity: 0; }
    30% { opacity: 0.7; }
    100% { background-position: 0 100%; opacity: 0; }
}

@keyframes electricity-trail {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.3; }
}

/* Electric pulse effect around the scrollbar */
@keyframes electric-pulse {
    0%, 100% { 
        box-shadow: 
            0 0 2px rgba(83, 109, 254, 0.3),
            0 0 4px rgba(83, 109, 254, 0.2);
    }
    50% { 
        box-shadow: 
            0 0 5px rgba(83, 109, 254, 0.5),
            0 0 10px rgba(83, 109, 254, 0.3);
    }
}

/* Apply pulse effect to scrollbar when scrolling */
.scrolling.active-scroll ::-webkit-scrollbar {
    animation: electric-pulse 1s infinite;
}

/* Enhanced dark mode electric pulse */
[data-theme="dark"] .scrolling.active-scroll ::-webkit-scrollbar {
    animation: dark-electric-pulse 1s infinite;
}

@keyframes dark-electric-pulse {
    0%, 100% { 
        box-shadow: 
            0 0 3px rgba(83, 109, 254, 0.4),
            0 0 6px rgba(83, 109, 254, 0.3);
    }
    50% { 
        box-shadow: 
            0 0 8px rgba(83, 109, 254, 0.7),
            0 0 12px rgba(83, 109, 254, 0.5);
    }
}

/* Increase glow intensity with scroll speed */
.scroll-fast ::-webkit-scrollbar {
    animation-duration: 0.6s !important;
}

.scroll-medium ::-webkit-scrollbar {
    animation-duration: 0.8s !important;
}

.scroll-slow ::-webkit-scrollbar {
    animation-duration: 1.2s !important;
}

/* Efek petir saat scroll down (arah ke bawah) */
.scrolling.scroll-down ::-webkit-scrollbar-track::before {
    background: linear-gradient(to bottom, 
        rgba(83, 109, 254, 0) 0%,
        rgba(83, 109, 254, 0.2) 30%,
        rgba(83, 109, 254, 0.5) 50%,
        rgba(83, 109, 254, 0.2) 70%,
        rgba(83, 109, 254, 0) 100%);
    background-size: 100% 200px;
    background-repeat: no-repeat;
    animation: track-lightning-down 1s cubic-bezier(0.215, 0.610, 0.355, 1) forwards;
}

/* Efek petir saat scroll up (arah ke atas) */
.scrolling.scroll-up ::-webkit-scrollbar-track::before {
    background: linear-gradient(to top, 
        rgba(83, 109, 254, 0) 0%,
        rgba(83, 109, 254, 0.2) 30%,
        rgba(83, 109, 254, 0.5) 50%,
        rgba(83, 109, 254, 0.2) 70%,
        rgba(83, 109, 254, 0) 100%);
    background-size: 100% 200px;
    background-repeat: no-repeat;
    animation: track-lightning-up 1s cubic-bezier(0.215, 0.610, 0.355, 1) forwards;
}

@keyframes track-lightning-down {
    0% {
        background-position: 0 -200px;
        opacity: 1;
    }
    100% {
        background-position: 0 calc(100% + 200px);
        opacity: 0;
    }
}

@keyframes track-lightning-up {
    0% {
        background-position: 0 calc(100% + 200px);
        opacity: 1;
    }
    100% {
        background-position: 0 -200px;
        opacity: 0;
    }
}

/* Tambahan efek petir di pinggir scrollbar */
.scrollbar-lightning {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.lightning-bolt {
    position: absolute;
    width: 100%;
    height: 100px;
    opacity: 0;
    background-repeat: no-repeat;
    background-size: contain;
    filter: drop-shadow(0 0 5px var(--primary-color));
}

/* Variasi khusus untuk mode gelap */
[data-theme="dark"] ::-webkit-scrollbar {
    background-color: rgba(31, 41, 55, 0.3);
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background-color: rgba(31, 41, 55, 0.7);
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #536dfe, #3f51b5);
    box-shadow: inset 0 0 6px rgba(83, 109, 254, 0.5);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #6d83ff, #536dfe);
}

/* Efek petir yang lebih terlihat di mode gelap */
[data-theme="dark"] ::-webkit-scrollbar-thumb::before {
    background-image: 
        linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.9) 50%, transparent 100%),
        linear-gradient(-90deg, transparent 30%, rgba(255, 255, 255, 0.9) 50%, transparent 70%);
    opacity: 0;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb::after {
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(131, 156, 255, 0.7) 30%, transparent 70%);
}

[data-theme="dark"] .scrolling ::-webkit-scrollbar-thumb::before,
[data-theme="dark"] .scrolling ::-webkit-scrollbar-thumb::after {
    opacity: 1;
}

[data-theme="dark"] .scrolling.active-scroll ::-webkit-scrollbar-track::before {
    opacity: 1;
    filter: drop-shadow(0 0 8px rgba(131, 156, 255, 0.8));
}

/* Efek jejak petir di belakang scroll */
.lightning-trail {
    position: fixed;
    right: 0;
    width: var(--scrollbar-width, 12px);
    height: 0;
    background: linear-gradient(to bottom, transparent, rgba(83, 109, 254, 0.5), transparent);
    pointer-events: none;
    z-index: 98;
    opacity: 0;
    transition: height 0.3s ease, opacity 0.3s ease;
    transform-origin: top center;
}

/* Efek berbeda untuk scroll keatas vs kebawah */
.scroll-down .lightning-trail {
    transform-origin: top center;
    background: linear-gradient(to bottom, 
        transparent 0%, 
        rgba(83, 109, 254, 0.2) 20%, 
        rgba(131, 156, 255, 0.6) 50%,
        rgba(83, 109, 254, 0.2) 80%, 
        transparent 100%);
}

.scroll-up .lightning-trail {
    transform-origin: bottom center;
    background: linear-gradient(to top, 
        transparent 0%, 
        rgba(83, 109, 254, 0.2) 20%, 
        rgba(131, 156, 255, 0.6) 50%,
        rgba(83, 109, 254, 0.2) 80%, 
        transparent 100%);
}

[data-theme="dark"] .lightning-trail {
    background: linear-gradient(to bottom, transparent, rgba(131, 156, 255, 0.7), transparent);
    box-shadow: 0 0 10px rgba(83, 109, 254, 0.5);
}

/* Styling untuk Firefox */
@supports not selector(::-webkit-scrollbar) {
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--primary-color) rgba(0, 0, 0, 0.05);
    }
    
    [data-theme="dark"] * {
        scrollbar-color: #536dfe rgba(31, 41, 55, 0.7);
    }
}

/* Enhanced electricity trails when scrolling fast */
.scroll-fast .electricity-trail {
    opacity: 1 !important;
    height: calc(var(--trail-height, 100px) * 1.5) !important;
    filter: brightness(1.2) drop-shadow(0 0 5px rgba(83, 109, 254, 0.9)) !important;
}

/* Intensity based on scroll speed */
.scroll-medium .electricity-trail {
    opacity: 0.8 !important;
    height: var(--trail-height, 100px) !important;
}

.scroll-slow .electricity-trail {
    opacity: 0.5 !important;
    height: calc(var(--trail-height, 100px) * 0.7) !important;
}

/* Enhanced scrollbar thumb glow on scroll */
.scrolling:not(.active-scroll) ::-webkit-scrollbar-thumb {
    transition: box-shadow 0.5s ease;
}

.scrolling.active-scroll ::-webkit-scrollbar-thumb {
    box-shadow: 
        inset 0 0 6px rgba(0, 0, 0, 0.1),
        0 0 8px rgba(83, 109, 254, 0.6);
    transition: box-shadow 0.2s ease;
}

/* Additional effects for dark mode */
[data-theme="dark"] .scrolling.active-scroll ::-webkit-scrollbar-thumb {
    box-shadow: 
        inset 0 0 6px rgba(0, 0, 0, 0.2),
        0 0 10px 2px rgba(83, 109, 254, 0.8);
}

/* Enhanced lightning trails when scrolling in dark mode */
[data-theme="dark"] .scroll-fast .electricity-trail {
    filter: brightness(1.3) drop-shadow(0 0 8px rgba(83, 109, 254, 1)) !important;
}

/* Adjust opacity for smoother transitions */
.electricity-trail {
    transition: opacity 0.15s ease, height 0.2s ease, filter 0.2s ease;
}
