/* Aura Emotion AI - Enhanced UI Styles */

/* CSS Variables for Theming */
:root {
  /* Dark mode colors */
  --bg-primary: #1a1a1c;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #222222;
  --code-bg: #23233a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-muted: #777777;
  --border-color: #444444;
  --shadow-color: rgba(0, 0, 0, 0.3);

  /* Component specific colors */
  --header-bg: #6200ea;
  --header-text: #ffffff;
  --message-user-bg: #336b07;
  --message-aura-bg: #1616c2;
  --panel-bg: rgba(40, 40, 42, 0.95);
  --panel-border: rgba(255, 255, 255, 0.1);

  /* Accent colors */
  --accent-primary: #6200ea;
  --accent-secondary: #667eea;
  --accent-success: #4caf50;
  --accent-error: #f44336;
  --accent-warning: #ff9800;

  /* Transitions */
  --transition-speed: 0.3s;
}

/* Light mode */
[data-theme="light"] {
  --bg-primary: #f4f4f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f9f9f9;
  --code-bg: #eaeaff;
  --text-primary: #2c2c2e;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border-color: #e0e0e0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --message-user-bg: #4caf50;
  --message-aura-bg: #2196f3;
  --panel-bg: rgba(255, 255, 255, 0.95);
  --panel-border: rgba(0, 0, 0, 0.1);
}

/* Global Styles */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color var(--transition-speed), color var(--transition-speed);
  height: 100vh;
  overflow: hidden;
}

/* Main Layout Container */
#app-container {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  grid-template-rows: 60px 1fr;
  height: 100vh;
  gap: 0;
}

/* Enhanced Dynamic Header */
.aura-enhanced-header {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--header-bg), var(--accent-secondary));
  color: var(--header-text);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 12px var(--shadow-color);
  z-index: 100;
  transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  min-height: 80px;
}

/* Dynamic background overlay for emotional states */
.aura-enhanced-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--emotion-color, transparent);
  opacity: 0.2;
  transition: all 1.2s ease;
  z-index: -1;
}

/* Animated neural background */
.neural-background {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px);
  background-size: 30px 30px;
  animation: neural-drift 25s linear infinite;
  z-index: -1;
  opacity: 0.3;
}

@keyframes neural-drift {
  from { transform: translate(0, 0) rotate(0deg); }
  to { transform: translate(30px, 30px) rotate(360deg); }
}

.header-main-section {
  display: flex;
  align-items: center;
  gap: 30px;
}

.aura-title-section h1 {
  font-size: 1.6rem;
  margin: 0;
  font-weight: 700;
  background: linear-gradient(45deg, #ffffff, rgba(255,255,255,0.8));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.user-greeting {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 2px;
}

/* Neural Activity Display */
.neural-activity-display {
  display: flex;
  gap: 20px;
  align-items: center;
}

.brainwave-indicator, .neurotransmitter-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.15);
  padding: 8px 12px;
  border-radius: 20px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.brainwave-indicator .label, .neurotransmitter-indicator .label {
  font-size: 1rem;
}

.brainwave-indicator .value, .neurotransmitter-indicator .value {
  font-size: 0.85rem;
  font-weight: 600;
}

.wave-pattern {
  width: 40px;
  height: 16px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.6) 50%,
    transparent 100%);
  border-radius: 8px;
  animation: brainwave-pulse 2s ease-in-out infinite;
}

.chemical-level {
  width: 30px;
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.chemical-level::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: var(--chemical-intensity, 70%);
  background: linear-gradient(90deg, #4caf50, #8bc34a);
  border-radius: 2px;
  transition: width 0.8s ease;
}

@keyframes brainwave-pulse {
  0%, 100% { opacity: 0.6; transform: scaleX(1); }
  50% { opacity: 1; transform: scaleX(1.2); }
}

/* Simplified User Controls - Replace dropdown with inline editing */
.user-controls {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.15);
  padding: 10px 16px;
  border-radius: 12px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.user-controls:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

/* Hide old dropdown elements */
.user-settings-btn,
.user-dropdown {
  display: none !important;
}

/* New simplified inline user interface */
.simplified-user-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-label {
  font-size: 0.85rem;
  opacity: 0.8;
  white-space: nowrap;
  color: white;
}

.inline-username-input {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  min-width: 100px;
  max-width: 150px;
  transition: all 0.3s ease;
}

.inline-username-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.inline-username-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
}

