/**
 * GHIA Host Design System
 * Technology & Cognition Inspired Theme with Dark Mode Support
 * Version 5.0 - Enhanced Readability & Aesthetics
 */

/* ============================================
   1. DESIGN TOKENS - LIGHT THEME (DEFAULT)
   ============================================ */

:root {
  /* Theme indicator */
  --theme-mode: light;
  /* === Color Palette === */

  /* Background hierarchy (soft sky blue theme - lighter for better readability) */
  --bg-base: #F8FBFF;
  --bg-deep: #EEF6FF;
  --bg-primary: #DBEAFE;
  --bg-elevated: #F8FBFF;
  --bg-panel: rgba(255, 255, 255, 0.92);
  --bg-panel-hover: rgba(240, 248, 255, 0.95);
  --bg-surface: rgba(255, 255, 255, 0.85);
  --bg-surface-hover: rgba(240, 248, 255, 0.9);

  /* Text hierarchy - Enhanced contrast for readability */
  --text-primary: #0F172A;
  --text-secondary: #334155;
  --text-tertiary: #475569;
  --text-muted: #64748B;
  --text-inverse: #FFFFFF;

  /* Accent colors - Soft Sky Blue */
  --accent-primary: #3B82F6;
  --accent-primary-hover: #2563EB;
  --accent-primary-muted: rgba(59, 130, 246, 0.12);
  --accent-primary-glow: rgba(59, 130, 246, 0.15);

  --accent-secondary: #475569;
  --accent-secondary-hover: #334155;
  --accent-secondary-muted: rgba(71, 85, 105, 0.1);

  --accent-cyan: #06B6D4;
  --accent-cyan-muted: rgba(6, 182, 212, 0.12);

  /* Semantic colors - Enhanced for visibility */
  --color-success: #059669;
  --color-success-muted: rgba(5, 150, 105, 0.1);
  --color-success-light: #D1FAE5;
  --color-warning: #D97706;
  --color-warning-muted: rgba(217, 119, 6, 0.1);
  --color-warning-light: #FEF3C7;
  --color-error: #DC2626;
  --color-error-muted: rgba(220, 38, 38, 0.1);
  --color-error-light: #FEE2E2;
  --color-info: #0284C7;
  --color-info-light: #E0F2FE;

  /* Border colors - Enhanced visibility */
  --border-subtle: rgba(148, 163, 184, 0.3);
  --border-default: rgba(100, 116, 139, 0.25);
  --border-emphasis: rgba(71, 85, 105, 0.35);
  --border-accent: rgba(59, 130, 246, 0.4);

  /* === Typography === */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  /* Font sizes */
  --text-xs: 0.6875rem;    /* 11px */
  --text-sm: 0.75rem;      /* 12px */
  --text-base: 0.8125rem;  /* 13px */
  --text-md: 0.875rem;     /* 14px */
  --text-lg: 1rem;         /* 16px */
  --text-xl: 1.125rem;     /* 18px */
  --text-2xl: 1.25rem;     /* 20px */
  --text-3xl: 1.5rem;      /* 24px */

  /* Font weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Line heights */
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Letter spacing */
  --tracking-tight: -0.01em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;

  /* === Spacing Scale === */
  --space-0: 0;
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */

  /* === Border Radius === */
  --radius-sm: 0.375rem;   /* 6px */
  --radius-md: 0.5rem;     /* 8px */
  --radius-lg: 0.75rem;    /* 12px */
  --radius-xl: 1rem;       /* 16px */
  --radius-2xl: 1.25rem;   /* 20px */
  --radius-full: 9999px;

  /* === Shadows (sky blue tinted) === */
  --shadow-sm: 0 1px 2px 0 rgba(14, 165, 233, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(14, 165, 233, 0.1), 0 2px 4px -1px rgba(14, 165, 233, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(14, 165, 233, 0.12), 0 4px 6px -2px rgba(14, 165, 233, 0.06);
  --shadow-xl: 0 20px 25px -5px rgba(14, 165, 233, 0.15), 0 10px 10px -5px rgba(14, 165, 233, 0.08);
  --shadow-glow: 0 0 0 3px rgba(14, 165, 233, 0.15);
  --shadow-glow-accent: 0 0 0 3px rgba(14, 165, 233, 0.25);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --shadow-focus: 0 0 0 3px rgba(14, 165, 233, 0.25);

  /* === Transitions === */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* === Z-Index Scale === */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-popover: 500;
  --z-tooltip: 600;

  /* === Layout === */
  --sidebar-width: 280px;
  --sidebar-collapsed: 72px;
  --topbar-height: 56px;
  --panel-width: 320px;
  --content-max-width: 1000px;
  --composer-max-width: 900px;
}

/* ============================================
   1b. DARK THEME OVERRIDES
   ============================================ */

[data-theme="dark"] {
  --theme-mode: dark;

  /* Background hierarchy (dark technology theme) */
  --bg-base: #0B1120;
  --bg-deep: #111827;
  --bg-primary: #1E293B;
  --bg-elevated: #111827;
  --bg-panel: rgba(17, 24, 39, 0.95);
  --bg-panel-hover: rgba(30, 41, 59, 0.9);
  --bg-surface: rgba(15, 23, 42, 0.9);
  --bg-surface-hover: rgba(30, 41, 59, 0.85);

  /* Text hierarchy - Enhanced contrast for dark mode */
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-tertiary: #94A3B8;
  --text-muted: #64748B;
  --text-inverse: #0B1120;

  /* Accent colors - Bright blue for dark mode visibility */
  --accent-primary: #60A5FA;
  --accent-primary-hover: #93C5FD;
  --accent-primary-muted: rgba(96, 165, 250, 0.2);
  --accent-primary-glow: rgba(96, 165, 250, 0.25);

  --accent-secondary: #94A3B8;
  --accent-secondary-hover: #CBD5E1;
  --accent-secondary-muted: rgba(148, 163, 184, 0.2);

  --accent-cyan: #22D3EE;
  --accent-cyan-muted: rgba(34, 211, 238, 0.2);

  /* Semantic colors - Bright for dark mode visibility */
  --color-success: #34D399;
  --color-success-muted: rgba(52, 211, 153, 0.2);
  --color-success-light: rgba(52, 211, 153, 0.2);
  --color-warning: #FBBF24;
  --color-warning-muted: rgba(251, 191, 36, 0.2);
  --color-warning-light: rgba(251, 191, 36, 0.2);
  --color-error: #F87171;
  --color-error-muted: rgba(248, 113, 113, 0.2);
  --color-error-light: rgba(248, 113, 113, 0.2);
  --color-info: #38BDF8;
  --color-info-light: rgba(56, 189, 248, 0.2);

  /* Border colors - Better visibility in dark mode */
  --border-subtle: rgba(148, 163, 184, 0.15);
  --border-default: rgba(148, 163, 184, 0.25);
  --border-emphasis: rgba(148, 163, 184, 0.4);
  --border-accent: rgba(96, 165, 250, 0.5);

  /* Shadows - Enhanced for dark mode */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6), 0 2px 4px -1px rgba(59, 130, 246, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7), 0 4px 6px -2px rgba(59, 130, 246, 0.15);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.8), 0 10px 10px -5px rgba(59, 130, 246, 0.2);
  --shadow-glow: 0 0 0 3px rgba(96, 165, 250, 0.25);
  --shadow-glow-accent: 0 0 0 3px rgba(96, 165, 250, 0.35);
  --shadow-inset: inset 0 1px 0 rgba(148, 163, 184, 0.1);
  --shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.35);
}

