/* Sidebar Organism - SPACING CONTRACT: Fill parent height, fixed width, no margins */
.sidebar {
  width: var(--sidebar-width-expanded);
  height: 100%;  /* Fill parent container exactly */
  background-color: var(--bg-surface);
  border-right: var(--border-width-1) solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: var(--sidebar-transition);
  border-top-right-radius: var(--border-radius-xl);
  border-bottom-right-radius: var(--border-radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 50;
  margin: 0;
}

.sidebar[data-state="collapsed"] {
  width: var(--sidebar-width-collapsed);
  overflow: visible;  /* Allow tooltips to extend beyond sidebar bounds */
}

.sidebar-navigation {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar[data-state="collapsed"] .sidebar-navigation {
  overflow: visible;  /* Allow tooltips to extend beyond bounds */
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 0 0 var(--space-4) 0;  /* 0 0 16px 0 (matches TEST) */
  overflow-x: hidden;
  overflow-y: auto;
}

.sidebar[data-state="collapsed"] .sidebar-nav {
  overflow: visible;  /* Allow tooltips to extend beyond bounds */
}

.nav-section-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-2) var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
}

.nav-section-header:first-child {
  margin-top: var(--space-2);
}

.sidebar[data-state="collapsed"] .nav-section-header {
  padding: var(--space-3) 0;
  justify-content: center;
}

.sidebar[data-state="collapsed"] .section-title {
  display: none;
}

.nav-expandable {
  position: relative;
}

.nav-expandable-content {
  display: none;
  padding-left: var(--space-4);
}

.nav-expandable.expanded .nav-expandable-content {
  display: block;
}

.sidebar[data-state="collapsed"] .nav-expandable-content {
  display: none !important;
}

/* ===================================
   NAVIGATION LIST
   =================================== */

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-sublist {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ===================================
   NAVIGATION ITEMS
   Extends NavItem molecule with sidebar-specific styles
   =================================== */

/* Sidebar-specific nav-item overrides */
.sidebar .nav-item {
  padding: var(--space-1) var(--space-2);  /* 4px 8px - tighter vertical spacing */
  margin: 0 var(--space-1) 0;  /* 0 4px 0 - no bottom margin */
  min-height: var(--space-8);  /* 32px - consistent height in both states */
  gap: var(--space-2);  /* 8px - tighter chevron->icon and icon->label spacing */
  cursor: pointer;
  position: relative;
}

.sidebar .nav-item.active .nav-icon svg {
  fill: var(--color-primary);
}

/* Level 1 items (main categories) - same weight, hierarchy via position */
.nav-item.l1 {
  /* No font-weight override - consistent with all nav items */
}

/* Level 2 items (sub-items) - same font size, tighter spacing for hierarchy */
.nav-item.l2 {
  padding: var(--space-0_5) var(--space-2) var(--space-0_5) var(--space-4);  /* 2px 8px 2px 16px - tighter vertical */
  min-height: var(--space-6);  /* 24px - more compact than L1's 32px */
}

/* L2 icons - match L1 size since font size is uniform */
.nav-item.l2 .nav-icon {
  width: var(--icon-size-sm);   /* 16px - same as L1 */
  height: var(--icon-size-sm);
}

.nav-item.l2 .nav-icon svg {
  width: var(--icon-size-sm);   /* 16px */
  height: var(--icon-size-sm);
}

/* Level 3 items (sections within departments) - further indented */
.nav-item.l3 {
  padding: var(--space-0_5) var(--space-2) var(--space-0_5) var(--space-8);  /* 2px 8px 2px 32px */
  min-height: var(--space-6);
}

.nav-item.l3 .nav-icon {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

.nav-item.l3 .nav-icon svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

/* Level 4 items (child sections: Meat, FOH, BOH, etc.) - deepest indent */
.nav-item.l4 {
  padding: var(--space-0_5) var(--space-2) var(--space-0_5) var(--space-10);  /* 2px 8px 2px 40px */
  min-height: var(--space-6);
}

.nav-item.l4 .nav-icon {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

.nav-item.l4 .nav-icon svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

/* ===================================
   NAVIGATION ICONS
   =================================== */

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--icon-size-md);   /* 20px - matches wholesale operator nav icon sizing */
  height: var(--icon-size-md);
}

.nav-icon svg {
  width: var(--icon-size-sm);   /* 16px - uses design token */
  height: var(--icon-size-sm);
}

/* ===================================
   NAVIGATION LABELS
   =================================== */

.nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity var(--duration-200) var(--easing-out);  /* Smooth fade */
}

.sidebar[data-state="collapsed"] .nav-label {
  opacity: 0;  /* Fade out */
  visibility: hidden;  /* Hide but preserve space for consistent height */
  width: 0;  /* Collapse width to not push arrow */
  overflow: hidden;
}

/* ===================================
   NAVIGATION EXPAND ARROW (left-side chevron)
   Hit-zone container is static (owns hover/focus); inner glyph owns rotation.
   =================================== */

