/* ==========================================
   ArbiMax Sidebar v2 - Dashboard Blue Pills
   Build: 20260201_PILL_v2
   ==========================================
   
   CHANGES:
   - Unified #2B8CFF dashboard blue (NO GRADIENTS)
   - Compact 44px capsule pills (999px radius)
   - Icons NEVER overlap scrollbar
   - Single scrollbar for all content
   - RTL-ready (logical properties)
   
   STRUCTURE:
   .sidebar (root container - scrollable)
     .sidebar-section  → Group of links
       .navList        → List of nav items
       .navItem        → Individual link (grid layout)
   
   STATE CLASSES:
   body.sidebar-collapsed  → Icons only, centered
   body.sidebar-open       → Mobile drawer open
   .navItem.is-active      → Current route
   ========================================== */

/* ==========================================
   CSS VARIABLES - Dashboard Blue (UNIFIED, NO GRADIENTS)
   ========================================== */
:root {
  /* Layout */
  --sb-width: 280px;
  --sb-width-collapsed: 82px;
  --sb-transition: 200ms ease;
  --header-h: 96px; /* Fallback - JS will override */
  
  /* Dashboard Blue Identity - SINGLE ACCENT */
  --sb-accent: #2B8CFF;
  --sb-accent-glow: rgba(43, 140, 255, 0.25);
  --sb-accent-hover: rgba(43, 140, 255, 0.10);
  --sb-accent-active: rgba(43, 140, 255, 0.22);
  --sb-accent-press: rgba(43, 140, 255, 0.28);
  
  /* Backgrounds */
  --sb-bg: rgba(10, 16, 28, 0.94);
  --sb-bg-blur: rgba(10, 16, 28, 0.96);
  --sb-panel: rgba(255, 255, 255, 0.04);
  --sb-panel-2: rgba(255, 255, 255, 0.07);
  
  /* Borders */
  --sb-border: rgba(43, 140, 255, 0.18);
  --sb-border-hover: rgba(43, 140, 255, 0.35);
  --sb-border-active: rgba(43, 140, 255, 0.50);
  
  /* Text - Dashboard Blue Identity */
  --sb-text: #EAF2FF;
  --sb-text-muted: rgba(234, 242, 255, 0.65);
  --sb-text-dim: rgba(234, 242, 255, 0.40);
  
  /* Scrollbar */
  --sb-scrollbar-thumb: rgba(43, 140, 255, 0.55);
  --sb-scrollbar-track: rgba(255, 255, 255, 0.03);
  --sb-scrollbar-width: 8px;
  
  /* Nav Item Sizing - Compact Pills */
  --sb-item-height: 44px;
  --sb-item-radius: 999px;
  --sb-item-gap: 5px;
}

/* ==========================================
   SIDEBAR ROOT CONTAINER
   Starts BELOW header - no overlap
   ========================================== */
.sidebar,
#arbimax-sidebar {
  position: fixed !important;
  top: var(--header-h, 96px) !important;
  right: 0 !important;
  bottom: 0 !important;
  left: auto !important;
  width: var(--sb-width) !important;
  height: calc(100vh - var(--header-h, 96px)) !important;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--sb-bg-blur) !important;
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-left: 1px solid var(--sb-border) !important;
  border-right: none !important;
  transition: width var(--sb-transition), transform var(--sb-transition);
  overflow: hidden;
  padding: 0 !important;
}

/* RTL: border on right side */
[dir="rtl"] .sidebar,
[dir="rtl"] #arbimax-sidebar {
  border-left: none !important;
  border-right: 1px solid var(--sb-border) !important;
}

/* ==========================================
   SIDEBAR BRAND AREA (TOP)
   ========================================== */
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
  min-height: 72px;
}

.sidebar__brandLogo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(13, 19, 32, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--sb-border);
}

.sidebar__brandLogo img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.sidebar__brandInfo {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  opacity: 1;
  transition: opacity 150ms ease;
}

.sidebar__brandName {
  font-size: 15px;
  font-weight: 700;
  color: var(--sb-text);
  white-space: nowrap;
}

.sidebar__brandRole {
  font-size: 10px;
  font-weight: 600;
  color: var(--sb-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ==========================================
   SIDEBAR SCROLL CONTAINER - UNIFIED SCROLL
   One scrollbar for ALL sidebar content
   Icons NEVER overlap scrollbar
   ========================================== */
#arbimax-sidebar {
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  /* Padding to prevent content from overlapping scrollbar */
  padding-inline-end: 4px;
}

.sidebarScroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 0 20px;
  min-height: min-content;
}

/* ==========================================
   NAVIGATION CONTAINER
   ========================================== */
.sidebar__nav,
.sidebar-nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  margin: 0;
}

