/* Enhanced sidebar styles with improved section layout - FIXED VERSION */
:root {
  --social-yellow: #FBB040;
  --social-green: #009245;
  --social-dark-green: #00793A;
  --social-light-green: #E8F5E8;
  --social-gray: #444444;
  --social-blue: #1e429f;
}

.sidebar {
  background: linear-gradient(180deg, var(--social-green) 0%, var(--social-dark-green) 100%);
  width: 16rem;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

/* Desktop collapsed state */
@media (min-width: 1024px) {
  .sidebar.collapsed {
    width: 4.5rem;
  }
  
  .main-content {
    transition: margin-left 0.3s ease;
    margin-left: 16rem;
  }
  
  .main-content.sidebar-collapsed {
    margin-left: 4.5rem;
  }
}

/* Mobile state */
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
}

/* Logo section */
.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 3.5rem;
  padding: 0.75rem;
  background: linear-gradient(135deg, var(--social-green) 0%, var(--social-dark-green) 100%);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: visible;
  min-height: 3.5rem;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.logo-container img {
  max-width: 100%;
  height: auto;
  max-height: 2.5rem;
  object-fit: contain;
  filter: brightness(0) invert(1);
  transition: all 0.3s ease;
}

.logo-container:hover img {
  transform: scale(1.05);
  filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.sidebar.collapsed .logo-container {
  padding: 0.5rem;
  height: 3rem;
}

.sidebar.collapsed .logo-container img {
  max-width: 2rem;
  max-height: 2rem;
}

/* Search section */
.search-section {
  padding: 1rem 0.75rem;
  background: rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  padding-left: 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  font-size: 0.875rem;
  background: rgba(255, 255, 255, 0.9);
  color: var(--social-gray);
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.search-input:focus {
  outline: none;
  border-color: var(--social-yellow);
  background: white;
  box-shadow: 0 0 0 2px rgba(251, 176, 64, 0.2);
}

.search-icon {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--social-green);
  pointer-events: none;
  z-index: 1;
  width: 1rem;
  height: 1rem;
}

/* Enhanced navigation sections with better spacing */
.nav-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.nav-content::-webkit-scrollbar {
  width: 4px;
}

.nav-content::-webkit-scrollbar-track {
  background: transparent;
}

.nav-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

/* Navigation section container - REDUCED SPACING */
.nav-section {
  margin-bottom: 0.5rem;
}

.nav-section:last-child {
  margin-bottom: 0.25rem;
}

/* Section header with better UX - ADJUSTED PADDING */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.875rem;
  margin: 0 0.5rem 0.125rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s ease;
  position: relative;
  user-select: none;
  min-height: 2.5rem;
}

.section-header:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(1px);
}

/* Section header content (icon + title) - ADJUSTED FOR ICON REPLACEMENT */
.section-header-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  position: relative;
}

/* Remove the old section icon styling and add the new one above */

/* Section title - MORE SUBTLE */
.section-title {
  text-transform: uppercase;
  font-size: 0.6875rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.1em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  margin: 0;
  transition: color 0.15s ease;
}

.section-header:hover .section-title {
  color: white;
}

/* Section toggle button - CONDITIONAL DISPLAY WITH ICON REPLACEMENT */
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 4px;
  padding: 0;
  transform: rotate(0deg);
  flex-shrink: 0;
  opacity: 0;
  visibility: hidden;
  position: absolute;
  right: 0.875rem;
}

.section-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  transform: scale(1.05);
}

/* Show toggle when section is open */
.nav-section.section-open .section-toggle {
  opacity: 1;
  visibility: visible;
  position: relative;
  right: auto;
}

/* Hide section icon when section is open */
.nav-section.section-open .section-icon {
  opacity: 0;
  visibility: hidden;
  width: 0;
}

/* Section icon transition */
.section-icon {
  width: 1rem;
  height: 1rem;
  color: rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
  transition: all 0.15s ease, opacity 0.15s ease, visibility 0.15s ease, width 0.15s ease;
}

.section-header:hover .section-icon {
  color: white;
  transform: scale(1.05);
}

/* Ensure smooth transition between icon and toggle */
.section-header-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  position: relative;
}

.section-toggle svg {
  transition: transform 0.2s ease;
}

/* Section content with smooth animations - ADJUSTED PADDING.
   Scoped to .sidebar — .section-content is also used by the group_onboardings
   edit form and groups form accordions, where an unscoped max-height: 0
   silently collapses those forms. */
