:root {
  /* Secondary surfaces (previously undefined) */
  --color-surface-secondary: #f2f2f2;
  --color-surface-secondary-hover: rgba(0, 0, 0, 0.05);
}

/* ====================== Loading Spinner ====================== */
.loading-spinner {
  position: fixed;
  top: 60px;
  right: 20px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-stroke-subtle);
  border-top: 2px solid var(--color-text-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.loading-spinner.show {
  opacity: 1;
  visibility: visible;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ====================== Toolbar ====================== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: visible !important; /* Allow overflow in both directions */
  /* If horizontal scrolling becomes necessary, consider wrapping the buttons in an inner element that handles horizontal scroll only. */
  height: 48px !important; /* Consistent toolbar height */
}

/* Prevent category containers from shrinking (avoids jitter) */
.toolbar-category-container {
  flex: 0 0 auto;
}

/* Base button style */
.toolbar-button {
  font-family: var(--font-family-base);
  font-size: 0.9rem !important;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px !important;
  padding: 0 16px !important;
  color: var(--color-text-primary);
  background-color: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.toolbar-button:hover,
.toolbar-button:focus-visible {
  outline: none;
  background-color: var(--color-surface-secondary-hover);
}

/* Active (dropdown open) */
.toolbar-button[aria-expanded="true"] {
  color: var(--color-text-accent);
  box-shadow: inset 0 -2px 0 var(--color-text-accent);
}

/* Chevron arrow – only for buttons that open menus */
.toolbar-button::after {
  content: none;
}
.toolbar-button[aria-haspopup="true"]::after {
  content: ' \25BE'; /* small downward triangle */
  font-size: 0.8em;
  margin-left: 6px;
  color: var(--color-text-secondary);
  transition: transform 0.2s ease;
}

.toolbar-button[aria-expanded="true"][aria-haspopup="true"]::after {
  transform: rotate(180deg);
}

/* ====================== Dropdown ===================== */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  font-family: var(--font-family-base);
  font-size: 0.9rem !important;
  min-width: 220px !important;
  background-color: var(--color-surface-flyout);
  border: 1px solid var(--color-stroke-card-default);
  border-radius: 6px;
  box-shadow: var(--shadow-depth-8);
  padding: 8px 0;
  z-index: 1000;
}

.dropdown-item {
  padding: 6px 16px !important;
  display: block;
  color: var(--color-text-primary);
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
  border-radius: 4px;
}

.dropdown-item:hover {
  background-color: var(--color-surface-secondary-hover);
  color: var(--color-text-accent);
}

.dropdown-divider {
  height: 1px;
  margin: 6px 8px;
  background-color: var(--color-stroke-subtle);
}

.dropdown-header {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 16px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

/* ====================== App Bar ===================== */
.app-bar {
  height: 56px !important; /* Consistent app bar height */
  overflow: visible !important; /* allow dropdown menus to render outside header */
}

/* === Functions Sidebar Layout Fixes === */
.functions-sidebar {
  display: flex !important;
  flex-direction: column !important;
  z-index: 80 !important;
  position: fixed !important;
  top: 56px !important; /* Below header only */
  left: 0 !important;
  bottom: 0 !important;
  width: var(--functions-sidebar-width) !important;
  transform: translateX(0) !important;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  background-color: var(--color-surface-default) !important;
  border-right: 1px solid var(--color-stroke-card-default) !important;
  box-shadow: var(--shadow-depth-8) !important;
  font-family: var(--font-family-base) !important;
}

/* Hide desktop sidebar completely on mobile */
@media (max-width: 768px) {
  .functions-sidebar {
    display: none !important;
  }
}

/* make the scrollable area grow */
.functions-sidebar-content {
  flex: 1 1 auto !important;
  height: auto !important;
  overflow-y: auto !important;
}

/* Sidebar footer removed - using header sign-in button */

/* Main content layout - simplified */
.main-content {
  margin-left: var(--functions-sidebar-width) !important;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  height: calc(100vh - 56px) !important;
  overflow: hidden !important;
}

/* When sidebar is closed, remove margin */
body.sidebar-closed .main-content {
  margin-left: 0 !important;
}

/* Keep app bar static for better UX */
.app-bar {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  height: 56px !important;
  z-index: 100 !important;
  box-shadow: var(--shadow-depth-4) !important;
  display: flex !important;
}

/* Hide toolbar completely */
#toolbar {
  display: none !important;
}

/* Header Sign-In button: ensure it is visible and uses the correct font */
#sign-in-btn {
  display: inline-flex !important;
  font-family: var(--font-family-base) !important;
  font-size: 0.9rem !important;
  font-weight: 500;
  padding: 8px 16px !important;
  border-radius: 6px !important;
  transition: all 0.2s ease !important;
}