/* ==========================================
   MODERN SCROLLBAR STYLING - Dashboard Blue
   ========================================== */
/* WebKit browsers */
.sidebarScroll::-webkit-scrollbar,
#arbimax-sidebar::-webkit-scrollbar {
  width: var(--sb-scrollbar-width);
}

.sidebarScroll::-webkit-scrollbar-track,
#arbimax-sidebar::-webkit-scrollbar-track {
  background: var(--sb-scrollbar-track);
}

.sidebarScroll::-webkit-scrollbar-thumb,
#arbimax-sidebar::-webkit-scrollbar-thumb {
  background: var(--sb-scrollbar-thumb);
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

.sidebarScroll:hover::-webkit-scrollbar-thumb,
#arbimax-sidebar:hover::-webkit-scrollbar-thumb {
  background: rgba(43, 140, 255, 0.70);
  border: 2px solid transparent;
  background-clip: content-box;
}

/* Firefox */
.sidebarScroll,
#arbimax-sidebar {
  scrollbar-width: thin;
  scrollbar-color: var(--sb-scrollbar-thumb) var(--sb-scrollbar-track);
}

/* Legacy scrollbar styling */
.sidebar__nav::-webkit-scrollbar,
.sidebar-nav-list::-webkit-scrollbar {
  width: 10px;
}

.sidebar__nav::-webkit-scrollbar-track,
.sidebar-nav-list::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar__nav::-webkit-scrollbar-thumb,
.sidebar-nav-list::-webkit-scrollbar-thumb {
  background: var(--sb-border);
  border-radius: 4px;
}

/* ==========================================
   NAVIGATION SECTION
   ========================================== */