.inline-save-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.inline-save-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.inline-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.user-status {
  font-size: 0.7rem;
  padding: 3px 6px;
  border-radius: 4px;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.user-status.success {
  background: var(--accent-success);
  color: white;
}

.user-status.error {
  background: var(--accent-error);
  color: white;
}

.user-status.warning {
  background: var(--accent-warning);
  color: white;
}

.user-status.hidden {
  display: none;
}

#header-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* Dark Mode Toggle */
.theme-toggle {
  position: relative;
  width: 50px;
  height: 24px;
  background-color: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  cursor: pointer;
  transition: all var(--transition-speed);
  outline: none;
  display: block;
}

.theme-toggle:hover {
  background-color: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

.theme-toggle:focus {
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
}

.theme-toggle-slider {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 18px;
  height: 18px;
  background-color: white;
  border-radius: 50%;
  transition: transform var(--transition-speed);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .theme-toggle-slider {
  transform: translateX(26px);
}

/* Light theme toggle adjustments */
[data-theme="light"] .theme-toggle {
  background-color: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] .theme-toggle:hover {
  background-color: rgba(0, 0, 0, 0.25);
  border-color: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .theme-toggle:focus {
  border-color: rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.3);
}

/* Enhanced Status Grid */
#aura-status-grid {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
.status-container {
  position: relative;
  background: rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(15px);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 12px;
  min-width: 140px;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
  min-width: 140px;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.status-container:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.status-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.status-icon {
  font-size: 1.1rem;
  transition: transform 0.3s ease;
}

.status-container:hover .status-icon {
  transform: scale(1.1);
}

.status-label {
  font-size: 0.75rem;
  opacity: 0.8;
  font-weight: 500;
}

.status-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.status-value {
  font-weight: 700;
  font-size: 0.9rem;
  color: white;
}

.intensity-level, .focus-energy, .connection-status {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.2);
}

.status-details {
  font-size: 0.7rem;
  opacity: 0.7;
  line-height: 1.2;
}

/* Emotional State Specific Styling */
.emotional-state {
  border-left: 4px solid var(--emotion-accent, #4caf50);
}

.emotional-state.happy { --emotion-accent: #ffeb3b; }
.emotional-state.sad { --emotion-accent: #2196f3; }
.emotional-state.angry { --emotion-accent: #f44336; }
.emotional-state.excited { --emotion-accent: #ff9800; }
.emotional-state.calm { --emotion-accent: #4caf50; }
.emotional-state.curious { --emotion-accent: #9c27b0; }
.emotional-state.love { --emotion-accent: #e91e63; }
.emotional-state.fear { --emotion-accent: #795548; }

/* Cognitive State Specific Styling */
.cognitive-state {
  border-left: 4px solid var(--cognitive-accent, #2196f3);
}

.cognitive-state.learning { --cognitive-accent: #2196f3; }
.cognitive-state.creative { --cognitive-accent: #9c27b0; }
.cognitive-state.analytical { --cognitive-accent: #607d8b; }
.cognitive-state.social { --cognitive-accent: #4caf50; }
.cognitive-state.focused { --cognitive-accent: #ff9800; }

/* System Health Styling */
.system-health {
  border-left: 4px solid var(--system-accent, #4caf50);
}

.system-health.optimal { --system-accent: #4caf50; }
.system-health.warning { --system-accent: #ff9800; }
.system-health.error { --system-accent: #f44336; }
.system-health.connecting { --system-accent: #2196f3; }

/* Emotional State Color Variables */
:root {
  --emotion-normal: #4caf50;
  --emotion-happy: #ffeb3b;
  --emotion-sad: #2196f3;
  --emotion-angry: #f44336;
  --emotion-excited: #ff9800;
  --emotion-fear: #795548;
  --emotion-love: #e91e63;
  --emotion-curious: #9c27b0;
  --emotion-creative: #673ab7;
  --emotion-peaceful: #009688;
}

/* Dynamic header background based on emotion */
.aura-enhanced-header.emotion-happy {
  --emotion-color: var(--emotion-happy);
}

.aura-enhanced-header.emotion-sad {
  --emotion-color: var(--emotion-sad);
}

.aura-enhanced-header.emotion-angry {
  --emotion-color: var(--emotion-angry);
}

.aura-enhanced-header.emotion-excited {
  --emotion-color: var(--emotion-excited);
}

.aura-enhanced-header.emotion-love {
  --emotion-color: var(--emotion-love);
}

.aura-enhanced-header.emotion-curious {
  --emotion-color: var(--emotion-curious);
}

.aura-enhanced-header.emotion-creative {
  --emotion-color: var(--emotion-creative);
}

.aura-enhanced-header.emotion-peaceful {
  --emotion-color: var(--emotion-peaceful);
}

.aura-enhanced-header.emotion-normal {
  --emotion-color: var(--emotion-normal);
}

/* Brainwave-specific animations */
.wave-alpha { animation: brainwave-alpha 2s ease-in-out infinite; }
.wave-beta { animation: brainwave-beta 1.5s ease-in-out infinite; }
.wave-gamma { animation: brainwave-gamma 1s ease-in-out infinite; }
.wave-theta { animation: brainwave-theta 3s ease-in-out infinite; }
.wave-delta { animation: brainwave-delta 4s ease-in-out infinite; }

@keyframes brainwave-alpha {
  0%, 100% { opacity: 0.6; transform: scaleX(1) scaleY(0.8); }
  50% { opacity: 1; transform: scaleX(1.2) scaleY(1.2); }
}

@keyframes brainwave-beta {
  0%, 100% { opacity: 0.7; transform: scaleX(1) scaleY(0.9); }
  25%, 75% { opacity: 1; transform: scaleX(1.1) scaleY(1.1); }
  50% { opacity: 0.8; transform: scaleX(1.3) scaleY(1.3); }
}

@keyframes brainwave-gamma {
  0%, 100% { opacity: 0.8; transform: scaleX(1) scaleY(1); }
  33% { opacity: 1; transform: scaleX(1.1) scaleY(1.1); }
  66% { opacity: 0.9; transform: scaleX(1.2) scaleY(1.2); }
}

@keyframes brainwave-theta {
  0%, 100% { opacity: 0.5; transform: scaleX(1) scaleY(0.7); }
  50% { opacity: 0.9; transform: scaleX(1.1) scaleY(1.1); }
}

@keyframes brainwave-delta {
  0%, 100% { opacity: 0.4; transform: scaleX(1) scaleY(0.6); }
  50% { opacity: 0.8; transform: scaleX(1.05) scaleY(1.05); }
}

/* Mobile responsiveness for enhanced header */
@media (max-width: 1024px) {
  .aura-enhanced-header {
    min-height: 100px;
    flex-direction: column;
    padding: 8px 16px;
    gap: 8px;
  }

  .header-main-section {
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }

  .neural-activity-display {
    justify-content: center;
  }

  #aura-status-grid {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .status-container {
    min-width: 120px;
    padding: 8px;
  }

  .user-controls {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }

  .simplified-user-section {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
  }

  .inline-username-input {
    min-width: auto;
    max-width: none;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .aura-enhanced-header {
    min-height: 120px;
  }

  .aura-title-section h1 {
    font-size: 1.4rem;
  }

  .neural-activity-display {
    flex-direction: column;
    gap: 8px;
  }

  #aura-status-grid {
    flex-direction: column;
    align-items: center;
  }

  .status-container {
    width: 100%;
    max-width: 200px;
  }
}

/* Left Panel - Chat History */
#left-panel {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  transition: transform var(--transition-speed);
}

#left-panel.collapsed {
  transform: translateX(-280px);
}

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0;
}

.collapse-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color var(--transition-speed);
}

.collapse-btn:hover {
  background-color: var(--bg-tertiary);
}

#new-chat-btn {
  width: calc(100% - 32px);
  margin: 16px;
  padding: 10px;
  background-color: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color var(--transition-speed);
}

#new-chat-btn:hover {
  background-color: var(--accent-secondary);
}

.chat-history-container {
  height: calc(100vh - 180px); /* Account for header, new chat button, and padding */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-history-list {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  /* scrollbar-width: thin; */
}

.chat-history-list::-webkit-scrollbar {
  width: 6px;
}

.chat-history-list::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 3px;
}

.chat-history-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.chat-history-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.chat-session-item {
  padding: 12px;
  margin: 4px 0;
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color var(--transition-speed);
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-session-item:hover .session-delete-btn {
  opacity: 1;
}

.chat-session-item:hover {
  background-color: var(--panel-bg);
}

.chat-session-item.active {
  background-color: var(--accent-primary);
  color: white;
}

.session-title {
  font-weight: 500;
  margin-bottom: 4px;
}

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

.chat-session-item.active .session-meta {
  color: rgba(255, 255, 255, 0.8);
}

/* Delete button styling */
.session-delete-btn {
  opacity: 0;
  background: var(--accent-error);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition-speed);
  margin-left: 8px;
  flex-shrink: 0;
}

.session-delete-btn:hover {
  background: #d32f2f;
  transform: scale(1.05);
}

.chat-session-item.active .session-delete-btn {
  opacity: 0.8;
}

.chat-session-item:hover .session-delete-btn {
  opacity: 1;
}

/* Delete confirmation modal */
.delete-confirmation-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.delete-confirmation-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  box-shadow: 0 8px 32px var(--shadow-color);
  text-align: center;
}

.delete-confirmation-content h3 {
  color: var(--accent-error);
  margin: 0 0 12px 0;
  font-size: 1.1rem;
}

.delete-confirmation-content p {
  color: var(--text-secondary);
  margin: 0 0 20px 0;
  line-height: 1.4;
}

.delete-confirmation-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.delete-confirm-btn, .delete-cancel-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-speed);
}

.delete-confirm-btn {
  background: var(--accent-error);
  color: white;
}

.delete-confirm-btn:hover {
  background: #d32f2f;
}

.delete-cancel-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.delete-cancel-btn:hover {
  background: var(--panel-bg);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.no-history {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
}

.error-message {
  padding: 12px;
  color: var(--accent-error);
  text-align: center;
  background-color: rgba(244, 67, 54, 0.1);
  border-radius: 8px;
  margin: 8px;
}

/* Center Panel - Chat Container */
#chat-container {
  display: flex; /* Ensure chat container itself is a flex container */
  flex-direction: column; /* Stack message area and form vertically */
  overflow: hidden; /* Prevent content from spilling */
  background-color: var(--bg-tertiary); /* Or your desired chat background */
}

/* Message Area */
#message-area {
  flex-grow: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column; /* Explicitly set to column, new items at bottom */
  gap: 10px; /* Space between bubbles */
}

/* Ensure scrollbar is visible */
#message-area::-webkit-scrollbar {
  width: 8px;
}

#message-area::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

#message-area::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

#message-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Add bottom padding to ensure last message is visible */
#message-area::after {
  content: "";
  display: block;
  height: 20px;
  flex-shrink: 0;
}

/* Message Bubbles */
.message-bubble {
  padding: 10px 15px;
  border-radius: 18px;
  max-width: 75%;
  word-wrap: break-word;
  line-height: 1.4;
  box-shadow: 0 1px 2px var(--shadow-color);
  /* Ensure text color contrasts with bubble background */
  color: var(--text-primary); /* Default text color, overridden by specific types */
}

.message-bubble.user {
  background-color: var(--message-user-bg);
  color: white; /* Assuming user message text should be white/light */
  align-self: flex-end; /* Aligns user messages to the right */
  margin-left: auto;
  border-bottom-right-radius: 5px; /* Common chat bubble styling */
}

.message-bubble.aura {
  background-color: var(--message-aura-bg);
  color: white; /* Assuming aura message text should be white/light */
  align-self: flex-start; /* Aligns aura messages to the left */
  margin-right: auto;
  border-bottom-left-radius: 5px; /* Common chat bubble styling */
}

.message-bubble.error {
  background-color: var(--accent-error);
  color: white;
  align-self: stretch; /* Errors can span more width if needed */
  text-align: center;
  border-radius: 8px; /* Consistent with other error messages */
}

.typing-indicator {
  font-style: italic;
  color: var(--text-secondary);
  padding: 12px 16px;
  align-self: flex-start;
  margin-right: auto;
}

.thinking-phases {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  background-color: var(--panel-bg);
  border-radius: 8px;
}

/* Modifier for horizontal layout */
.thinking-phases.horizontal {
  flex-direction: row;
}

.phase-indicator {
  opacity: 0.3;
  transition: opacity 0.3s ease;
  font-size: 0.9rem;
}

.phase-indicator.active {
  opacity: 1;
  color: var(--accent-primary);
}

/* Message Actions */
.message-actions {
  position: absolute;
  top: -8px;
  right: 8px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 4px;
  gap: 4px;
  box-shadow: 0 2px 8px var(--shadow-color);
  z-index: 10;
  display: none;
}

.action-btn {
  background: none;
  border: none;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all var(--transition-speed);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
}

.action-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  transform: scale(1.1);
}

.edit-btn:hover {
  color: var(--accent-secondary);
}

.delete-btn:hover {
  color: var(--accent-error);
}

.regenerate-btn:hover {
  color: var(--accent-primary);
}

.save-btn:hover {
  color: var(--accent-success);
}

.cancel-btn:hover {
  color: var(--accent-warning);
}

/* Edit Mode Styles */
.edit-textarea {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.5;
  outline: none;
  margin-bottom: 8px;
  width: 100%;
  min-height: 60px;
  resize: vertical;
}

.edit-textarea:focus {
  border-color: var(--accent-primary);
}

.edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.edit-actions .action-btn {
  position: static;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  font-size: 0.85rem;
  gap: 4px;
}

/* Chat Form */
#chat-form {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  align-items: center;
  background-color: var(--bg-secondary);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  padding: 12px 20px;
  border: 1px solid var(--border-color);
  border-radius: 24px;
  font-size: 1rem;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-speed);
}

#message-input:focus {
  border-color: var(--accent-primary);
}

#send-button {
  padding: 12px 24px;
  background-color: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 24px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-speed);
}

#send-button:hover:not(:disabled) {
  background-color: var(--accent-secondary);
}

#send-button:disabled {
  background-color: var(--text-secondary);
  cursor: not-allowed;
}

/* Right Panel */
#right-panel {
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  overflow-y: auto;
  transition: transform var(--transition-speed);
}

#right-panel.collapsed {
  transform: translateX(320px);
}