.sidebar .section-content {
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 0;
  margin: 0 0.5rem;
  padding: 0;
}

.sidebar .nav-section.section-open .section-content {
  padding: 0.125rem 0 0.375rem;
}

/* Active section state - REDUCED SIZE */
.nav-section.section-open .section-header {
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 0.25rem;
}

.nav-section.section-open .section-toggle {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  transform: rotate(90deg);
}

/* Section with active link gets special styling - IMPROVED */
.nav-section.has-active-link .section-header {
  background: rgba(251, 176, 64, 0.15);
  border: 1px solid rgba(251, 176, 64, 0.3);
}

.nav-section.has-active-link .section-header:hover {
  background: rgba(251, 176, 64, 0.2);
  border-color: rgba(251, 176, 64, 0.4);
}

.nav-section.has-active-link .section-icon,
.nav-section.has-active-link .section-title {
  color: rgba(251, 176, 64, 1);
}

.nav-section.has-active-link .section-header:hover .section-icon,
.nav-section.has-active-link .section-header:hover .section-title {
  color: rgb(251, 176, 64);
}

.nav-section.has-active-link .section-toggle {
  background: rgba(251, 176, 64, 0.2);
  color: var(--social-yellow);
}

/* MAIN LINKS - Top level navigation (Dashboard) - MORE SUBTLE */
.nav-section > .sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  margin: 0 0.5rem 0.25rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  transition: all 0.15s ease;
  position: relative;
  backdrop-filter: blur(10px);
  overflow: hidden;
  font-weight: 500;
  font-size: 0.875rem;
  min-height: 3rem;
}

.nav-section > .sidebar-link:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.nav-section > .sidebar-link.active {
  background: var(--social-yellow);
  color: var(--social-gray);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(251, 176, 64, 0.3);
  border-left: 3px solid white;
  padding-left: calc(1rem - 3px);
}

/* SECTION LINKS - Links inside collapsible sections - INCREASED SIZE */
.section-content .sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  margin: 0.25rem 0.5rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  transition: all 0.2s ease;
  position: relative;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 3rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
}