/* Hide header sign-in button on mobile - use sidebar button instead */
@media (max-width: 768px) {
  #sign-in-btn {
    display: none !important;
  }
}

/* Sidebar toggle button in header */
.sidebar-toggle {
  display: none !important; /* Hidden on mobile */
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--color-text-primary);
  border-radius: 4px;
  transition: all 0.2s ease;
  margin-right: 8px;
}

.sidebar-toggle:hover {
  background-color: var(--color-surface-secondary-hover);
  color: var(--color-text-accent);
}

@media (min-width: 769px) {
  .sidebar-toggle {
    display: inline-flex !important; /* Show on desktop */
    align-items: center;
    justify-content: center;
  }
}

/* Large sidebar indicator when closed */
.sidebar-indicator {
  position: fixed;
  top: 56px; /* Below header */
  left: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(
    to bottom,
    var(--color-text-accent),
    color-mix(in srgb, var(--color-text-accent) 70%, transparent)
  );
  z-index: 200;
  cursor: pointer;
  opacity: 0;
  transform: translateX(-16px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 4px 0 12px rgba(0, 120, 212, 0.3);
  border-radius: 0 8px 8px 0;
}

.sidebar-indicator:hover {
  width: 32px;
  opacity: 1;
  transform: translateX(0);
  box-shadow: 8px 0 20px rgba(0, 120, 212, 0.4);
  background: linear-gradient(
    135deg,
    var(--color-text-accent),
    color-mix(in srgb, var(--color-text-accent) 80%, white)
  );
}

/* Arrow indicator */
.sidebar-indicator::before {
  content: '';
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid white;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  opacity: 0;
  transition: all 0.2s ease;
}

.sidebar-indicator:hover::before {
  opacity: 0.9;
  right: 8px;
}

/* Dots indicator for more visibility */
.sidebar-indicator::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 20px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.6) 0px,
    rgba(255, 255, 255, 0.6) 2px,
    transparent 2px,
    transparent 4px
  );
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.sidebar-indicator:hover::after {
  opacity: 0;
}

/* Sidebar indicator visibility is controlled by JavaScript */

/* Hide on mobile */
@media (max-width: 768px) {
  .sidebar-indicator {
    display: none;
  }
}

/* ====================== Layout & Font Fixes (2025-07) ====================== */
/* Sidebar sign-in button removed - using header button */

/* Desktop sidebar and layout behavior */
@media (min-width: 769px) {
  /* Ensure sidebar stays below dialogs but not above dropdowns */
  .functions-sidebar {
    z-index: 50 !important;
  }
  
  /* Ensure the editor area starts below the App Bar (56px) only */
  .mainPanel {
    top: 56px !important;
  }
  
  /* Static toolbar and header for consistent UX */
  .app-bar,
  #toolbar {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  /* Make sure the main panel and CodeMirror container respond to width changes */
  .mainPanel,
  .CodeMirror {
    width: 100% !important;
  }
}

/* Mobile behavior */
@media (max-width: 768px) {
  /* Show mobile menu toggle */
  .mobile-menu-toggle {
    display: block !important;
  }
  
  /* On mobile, main content takes full width with no sidebar margin */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
}

/* Additional layout stability rules */
* {
  box-sizing: border-box !important;
}