/* Memory Search Panel */
.memory-panel, .insights-panel {
  margin: 16px;
  padding: 16px;
  background-color: var(--panel-bg);
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.memory-panel h3, .insights-panel h3 {
  margin: 0 0 12px 0;
  font-size: 1rem;
  font-weight: 600;
}

/* Enhanced Memory Search System */
.memory-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.memory-search-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#memory-query {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-speed);
}

#memory-query:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(98, 0, 234, 0.1);
}

.search-options {
  display: flex;
  gap: 16px;
  margin: 8px 0;
}

.search-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-user-select: none; /* Safari */
  user-select: none;
}

.search-option input[type="checkbox"] {
  accent-color: var(--accent-primary);
}

.search-option:hover {
  color: var(--text-primary);
}

/* Video Archive Management */
.video-archive-section {
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  margin-top: 16px;
}

.video-archive-section h4 {
  margin: 0 0 12px 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.archive-status {
  background-color: var(--bg-tertiary);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}

.archive-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.archive-info div {
  color: var(--text-secondary);
}

.archive-error {
  color: var(--accent-error);
  font-size: 0.85rem;
  text-align: center;
  padding: 8px;
}

.status-loading {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  font-style: italic;
}

/* Enhanced Memory Results */
.memory-result {
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  padding: 14px;
  margin: 10px 0;
  border-left: 3px solid var(--accent-secondary);
  transition: all var(--transition-speed);
}

.memory-result:hover {
  background-color: var(--panel-bg);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px var(--shadow-color);
}

.memory-result.error {
  border-left-color: var(--accent-error);
  background-color: rgba(244, 67, 54, 0.05);
}

.memory-result[data-source*="video"] {
  border-left-color: var(--accent-warning);
}

.memory-result[data-source*="active"] {
  border-left-color: var(--accent-primary);
}

.search-summary {
  margin-top: 16px;
  padding: 12px;
  background: linear-gradient(135deg, var(--bg-tertiary), var(--panel-bg));
  border-radius: 8px;
  font-size: 0.9em;
  border: 1px solid var(--panel-border);
  line-height: 1.5;
}

.search-summary strong {
  color: var(--accent-primary);
}

/* Insights Controls */
.insights-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#insights-period {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

#insights-period:focus {
  border-color: var(--accent-primary);
}

