/* ======== SIDEBAR STYLES ======== */
#sidebar {
  width: 20%;
  background: var(--bg-primary);
  padding: 20px 20px 0 20px;
  overflow-y: auto;
  border-right: 1px solid var(--border-color);
  transition: all 0.3s ease;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  box-shadow: 0 2px 4px var(--shadow-color);
  height: 100vh;
}

#sidebar.minimized {
  width: 80px;
  padding: 20px 10px;
  overflow-x: hidden;
}

/* Logo space below buttons */
#logo-space {
  padding: 0 20px 20px 20px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

#logo-space img {
  width: 128px;
  height: 128px;
  object-fit: contain;
}

#sidebar.minimized #logo-space {
  padding: 10px;
  width: 100%;
  margin-bottom: 15px;
}

#sidebar.minimized #logo-space img {
  width: 64px;
  height: 64px;
}

/* Toggle button positioning */
#sidebar-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 28px;
  height: 28px;
  background: var(--button-bg);
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  border: 1px solid var(--button-border);
  border-radius: 4px;
  box-shadow: 0 2px 4px var(--shadow-color);
}

#sidebar.minimized #sidebar-toggle {
  display: none;  /* Hide when minimized, logo handles expansion */
}

/* Expand button (shown when sidebar is minimized) */
#expand-sidebar {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 28px;
  height: 28px;
  background: var(--button-bg);
  padding: 0;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10;
  border: 1px solid var(--button-border);
  border-radius: 4px;
  box-shadow: 0 2px 4px var(--shadow-color);
  cursor: pointer;
}

#sidebar.minimized #expand-sidebar {
  display: flex;  /* Show when minimized */
}

#expand-sidebar:hover {
  background: var(--button-hover);
}

#sidebar h2 {
  font-size: 1.2em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  height: 40px;  /* Consistent height for all states */
  position: relative;
}

#sidebar.minimized h2 {
  justify-content: center;
  margin-bottom: 20px;
}

#sidebar.minimized h2 span {
  display: none;
}

#sidebar h2 i,
#sidebar h2 .user-icon {
  margin-right: 10px;
  min-width: 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;  /* Take full height of parent */
}


#sidebar.minimized h2 i,
#sidebar.minimized h2 .user-icon {
  margin-right: 0;  /* Remove margin in minimized state */
  font-size: 1.4em;
}

/* Connection status alignment */
#connection-status {
  height: 40px;  /* Match other elements */
  display: flex;
  align-items: center;
}

#sidebar.minimized #connection-status {
  justify-content: center;
}

/* Logo space styles */
#logo-space {
  cursor: pointer;
  transition: transform 0.2s ease;
}

#logo-space:hover {
  transform: scale(1.05);
}

#sidebar.minimized #logo-space {
  padding: 10px;
  width: 100%;
  margin-bottom: 20px;  /* Consistent spacing */
}

/* Tooltip for minimized sidebar */
#sidebar.minimized h2::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.9em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1000;
}

#sidebar.minimized h2:hover::after {
  opacity: 1;
}

#sidebar ul {
  list-style: none;
  margin-bottom: 20px;
  transition: opacity 0.3s ease;
}

#sidebar.minimized ul {
  opacity: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
}

#sidebar li {
  padding: 8px 10px;
  cursor: pointer;
  color: var(--accent-color);
  border-radius: 4px;
  transition: background-color 0.2s ease;
  margin: 2px 0;
}

#sidebar li:hover {
  background-color: var(--hover-bg);
}

#sidebar li.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
}

#sidebar li.history-item .conversation-description {
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.85em;
  flex: 1;
}

/* Favorite star styles */
.favorite-star {
  margin-left: auto;
  cursor: pointer;
  transition: color 0.2s ease, transform 0.1s ease;
  font-size: 0.9em;
  padding: 2px;
}

.favorite-star:hover {
  transform: scale(1.1);
}

.favorite-star.fas {
  color: var(--status-warning) !important;
}