.section-content .sidebar-link:hover {
  color: white;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(3px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.section-content .sidebar-link.active {
  background: linear-gradient(135deg, var(--social-yellow), #f59e0b);
  color: var(--social-gray);
  font-weight: 600;
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 3px 12px rgba(251, 176, 64, 0.4);
}

.section-content .sidebar-link.active:hover {
  transform: translateX(3px) translateY(-1px);
  box-shadow: 0 4px 16px rgba(251, 176, 64, 0.5);
}

/* Sidebar icons - ADJUSTED FOR NEW SIZES */
.sidebar-icon {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  margin-right: 0.75rem;
  transition: all 0.2s ease;
}

.section-content .sidebar-icon {
  width: 1.125rem;
  height: 1.125rem;
  margin-right: 0.75rem;
}

.sidebar-text {
  font-size: inherit;
  transition: opacity 0.3s ease;
  white-space: nowrap;
  line-height: 1.2;
}

/* Left accent line for section links - MORE SUBTLE */
.section-content .sidebar-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--social-yellow);
  border-radius: 0 2px 2px 0;
  transition: height 0.15s ease;
}

.section-content .sidebar-link:hover::before {
  height: 60%;
}

.section-content .sidebar-link.active::before {
  height: 80%;
  background: white;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

/* Collapsed sidebar behavior - ADJUSTED FOR NEW SIZES */
@media (min-width: 1024px) {
  .sidebar.collapsed .section-header {
    justify-content: center;
    padding: 0.375rem;
    flex-direction: column;
    gap: 0.125rem;
    min-height: 2.75rem;
    margin: 0 0.25rem 0.25rem;
  }

  .sidebar.collapsed .section-header-content {
    flex-direction: column;
    gap: 0.125rem;
    align-items: center;
  }

  .sidebar.collapsed .section-icon {
    width: 1.25rem;
    height: 1.25rem;
    margin-bottom: 0.0625rem;
  }

  .sidebar.collapsed .section-title {
    font-size: 0.5625rem;
    text-align: center;
    line-height: 1.1;
    margin: 0;
    max-width: 100%;
    word-break: break-word;
  }

  .sidebar.collapsed .section-toggle {
    display: none;
  }

  .sidebar.collapsed .section-content {
    max-height: none !important;
    overflow: visible;
    padding: 0;
    margin: 0.125rem;
  }

  .sidebar.collapsed .sidebar-text {
    display: none;
  }
  
  .sidebar.collapsed .sidebar-icon {
    margin-right: 0;
  }
  
  .sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 0.625rem;
    margin: 0.125rem;
    border-radius: 8px;
    min-height: 2.75rem;
  }

  .sidebar.collapsed .section-content .sidebar-link {
    justify-content: center;
    padding: 0.625rem;
    margin: 0.125rem;
    min-height: 2.75rem;
  }

  .sidebar.collapsed .sidebar-link.active {
    border-left: none;
    padding: 0.625rem;
  }

  .sidebar.collapsed .section-content .sidebar-link.active {
    padding: 0.625rem;
  }

  .sidebar.collapsed .section-content .sidebar-link::before {
    display: none;
  }
}

/* Search collapsed/expanded states */
.search-collapsed {
  display: none;
}

.search-expanded {
  display: block;
  position: relative;
}

.search-collapsed button {
  width: 100%;
  padding: 0.75rem;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-collapsed button:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

@media (min-width: 1024px) {
  .sidebar.collapsed .search-collapsed {
    display: block;
  }

  .sidebar.collapsed .search-expanded {
    display: none;
  }
}

/* Toggle button - IMPROVED STYLING */
.sidebar-toggle {
  position: fixed;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--social-yellow);
  color: var(--social-gray);
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-weight: 600;
}

.sidebar-toggle:hover {
  background: #f59e0b;
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Desktop toggle positioning */
@media (min-width: 1024px) {
  .sidebar-toggle {
    top: 1.5rem;
    left: calc(16rem - 1.25rem);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    transition: all 0.3s ease;
  }
  
  .sidebar.collapsed ~ .sidebar-toggle {
    left: calc(4.5rem - 1.25rem);
  }
}

/* Mobile toggle positioning */
@media (max-width: 1023px) {
  .sidebar-toggle {
    top: 1rem;
    left: 1rem;
    width: 3rem;
    height: 3rem;
    border-radius: 8px;
  }
}

/* Backdrop - IMPROVED */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 20;
  transition: opacity 0.3s ease;
  opacity: 0;
  visibility: hidden;
  backdrop-filter: blur(4px);
}

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

/* Loading states - IMPROVED */
.sidebar-link.loading {
  opacity: 0.7;
  pointer-events: none;
}

.sidebar-link.loading::after {
  content: '';
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.section-loading .section-header {
  opacity: 0.7;
  pointer-events: none;
}

.section-loading .section-toggle::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Main content - IMPROVED */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #f8fafc;
}

.main-header {
  background: white;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

@media (max-width: 768px) {
  .content-area {
    padding: 1rem;
  }
}

/* User dropdown - IMPROVED */
.user-dropdown {
  position: relative;
}

.user-dropdown-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--social-gray);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.user-dropdown-button:hover {
  background: var(--social-light-green);
  color: var(--social-green);
}

.user-dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.5rem;
  min-width: 12rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  border: 1px solid #e2e8f0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 50;
}

.user-dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-dropdown-menu a,
.user-dropdown-menu button {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  color: var(--social-gray);
  text-decoration: none;
  border: none;
  background: transparent;
  text-align: left;
  transition: background-color 0.2s ease;
  cursor: pointer;
}

.user-dropdown-menu a:hover,
.user-dropdown-menu button:hover {
  background: var(--social-light-green);
  color: var(--social-green);
}

