/* ===========================================
   SIDEBAR - Left Floating Navigation
   =========================================== */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 72px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  z-index: var(--z-fixed);
  display: flex;
  flex-direction: column;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

/* Desktop: expand on hover */
@media (min-width: 1024px) {
  .sidebar:hover,
  .sidebar.expanded {
    width: 260px;
  }
}

/* Mobile: hidden by default */
@media (max-width: 1023px) {
  .sidebar {
    width: 280px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 16px;
  border-bottom: 1px solid var(--glass-border);
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
  flex: 1;
}

.sidebar-brand-icon {
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  border-radius: 12px;
  color: white;
}

.sidebar-brand-icon svg {
  width: 22px;
  height: 22px;
}

.sidebar-brand-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-on-surface);
  white-space: nowrap;
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease, max-width 0.25s ease;
}

.sidebar:hover .sidebar-brand-text,
.sidebar.expanded .sidebar-brand-text {
  opacity: 1;
  max-width: 200px;
}

.sidebar-toggle {
  width: 32px;
  height: 32px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--color-on-surface-variant);
  background: none;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0;
  max-width: 0;
  overflow: hidden;
}

.sidebar:hover .sidebar-toggle,
.sidebar.expanded .sidebar-toggle {
  opacity: 1;
  max-width: 32px;
}

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

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
  transition: transform 0.3s ease;
}

.sidebar.expanded .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
}

.sidebar-nav-section {
  margin-bottom: 20px;
}

.sidebar-nav-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-on-surface-disabled);
  padding: 0 8px;
  margin-bottom: 8px;
  white-space: nowrap;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.25s ease, max-height 0.25s ease, margin 0.25s ease;
}

.sidebar:hover .sidebar-nav-title,
.sidebar.expanded .sidebar-nav-title {
  opacity: 1;
  max-height: 30px;
}

.sidebar-nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-nav-item {
  position: relative;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--color-on-surface-variant);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.15s ease;
  position: relative;
}

.sidebar-nav-link:hover {
  background: var(--color-surface-container);
  color: var(--color-on-surface);
}

.sidebar-nav-link.active {
  background: var(--color-primary-50);
  color: var(--color-primary);
}

[data-theme="dark"] .sidebar-nav-link.active {
  background: var(--color-primary-900);
}

/* Active indicator */
.sidebar-nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--color-primary);
  border-radius: 0 4px 4px 0;
}

/* Icon */
.sidebar-nav-icon {
  width: 22px;
  height: 22px;
  min-width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.sidebar-nav-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Label - hidden by default, shown on hover */
.sidebar-nav-label {
  flex: 1;
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease, max-width 0.25s ease;
}

.sidebar:hover .sidebar-nav-label,
.sidebar.expanded .sidebar-nav-label {
  opacity: 1;
  max-width: 200px;
}

/* Badge */
.sidebar-nav-badge {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-primary);
  color: white;
  border-radius: 10px;
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease, max-width 0.25s ease;
}

.sidebar:hover .sidebar-nav-badge,
.sidebar.expanded .sidebar-nav-badge {
  opacity: 1;
  max-width: 50px;
}

/* Tooltip for collapsed state */
@media (min-width: 1024px) {
  .sidebar:not(:hover):not(.expanded) .sidebar-nav-link::after {
    content: attr(data-label);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(8px);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    background: #1a1a1a;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: opacity 0.15s ease, visibility 0.15s ease;
  }

  .sidebar:not(:hover):not(.expanded) .sidebar-nav-item:hover .sidebar-nav-link::after {
    opacity: 1;
    visibility: visible;
  }

  .sidebar:not(:hover):not(.expanded) .sidebar-nav-link.active::after {
    background: var(--color-primary);
  }
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.sidebar-auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-auth-buttons .btn {
  width: 100%;
  justify-content: center;
  white-space: nowrap;
}

/* In collapsed state, hide button text */
.sidebar:not(:hover):not(.expanded) .sidebar-auth-buttons {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.25s ease, max-height 0.25s ease;
}

.sidebar:hover .sidebar-auth-buttons,
.sidebar.expanded .sidebar-auth-buttons {
  opacity: 1;
  max-height: 100px;
}

/* User section */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 10px;
  transition: background 0.15s ease;
}

.sidebar-user:hover {
  background: var(--color-surface-container);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease, max-width 0.25s ease;
}

.sidebar:hover .sidebar-user-info,
.sidebar.expanded .sidebar-user-info {
  opacity: 1;
  max-width: 200px;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-on-surface);
  white-space: nowrap;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--color-on-surface-disabled);
  white-space: nowrap;
}

/* Overlay for mobile */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  z-index: 399;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

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

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

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
  .sidebar-nav-link {
    padding: 14px 12px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar * {
    transition-duration: 0.01ms !important;
  }
}