.navSection {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ==========================================
   SECTION DIVIDER
   ========================================== */
.navDivider,
.sidebar-nav-list hr {
  height: 1px;
  background: var(--sb-border);
  border: none;
  margin: 12px 8px;
  opacity: 0.6;
}

/* ==========================================
   SECTION LABEL (ADMIN CONTROL)
   ========================================== */
.navSectionLabel,
.admin-control-label {
  padding: 16px 14px 10px;
  font-size: 9px;
  font-weight: 600;
  color: var(--sb-accent);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 150ms ease;
  text-align: center;
  opacity: 0.85;
}

/* ==========================================
   NAVIGATION ITEM - Compact Pills (Capsules)
   SOLID BLUE - NO GRADIENTS
   ========================================== */
.navItem,
.sidebar-link {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: center;
  height: var(--sb-item-height);
  padding: 0 16px;
  border-radius: var(--sb-item-radius);
  color: var(--sb-text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  position: relative;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--sb-panel);
  margin-inline-end: 8px; /* Keep away from scrollbar */
  /* Smooth transitions */
  transition: 
    transform 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    box-shadow 200ms ease,
    color 180ms ease;
}

/* HOVER STATE - Subtle blue outline + lift */
.navItem:hover,
.sidebar-link:hover {
  transform: translateY(-1px);
  background: var(--sb-accent-hover);
  border-color: var(--sb-border-hover);
  color: var(--sb-text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* PRESSED STATE - Solid darker blue */
.navItem:active,
.sidebar-link:active {
  transform: translateY(0) scale(0.98);
  background: var(--sb-accent-press);
  transition-duration: 60ms;
}

/* ACTIVE ROUTE STATE - Solid blue fill (NO GRADIENT) */
.navItem.is-active,
.sidebar-link.active {
  background: var(--sb-accent-active);
  border-color: var(--sb-border-active);
  color: var(--sb-text);
  box-shadow: 0 2px 12px rgba(43, 140, 255, 0.15);
}

/* ACTIVE INDICATOR BAR - Solid blue, RTL: inset-inline-start */
.navItem.is-active::after,
.sidebar-link.active::after {
  content: '';
  position: absolute;
  top: 10px;
  bottom: 10px;
  inset-inline-start: 8px;
  width: 3px;
  border-radius: 999px;
  background: var(--sb-accent);
  box-shadow: 0 0 8px var(--sb-accent-glow);
}

/* ==========================================
   NAV ITEM ICON - Grid aligned
   ========================================== */
.navItem__icon,
.am-nav-dot,
.navIcon {
  width: 24px;
  height: 24px;
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.75;
  transition: opacity 150ms ease, transform 150ms ease;
}

.navItem:hover .navItem__icon,
.sidebar-link:hover .am-nav-dot,
.navItem.is-active .navItem__icon,
.sidebar-link.active .am-nav-dot {
  opacity: 1;
  transform: scale(1.05);
}

.navItem__icon svg,
.am-nav-dot svg,
.navIcon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

/* Active icon glow */
.sidebar-link.active .am-nav-dot svg,
.navItem.is-active .navIcon svg {
  stroke: var(--sb-accent);
  filter: drop-shadow(0 0 4px var(--sb-accent-glow));
}

/* Legacy dot fallback */
.am-nav-dot:not(:has(svg))::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.sidebar-link.active .am-nav-dot:not(:has(svg))::before {
  background: var(--sb-accent);
  opacity: 1;
  box-shadow: 0 0 8px var(--sb-accent-glow);
}

/* ==========================================
   NAV ITEM TEXT
   ========================================== */
.navItem__text,
.nav-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 150ms ease, width 150ms ease;
}

/* ==========================================
   COLLAPSED STATE - Icons only, centered
   Icons NEVER overlap scrollbar
   ========================================== */
body.sidebar-collapsed .sidebar,
body.sidebar-collapsed #arbimax-sidebar {
  width: var(--sb-width-collapsed) !important;
}

body.sidebar-collapsed .sidebar__brandInfo {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

body.sidebar-collapsed .sidebar__brand {
  justify-content: center;
  padding: 20px 10px;
}

body.sidebar-collapsed .navSectionLabel,
body.sidebar-collapsed .admin-control-label {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

/* Collapsed nav items - centered icons */
body.sidebar-collapsed .navItem,
body.sidebar-collapsed .sidebar-link {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 0 12px;
  margin-inline-end: 12px; /* Extra margin to avoid scrollbar */
  height: 44px;
}

body.sidebar-collapsed .navItem__text,
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .navLabel {
  display: none;
}

body.sidebar-collapsed .navItem__icon,
body.sidebar-collapsed .am-nav-dot,
body.sidebar-collapsed .navIcon {
  margin: 0;
}

/* Collapsed section padding */
body.sidebar-collapsed .sidebar-section {
  padding: 6px 8px;
}

/* Tooltip on hover when collapsed */
body.sidebar-collapsed .navItem,
body.sidebar-collapsed .sidebar-link {
  position: relative;
}

body.sidebar-collapsed .navItem::before,
body.sidebar-collapsed .sidebar-link::before {
  content: attr(data-label) attr(data-tooltip);
  position: absolute;
  inset-inline-start: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 14px;
  background: rgba(15, 22, 38, 0.96);
  border: 1px solid var(--sb-border);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--sb-text);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 150ms ease, visibility 150ms ease;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body.sidebar-collapsed .navItem:hover::before,
body.sidebar-collapsed .sidebar-link:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Active bar adjusts for collapsed */
body.sidebar-collapsed .navItem.is-active::after,
body.sidebar-collapsed .sidebar-link.active::after {
  top: 10px;
  bottom: 10px;
  inset-inline-start: 6px;
}

/* Divider in collapsed - just spacing */
body.sidebar-collapsed .navDivider,
body.sidebar-collapsed .sidebar-nav-list hr {
  margin: 8px 12px;
}

/* ==========================================
   MOBILE DRAWER MODE (<768px)
   ========================================== */
@media (max-width: 767px) {
  .sidebar,
  #arbimax-sidebar {
    width: var(--sb-width);
    transform: translateX(100%);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
  }
  
  [dir="ltr"] .sidebar,
  [dir="ltr"] #arbimax-sidebar {
    right: auto;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }
  
  body.sidebar-open .sidebar,
  body.sidebar-open #arbimax-sidebar {
    transform: translateX(0);
  }
  
  /* Override collapsed on mobile - always full width when open */
  body.sidebar-collapsed.sidebar-open .sidebar,
  body.sidebar-collapsed.sidebar-open #arbimax-sidebar {
    width: var(--sb-width);
  }
  
  body.sidebar-collapsed.sidebar-open .sidebar__brandInfo {
    opacity: 1;
    width: auto;
  }
  
  body.sidebar-collapsed.sidebar-open .navSectionLabel,
  body.sidebar-collapsed.sidebar-open .admin-control-label {
    opacity: 1;
    height: auto;
    padding: 12px 14px 8px;
  }
  
  body.sidebar-collapsed.sidebar-open .navItem,
  body.sidebar-collapsed.sidebar-open .sidebar-link {
    justify-content: flex-start;
    padding: 12px 14px;
  }
  
  body.sidebar-collapsed.sidebar-open .navItem__text,
  body.sidebar-collapsed.sidebar-open .nav-text {
    opacity: 1;
    width: auto;
  }
}

/* ==========================================
   MOBILE OVERLAY
   ========================================== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 89;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}

body.sidebar-open .sidebar-overlay {
  opacity: 1;
  visibility: visible;
}

@media (min-width: 768px) {
  .sidebar-overlay {
    display: none !important;
  }
}

/* ==========================================
   MAIN CONTENT ADJUSTMENT
   ========================================== */
