.collapsible-section {
  background-color: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--spacing-lg);
  overflow: hidden;
  transition: all var(--transition-fast);
}

.collapsible-section:hover {
  box-shadow: var(--shadow-md);
}

.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-xl) var(--spacing-lg);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-fast);
  min-height: 80px;
}

.collapsible-header:hover {
  background-color: var(--bg-secondary);
}

.collapsible-header:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: -2px;
}

.collapsible-title-group {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex: 1;
  padding: var(--spacing-sm) 0;
}

.collapsible-icon {
  font-size: 1.5rem;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: var(--spacing-xs);
  flex-shrink: 0;
}

.collapsible-text {
  flex: 1;
}

.collapsible-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.collapsible-subtitle {
  margin: var(--spacing-sm) 0 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.collapsible-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.collapsible-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.collapsible-toggle {
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 1.5rem;
  padding: var(--spacing-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.collapsible-toggle:hover {
  background-color: var(--bg-secondary);
  transform: scale(1.1);
}

.collapsible-content {
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out, padding 0.3s ease-out;
  max-height: 0;
  opacity: 0;
}

.collapsible-section.open .collapsible-content {
  max-height: 5000px; /* Large enough for most content */
  opacity: 1;
  transition: max-height 0.3s ease-in, opacity 0.3s ease-in, padding 0.3s ease-in;
}

/* Ensure collapsed content takes zero space */
.collapsible-section.closed .collapsible-content {
  max-height: 0 !important;
  opacity: 0 !important;
  padding: 0 !important;
}

.collapsible-section.closed .collapsible-inner {
  padding: 0 !important;
}

/* Override chart container styles when collapsed */
.collapsible-section.closed .collapsible-inner .chart-container,
.collapsible-section.closed .collapsible-inner .chart-row,
.collapsible-section.closed .collapsible-inner .dashboard-section {
  min-height: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: none !important;
}

.collapsible-inner {
  padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-xl);
}

/* Enhanced spacing for open sections */
.collapsible-section.open {
  margin-bottom: var(--spacing-xl);
}

.collapsible-section.open .collapsible-header {
  padding: var(--spacing-xl) var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
  min-height: 80px;
}

.collapsible-section.open .collapsible-title-group {
  padding: var(--spacing-md) 0;
}

.collapsible-section.open .collapsible-text {
  padding: var(--spacing-sm) 0;
}

/* Add subtle background to content area when open */
.collapsible-section.open .collapsible-content {
  background: rgba(248, 250, 252, 0.5);
}

/* Ensure proper spacing for dashboard sections inside collapsible */
.collapsible-section .chart-container {
  margin-bottom: var(--spacing-md);
}

.collapsible-section .chart-container:last-child {
  margin-bottom: 0;
}

/* Nested sections */
.collapsible-section .collapsible-section {
  margin-bottom: var(--spacing-md);
  box-shadow: none;
  border: 1px solid var(--border-color);
}

.collapsible-section .collapsible-section:hover {
  box-shadow: var(--shadow-sm);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .collapsible-header {
    padding: var(--spacing-md);
  }
  
  .collapsible-inner {
    padding: 0 var(--spacing-md) var(--spacing-md);
  }
  
  .collapsible-title {
    font-size: 1rem;
  }
  
  .collapsible-icon {
    font-size: 1.25rem;
  }
}

/* Animation for smooth content reveal */
@keyframes slideIn {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-10px);
    opacity: 0;
  }
}

.collapsible-section.open .collapsible-inner {
  animation: slideIn 0.2s ease-out;
}

.collapsible-section.closed .collapsible-inner {
  animation: slideOut 0.15s ease-in;
}

/* Improved collapsed state visual cues */
.collapsible-section.closed {
  margin-bottom: 1rem !important;
}

.collapsible-section.closed .collapsible-header {
  border-bottom: none;
  padding: 1rem !important;
}

/* Add internal spacing for collapsed header elements */
.collapsible-section.closed .collapsible-title-group {
  padding: var(--spacing-xs) 0;
}

.collapsible-section.closed .collapsible-title {
  margin-bottom: var(--spacing-xs);
}

.collapsible-section.closed .collapsible-subtitle {
  margin-top: var(--spacing-xs);
}

.collapsible-section.closed:hover {
  box-shadow: var(--shadow-sm);
}