#insights-period option {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

#search-memories, #show-insights {
  padding: 8px 16px;
  background-color: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color var(--transition-speed);
}

#search-memories:hover, #show-insights:hover {
  background-color: var(--accent-secondary);
}

#memory-results, #insights-content {
  margin-top: 12px;
}

.memory-result {
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
  border-left: 3px solid var(--accent-secondary);
}

.memory-content {
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 4px;
}

.memory-meta {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-style: italic;
}

.search-error {
  color: var(--accent-error);
  background-color: rgba(244, 67, 54, 0.1);
  border: 1px solid var(--accent-error);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 0.85rem;
  text-align: center;
  display: none; /* Hidden by default */
}

.search-error:not(:empty) {
  display: block; /* Show when has content */
}

.insights-data {
  color: var(--text-primary);
  line-height: 1.5;
}

.insights-data p {
  margin: 8px 0;
}

.insights-data strong {
  color: var(--accent-primary);
}

.recommendations {
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
  border-left: 3px solid var(--accent-warning);
}

.recommendations h4 {
  margin: 0 0 8px 0;
  color: var(--accent-primary);
  font-size: 0.95rem;
}

.emotional-breakdown {
  margin-top: 16px;
  padding: 12px;
  background-color: var(--bg-tertiary);
  border-radius: 8px;
}