/* Productive sidebar header with New Sheet + Close */
.functions-sidebar-header {
  background-color: var(--color-surface-default) !important;
  border-bottom: 1px solid var(--color-stroke-card-default) !important;
  padding: 8px 12px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  min-height: 44px !important;
  flex-shrink: 0 !important;
  gap: 8px !important;
}

/* New Sheet button styling */
.new-sheet-btn {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  background: var(--color-text-accent) !important;
  color: var(--color-text-on-accent) !important;
  border: none !important;
  padding: 6px 10px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  font-size: 0.8rem !important;
  font-weight: 500 !important;
  font-family: var(--font-family-base) !important;
  transition: all 0.2s ease !important;
  flex: 1 !important;
  justify-content: center !important;
}

.new-sheet-btn:hover {
  background: color-mix(in srgb, var(--color-text-accent) 90%, #000) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(0, 120, 212, 0.3) !important;
}

.new-sheet-btn svg {
  width: 14px !important;
  height: 14px !important;
}

.new-sheet-btn.disabled {
  background: var(--color-surface-secondary) !important;
  color: var(--color-text-secondary) !important;
  cursor: pointer !important;
  pointer-events: auto !important;
}

.new-sheet-btn.disabled:hover {
  background: var(--color-surface-secondary-hover) !important;
  transform: none !important;
  box-shadow: none !important;
}

.sidebar-close {
  background: none !important;
  border: none !important;
  cursor: pointer !important;
  padding: 6px !important;
  color: var(--color-text-secondary) !important;
  border-radius: 4px !important;
  transition: all 0.2s ease !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.sidebar-close:hover {
  background-color: var(--color-surface-secondary-hover) !important;
  color: var(--color-text-primary) !important;
}

/* New Sidebar Layout - Logical Structure */
.functions-sidebar {
  display: flex !important;
  flex-direction: column !important;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1) !important;
}

.functions-sidebar-header {
  background: linear-gradient(135deg, var(--color-surface-default), var(--color-surface-flyout)) !important;
  border-bottom: 2px solid var(--color-stroke-card-default) !important;
  flex-shrink: 0 !important;
  cursor: pointer !important; /* Make header clickable when minimized */
}

.sidebar-content {
  flex: 1 !important;
  overflow-y: auto !important;
  scrollbar-width: none !important;
  padding-bottom: 20px !important; /* Reduced padding since we removed footer */
}

.sidebar-content::-webkit-scrollbar {
  display: none !important;
}

/* Sidebar footer and sign-in button removed */

.sidebar-section {
  border-bottom: 1px solid var(--color-stroke-subtle);
  flex-shrink: 0;
  margin-bottom: 4px;
}

/* Special scrollable section for functions */
.sidebar-section-scrollable {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-section-scrollable .sidebar-section-content {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
}

.sidebar-section-scrollable .sidebar-section-content::-webkit-scrollbar {
  display: none;
}

/* Option groups styling - more compact */
.option-group {
  margin: 8px 0;
}

.option-group-title {
  display: block;
  padding: 3px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-family: var(--font-family-base);
}

.option-pair {
  display: flex;
  margin: 3px 8px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--color-stroke-subtle);
}

.sidebar-option {
  flex: 1;
  background: var(--color-surface-default);
  border: none;
  padding: 6px 8px;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family-base);
}

.sidebar-option:hover {
  background: var(--color-surface-secondary-hover);
}

.sidebar-option.active {
  background: var(--color-text-accent);
  color: var(--color-text-on-accent);
  font-weight: 500;
}

.sidebar-option:first-child {
  border-right: 1px solid var(--color-stroke-subtle);
}

/* Desktop sidebar behavior */
@media (min-width: 769px) {
  /* Default state: sidebar visible */
  .functions-sidebar {
    transform: translateX(0) !important;
    display: flex !important;
  }
  
  /* When explicitly closed, hide sidebar */
  .functions-sidebar.closed {
    transform: translateX(-100%) !important;
  }
  
  /* Adjust main content for sidebar states */
  .main-content {
    margin-left: var(--functions-sidebar-width) !important;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  
  /* Remove margin when sidebar is closed */
  body:has(.functions-sidebar.closed) .main-content {
    margin-left: 0 !important;
  }
  
  /* Alternative selector for older browsers */
  .functions-sidebar.closed ~ .main-content {
    margin-left: 0 !important;
  }
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--color-surface-flyout);
  cursor: pointer;
  transition: background-color 0.2s ease;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-family-base);
}

