/**
 * Course Sidebar Navigation Styles
 * Sidebar with accordion modules, search, and mobile drawer
 * Scoped to .course-sidebar and related classes
 */

/* ═══════════════════════════════════════
   CSS VARIABLES (sidebar-specific)
   ═══════════════════════════════════════ */
:root {
  --sidebar-width: 272px;
  /* --color-progress already defined in variables.css */
  --color-sidebar-bg: var(--color-surface);
  --color-sidebar-border: var(--color-course-border);
  --color-sidebar-muted: var(--color-course-text-muted);
}

/* ═══════════════════════════════════════
   LAYOUT: sidebar + content wrapper
   ═══════════════════════════════════════ */

/* When sidebar is present, offset the main content */
html:has(.course-sidebar) .lesson-page {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

html:has(.course-sidebar) main {
  position: relative;
  margin-left: var(--sidebar-width) !important;
  margin-right: 0 !important;
  max-width: calc(100% - var(--sidebar-width)) !important;
}

/* Progress header spans full width above content (not sidebar) */
html:has(.course-sidebar) .lesson-progress-header {
  position: sticky;
  top: 0;
  z-index: calc(var(--z-sidebar, 300) + 5);
  background: rgba(var(--color-background-rgb, 255,255,255), 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: var(--spacing-md) var(--spacing-3xl, 64px);
  border-bottom: 1px solid var(--color-border-light);
}

/* Bottom nav: no left offset needed — main already has margin-left */

/* Footer offset for sidebar */
html:has(.course-sidebar) footer {
  margin-left: var(--sidebar-width);
}

/* ═══════════════════════════════════════
   SIDEBAR CONTAINER
   ═══════════════════════════════════════ */
.course-sidebar {
  position: fixed;
  top: var(--header-height, 73px);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100dvh - var(--header-height, 73px));
  background: var(--color-sidebar-bg);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-right: 1px solid var(--color-sidebar-border);
  box-shadow: none;
  z-index: var(--z-sidebar, 300);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md) var(--spacing-md) var(--spacing-xl);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background: var(--color-surface);
}

/* Custom scrollbar */
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}
.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(75, 96, 110, 0.15);
  border-radius: 3px;
}
.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: rgba(75, 96, 110, 0.25);
}

/* ═══════════════════════════════════════
   SIDEBAR HEADER
   ═══════════════════════════════════════ */
.sidebar-header {
  position: sticky;
  top: 0;
  background: var(--color-sidebar-bg);
  backdrop-filter: none;
  padding: 12px 16px 8px;
  margin: calc(-1 * var(--spacing-md));
  margin-bottom: var(--spacing-md);
  border-bottom: 1px solid rgba(75, 96, 110, 0.08);
  z-index: 10;
}

.sidebar-header__course {
  font-family: var(--font-family-heading);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

/* Progress bar */
.sidebar-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.sidebar-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--color-course-border);
  border-radius: 2px;
  overflow: hidden;
}

.sidebar-progress-fill {
  height: 100%;
  background: var(--color-progress);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.sidebar-progress-label {
  font-size: var(--font-size-caption);
  color: var(--color-sidebar-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════
   SEARCH
   ═══════════════════════════════════════ */
/* ═══════════════════════════════════════
   MODULES ACCORDION
   ═══════════════════════════════════════ */
.sidebar-modules {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.module {
  border-radius: var(--radius-md);
  overflow: hidden;
}

.module__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  cursor: pointer;
  list-style: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  border-radius: var(--radius-md);
  transition: background 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  min-height: 44px;
}

.module__summary:hover {
  background: rgba(75, 96, 110, 0.05);
}

.module__header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2xs);
}

.module__title {
  font-size: var(--font-size-caption);
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--color-sidebar-muted);
  transition: color var(--transition-fast);
  font-family: var(--font-family);
}

.module__icon {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  opacity: 0.7;
}

.module.is-open .module__icon {
  transform: rotate(180deg);
}

/* Mini progress bar */
.module__progress-bar {
  height: 3px;
  background: rgba(75, 96, 110, 0.08);
  border-radius: 2px;
  margin: 0 var(--spacing-md);
  margin-top: 4px;
  overflow: hidden;
}

.module__progress-bar-fill {
  height: 100%;
  background: var(--color-success);
  border-radius: 2px;
  transition: width var(--transition-slow);
}