.emotional-breakdown h4 {
  margin: 0 0 12px 0;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.emotion-stat {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

.emotion-stat:last-child {
  border-bottom: none;
}

.emotion-stat span:first-child {
  font-weight: 500;
  color: var(--accent-primary);
}

.emotion-stat span:last-child {
  color: var(--text-secondary);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 6px;
  min-height: 50px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-primary);
}

/* Firefox scrollbar support */
/* * {
  scrollbar-width: thin;
} */

/* Mobile Responsive */
@media (max-width: 1024px) {
  #app-container {
    grid-template-columns: 0 1fr 0;
  }

  #left-panel, #right-panel {
    position: fixed;
    height: calc(100vh - 60px);
    top: 60px;
    z-index: 50;
    box-shadow: 2px 0 8px var(--shadow-color);
  }

  #left-panel {
    left: 0;
    width: 280px;
  }

  #right-panel {
    right: 0;
    width: 320px;
  }

  #left-panel:not(.collapsed), #right-panel:not(.collapsed) {
    transform: translateX(0);
  }

  .mobile-menu-btn {
    display: block !important;
  }

  /* Adjust chat history container for mobile */
  .chat-history-container {
    height: calc(100vh - 140px); /* Account for mobile header size */
  }

  /* Ensure delete confirmations work on mobile */
  .delete-confirmation-content {
    margin: 16px;
    max-width: calc(100vw - 32px);
  }
}