#main-content,
.main-content {
  margin-right: var(--sb-width) !important;
  margin-left: 0 !important;
  transition: margin var(--sb-transition);
}

[dir="ltr"] #main-content,
[dir="ltr"] .main-content {
  margin-right: 0 !important;
  margin-left: var(--sb-width) !important;
}

body.sidebar-collapsed #main-content,
body.sidebar-collapsed .main-content {
  margin-right: var(--sb-width-collapsed) !important;
}

[dir="ltr"] body.sidebar-collapsed #main-content,
[dir="ltr"] body.sidebar-collapsed .main-content {
  margin-right: 0 !important;
  margin-left: var(--sb-width-collapsed) !important;
}

@media (max-width: 767px) {
  #main-content,
  .main-content {
    margin-right: 0 !important;
    margin-left: 0 !important;
  }
}

/* ==========================================
   HIDE SIDEBAR ON AUTH PAGES
   ========================================== */
body.auth-public .sidebar,
body.auth-public #arbimax-sidebar,
body.auth-route .sidebar,
body.auth-route #arbimax-sidebar {
  display: none !important;
}

body.auth-public #main-content,
body.auth-route #main-content {
  margin-right: 0 !important;
  margin-left: 0 !important;
}

/* ==========================================
   ADMIN NAV VISIBILITY
   ========================================== */
#adminNav {
  display: none; /* Hidden by default - shown only for admins */
  flex-direction: column;
  gap: 4px;
}

/* Only show when NOT hidden (admin users) */
#adminNav:not(.hidden) {
  display: flex !important;
}

#adminNav.hidden {
  display: none !important;
  visibility: hidden !important;
}

/* ==========================================
   FOCUS STATES (Accessibility)
   ========================================== */
.navItem:focus-visible,
.sidebar-link:focus-visible {
  outline: none;
  box-shadow: 
    0 0 0 2px var(--sb-bg),
    0 0 0 4px var(--sb-accent);
  border-color: var(--sb-accent);
}

/* ==========================================
   HIDE DUPLICATE LI WRAPPERS
   (Legacy structure cleanup)
   ========================================== */
.sidebar-nav-list > li {
  display: contents;
}

.sidebar-nav-list > li.mt-5 {
  display: block;
}

/* ==========================================
   SIDEBAR SECTION STRUCTURE
   All sections in one scroll flow
   ========================================== */
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: var(--sb-item-gap);
  padding: 8px 10px;
  flex-shrink: 0;
}

.sidebar-section .sidebar-nav-list {
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sb-item-gap);
}

/* Admin section - subtle separation, SOLID border */
.sidebar-section-admin {
  border-top: 1px solid var(--sb-border);
  padding-top: 12px;
  margin-top: 8px;
  background: rgba(0, 0, 0, 0.06);
}

.sidebar-section-admin.hidden {
  display: none !important;
}

/* Section divider - SOLID, NO GRADIENT */
.sidebar-section + .sidebar-section-admin::before {
  content: '';
  display: block;
  height: 1px;
  background: var(--sb-border);
  margin: 0 12px 10px;
  opacity: 0.6;
}

/* ==========================================
   OVERRIDE OLD SIDEBAR STYLES
   ========================================== */
#arbimax-sidebar {
  /* Reset any old styles */
  left: auto !important;
  transform: none;
}

/* Layout root needs to accommodate header */
#layout-root {
  margin-top: var(--header-h, 96px) !important;
  height: calc(100vh - var(--header-h, 96px)) !important;
  position: relative;
}

@media (max-width: 767px) {
  #arbimax-sidebar {
    transform: translateX(100%);
    top: 0 !important;
    height: 100vh !important;
    z-index: 100;
  }
  
  body.sidebar-open #arbimax-sidebar {
    transform: translateX(0);
  }
}

/* Override old chrome.css / layout-shell.css sidebar rules */
body:not(.sidebar-collapsed) #arbimax-sidebar {
  width: var(--sb-width) !important;
}

/* Ensure proper nav list display */
#arbimax-sidebar .sidebar-nav-list {
  list-style: none;
  padding: 4px 0;
  margin: 0;
}

#arbimax-sidebar .sidebar-nav-list li {
  list-style: none;
}

/* ==========================================
   ICON ENHANCEMENTS
   ========================================== */
.am-nav-dot svg,
.navIcon svg {
  stroke-width: 1.8;
  transition: transform 150ms ease;
}

.sidebar-link:hover .am-nav-dot svg,
.navItem:hover .navIcon svg {
  transform: scale(1.1);
}

.sidebar-link.active .am-nav-dot svg,
.navItem.is-active .navIcon svg {
  stroke: var(--sb-accent);
  filter: drop-shadow(0 0 4px var(--sb-accent-glow));
}