.sidebar-section-header:hover {
  background: var(--color-surface-secondary-hover);
}

.sidebar-section-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-section-toggle {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 0.75rem;
  transition: transform 0.2s ease;
  padding: 3px;
  border-radius: 3px;
  min-width: 18px;
  min-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Sheet actions removed - now handled by header button and per-sheet context */

.sheets-list {
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 2px 0;
}

.sheets-list::-webkit-scrollbar {
  display: none;
}

/* Simplified sidebar sheet list items */
.sidebar-sheet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 12px;
  border-radius: 6px;
  background: white;
  border: 1px solid var(--color-stroke-subtle);
  transition: all 0.2s ease;
  overflow: hidden;
}

.sidebar-sheet-item:hover {
  background: var(--color-surface-secondary-hover);
}

.sidebar-sheet-item.sidebar-sheet-active {
  background: var(--color-surface-secondary);
  border-color: var(--color-stroke-default);
}

.sidebar-sheet-name-container {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  min-width: 0;
}

.sidebar-sheet-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-primary);
}

.sidebar-sheet-indicator {
  color: var(--color-text-accent);
  font-size: 0.7rem;
  margin-left: 8px;
  flex-shrink: 0;
}

.sidebar-sheet-actions {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  gap: 4px;
}

.sidebar-sheet-action {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 4px;
  color: var(--color-text-secondary);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.sidebar-sheet-action:hover {
  background: var(--color-surface-secondary-hover);
  color: var(--color-text-primary);
  opacity: 1;
}

.sidebar-sheet-item:hover .sidebar-sheet-action {
  opacity: 1;
}

.empty-sheets {
  color: var(--color-text-tertiary);
  font-style: italic;
  cursor: default;
  text-align: center;
  padding: 16px;
}

.empty-sheets:hover {
  background: transparent;
}

/* Enhance toolbar visual weight */
#toolbar {
  font-weight: 500 !important;
  backdrop-filter: blur(8px) !important;
}

/* Clear contextual distinction */
.toolbar-button {
  background-color: rgba(255, 255, 255, 0.8) !important;
  border: 1px solid transparent !important;
}

[data-theme="dark"] .toolbar-button {
  background-color: rgba(45, 45, 48, 0.9) !important;
}

.toolbar-button:hover {
  border-color: var(--color-text-accent) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(0, 120, 212, 0.2) !important;
}

/* Dark mode support for new sidebar */
[data-theme="dark"] .functions-sidebar {
  background-color: var(--color-surface-default) !important;
  border-right-color: var(--color-stroke-default) !important;
}

[data-theme="dark"] .functions-sidebar-header {
  background-color: var(--color-surface-default) !important;
  border-bottom-color: var(--color-stroke-default) !important;
}

[data-theme="dark"] .sidebar-section-header {
  background: var(--color-surface-flyout) !important;
}

[data-theme="dark"] .sidebar-section-header:hover {
  background: var(--color-surface-secondary-hover) !important;
}

[data-theme="dark"] .sidebar-item:hover {
  background: rgba(79, 195, 247, 0.15) !important;
  color: var(--color-text-accent) !important;
}

[data-theme="dark"] .sidebar-divider {
  background: var(--color-stroke-subtle) !important;
}

[data-theme="dark"] .sidebar-subsection-title {
  background: var(--color-surface-secondary) !important;
}

/* Dark theme sign-in section removed */

[data-theme="dark"] .main-content {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%) !important;
}

[data-theme="dark"] .mainPanel {
  background: rgba(15, 23, 42, 0.8) !important;
}

/* Dark theme sidebar indicator */
[data-theme="dark"] .sidebar-indicator {
  background: linear-gradient(
    to bottom,
    var(--color-text-accent),
    color-mix(in srgb, var(--color-text-accent) 60%, transparent)
  );
  box-shadow: 4px 0 12px rgba(79, 195, 247, 0.4);
}