.nav-expand-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-size-md);   /* 20px visual slot (glyph is 16px, centered) */
  height: var(--icon-size-md);
  flex-shrink: 0;
  position: relative;           /* positioning context for ::before click-zone extension */
  /* Reset button defaults */
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: color var(--duration-150) var(--easing-out);
}

/* Extended click zone: invisible ::before pseudo-element that absorbs the row's
   left padding so the chevron is easier to hit. Per-level overrides below set
   the exact extension width to match each level's row padding. */
.nav-expand-arrow::before {
  content: '';
  position: absolute;
  top: calc(-1 * var(--space-1));      /* default: cover L1 vertical padding */
  bottom: calc(-1 * var(--space-1));
  left: calc(-1 * var(--space-2));     /* default: absorb L1 left padding (8px) */
  right: 0;
}

.nav-item.l2 > .nav-expand-arrow::before,
.nav-item.l3 > .nav-expand-arrow::before,
.nav-item.l4 > .nav-expand-arrow::before {
  top: calc(-1 * var(--space-0_5));    /* L2/L3/L4 have tighter vertical padding */
  bottom: calc(-1 * var(--space-0_5));
}

.nav-item.l2 > .nav-expand-arrow::before {
  left: calc(-1 * var(--space-4));     /* absorb L2 left padding (16px) */
}

.nav-item.l3 > .nav-expand-arrow::before {
  left: calc(-1 * var(--space-8));     /* absorb L3 left padding (32px) */
}

.nav-item.l4 > .nav-expand-arrow::before {
  left: calc(-1 * var(--space-10));    /* absorb L4 left padding (40px) */
}

.nav-expand-arrow:focus-visible {
  outline: var(--border-width-1) solid var(--color-primary);
  outline-offset: var(--border-width-1);
}

/* Inner glyph: this is what rotates, not the hit zone */
.nav-expand-arrow-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-size-md);   /* 20px wrapper centers the 16px svg */
  height: var(--icon-size-md);
  transform-origin: center;
  transition: transform var(--duration-300) var(--easing-out);
}

.nav-expand-arrow-glyph svg {
  width: var(--icon-size-sm);   /* 16px glyph -- smaller than the 20px button slot */
  height: var(--icon-size-sm);
}

/* Expanded state: glyph rotates to point down. Hit-zone container stays still. */
.nav-expandable.expanded > .nav-item > .nav-expand-arrow > .nav-expand-arrow-glyph,
[data-expand-content][style*="display: block"] ~ .nav-item .nav-expand-arrow-glyph,
.nav-item[data-expand-target] + [style*="display: block"] ~ .nav-expand-arrow-glyph {
  transform: rotate(90deg);
}

/* Spacer for non-expandable rows -- reserves the chevron slot so icons align */
.nav-expand-spacer {
  display: inline-block;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  flex-shrink: 0;
}

.sidebar[data-state="collapsed"] .nav-expand-arrow,
.sidebar[data-state="collapsed"] .nav-expand-spacer {
  display: none;
}

/* ===================================
   NAVIGATION TOOLTIPS
   Uses Tooltip atom for consistency
   =================================== */

/* Hide tooltips in sidebar by default (scoped to sidebar only) */
.sidebar .tooltip {
  display: none;
  opacity: 0;
}

/* ONLY show tooltips on L1 items when sidebar is collapsed and on hover */
.sidebar[data-state="collapsed"] .nav-item.l1:hover .tooltip {
  display: block;
  opacity: 1;
}

/* ===================================
   SIDEBAR TOGGLE BUTTON
   =================================== */

.nav-item.sidebar-toggle {
  margin-bottom: var(--space-2);
  border-bottom: var(--border-width-1) solid var(--border-subtle);
  border-radius: 0;
  /* Uses standard padding from .nav-item for consistent vertical centering */
}

.sidebar[data-state="expanded"] .nav-item.sidebar-toggle .nav-expand-arrow {
  display: inline-flex;  /* Only show toggle arrow when expanded */
  order: 99;             /* Sidebar toggle keeps chevron on the right (hamburger icon leads) */
}

.sidebar[data-state="collapsed"] .nav-item.sidebar-toggle .nav-expand-arrow {
  display: none;  /* Hide toggle arrow when collapsed (hamburger icon is sufficient) */
}

/* ===================================
   EXPANDABLE CONTENT (children lists)
   =================================== */

.nav-expandable-content {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;  /* Collapsed state */
  overflow: hidden;
  opacity: 0;
  transition: max-height var(--duration-300) var(--easing-out),
              opacity var(--duration-200) var(--easing-out);  /* Smooth slide + fade */
}

[data-expand-content][style*="display: block"],
.nav-expandable.expanded .nav-expandable-content {
  max-height: 600px;  /* Large enough for content */
  opacity: 1;
  /* Transition already defined on base class */
}

/* ===================================
   RESPONSIVE
   =================================== */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
  }

  .sidebar[data-state="expanded"] {
    transform: translateX(0);
  }
}