/* Dark theme background pattern - Technology/Neural network inspired */
[data-theme="dark"] .app-shell::before {
  background:
    /* Neural glow top center */
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(96, 165, 250, 0.12) 0%, transparent 50%),
    /* Right synapse glow */
    radial-gradient(ellipse 60% 60% at 100% 30%, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
    /* Left cognition glow */
    radial-gradient(ellipse 70% 50% at 0% 70%, rgba(34, 211, 238, 0.08) 0%, transparent 50%),
    /* Center deep glow */
    radial-gradient(ellipse 90% 70% at 50% 50%, rgba(59, 130, 246, 0.05) 0%, transparent 60%),
    /* Base gradient */
    linear-gradient(180deg, #0B1120 0%, #111827 50%, #0F172A 100%);
}

[data-theme="dark"] .app-shell::after {
  background-image:
    /* Neural connection nodes */
    radial-gradient(circle 2px at 20% 20%, rgba(96, 165, 250, 0.3) 0%, transparent 100%),
    radial-gradient(circle 2px at 80% 30%, rgba(96, 165, 250, 0.25) 0%, transparent 100%),
    radial-gradient(circle 2px at 40% 60%, rgba(96, 165, 250, 0.2) 0%, transparent 100%),
    radial-gradient(circle 2px at 70% 80%, rgba(96, 165, 250, 0.25) 0%, transparent 100%),
    radial-gradient(circle 2px at 10% 85%, rgba(34, 211, 238, 0.2) 0%, transparent 100%),
    /* Circuit grid pattern */
    linear-gradient(rgba(96, 165, 250, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96, 165, 250, 0.03) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 50px 50px, 50px 50px;
}

/* Dark theme code blocks */
[data-theme="dark"] .message-content pre {
  background: #0F172A;
  border-color: #334155;
}

[data-theme="dark"] .message-content pre code {
  color: #E2E8F0;
}

/* ============================================
   2. RESET & BASE
   ============================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--bg-base);
  min-height: 100vh;
  overflow: hidden;
}

/* ============================================
   3. APP SHELL & BACKGROUND GRAPHICS
   ============================================ */

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
  overflow: hidden;
}

/* Technology & Cognition inspired background - Light theme */
.app-shell::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    /* Neural network glow - top center */
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(147, 197, 253, 0.5) 0%, transparent 50%),
    /* Synapse glow - right */
    radial-gradient(ellipse 60% 60% at 100% 25%, rgba(96, 165, 250, 0.3) 0%, transparent 50%),
    /* Cognition glow - left bottom */
    radial-gradient(ellipse 70% 50% at 0% 80%, rgba(6, 182, 212, 0.25) 0%, transparent 50%),
    /* Center soft ambient */
    radial-gradient(ellipse 100% 80% at 50% 50%, rgba(240, 248, 255, 0.6) 0%, transparent 70%),
    /* Base gradient - lighter sky blue */
    linear-gradient(180deg, #F8FBFF 0%, #EEF6FF 30%, #DBEAFE 70%, #BFDBFE 100%);
  pointer-events: none;
}