[data-theme="dark"] .sidebar-indicator:hover {
  background: linear-gradient(
    135deg,
    var(--color-text-accent),
    color-mix(in srgb, var(--color-text-accent) 80%, #000)
  );
  box-shadow: 8px 0 20px rgba(79, 195, 247, 0.5);
}

[data-theme="dark"] .sidebar-indicator::before {
  border-left-color: rgba(0, 0, 0, 0.8);
}

/* Dark theme new sheet button */
[data-theme="dark"] .new-sheet-btn {
  background: var(--color-text-accent) !important;
  color: var(--color-text-on-accent) !important;
}

[data-theme="dark"] .new-sheet-btn:hover {
  background: color-mix(in srgb, var(--color-text-accent) 80%, #000) !important;
  box-shadow: 0 2px 8px rgba(79, 195, 247, 0.4) !important;
}

/* Ensure layout stability during transitions - only animate content */
.main-content {
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Static elements should not animate position */
.app-bar,
#toolbar {
  transition: none !important;
}

/* Prevent content jumping during transition */
.mainPanel {
  position: relative !important;
  overflow: hidden !important;
}

/* Ensure CodeMirror responds properly to container changes */
.CodeMirror {
  width: 100% !important;
  height: 100% !important;
}

.sidebar-section-content {
  padding: 2px 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
  color: var(--color-text-primary);
  font-size: 0.8rem;
  font-family: var(--font-family-base);
  border-radius: 3px;
  margin: 1px 3px;
  position: relative;
}

.sidebar-item:hover {
  background: rgba(0, 120, 212, 0.1);
  color: var(--color-text-accent);
}

.sidebar-item-icon {
  margin-right: 6px;
  font-size: 0.8rem;
  width: 14px;
  display: flex;
  justify-content: center;
}

.sidebar-item-text {
  flex: 1;
  font-weight: 400;
}

.sidebar-subsection {
  margin: 0;
}

.sidebar-subsection-title {
  display: block;
  padding: 4px 12px 2px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--color-surface-secondary);
  font-family: var(--font-family-base);
}

.sidebar-divider {
  height: 1px;
  background: var(--color-stroke-subtle);
  margin: 4px 0;
}

/* Content area scrolling */
.functions-sidebar-content {
  flex: 1 !important;
  overflow-y: auto !important;
  padding-bottom: 20px !important; /* Reduced padding since we removed footer */
}

/* Symbol items styling */
.symbol-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 1px 3px;
  border-radius: 3px;
  transition: background-color 0.15s ease;
}

.symbol-item:hover {
  background: rgba(0, 120, 212, 0.1);
  color: var(--color-text-accent);
}

.symbol-favorite {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 3px;
  color: var(--color-text-secondary);
  transition: all 0.2s ease;
  opacity: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
}

.symbol-favorite:hover {
  background: rgba(0, 120, 212, 0.1);
  color: var(--color-text-accent);
  opacity: 1;
}

.symbol-favorite.favorited {
  color: #FFD700;
  opacity: 1;
}

.symbol-favorite.favorited svg {
  fill: currentColor;
}

.symbol-item:hover .symbol-favorite {
  opacity: 1;
}

/* Dark mode symbol styles */
[data-theme="dark"] .symbol-item:hover {
  background: rgba(79, 195, 247, 0.15);
  color: var(--color-text-accent);
}

[data-theme="dark"] .symbol-favorite:hover {
  background: rgba(79, 195, 247, 0.15);
  color: var(--color-text-accent);
}

/* Constant items styling */
.constant-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 1px 3px;
  border-radius: 3px;
  transition: background-color 0.15s ease;
  background: none;
  border: none;
  width: calc(100% - 6px);
  text-align: left;
  cursor: pointer;
  color: var(--color-text-primary);
  font-family: var(--font-family-base);
}

.constant-item:hover {
  background: rgba(0, 120, 212, 0.1);
  color: var(--color-text-accent);
}