.favorite-star.far {
  color: var(--text-secondary);
}

.favorite-star.far:hover {
  color: var(--status-warning);
}

#sidebar .top-sections {
  height: calc(100vh - 300px); /* Fixed height, leaving space for logo and bottom sections */
  overflow-y: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

/* History container with scrolling */
#history-container {
  overflow-y: auto;
  margin-bottom: 20px;
  flex: 1;
  min-height: 0;
}

/* Middle sections - now empty but keep for structure */
#sidebar .middle-sections {
  flex: 1; /* Take up remaining space to push bottom sections down */
  min-height: 0;
}

/* Connection status styles */
#connection-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  margin-bottom: 15px;
}

.led-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--status-error);  /* Default to red */
  transition: background-color 0.3s ease;
}

.led-indicator.connected {
  background-color: var(--status-success);  /* Green when connected */
}

.connection-text {
  font-size: 0.9em;
  color: var(--text-secondary);
}

/* Handle minimized state */
#sidebar.minimized #connection-status {
  justify-content: center;
  padding: 5px 0;
}

#sidebar.minimized .connection-text {
  display: none;
}

#sidebar.minimized .led-indicator {
  width: 16px;
  height: 16px;
}

/* Bottom sections layout - align to bottom */
#sidebar .bottom-sections {
  position: relative;
  z-index: 100;
  margin-top: auto;
  margin-bottom: 0;
}

/* Settings and User row layout */
.settings-user-row {
  display: flex;
  gap: 10px;
  margin-bottom: 0px; /* Remove margin to move controls closer to bottom */
}

.settings-user-row h2 {
  flex: 1;
  margin-bottom: 0;
  font-size: 1em;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.settings-user-row h2:hover {
  background-color: var(--hover-bg);
}

/* User icon connection status colors */
#user-btn i {
  transition: color 0.3s ease;
  color: var(--status-error) !important; /* Default to error color until connected */
}

#user-btn.connected i {
  color: var(--status-success) !important; /* Green when connected */
}

#user-btn.disconnected i {
  color: var(--status-error) !important; /* Red when disconnected */
}

/* Settings and User button margin adjustments */
#settings-btn,
#user-btn {
  margin-bottom: 0px;
}

/* Remove margin from settings-user-row to move controls closer to bottom */
#settings-user-row {
  margin-bottom: 0px;
}

/* Connection LED in bottom right corner */
.connection-led-corner {
  position: absolute;
  bottom: 0;
  right: 0;
  padding: 5px;
}

.connection-led-corner .led-indicator {
  width: 10px;
  height: 10px;
}

/* Handle minimized state for new layout */
#sidebar.minimized .settings-user-row {
  flex-direction: column;
  gap: 5px;
}

#sidebar.minimized .settings-user-row h2 {
  justify-content: center;
  padding: 5px;
}

#sidebar.minimized .connection-led-corner {
  position: absolute;
  bottom: 5px;
  right: 5px;
}

/* User icon connection status in minimized state */
#sidebar.minimized #user-btn i {
  color: var(--status-error) !important; /* Default to error color until connected */
}

#sidebar.minimized #user-btn.connected i {
  color: var(--status-success) !important; /* Green when connected */
}

#sidebar.minimized #user-btn.disconnected i {
  color: var(--status-error) !important; /* Red when disconnected */
}

/* Ensure proper menu positioning */
#sidebar .bottom-sections h2 {
  cursor: pointer;
  position: relative;
}

/* User menu positioning */
#user-menu {
  position: absolute;
  z-index: 1000;
  background: var(--bg-secondary);
  box-shadow: 0 2px 10px var(--shadow-color);
}

#sidebar.minimized #user-menu {
  position: fixed;
}

#sidebar button.sidebar-btn {
  transition: opacity 0.3s ease;
}

#sidebar.minimized button.sidebar-btn,
#sidebar.minimized p {
  opacity: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
}

/* Copy Controls - removed from sidebar, now in chat container */

