/**
 * Modern Scrollbar Design - Vuxy Theme
 * Global scrollbar styling consistent with the Vuxy design system
 * Supports both LTR and RTL layouts with light/dark themes
 */

/* ============================================
   Scrollbar Variables (aligned with Vuxy theme)
   ============================================ */
:root {
  /* Scrollbar dimensions */
  --scrollbar-width: 8px;
  --scrollbar-width-thin: 6px;
  --scrollbar-width-thick: 12px;

  /* Light theme colors */
  --scrollbar-track-bg: #f3f2f3;
  --scrollbar-thumb-bg: #c1bfc5;
  --scrollbar-thumb-hover-bg: #97959e;
  --scrollbar-thumb-active-bg: #7367f0;

  /* Scrollbar border radius */
  --scrollbar-border-radius: 10px;
  --scrollbar-thumb-border-radius: 10px;

  /* Scrollbar transitions */
  --scrollbar-transition: background 0.2s ease, opacity 0.2s ease;
}

/* Dark theme scrollbar colors */
[data-bs-theme="dark"] {
  --scrollbar-track-bg: #1a1a1f;
  --scrollbar-thumb-bg: #4a4a52;
  --scrollbar-thumb-hover-bg: #5a5a63;
  --scrollbar-thumb-active-bg: #7367f0;
}

/* ============================================
   Global Scrollbar Styles (Webkit Browsers)
   ============================================ */

/* Force hide ALL scrollbar arrow buttons - comprehensive approach based on WebKit spec */
::-webkit-scrollbar-button {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
}

/* Hide buttons in all states and orientations */
::-webkit-scrollbar-button:vertical:decrement,
::-webkit-scrollbar-button:vertical:increment,
::-webkit-scrollbar-button:horizontal:decrement,
::-webkit-scrollbar-button:horizontal:increment {
  display: none !important;
  height: 0 !important;
  width: 0 !important;
}

/* Hide buttons at start and end positions */
::-webkit-scrollbar-button:vertical:start:decrement,
::-webkit-scrollbar-button:vertical:end:increment,
::-webkit-scrollbar-button:horizontal:start:decrement,
::-webkit-scrollbar-button:horizontal:end:increment {
  display: none !important;
  height: 0 !important;
  width: 0 !important;
}

/* Hide single and double button configurations */
::-webkit-scrollbar-button:vertical:single-button,
::-webkit-scrollbar-button:vertical:double-button,
::-webkit-scrollbar-button:horizontal:single-button,
::-webkit-scrollbar-button:horizontal:double-button {
  display: none !important;
  height: 0 !important;
  width: 0 !important;
}

/* Default scrollbar styling for all elements */
* {
  --scrollbar-track-color-visible: var(--scrollbar-track-bg);
  --scrollbar-thumb-color-visible: var(--scrollbar-thumb-bg);
  --scrollbar-thumb-color-hover: var(--scrollbar-thumb-hover-bg);
  --scrollbar-thumb-color-active: var(--scrollbar-thumb-active-bg);
  --scrollbar-track-color-current: transparent;
  --scrollbar-thumb-color-current: transparent;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

*:hover,
*:focus,
*:focus-within {
  --scrollbar-track-color-current: var(--scrollbar-track-color-visible);
  --scrollbar-thumb-color-current: var(--scrollbar-thumb-color-visible);
  scrollbar-color: var(--scrollbar-thumb-color-current) var(--scrollbar-track-color-current);
}

/* Webkit scrollbar (Chrome, Safari, Edge) */
*::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: var(--scrollbar-width);
  background-color: transparent;
  transition: opacity 0.2s ease;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track-color-current);
  border-radius: var(--scrollbar-border-radius);
  margin: 2px;
  transition: background 0.2s ease;
}

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

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

*::-webkit-scrollbar-thumb:active {
  background: var(--scrollbar-thumb-color-active);
  border: 1px solid transparent;
  background-clip: padding-box;
}

/* Scrollbar corner (where vertical and horizontal scrollbars meet) */
*::-webkit-scrollbar-corner {
  background: var(--scrollbar-track-bg);
  border-radius: var(--scrollbar-border-radius);
}


/* ============================================
   Utility Classes for Custom Scrollbar Widths
   ============================================ */