/* Technology circuit/neural pattern overlay - Light theme */
.app-shell::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    /* Neural nodes scattered across */
    radial-gradient(circle 3px at 15% 20%, rgba(59, 130, 246, 0.15) 0%, transparent 100%),
    radial-gradient(circle 3px at 85% 25%, rgba(59, 130, 246, 0.12) 0%, transparent 100%),
    radial-gradient(circle 3px at 30% 55%, rgba(59, 130, 246, 0.1) 0%, transparent 100%),
    radial-gradient(circle 3px at 75% 70%, rgba(59, 130, 246, 0.12) 0%, transparent 100%),
    radial-gradient(circle 3px at 50% 85%, rgba(6, 182, 212, 0.1) 0%, transparent 100%),
    radial-gradient(circle 3px at 5% 75%, rgba(6, 182, 212, 0.08) 0%, transparent 100%),
    radial-gradient(circle 3px at 95% 80%, rgba(59, 130, 246, 0.1) 0%, transparent 100%),
    /* Subtle circuit grid */
    linear-gradient(rgba(59, 130, 246, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59, 130, 246, 0.04) 1px, transparent 1px),
    /* Hexagon-like tech pattern (very subtle) */
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5L52 17.5v25L30 55 8 42.5v-25L30 5z' fill='none' stroke='rgba(59,130,246,0.03)' stroke-width='1'/%3E%3C/svg%3E");
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 60px 60px, 60px 60px, 60px 60px;
  pointer-events: none;
}