/* ======== WORKSPACE STYLES ======== */
#workspaces-container {
  margin-bottom: 20px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#workspaces-list {
  transition: opacity 0.3s ease;
}

#sidebar.minimized #workspaces-list {
  opacity: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
}

.workspace-item {
  margin: 2px 0;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.workspace-header {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--accent-color);
  border-radius: 4px;
  transition: background-color 0.2s ease;
  gap: 8px;
}

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

.workspace-twiddle {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  font-size: 12px;
  color: var(--text-secondary);
}

.workspace-item.expanded .workspace-twiddle {
  transform: rotate(90deg);
}

.workspace-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.workspace-name {
  flex: 1;
  font-weight: 500;
  font-size: 1.0em;
  color: var(--text-secondary);
}

.workspace-stats {
  font-size: 0.8em;
  color: var(--text-secondary);
  margin-left: auto;
}

.workspace-conversations {
  margin-left: 24px;
  padding-left: 12px;
  border-left: 2px solid var(--border-color);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.workspace-item.expanded .workspace-conversations {
  max-height: 500px;
  padding-top: 4px;
  padding-bottom: 4px;
}

.workspace-conversation {
  padding: 6px 8px;
  margin: 2px 0;
  cursor: pointer;
  border-radius: 3px;
  transition: background-color 0.2s ease;
  font-size: 0.85em;
}

.workspace-conversation:hover {
  background-color: var(--hover-bg);
}

.workspace-conversation.active {
  background-color: var(--accent-color);
  font-weight: 500;
}

.workspace-conversation-title {
  color: var(--text-primary);
}

/* Dark theme override for workspace conversation title */
[data-theme="dark"] .workspace-conversation-title {
  color: var(--text-secondary);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .workspace-conversation-title {
    color: var(--text-secondary);
  }
}

.workspace-conversation-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8em;
  color: var(--text-secondary);
}

/* Dark theme override for workspace conversation meta */
[data-theme="dark"] .workspace-conversation-meta {
  color: var(--text-primary);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .workspace-conversation-meta {
    color: var(--text-primary);
  }
}

.workspace-conversation-date {
  font-size: 0.75em;
}

.workspace-conversation-stats {
  font-size: 0.75em;
}

/* Favorite star in workspace conversations */
.workspace-conversation .favorite-star {
  margin-left: 4px;
  font-size: 0.8em;
}

/* Empty state for workspaces */
.workspace-empty {
  padding: 8px 12px;
  font-size: 0.8em;
  color: var(--text-secondary);
  font-style: italic;
  margin-left: 24px;
}

/* Workspace item hover effects */
.workspace-item:hover .workspace-twiddle {
  color: var(--accent-color);
}

/* Responsive adjustments for minimized sidebar */
#sidebar.minimized .workspace-item {
  display: none;
}

/* ======== ACCORDION STYLES ======== */
.accordion-section {
}

.accordion-header {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px; /* Match settings padding exactly */
  transition: background-color 0.2s ease;
  border-radius: 4px;
  user-select: none;
  position: relative;
}

/* Make accordion headers follow the same pattern as settings h2 elements */
.accordion-header i:first-child {
  margin-right: 10px !important; /* Same as other h2 icons */
  position: static;
  min-width: 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.accordion-header span {
  margin-left: 0;
  padding-left: 0;
  text-align: left;
  flex: 1;
  position: static;
}

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

.accordion-icon {
  font-size: 0.8em;
  transition: transform 0.3s ease;
  color: var(--text-secondary);
  position: absolute;
  right: 28px; /* Align with the right edge of the close button (20px + 8px padding) */
}

.accordion-section.collapsed .accordion-icon {
  transform: rotate(-90deg);
}

.accordion-content {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 1000px;
  opacity: 1;
}

.accordion-section.collapsed .accordion-content {
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
}


/* Handle minimized state for accordion */
#sidebar.minimized .accordion-icon {
  display: none;
}

#sidebar.minimized .accordion-section.collapsed .accordion-content {
  max-height: 0;
  opacity: 0;
}