/* Thin scrollbar variant */
.scrollbar-thin,
.scrollbar-thin *::-webkit-scrollbar {
  width: var(--scrollbar-width-thin);
  height: var(--scrollbar-width-thin);
}

.scrollbar-thin {
  scrollbar-width: thin;
}

/* Thick scrollbar variant */
.scrollbar-thick,
.scrollbar-thick *::-webkit-scrollbar {
  width: var(--scrollbar-width-thick);
  height: var(--scrollbar-width-thick);
}

/* Hidden scrollbar (but still scrollable) */
.scrollbar-hidden {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scrollbar-hidden::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

/* Auto-hide scrollbar - shows only on hover */
.scrollbar-autohide::-webkit-scrollbar {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.scrollbar-autohide:hover::-webkit-scrollbar {
  opacity: 1;
}

.scrollbar-autohide::-webkit-scrollbar-thumb {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.scrollbar-autohide:hover::-webkit-scrollbar-thumb {
  opacity: 1;
}

/* ============================================
   Component-Specific Scrollbar Styles
   ============================================ */

/* Menu/Sidebar scrollbar - thinner and more subtle */
.menu,
.layout-menu,
.sidebar,
aside {
  scrollbar-width: thin;
  overflow-x: hidden !important;
  --scrollbar-track-color-visible: transparent;
  --scrollbar-thumb-color-visible: rgba(var(--bs-primary-rgb), 0.2);
  --scrollbar-thumb-color-hover: rgba(var(--bs-primary-rgb), 0.35);
  --scrollbar-thumb-color-active: rgba(var(--bs-primary-rgb), 0.45);
}

.menu::-webkit-scrollbar,
.layout-menu::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
aside::-webkit-scrollbar {
  width: 6px;
}

.menu::-webkit-scrollbar-track,
.layout-menu::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track,
aside::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}

.menu::-webkit-scrollbar-thumb,
.layout-menu::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
aside::-webkit-scrollbar-thumb {
  border: 1px solid transparent;
}

/* Prevent horizontal scrolling on menu containers */
.layout-menu,
.menu-inner {
  overflow-x: hidden !important;
  max-width: 100%;
  box-sizing: border-box;
}

/* Ensure all menu content stays within bounds */
.layout-menu *,
.menu-inner * {
  box-sizing: border-box;
}

/* Card scrollbar - matches card styling */
.card,
.card-body {
  scrollbar-width: thin;
  --scrollbar-track-color-visible: rgba(var(--bs-gray-rgb), 0.05);
  --scrollbar-thumb-color-visible: rgba(var(--bs-gray-rgb), 0.3);
  --scrollbar-thumb-color-hover: rgba(var(--bs-gray-rgb), 0.5);
  --scrollbar-thumb-color-active: rgba(var(--bs-gray-rgb), 0.6);
  --scrollbar-border-radius: 8px;
  --scrollbar-thumb-border-radius: 8px;
}

.card::-webkit-scrollbar,
.card-body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.card::-webkit-scrollbar-track,
.card-body::-webkit-scrollbar-track {
  border-radius: 8px;
}

.card::-webkit-scrollbar-thumb,
.card-body::-webkit-scrollbar-thumb {
  border-radius: 8px;
}

/* Modal scrollbar */
.modal-body {
  scrollbar-width: thin;
  --scrollbar-track-color-visible: var(--scrollbar-track-bg);
  --scrollbar-thumb-color-visible: var(--scrollbar-thumb-bg);
  --scrollbar-thumb-color-hover: var(--scrollbar-thumb-hover-bg);
  --scrollbar-thumb-color-active: var(--scrollbar-thumb-active-bg);
  --scrollbar-border-radius: 10px;
  --scrollbar-thumb-border-radius: 10px;
}

.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  border-radius: 10px;
  margin: 10px 0;
}

.modal-body::-webkit-scrollbar-thumb {
  border-radius: 10px;
}

/* Dropdown menu scrollbar - very thin and subtle */
.dropdown-menu {
  scrollbar-width: thin;
  --scrollbar-width: 4px;
  --scrollbar-track-color-visible: transparent;
  --scrollbar-thumb-color-visible: rgba(var(--bs-primary-rgb), 0.2);
  --scrollbar-thumb-color-hover: rgba(var(--bs-primary-rgb), 0.4);
  --scrollbar-thumb-color-active: rgba(var(--bs-primary-rgb), 0.5);
  --scrollbar-thumb-border-radius: 4px;
}

.dropdown-menu::-webkit-scrollbar {
  width: 4px;
}

.dropdown-menu::-webkit-scrollbar-track {
  margin: 4px 0;
}

.dropdown-menu::-webkit-scrollbar-thumb {
  border-radius: 4px;
}

/* Table scrollbar */
.table-responsive,
.dataTables_wrapper {
  scrollbar-width: thin;
  --scrollbar-track-color-visible: var(--scrollbar-track-bg);
  --scrollbar-thumb-color-visible: var(--scrollbar-thumb-bg);
  --scrollbar-thumb-color-hover: var(--scrollbar-thumb-hover-bg);
  --scrollbar-thumb-color-active: var(--scrollbar-thumb-active-bg);
  --scrollbar-border-radius: 8px;
  --scrollbar-thumb-border-radius: 8px;
}

.table-responsive::-webkit-scrollbar,
.dataTables_wrapper::-webkit-scrollbar {
  height: 8px;
}

.table-responsive::-webkit-scrollbar-track,
.dataTables_wrapper::-webkit-scrollbar-track {
  border-radius: 8px;
  margin: 0 10px;
}

.table-responsive::-webkit-scrollbar-thumb,
.dataTables_wrapper::-webkit-scrollbar-thumb {
  border-radius: 8px;
}

/* Code blocks and pre elements */
pre,
code {
  scrollbar-width: thin;
  --scrollbar-track-color-visible: rgba(0, 0, 0, 0.05);
  --scrollbar-thumb-color-visible: rgba(0, 0, 0, 0.2);
  --scrollbar-thumb-color-hover: rgba(0, 0, 0, 0.35);
  --scrollbar-thumb-color-active: rgba(0, 0, 0, 0.45);
  --scrollbar-border-radius: 8px;
  --scrollbar-thumb-border-radius: 8px;
}

pre::-webkit-scrollbar,
code::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

pre::-webkit-scrollbar-track,
code::-webkit-scrollbar-track {
  border-radius: 8px;
}

pre::-webkit-scrollbar-thumb,
code::-webkit-scrollbar-thumb {
  border-radius: 8px;
}

/* ============================================
   Themed Scrollbar Variants
   ============================================ */

/* Primary theme scrollbar */
.scrollbar-primary {
  --scrollbar-track-color-visible: rgba(var(--bs-primary-rgb), 0.1);
  --scrollbar-thumb-color-visible: rgba(var(--bs-primary-rgb), 0.6);
  --scrollbar-thumb-color-hover: rgba(var(--bs-primary-rgb), 0.8);
  --scrollbar-thumb-color-active: var(--bs-primary);
}

/* Success theme scrollbar */
.scrollbar-success {
  --scrollbar-track-color-visible: rgba(var(--bs-success-rgb), 0.1);
  --scrollbar-thumb-color-visible: rgba(var(--bs-success-rgb), 0.6);
  --scrollbar-thumb-color-hover: rgba(var(--bs-success-rgb), 0.8);
  --scrollbar-thumb-color-active: rgba(var(--bs-success-rgb), 0.9);
}

/* Info theme scrollbar */
.scrollbar-info {
  --scrollbar-track-color-visible: rgba(var(--bs-info-rgb), 0.1);
  --scrollbar-thumb-color-visible: rgba(var(--bs-info-rgb), 0.6);
  --scrollbar-thumb-color-hover: rgba(var(--bs-info-rgb), 0.8);
  --scrollbar-thumb-color-active: rgba(var(--bs-info-rgb), 0.9);
}

/* Warning theme scrollbar */
.scrollbar-warning {
  --scrollbar-track-color-visible: rgba(var(--bs-warning-rgb), 0.1);
  --scrollbar-thumb-color-visible: rgba(var(--bs-warning-rgb), 0.6);
  --scrollbar-thumb-color-hover: rgba(var(--bs-warning-rgb), 0.8);
  --scrollbar-thumb-color-active: rgba(var(--bs-warning-rgb), 0.9);
}

/* Danger theme scrollbar */
.scrollbar-danger {
  --scrollbar-track-color-visible: rgba(var(--bs-danger-rgb), 0.1);
  --scrollbar-thumb-color-visible: rgba(var(--bs-danger-rgb), 0.6);
  --scrollbar-thumb-color-hover: rgba(var(--bs-danger-rgb), 0.8);
  --scrollbar-thumb-color-active: rgba(var(--bs-danger-rgb), 0.9);
}

/* ============================================
   Smooth Scrolling Behavior
   ============================================ */

/* Enable smooth scrolling globally */
html {
  scroll-behavior: smooth;
}

/* Smooth scrolling for specific containers */
.smooth-scroll {
  scroll-behavior: smooth;
}

/* Disable smooth scroll when user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  html,
  .smooth-scroll {
    scroll-behavior: auto;
  }
}

/* ============================================
   RTL Scrollbar Adjustments
   ============================================ */

/* RTL scrollbar positioning - ensure scrollbar appears on the left in RTL */
[dir='rtl'] *::-webkit-scrollbar {
  direction: rtl;
}

/* ============================================
   Mobile & Touch Device Optimizations
   ============================================ */

/* Thinner scrollbars on mobile for better touch experience */
@media (max-width: 768px) {
  *::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  .scrollbar-thick::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
}

/* Hide scrollbar on very small screens (mobile) but keep scrolling functional */
@media (max-width: 576px) {
  .scrollbar-mobile-hide {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .scrollbar-mobile-hide::-webkit-scrollbar {
    display: none;
  }
}

/* ============================================
   Performance Optimizations
   ============================================ */

/* Optimize scroll performance with CSS containment */
.scroll-optimized {
  contain: layout style paint;
  content-visibility: auto;
}

/* GPU acceleration for smooth scrolling */
.scroll-gpu-accelerated {
  transform: translateZ(0);
  will-change: scroll-position;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   Accessibility Improvements
   ============================================ */

/* High contrast scrollbar for better visibility */
@media (prefers-contrast: high) {
  *::-webkit-scrollbar-thumb {
    background: var(--bs-emphasis-color);
    border: 1px solid var(--bs-body-bg);
  }

  *::-webkit-scrollbar-track {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
  }
}

/* Larger scrollbar for users who prefer it */
@media (prefers-scrollbar-width: thick) {
  *::-webkit-scrollbar {
    width: var(--scrollbar-width-thick);
    height: var(--scrollbar-width-thick);
  }
}

/* ============================================
   Custom Overlay Scrollbar (Modern macOS Style)
   ============================================ */

/* Overlay scrollbar - appears only when scrolling */
.scrollbar-overlay {
  overflow: overlay;
  scrollbar-width: thin;
  --scrollbar-width: 10px;
  --scrollbar-track-color-visible: transparent;
  --scrollbar-thumb-color-visible: rgba(var(--bs-gray-rgb), 0.4);
  --scrollbar-thumb-color-hover: rgba(var(--bs-gray-rgb), 0.6);
  --scrollbar-thumb-color-active: rgba(var(--bs-primary-rgb), 0.7);
  --scrollbar-thumb-border-radius: 10px;
}

.scrollbar-overlay::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

.scrollbar-overlay::-webkit-scrollbar-thumb {
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.scrollbar-overlay:hover::-webkit-scrollbar-thumb {
  opacity: 1;
}

.scrollbar-overlay::-webkit-scrollbar-thumb:hover {
  opacity: 1;
}

.scrollbar-overlay::-webkit-scrollbar-thumb:active {
  opacity: 1;
}

/* ============================================
   Animated Scrollbar (Optional - Add class when needed)
   ============================================ */

/* Scrollbar with pulsing animation for attention */
@keyframes scrollbar-pulse {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

.scrollbar-pulse::-webkit-scrollbar-thumb {
  animation: scrollbar-pulse 2s ease-in-out infinite;
}

/* Gradient scrollbar thumb */
.scrollbar-gradient {
  --scrollbar-thumb-color-visible: rgba(var(--bs-primary-rgb), 0.7);
  --scrollbar-thumb-color-hover: rgba(var(--bs-primary-rgb), 0.85);
  --scrollbar-thumb-color-active: rgba(var(--bs-primary-rgb), 1);
}

.scrollbar-gradient:hover::-webkit-scrollbar-thumb,
.scrollbar-gradient:focus::-webkit-scrollbar-thumb,
.scrollbar-gradient:focus-within::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    rgba(var(--bs-primary-rgb), 0.8),
    rgba(var(--bs-primary-rgb), 0.4)
  );
}

.scrollbar-gradient:hover::-webkit-scrollbar-thumb:hover,
.scrollbar-gradient:focus::-webkit-scrollbar-thumb:hover,
.scrollbar-gradient:focus-within::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(
    180deg,
    rgba(var(--bs-primary-rgb), 1),
    rgba(var(--bs-primary-rgb), 0.6)
  );
}

/* ============================================
   Sidebar Navigation Scrollable
   ============================================ */

/* Sidebar scrollable menu - desktop */
.sidebar-scrollable {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  max-height: calc(100svh - 120px);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  width: 100%;
  max-width: 100%;
}

 
 
.sidebar-scrollable .badge {
  flex-shrink: 0;
}

/* Mobile adjustments - account for bottom navigation */
@media (max-width: 1199px) {
  .sidebar-scrollable {
    /* Account for: header (120px) + bottom nav (60-70px) + extra safe space */
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    max-height: calc(100svh - 200px);
    /* Padding to ensure last items are always accessible above bottom nav */
    padding-bottom: 90px !important;
  }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 1199px) {
  .sidebar-scrollable {
    /* Slightly more space on tablets */
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    max-height: calc(100svh - 200px);
    padding-bottom: 90px !important;
  }
}

/* Small phones */
@media (max-width: 576px) {
  .sidebar-scrollable {
    /* More padding for small screens */
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    max-height: calc(100svh - 200px);
    /* Extra padding for small screens to ensure last items are always visible */
    padding-bottom: 110px !important;
  }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .sidebar-scrollable {
    /* Less space in landscape but still need padding for bottom nav */
    max-height: calc(100vh - 150px);
    max-height: calc(100dvh - 150px);
    max-height: calc(100svh - 150px);
    padding-bottom: 80px !important;
  }
}

/* Hide scrollbar on mobile if content doesn't overflow on desktop */
@media (min-width: 1200px) {
  .sidebar-scrollable::-webkit-scrollbar {
    /* Show only when actually scrolling/hovering */
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sidebar-scrollable:hover::-webkit-scrollbar,
  .sidebar-scrollable:focus-within::-webkit-scrollbar {
    opacity: 1;
  }
}

/* ============================================
   Implementation Notes & Best Practices
   ============================================ */

/*
 * Modern Scrollbar Design System for Vuxy
 *
 * Features:
 * 1. Consistent with Vuxy color scheme and design language
 * 2. Supports light/dark themes automatically
 * 3. RTL-aware scrollbar positioning
 * 4. Component-specific scrollbar styles
 * 5. Accessibility-focused (high contrast, reduced motion support)
 * 6. Mobile-optimized with touch-friendly dimensions
 * 7. Performance-optimized with GPU acceleration
 * 8. Utility classes for easy customization
 * 9. NO SCROLLBAR ARROW BUTTONS (completely hidden)
 *
 * Usage:
 * - Default scrollbar is applied globally
 * - Use utility classes (.scrollbar-thin, .scrollbar-overlay, etc.) for variations
 * - Theme-specific scrollbars (.scrollbar-primary, .scrollbar-success, etc.)
 * - Auto-hide scrollbar (.scrollbar-autohide) for cleaner UI
 * - Hidden scrollbar (.scrollbar-hidden) for custom scroll implementations
 *
 * Browser Support:
 * - Webkit browsers (Chrome, Safari, Edge): Full support with custom styling
 * - Firefox: Basic support via scrollbar-width and scrollbar-color
 * - Legacy browsers: Fallback to browser default scrollbar
 *
 * Performance Tips:
 * - Add .scroll-optimized for containers with lots of content
 * - Use .scroll-gpu-accelerated for smooth scrolling animations
 * - Consider .scrollbar-autohide to reduce visual clutter
 */
