/* 
 * Sidebar Stylesheet for Educational Platform
 * Optimized for Arabic content and reading comfort
 */

/* CSS Variables for consistent theming */
:root {
  /* Sidebar dimensions */
  --sidebar-width: clamp(240px, 28vw, 340px);
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.1rem;
  --space-xl: 2rem;
  
  /* Colors - defined here for sidebar.css to work independently */
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-accent: #f5f7fa;
  --text-primary: #333333;
  --text-secondary: #555555;
  --accent-primary: #3a6ea5;
  --accent-hover: #2a5a8f;
  --accent-secondary: #6c757d;
  --border-color: #e1e4e8;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.08);
}

/* Base Sidebar Styles */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  right: 0;
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow-sm);
  padding-bottom: var(--space-xl);
  direction: rtl; /* Ensures RTL layout */
  
  /* Custom scrollbar styling */
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  scrollbar-color: var(--accent-primary) var(--bg-secondary);
  max-width: 100vw;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0));
}

/* Custom Scrollbar */
.sidebar::-webkit-scrollbar {
  width: 8px; /* Increased from 6px to 8px */
}

.sidebar::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: 10px;
}

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

/* Sidebar Title */
.sidebar-title {
  padding: var(--space-lg) var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  background-color: var(--accent-primary);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  z-index: 1001;
}

.sidebar-title a {
  color: white;
  font-family: 'Cairo', sans-serif;
  font-size: clamp(1rem, 1.2vw + 0.6rem, 1.15rem);
  font-weight: 600;
  text-decoration: none;
  display: block;
  transition: color 0.2s ease;
}

.sidebar-title a:hover {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
}

.sidebar-title .home-link {
  font-size: 1.1rem;
  margin-bottom: var(--space-sm);
  opacity: 0.9;
  font-weight: 400;
  font-weight: bolder;
  color: darkorange;

}

.sidebar-title .home-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Navigation Elements */
.sidebar-nav {
  padding: var(--space-md) 0;
}

/* Chapter Elements */
.chapter {
  margin-bottom: var(--space-sm);
}

.chapter-title {
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
  position: relative;
  display: flex;
  align-items: center;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease;
  border-bottom: 1px solid var(--border-color);
  font-size: clamp(0.95rem, 0.8vw + 0.85rem, 1.05rem);
}


.chapter.expanded > .chapter-title::before {
  transform: rotate(0deg);
}

.chapter-title:hover {
  background-color: var(--bg-accent);
  color: var(--accent-primary);
}

/* Class List Styling */
.class-list {
  display: none;
  list-style: none;
  padding: 0;
  margin: 0;
  background-color: var(--bg-accent);
  border-bottom: 1px solid var(--border-color);
}

.chapter.expanded .class-list {
  display: block;
}

.class-list li {
  margin: 0;
}

.class-list a {
  color: var(--text-secondary);
  text-decoration: none;
  display: block;
  padding: clamp(0.6rem, 1.2vw, 0.9rem) var(--space-xl) clamp(0.6rem, 1.2vw, 0.9rem) var(--space-lg);
  transition: background-color 0.2s ease, color 0.2s ease, padding-right 0.2s ease;
  font-size: clamp(0.9rem, 0.5vw + 0.85rem, 1rem);
}

.class-list a:hover {
  background-color: rgba(74, 111, 165, 0.1);
  color: var(--accent-primary);
  padding-right: calc(var(--space-xl) + 5px);
  text-decoration: none;
}

.class-list a.active {
  background-color: rgba(74, 111, 165, 0.15);
  color: var(--accent-primary);
  font-weight: 600;
  border-right: 3px solid var(--accent-primary);
}

.chapter-title:focus-visible,
.class-list a:focus-visible,
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Mobile Sidebar Toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: var(--space-md);
  right: var(--space-md);
  z-index: 1001;
  background-color: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 4px;
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  font-size: 1.2rem;
  transition: background-color 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle:hover {
  background-color: var(--accent-hover);
}

/* Mobile Styles */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(100%);
    width: 280px;
    box-shadow: var(--shadow-md);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-toggle {
    display: block;
  }
  
  /* Overlay for mobile */
  body.sidebar-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: min(88vw, 300px);
  }
  .class-list a {
    padding: clamp(0.7rem, 3vw, 1rem) var(--space-lg);
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  :root {
    --sidebar-width: clamp(260px, 28vw, 320px);
  }
}

@media (min-width: 1440px) {
  :root {
    --sidebar-width: clamp(300px, 22vw, 360px);
  }
}

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
  body.auto-dark-mode {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-accent: #2a2a2a;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #909090;
    --border-color: #333333;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .chapter-title,
  .class-list a,
  .sidebar-toggle {
    transition: none;
  }
}