/* Remove noise texture */
.app-shell .noise-overlay {
  display: none;
}

/* ============================================
   4. SIDEBAR
   ============================================ */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(248, 251, 255, 0.95) 50%, rgba(238, 246, 255, 0.92) 100%);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-base);
  position: relative;
  z-index: var(--z-sticky);
  box-shadow: 2px 0 12px rgba(59, 130, 246, 0.08);
  backdrop-filter: blur(12px);
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

/* Sidebar Header with Logo */
.sidebar-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-height);
  background: var(--bg-panel);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}

.logo-icon img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.logo-icon-fallback {
  font-size: var(--text-md);
  font-weight: var(--font-bold);
  color: white;
  text-transform: uppercase;
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}

.logo-env-tag {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--accent-primary-muted);
  color: var(--accent-primary);
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .session-content,
.sidebar.collapsed .sidebar-status-details {
  display: none;
}

/* Sidebar Search */
.sidebar-search {
  padding: var(--space-3) var(--space-4);
}

.search-input-wrapper {
  position: relative;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-8);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

/* Session List */
.sessions-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sessions-header {
  padding: var(--space-3) var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sessions-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-2) var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: var(--border-emphasis) transparent;
}

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

.sessions-list::-webkit-scrollbar-track {
  background: transparent;
}

.sessions-list::-webkit-scrollbar-thumb {
  background: var(--border-emphasis);
  border-radius: var(--radius-full);
}

/* Session Item */
.session-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-1);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.session-item:hover {
  background: var(--bg-deep);
  border-color: var(--border-default);
}

.session-item.active {
  background: var(--accent-primary-muted);
  border-color: var(--accent-primary);
  border-left: 3px solid var(--accent-primary);
}

.session-item.pinned {
  border-left: 3px solid var(--color-success);
}

.session-checkbox {
  display: none;
  margin-top: 2px;
  accent-color: var(--accent-primary);
}

.selection-mode .session-checkbox {
  display: block;
}

.session-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.session-title {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: var(--space-1);
}

.session-item.pinned .session-title::before {
  content: '\uD83D\uDCCC ';
  font-size: var(--text-xs);
}

.session-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.session-meta-dot {
  width: 3px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
}

.session-actions {
  display: none;
  gap: var(--space-1);
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
}

.session-item:hover .session-actions {
  display: flex;
}

.session-action-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: 1;
  transition: all var(--transition-fast);
}

.session-action-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-emphasis);
}

/* Batch Actions */
.batch-actions {
  padding: var(--space-2) var(--space-4);
  background: var(--bg-surface);
  display: none;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.batch-actions.show {
  display: flex;
}

.batch-count {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* New Chat Button */
.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--accent-primary);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
  background: var(--accent-primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.sidebar.collapsed .new-chat-btn span {
  display: none;
}

/* Sidebar Status */
.sidebar-status {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-default);
  background: var(--bg-deep);
}

.sidebar-status-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-success);
  flex-shrink: 0;
  animation: pulse-dot 2s infinite;
}

.status-indicator.offline {
  background: var(--color-error);
  animation: none;
}