@media (max-width: 640px) {
  #left-panel {
    width: 85vw;
  }

  #right-panel {
    width: 90vw;
  }

  .message-bubble {
    max-width: 90%;
  }
}

/* Mobile menu buttons (hidden on desktop) */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--header-text);
  padding: 8px;
  cursor: pointer;
  font-size: 1.2rem;
}

/* Markdown content styling */
.message-bubble pre {
  background-color: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: 'SF Mono', Consolas, monospace;
}

.message-bubble code {
  background-color: var(--code-bg);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 0.9em;
}

.message-bubble p:first-child {
  margin-top: 0 !important;
}

.message-bubble p:last-child {
  margin-bottom: 0 !important;
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-secondary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Database Error Styling */
.database-error {
  background: linear-gradient(135deg, rgba(244, 67, 54, 0.1), rgba(255, 152, 0, 0.1));
  border: 2px solid var(--accent-error);
  border-radius: 12px;
  padding: 20px;
  margin: 16px;
  text-align: center;
  max-width: 400px;
}

.database-error .error-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.database-error .error-title {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--accent-error);
  margin-bottom: 12px;
}

.database-error .error-message {
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 16px;
  text-align: left;
}

.database-error ul {
  margin: 8px 0;
  padding-left: 20px;
}

.database-error .retry-button {
  background: var(--accent-error);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.3s ease;
}

.database-error .retry-button:hover {
  background: #d32f2f;
}

/* Thinking Display Styles */
.thinking-container {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  transition: background-color 0.3s ease;
}

.thinking-header:hover {
  background: rgba(255, 255, 255, 0.1);
}

.thinking-icon {
  font-size: 1rem;
}

.thinking-label {
  font-weight: 500;
  font-size: 0.85rem;
  flex: 1;
}

.thinking-toggle {
  font-size: 0.7rem;
  transition: transform 0.3s ease;
  opacity: 0.7;
}

.thinking-container.expanded .thinking-toggle {
  transform: rotate(180deg);
}

.thinking-metrics {
  font-size: 0.7rem;
  opacity: 0.6;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 10px;
}

.thinking-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.thinking-container.expanded .thinking-content {
  max-height: none; /* Allow unlimited expansion for long thinking content */
  overflow-y: auto; /* Add scroll if needed */
}

.thinking-summary {
  padding: 12px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.85rem;
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.thinking-summary p {
  margin: 0;
}

.thinking-summary:first-child {
  margin-top: 0;
}

.thinking-summary:last-child {
  margin-bottom: 0;
}

.message-content {
  /* Ensure message content is properly separated from thinking */
  margin-top: 0;
}

/* Light theme adjustments for thinking display */
[data-theme="light"] .thinking-container {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .thinking-header {
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .thinking-header:hover {
  background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .thinking-summary {
  background: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
  border-top-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .thinking-metrics {
  background: rgba(0, 0, 0, 0.1);
}
