/**
 * Responsive shared sidebar – one sidebar, one toggle.
 * Desktop: visible, collapse to icon-only (70px). Mobile: off-canvas, slide in + overlay.
 * Classes: .sidebar, .menu-toggle, .sidebar-overlay, .collapsed, .active
 */

/* ---- Overlay (mobile only) ---- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

body.active .sidebar-overlay {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--header-height, 56px);
  left: 0;
  bottom: 0;
  width: 260px;
  z-index: 50;
  transition: width 0.3s ease, left 0.3s ease, transform 0.3s ease;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 8px;
  box-sizing: border-box;
  background: #0F172A;
  color: var(--sidebar-fg, rgba(226, 232, 240, 0.88));
  border-right: 1px solid var(--sidebar-border, rgba(255, 255, 255, 0.08));
  /* Hide scrollbar, keep scroll (Chrome, Edge, Safari, Firefox) */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

/* Desktop: collapsed = icon-only */
body.collapsed .sidebar {
  width: 70px;
}

/* Mobile: off-canvas by default (override app.css transform) */
@media (max-width: 768px) {
  .sidebar {
    top: 0;
    left: -260px;
    width: 260px;
    height: 100vh;
    transform: translateX(-100%);
  }

  body.active .sidebar {
    left: 0;
    transform: translateX(0);
  }

  body.collapsed .sidebar {
    width: 260px;
  }

  /* Ensure overlay is visible when menu open (app.css uses .sidebar-mobile-open) */
  body.active .sidebar-overlay {
    display: block;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
}

/* ---- Main content area (shifts with sidebar) ---- */
.main-content {
  margin-left: 260px;
  transition: margin-left 0.3s ease;
}

body.collapsed .main-content {
  margin-left: 70px;
}

@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
  }

  body.collapsed .main-content {
    margin-left: 0;
  }

  body.active .main-content {
    margin-left: 0;
  }
}

/* ---- Toggle button ---- */
.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 10px;
  background: var(--card, rgba(255, 255, 255, 0.08));
  color: inherit;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.menu-toggle:hover {
  background: var(--surface-hover, rgba(255, 255, 255, 0.12));
}

.menu-toggle:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 2px;
}

.menu-toggle:focus:not(:focus-visible) {
  outline: none;
}

.menu-toggle .icon {
  font-size: 18px;
  line-height: 1;
}

/* ---- Sidebar logo (top) ---- */
.sidebar-logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  padding: 24px 12px;
  min-height: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.02em;
  transition: opacity 0.2s ease;
}

.sidebar-logo-row .sidebar-close {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.sidebar-logo:hover {
  color: #ffffff;
  opacity: 0.9;
}

.sidebar-logo-img {
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}

.sidebar-logo-img--full {
  max-height: 50px;
  max-width: 140px;
}

.sidebar-logo-img--small {
  max-height: 32px;
  max-width: 40px;
  display: none;
}

/* When only small logo exists, show it in expanded state too */
.sidebar-logo-img--small-only {
  display: block !important;
  max-height: 26px;
  max-width: 140px;
}

.sidebar-logo-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-divider {
  margin: 0 12px;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

/* ---- Sidebar profile (bottom) ---- */
.sidebar-profile {
  padding: 20px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  transition: background 0.2s ease;
  border-radius: 0 0 0 0;
}

.sidebar-profile:hover {
  background: rgba(255, 255, 255, 0.04);
}

.sidebar-profile__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-profile__info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-profile__name {
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-profile__role {
  font-size: 12px;
  color: rgba(226, 232, 240, 0.65);
}

.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-close:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.sidebar-close:focus:not(:focus-visible) {
  outline: none;
}

.sidebar-close-icon {
  font-size: 22px;
  line-height: 1;
  font-weight: 300;
}

@media (max-width: 768px) {
  .sidebar-logo-row {
    padding: 16px 12px 12px;
  }
  .sidebar-close {
    display: inline-flex;
  }
}

/* Sidebar inner (nav, labels) ---- */
.sidebar-inner {
  padding: 12px 10px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Collapsed: show small logo only, hide nav labels */
body.collapsed .sidebar .sidebar-logo-row {
  padding: 16px 10px;
  justify-content: center;
}
body.collapsed .sidebar .sidebar-logo-text {
  display: none;
}
body.collapsed .sidebar .sidebar-logo-img--full {
  display: none !important;
}
body.collapsed .sidebar .sidebar-logo-img--small {
  display: block !important;
  max-height: 32px;
  max-width: 40px;
}
body.collapsed .sidebar .sidebar-logo-img--small-only {
  max-height: 32px;
  max-width: 40px;
}
body.collapsed .sidebar .sidebar-close {
  display: none;
}
body.collapsed .sidebar .sidebar-divider {
  margin: 0 8px;
}

body.collapsed .sidebar .sidebar-profile {
  justify-content: center;
  padding: 16px 10px;
}
body.collapsed .sidebar .sidebar-profile__info {
  display: none;
}
body.collapsed .sidebar .sidebar-profile__avatar {
  width: 32px;
  height: 32px;
}

body.collapsed .sidebar .nav-label,
body.collapsed .sidebar .sidebar-brand-text,
body.collapsed .sidebar .nav-section-title {
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
  padding: 0;
}

body.collapsed .sidebar .nav-item {
  justify-content: center;
  padding-left: 10px;
  padding-right: 10px;
}

/* Keep icons visible when collapsed (prevent shrink / overflow) */
body.collapsed .sidebar .nav-icon {
  opacity: 1;
  visibility: visible;
  flex: 0 0 auto;
  min-width: 24px;
  min-height: 24px;
  width: 24px;
  height: 24px;
}

body.collapsed .sidebar .nav-item--toggle .nav-label {
  display: none;
}

/* Prevent body scroll when mobile menu open */
@media (max-width: 768px) {
  body.active {
    overflow: hidden;
  }
}

/* ---- Org / campus portal: match org dashboard sidebar (all app pages; layout adds body.org-portal) ---- */
body.org-portal .app-sidebar .sidebar-inner {
  padding: 16px 0;
}

body.org-portal .app-sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin: 0 8px;
  border-radius: 8px;
  color: rgba(226, 232, 240, 0.86);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  border-left: 3px solid transparent;
}

body.org-portal .app-sidebar .nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

body.org-portal .app-sidebar .nav-item.nav-item--active {
  background: var(--primary-gradient, linear-gradient(135deg, #6366f1 0%, #7c3aed 100%));
  border-left-color: transparent;
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 6px 14px rgba(124, 58, 237, 0.25);
}

body.org-portal .app-sidebar .nav-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0.9;
}

body.org-portal.collapsed .app-sidebar .nav-icon,
body.org-portal.sidebar-collapsed .app-sidebar .nav-icon {
  opacity: 1;
  visibility: visible;
  flex: 0 0 auto;
  min-width: 20px;
  min-height: 20px;
}