/* Lesson list animation */
.lesson-list {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.lesson-list > div {
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s ease 0.1s;
}

.module.is-open .lesson-list {
  grid-template-rows: 1fr;
}

.module.is-open .lesson-list > div {
  opacity: 1;
}

/* Lesson preview wrapper (not-started modules) */
.lesson-preview-wrapper {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}
.lesson-preview-wrapper > div {
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s ease 0.1s;
}
.module.is-open .lesson-preview-wrapper {
  grid-template-rows: 1fr;
}
.module.is-open .lesson-preview-wrapper > div {
  opacity: 1;
}

.lessons {
  display: flex;
  flex-direction: column;
  padding: var(--spacing-xs);
  gap: var(--spacing-2xs);
}

/* ═══════════════════════════════════════
   LESSON ITEMS
   ═══════════════════════════════════════ */
.sidebar-lesson {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 9px 20px 9px 25px;
  min-height: 44px;
  cursor: pointer;
  background: transparent;
  border-left: 3px solid transparent;
  transition: background 0.3s cubic-bezier(0.25, 0.1, 0.25, 1),
              border-color 0.2s ease;
  text-decoration: none;
  color: inherit;
}

.sidebar-lesson:hover {
  text-decoration: none;
  color: inherit;
  background: rgba(75, 96, 110, 0.04);
}

.sidebar-lesson:focus-visible {
  outline: 2px solid var(--color-main);
  outline-offset: 2px;
}

.sidebar-lesson__icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--font-size-sm);
}

.sidebar-lesson__icon--completed {
  color: var(--color-progress);
  opacity: 1;
}

.sidebar-lesson__icon--current {
  color: var(--color-text-inverse);
  background: var(--color-progress);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  position: relative;
  box-shadow: 0 0 0 3px rgba(56, 161, 105, 0.2);
}

.sidebar-lesson__icon--current::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--color-surface);
  border-radius: 50%;
}

.sidebar-lesson__icon--available {
  color: var(--color-text-muted);
  opacity: 0.7;
}

.sidebar-lesson__icon--locked {
  color: var(--color-text-muted);
  opacity: 0.35;
}

.sidebar-lesson__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-course-text-muted);
  flex: 1;
  transition: color var(--transition-fast);
  letter-spacing: -0.01em;
}

/* Completed lesson */
.sidebar-lesson--completed .sidebar-lesson__name {
  color: var(--color-text-body);
  opacity: 1;
  font-weight: var(--font-weight-normal);
}

/* Current lesson */
.sidebar-lesson--current {
  background: rgba(56, 161, 105, 0.14);
  border-left-color: var(--color-progress);
  border-radius: 0 8px 8px 0;
  font-weight: 600;
}

.sidebar-lesson--current:hover {
  background: rgba(56, 161, 105, 0.18);
}

.sidebar-lesson--current .sidebar-lesson__name {
  font-weight: 600;
  color: var(--color-text-body);
}

/* Available lesson */
.sidebar-lesson--available .sidebar-lesson__name {
  opacity: 0.85;
}

/* Locked lesson */
.sidebar-lesson--locked {
  cursor: default;
  opacity: 0.5;
}

.sidebar-lesson--locked .sidebar-lesson__name {
  opacity: 1;
}

/* ═══════════════════════════════════════
   MODULE STATES
   ═══════════════════════════════════════ */

/* Not started module */
.module--not-started .module__title {
  color: rgba(75, 96, 110, 0.50);
}

.module--not-started .lesson-preview {
  list-style: none;
  padding: var(--spacing-xs) var(--spacing-md) var(--spacing-sm);
}

.module--not-started .lesson-preview li {
  font-size: var(--font-size-sm);
  color: rgba(75, 96, 110, 0.45);
  cursor: default;
  padding: 6px var(--spacing-sm);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.module--not-started .lesson-preview li::before {
  content: '○';
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
  opacity: 0.5;
}

/* Locked module */
.module--locked .module__summary {
  cursor: default;
}

.module--locked .module__title {
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.module--locked .module__icon {
  opacity: 0.35;
}

/* ═══════════════════════════════════════
   HAMBURGER BUTTON (mobile)
   ═══════════════════════════════════════ */
.sidebar-hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text);
  transition: all var(--transition-fast);
}

.sidebar-hamburger-btn:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
}

.sidebar-hamburger-btn:focus-visible {
  outline: 2px solid var(--color-main);
  outline-offset: 2px;
}