.status-indicator.warning {
  background: var(--color-warning);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.sidebar-status-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.status-value {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: var(--font-medium);
}

/* ============================================
   5. MAIN CONTENT AREA
   ============================================ */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.breadcrumb-separator {
  color: var(--text-muted);
}

.breadcrumb-current {
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Token Meter */
.token-meter {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-deep);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.token-meter-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.token-meter-value {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.token-meter-bar {
  width: 60px;
  height: 4px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.token-meter-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

.token-meter-fill.warning {
  background: var(--color-warning);
}

/* User Menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-inverse);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.user-name {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-logout:hover {
  background: var(--color-error-light);
  border-color: var(--color-error);
  color: var(--color-error);
}

/* ============================================
   6. CONVERSATION AREA
   ============================================ */

.conversation-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Mode Toolbar */
.mode-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-default);
  overflow-x: auto;
  scrollbar-width: none;
}

.mode-toolbar::-webkit-scrollbar {
  display: none;
}

/* Toggle Pills */
.toggle-pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  background: var(--bg-deep);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.toggle-pill:hover {
  background: var(--bg-panel);
  border-color: var(--border-emphasis);
}

.toggle-pill.active {
  background: var(--accent-primary-muted);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.toggle-pill.ghia.active {
  background: var(--color-success-muted);
  border-color: var(--color-success);
  color: var(--color-success);
}

.toggle-pill.enhanced.active {
  background: var(--accent-secondary-muted);
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
}

.toggle-pill input[type="checkbox"] {
  display: none;
}

.toggle-pill-icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-pill-indicator {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  opacity: 0.5;
}

.toggle-pill.active .toggle-pill-indicator {
  opacity: 1;
}

/* Status Pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  background: var(--bg-deep);
  color: var(--text-tertiary);
  border: 1px solid var(--border-default);
}

.status-pill.online {
  background: var(--color-success-light);
  color: var(--color-success);
  border-color: var(--color-success);
}

.status-pill.offline {
  background: var(--color-error-light);
  color: var(--color-error);
  border-color: var(--color-error);
}

.status-pill-dot {
  width: 5px;
  height: 5px;
  border-radius: var(--radius-full);
  background: currentColor;
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  scrollbar-width: thin;
  scrollbar-color: var(--border-emphasis) transparent;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border-emphasis);
  border-radius: var(--radius-full);
}

.messages-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Message Card */
.message-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  background: var(--bg-panel);
  transition: all var(--transition-fast);
  animation: messageSlideIn 0.3s ease-out;
  box-shadow: var(--shadow-sm);
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-card:hover {
  border-color: var(--border-emphasis);
  box-shadow: var(--shadow-md);
}

.message-card.user {
  background: var(--accent-primary-muted);
  border-color: var(--accent-primary);
  margin-left: var(--space-8);
}

.message-card.assistant {
  background: var(--bg-panel);
  margin-right: var(--space-8);
}

.message-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.message-role {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-tertiary);
}

.message-card.user .message-role {
  color: var(--accent-primary);
}

.message-card.assistant .message-role {
  color: var(--accent-secondary);
}

.message-timestamp {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.message-content {
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.message-content p {
  margin-bottom: var(--space-3);
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content code {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  background: var(--bg-deep);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--accent-primary);
}

.message-content pre {
  background: #1E293B;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  margin: var(--space-3) 0;
}

.message-content pre code {
  background: none;
  padding: 0;
  font-size: var(--text-sm);
  color: #E2E8F0;
}

.message-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-default);
}

.message-action-btn {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.message-action-btn:hover {
  background: var(--bg-deep);
  color: var(--text-primary);
  border-color: var(--border-emphasis);
}

.message-action-btn.copied {
  color: var(--color-success);
  border-color: var(--color-success);
}

/* ============================================
   7. COMPOSER / INPUT AREA
   ============================================ */

.composer-wrapper {
  padding: var(--space-4) var(--space-6) var(--space-6);
  background: var(--bg-base);
}

.composer {
  max-width: var(--composer-max-width);
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-3);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast);
}

.composer:focus-within {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-lg), var(--shadow-focus);
}

.composer-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-deep);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.file-preview-item img {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.file-preview-item .remove-file {
  background: none;
  border: none;
  color: var(--color-error);
  cursor: pointer;
  padding: 2px;
  line-height: 1;
}

.composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
}

.composer-textarea {
  flex: 1;
  min-height: 48px;
  max-height: 200px;
  padding: var(--space-3);
  background: var(--bg-deep);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  resize: none;
  transition: all var(--transition-fast);
}

.composer-textarea::placeholder {
  color: var(--text-muted);
}

.composer-textarea:focus {
  outline: none;
  background: var(--bg-panel);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-focus);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.composer-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-deep);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.composer-btn:hover {
  background: var(--bg-panel);
  color: var(--text-primary);
  border-color: var(--border-emphasis);
}

.composer-btn.primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-inverse);
}

.composer-btn.primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.composer-btn.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.composer-btn.recording {
  background: var(--color-error);
  border-color: var(--color-error);
  color: white;
  animation: pulse-recording 1.5s infinite;
}