.constant-item .function-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}

.constant-item:hover .function-item-actions {
  opacity: 1;
}

/* Dark mode constant styles */
[data-theme="dark"] .constant-item:hover {
  background: rgba(79, 195, 247, 0.15);
  color: var(--color-text-accent);
}

/* Function category styles */
.function-category {
  margin-bottom: 8px;
}

.function-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--color-surface-flyout);
  cursor: pointer;
  transition: background-color 0.2s ease;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-family-base);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text-primary);
  border-radius: 4px;
}

.function-category-header:hover {
  background: var(--color-surface-secondary-hover);
}

.function-category-header.expanded {
  background: var(--color-surface-secondary);
}

.function-category-toggle {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  transition: transform 0.2s ease;
}

.function-category-header.expanded .function-category-toggle {
  transform: rotate(90deg);
}

.function-category-content {
  display: none;
  padding: 4px 0;
}

.function-category-content.expanded {
  display: block;
}

.function-subcategory {
  padding: 4px 12px 2px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--color-surface-secondary);
  font-family: var(--font-family-base);
}

.function-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 1px 3px;
  border-radius: 3px;
  transition: background-color 0.15s ease;
  background: none;
  border: none;
  width: calc(100% - 6px);
  text-align: left;
  cursor: pointer;
  color: var(--color-text-primary);
  font-family: var(--font-family-base);
}

.function-item:hover {
  background: rgba(0, 120, 212, 0.1);
  color: var(--color-text-accent);
}

.function-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.function-item-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.function-item-desc {
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.function-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}

.function-item:hover .function-item-actions {
  opacity: 1;
}

.function-favorite,
.function-info {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 3px;
  color: var(--color-text-secondary);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.function-favorite:hover,
.function-info:hover {
  background: rgba(0, 120, 212, 0.1);
  color: var(--color-text-accent);
}

.function-favorite.favorited {
  color: #FFD700;
}

.function-favorite.favorited svg {
  fill: currentColor;
}

/* Dark mode function category styles */
[data-theme="dark"] .function-category-header {
  background: var(--color-surface-flyout);
}

[data-theme="dark"] .function-category-header:hover {
  background: var(--color-surface-secondary-hover);
}

[data-theme="dark"] .function-category-header.expanded {
  background: var(--color-surface-secondary);
}

[data-theme="dark"] .function-subcategory {
  background: var(--color-surface-secondary);
}

[data-theme="dark"] .function-item:hover {
  background: rgba(79, 195, 247, 0.15);
  color: var(--color-text-accent);
}

[data-theme="dark"] .function-favorite:hover,
[data-theme="dark"] .function-info:hover {
  background: rgba(79, 195, 247, 0.15);
  color: var(--color-text-accent);
}

/* ===== Unified Sidebar (Desktop + Mobile) ===== */
@media (max-width: 768px) {
  .functions-sidebar {
    display: flex !important; /* override earlier rule that hid it */
  }
}

/* Hide legacy mobile menu panel – sidebar is reused */
#mobile-menu-panel {
  display: none !important;
}

/* Hide mobile-only menu artifacts on desktop */
@media (min-width: 769px) {
  .mobile-sidebar-section,
  .mobile-menu-divider {
    display: none !important;
  }
}

/* Ensure sidebar slides out when closed on mobile */
@media (max-width: 768px) {
  .functions-sidebar.closed {
    transform: translateX(-100%) !important;
  }
}

.mobile-menu-divider {
  display: none !important;
}

.mobile-sidebar-section {
  display: none !important;
}

/* ---- Symbol item action alignment fix (July 2025) ---- */
.symbol-item .function-item-actions {
  display: flex;
  flex-direction: row; /* ensure horizontal layout */
  align-items: center;
  gap: 4px;
  margin-left: auto; /* push icons to far right */
  opacity: 0.7;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}
.symbol-item:hover .function-item-actions {
  opacity: 1;
}
/* Remove excess left-margin so spacing matches other sections */
.symbol-item .function-favorite,
.symbol-item .function-info {
  margin-left: 0;
}