.sidebar-hamburger-btn svg {
  width: 20px;
  height: 20px;
}

/* Drawer backdrop (mobile) */
.sidebar-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  display: none;
}

.sidebar-drawer-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */
@media (max-width: 1023px) {
  .course-sidebar {
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
                visibility 0s linear 0.35s;
    width: 85vw;
    max-width: 320px;
    box-shadow: none;
  }

  .course-sidebar.active {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
                visibility 0s linear 0s;
    box-shadow: 8px 0 32px rgba(75, 96, 110, 0.12);
    z-index: 1000;
  }

  html:has(.course-sidebar) main {
    margin-left: 0 !important;
    margin-right: auto !important;
    max-width: 1200px !important;
  }

  .sidebar-hamburger-btn {
    display: inline-flex;
    position: fixed;
    top: calc(var(--header-height, 73px) + 8px);
    left: 16px;
    z-index: 305;
  }

  .sidebar-drawer-backdrop {
    display: block;
  }

  html:has(.course-sidebar) .screen-nav-premium {
    left: 0;
  }

  html:has(.course-sidebar) footer {
    margin-left: 0;
  }

  html:has(.course-sidebar) .lesson-progress-header {
    padding-left: 64px;
    padding-right: var(--spacing-lg);
  }
}

@media (max-width: 768px) {
  .course-sidebar {
    top: 57px;
    height: calc(100dvh - 57px);
    max-width: 300px;
  }

  .lessons {
    padding: var(--spacing-xs);
  }

  .sidebar-lesson {
    padding: 10px var(--spacing-sm);
    min-height: 40px;
  }

  .sidebar-lesson__name {
    font-size: var(--font-size-sm);
  }

  .module__title {
    font-size: var(--font-size-caption);
  }

  .sidebar-lesson__icon {
    font-size: var(--font-size-sm);
  }

  .sidebar-progress-label {
    font-size: var(--font-size-caption);
  }
}

/* ═══════════════════════════════════════
   CLOSE BUTTON (mobile drawer)
   ═══════════════════════════════════════ */
.sidebar-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: var(--font-size-base);
  line-height: 1;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.sidebar-close-btn:hover {
  background: rgba(75, 96, 110, 0.08);
  color: var(--color-text);
}

@media (max-width: 1023px) {
  .sidebar-close-btn {
    display: inline-flex;
  }

  .sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--spacing-sm);
  }
}

/* ═══════════════════════════════════════
   FOCUS & ACCESSIBILITY
   ═══════════════════════════════════════ */
.module__summary:focus-visible {
  outline: 2px solid var(--color-main);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .course-sidebar {
    transition: none;
  }

  .sidebar-lesson__icon--current::after {
    animation: none;
  }

  .lesson-list,
  .lesson-list > div,
  .lesson-preview-wrapper,
  .lesson-preview-wrapper > div {
    transition: none;
  }
}

/* ═══════════════════════════════════════
   CARD LAYOUT: sidebar as flex child (not fixed)
   When inside .lesson-card, sidebar is part of flex layout
   ═══════════════════════════════════════ */
.lesson-body .course-sidebar {
  position: static;
  height: auto;
  min-height: 100%;
  flex-shrink: 0;
  top: auto;
  left: auto;
  background: var(--color-surface);
}

.lesson-body > honox-island {
  display: flex;
  flex-shrink: 0;
  background: var(--color-surface);
}

html:has(.lesson-card) main {
  margin-left: 0 !important;
  margin-right: 0 !important;
  max-width: none !important;
  width: 100% !important;
}

html:has(.lesson-card) .screen-nav-premium {
  left: 0;
}

html:has(.lesson-card) footer {
  margin-left: 0;
}

@media (max-width: 1023px) {
  .lesson-body > honox-island {
    display: contents;
    background: none;
  }

  .lesson-body .course-sidebar {
    position: fixed;
    height: calc(100dvh - var(--header-height, 73px));
    top: var(--header-height, 73px);
    left: 0;
    z-index: 1000;
  }

  /* Hide the island wrapper so it doesn't take flex space (#568) */
  .lesson-body > honox-island {
    display: contents;
    background: none;
  }

  html:has(.lesson-card) main {
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}

/* Wider content area when sidebar is present — #492 */
html:has(.course-sidebar) .lesson-content-screen {
  max-width: 780px;
}