@keyframes pulse-recording {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.composer-btn svg,
.composer-btn .icon {
  width: 18px;
  height: 18px;
}

/* ============================================
   8. RIGHT PANEL (INSIGHTS)
   ============================================ */

.insights-panel {
  width: var(--panel-width);
  height: 100vh;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.insights-panel.collapsed {
  width: 0;
  border-left: none;
  overflow: hidden;
}

.insights-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-height);
}

.insights-title {
  font-size: var(--text-md);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.insights-close-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.insights-close-btn:hover {
  background: var(--bg-deep);
  color: var(--text-primary);
}

.insights-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-default);
}

.insights-tab {
  flex: 1;
  padding: var(--space-3);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.insights-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-deep);
}

.insights-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.insights-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

/* ============================================
   9. UTILITY CLASSES
   ============================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }

.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent-primary); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }

/* ============================================
   10. RESPONSIVE
   ============================================ */

@media (max-width: 1280px) {
  .insights-panel {
    display: none;
  }
}

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 260px;
  }

  .message-card.user {
    margin-left: var(--space-4);
  }

  .message-card.assistant {
    margin-right: var(--space-4);
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: var(--z-overlay);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-overlay) - 1);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
  }

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

  .topbar {
    padding: 0 var(--space-4);
  }

  .mode-toolbar {
    padding: var(--space-3) var(--space-4);
  }

  .messages-container {
    padding: var(--space-4);
  }

  .composer-wrapper {
    padding: var(--space-3) var(--space-4) var(--space-4);
  }

  .message-card.user,
  .message-card.assistant {
    margin-left: 0;
    margin-right: 0;
  }

  .token-meter {
    display: none;
  }

  .user-name {
    display: none;
  }
}

/* ============================================
   11. ANIMATIONS
   ============================================ */

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

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.animate-fade-in {
  animation: fadeIn var(--transition-base) ease-out;
}

.animate-slide-in-left {
  animation: slideInLeft var(--transition-base) ease-out;
}

.animate-slide-in-up {
  animation: slideInUp var(--transition-base) ease-out;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ============================================
   12. FOCUS STATES (Accessibility)
   ============================================ */

*:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ============================================
   13. LOADING STATES
   ============================================ */

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-deep) 0%, var(--bg-base) 50%, var(--bg-deep) 100%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   14. SCROLLBAR STYLES
   ============================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--border-emphasis);
  border-radius: var(--radius-full);
}

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

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-emphasis) var(--bg-base);
}

/* ============================================
   15. THEME TOGGLE
   ============================================ */

.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.theme-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-emphasis);
  color: var(--text-primary);
}

.theme-toggle-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle .sun-icon {
  display: block;
}

.theme-toggle .moon-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: block;
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-default);
  z-index: var(--z-modal);
  transform: translateX(100%);
  transition: transform var(--transition-base);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-elevated);
}

.settings-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.settings-close-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xl);
  line-height: 1;
  transition: all var(--transition-fast);
}

.settings-close-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

.settings-section {
  margin-bottom: var(--space-6);
}

.settings-section-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-3);
}

.settings-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}

.settings-option-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-option-label {
  font-size: var(--text-md);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.settings-option-description {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.toggle-switch.active {
  background: var(--accent-primary);
}

.toggle-switch-handle {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: var(--radius-full);
  transition: transform var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.toggle-switch.active .toggle-switch-handle {
  transform: translateX(20px);
}

/* Settings overlay */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-modal) - 1);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.settings-overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* Quick theme toggle button for header */
.quick-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
}

.quick-theme-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-emphasis);
  color: var(--accent-primary);
}

.quick-theme-toggle svg {
  width: 18px;
  height: 18px;
}

.quick-theme-toggle .sun-icon {
  display: block;
}

.quick-theme-toggle .moon-icon {
  display: none;
}

[data-theme="dark"] .quick-theme-toggle .sun-icon {
  display: none;
}

[data-theme="dark"] .quick-theme-toggle .moon-icon {
  display: block;
}