/* Flash messages - IMPROVED */
.flash-message {
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.flash-notice {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.flash-alert {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Tooltips for collapsed state - IMPROVED */
@media (min-width: 1024px) {
  .sidebar.collapsed .sidebar-link,
  .sidebar.collapsed .section-header {
    position: relative;
  }

  .sidebar.collapsed .sidebar-link::before,
  .sidebar.collapsed .section-header::before {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--social-gray);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  }

  .sidebar.collapsed .sidebar-link::after,
  .sidebar.collapsed .section-header::after {
    content: '';
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid var(--social-gray);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

  .sidebar.collapsed .sidebar-link:hover::before,
  .sidebar.collapsed .sidebar-link:hover::after,
  .sidebar.collapsed .section-header:hover::before,
  .sidebar.collapsed .section-header:hover::after {
    opacity: 1;
    visibility: visible;
    transition-delay: 0.5s;
  }

  /* Override for section content links in collapsed state */
  .sidebar.collapsed .section-content .sidebar-link::before {
    content: attr(data-tooltip) !important;
    display: block !important;
    background: var(--social-gray) !important;
    height: auto !important;
    width: auto !important;
    padding: 0.5rem 0.75rem !important;
    border-radius: 6px !important;
    left: calc(100% + 12px) !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }
}

/* Accessibility improvements */
.sidebar-link:focus,
.sidebar-toggle:focus,
.user-dropdown-button:focus,
.section-toggle:focus,
.section-header:focus-within {
  outline: 2px solid var(--social-yellow);
  outline-offset: 2px;
}

/* Smooth transitions for all interactive elements - MORE SUBTLE */
.section-icon,
.section-toggle svg,
.sidebar-icon {
  transition: transform 0.15s ease, color 0.15s ease;
}

/* Badge/count styling for future use */
.section-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.25rem;
  background: var(--social-yellow);
  color: var(--social-gray);
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: 10px;
  margin-left: auto;
  margin-right: 0.25rem;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Add this to your sidebar_optimized.css to fix height calculation issues */

/* Enhanced section content transition with better height calculation.
   Scoped to .sidebar — see note on the earlier .section-content block. */
.sidebar .section-content {
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 0;
  margin: 0 0.5rem;
  padding: 0;
}

/* When section is open, use CSS to calculate height instead of JavaScript */
.sidebar .nav-section.section-open .section-content {
  max-height: fit-content; /* Use CSS fit-content for better calculation */
  padding: 0.125rem 0 0.375rem;
}

/* Alternative: Use specific heights for known content */
.nav-section.section-open .section-content[data-section="groups"] {
  max-height: 180px; /* 3 links × ~48px each + padding */
}

.nav-section.section-open .section-content[data-section="payments"] {
  max-height: 240px; /* 4 links × ~48px each + padding */
}

.nav-section.section-open .section-content[data-section="loans"] {
  max-height: 240px; /* 4 links × ~48px each + padding */
}

.nav-section.section-open .section-content[data-section="communication"] {
  max-height: 180px; /* 3 links × ~48px each + padding */
}

.nav-section.section-open .section-content[data-section="processors"] {
  max-height: 120px; /* 2 links × ~48px each + padding */
}

/* Fallback for unknown sections */
.nav-section.section-open .section-content:not([data-section]) {
  max-height: 300px; /* Safe fallback */
}

/* Better mobile handling */
@media (max-width: 1023px) {
  .nav-section.section-open .section-content {
    max-height: none; /* Don't restrict height on mobile */
    overflow: visible;
  }
}

/* Collapsed sidebar - show all content */
@media (min-width: 1024px) {
  .sidebar.collapsed .section-content {
    max-height: none !important;
    overflow: visible !important;
    padding: 0.125rem !important;
    margin: 0.125rem !important;
  }
  
  .sidebar.collapsed .nav-section.section-open .section-content {
    max-height: none !important;
    overflow: visible !important;
  }
}

/* Enhanced sidebar link sizing for consistent calculations */
.section-content .sidebar-link {
  min-height: 48px; /* Consistent height for calculations */
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  margin: 0.125rem 0.5rem;
  border-radius: 8px;
  transition: all 0.2s ease;
}

/* Fix toggle button positioning and animation */
.section-toggle {
  transition: transform 0.3s ease;
  transform-origin: center;
}

.nav-section.section-open .section-toggle {
  transform: rotate(90deg);
}

/* Improve section header interaction */
.section-header {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
}

.section-header:active {
  transform: scale(0.98);
}

/* Loading states for sections */
.nav-section.loading .section-content {
  opacity: 0.7;
  pointer-events: none;
}

.nav-section.loading .section-toggle::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .section-content {
    transition: max-height 0.1s ease;
  }
  
  .section-toggle {
    transition: transform 0.1s ease;
  }
  
  .section-header:active {
    transform: none;
  }
}

/* Error state styling */
.nav-section.error {
  opacity: 0.8;
}

.nav-section.error .section-header {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Debug helpers (remove in production) */
.debug .section-content {
  border: 1px dashed rgba(255, 255, 255, 0.3) !important;
}

.debug .section-content::before {
  content: 'Height: ' attr(style);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.6);
  display: block;
  padding: 2px 4px;
}