/* ── Harmonious & Calming Color Palette ── */
:root {
  /* Deep dark backgrounds (unchanged) */
  --bg: #212121e6;
  --panel: #1a1a1f;
  --surface: #25252e;
  --surface-hover: #2f2f38;
  --text: #e0e0e0;
  --text-secondary: #a0a0ad;
  
  /* Harmonious, desaturated accents */
  --accent: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  --accent-hover: linear-gradient(135deg, #4a78e6 0%, #6d7f98 100%);
  --accent-glow: rgba(82, 133, 255, 0.12);
  --accent-secondary: linear-gradient(135deg, #5e91ff 0%, #8a9bb5 100%);
  
  /* Calming status colors */
  --danger: #8b6c6c;
  --danger-hover: #7a5e5e;
  --danger-glow: rgba(139, 108, 108, 0.15);
  --success: #6c8b7a;
  --success-glow: rgba(108, 139, 122, 0.15);
  
  /* Subtle borders */
  --border: #353542;
  --border-light: #42424f;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.35), inset 2px 2px 4px rgba(0,0,0,0.15);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.4), inset 3px 3px 6px rgba(0,0,0,0.2);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.45), inset 4px 4px 8px rgba(0,0,0,0.25);
  --shadow-glow: 0 0 12px rgba(82, 133, 255, 0.12);
  
  /* Rounded corners */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  
  /* Layout dimensions */
  --sidebar-width: 280px;
  --header-height: 56px;
  
  /* Smooth transitions */
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Light Theme ── */
body.light-theme {
  /* Light backgrounds */
  --bg: #f5f5f7;
  --panel: #ffffff;
  --surface: #e8e8ed;
  --surface-hover: #d8d8e0;
  --text: #1a1a2e;
  --text-secondary: #5a5a6e;
  
  /* Light accent gradients */
  --accent: linear-gradient(135deg, #5285ff 0%, #6a8fa8 100%);
  --accent-hover: linear-gradient(135deg, #4a78e6 0%, #5d7d92 100%);
  --accent-glow: rgba(82, 133, 255, 0.08);
  --accent-secondary: linear-gradient(135deg, #5e91ff 0%, #7a95a5 100%);
  
  /* Light status colors */
  --danger: #c47070;
  --danger-hover: #b06060;
  --danger-glow: rgba(196, 112, 112, 0.1);
  --success: #5a9a7a;
  --success-glow: rgba(90, 154, 122, 0.1);
  
  /* Light borders */
  --border: #d0d0da;
  --border-light: #c5c5d0;
  
  /* Light shadows */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.08), inset 1px 1px 2px rgba(255,255,255,0.8);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.1), inset 1px 1px 3px rgba(255,255,255,0.6);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.12), inset 1px 1px 4px rgba(255,255,255,0.5);
  --shadow-glow: 0 0 12px rgba(82, 133, 255, 0.08);
}

/* Light theme background mesh */
body.light-theme .bg-mesh::before {
  background-color: #f5f5f7;
  background-image: 
    linear-gradient(rgba(82, 133, 255, 0.01) 1px, transparent 1px),
    linear-gradient(90deg, rgba(82, 133, 255, 0.01) 1px, transparent 1px);
}

/* Light theme app gradient overlay */
body.light-theme .app::before {
  background-image: radial-gradient(circle at 20% 20%, rgba(82, 133, 255, 0.03), transparent 40%),
                   radial-gradient(circle at 80% 80%, rgba(122, 139, 163, 0.03), transparent 40%);
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
  margin: 0;
  padding: 0;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle background mesh */
.bg-mesh::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #020204;
  background-image: 
    linear-gradient(rgba(82, 133, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(82, 133, 255, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: -1;
}
.app { position: relative; }
.app::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 20% 20%, rgba(82, 133, 255, 0.05), transparent 40%),
                   radial-gradient(circle at 80% 80%, rgba(122, 139, 163, 0.05), transparent 40%);
  z-index: -1;
}

/* Streaming text shimmer effect */
@keyframes shimmer {
  0% { background-position: -100% 50%; }
  100% { background-position: 200% 50%; }
}

@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

@keyframes scanlineSweep {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

/* Streaming Effects (Softened) */
@keyframes textShimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

/* Streaming text shimmer effect */
.role-assistant .msg-content.streaming {
  animation: shimmer 2s linear infinite;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(82, 133, 255, 0.12) 50%, 
    transparent 100%);
  background-size: 200% 100%;
  cursor: text;
  position: relative;
}

.role-assistant .msg-content.streaming::after {
  content: '';
  display: inline-block;
  width: 3px;
  height: 1em;
  margin-left: 2px;
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  vertical-align: middle;
  animation: cursorBlink 1s step-end infinite;
}

/* Subtle scanline effect for modern feel */
.scanline-effect {
  position: relative;
  overflow: hidden;
}
.scanline-effect::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(82, 133, 255, 0.2), transparent);
  animation: scanlineSweep 4s linear infinite;
  pointer-events: none;
}

/* Theme Toggle Button */
.btn-toggle-theme {
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  border: 2px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-family: inherit;
}
.btn-toggle-theme:hover {
  color: #fff;
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  border-color: transparent;
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.18);
}

/* ── Modern Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { 
  background: var(--panel); 
  border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb { 
  background: linear-gradient(180deg, var(--surface), var(--surface-hover));
  border: 2px solid var(--bg);
  border-radius: var(--radius-sm);
  box-shadow: 0 0 4px rgba(82, 133, 255, 0.12);
  transition: all var(--transition);
}
::-webkit-scrollbar-thumb:hover { 
  background: linear-gradient(180deg, var(--surface-hover), var(--surface));
  box-shadow: 0 0 6px rgba(82, 133, 255, 0.2);
}
::-webkit-scrollbar-button { display: none; }

/* ── Layout ── */
.app { 
  display: flex; 
  height: 100dvh;
  border: 2px solid var(--border);
  box-shadow: var(--shadow-md);
  background: var(--bg);
  position: relative;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--panel);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition), opacity var(--transition);
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.sidebar.collapsed { transform: translateX(-100%); position: absolute; height: 100%; opacity: 0; pointer-events: none; }

.sidebar-header {
  padding: 12px;
  border-bottom: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.sidebar-brand .logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
  box-shadow: inset 2px 2px 4px rgba(255,255,255,0.1), 0 0 8px rgba(82, 133, 255, 0.2);
  transition: all var(--transition);
}
.sidebar-brand:hover .logo {
  box-shadow: inset 2px 2px 4px rgba(255,255,255,0.15), 0 0 12px rgba(82, 133, 255, 0.3);
}

.btn-new-chat {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
  text-transform: uppercase;
  background-clip: padding-box;
}
.btn-new-chat:hover { 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 12px rgba(82, 133, 255, 0.25), inset 0 0 12px rgba(82, 133, 255, 0.1);
}
.btn-new-chat:active {
  transform: scale(0.97);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
  background: radial-gradient(circle at top left, rgba(82, 133, 255, 0.03), transparent 60%),
              radial-gradient(circle at bottom right, rgba(122, 139, 163, 0.03), transparent 60%);
}
.sidebar-section-label {
  padding: 6px 8px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5285ff;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  border-bottom: 1px solid var(--border);
  text-shadow: 0 0 4px rgba(82, 133, 255, 0.2);
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  border: 1px solid transparent;
  background: var(--panel);
}
.conv-item:hover { 
  background: linear-gradient(to bottom, var(--surface-hover), var(--surface));
  border: 1px solid rgba(82, 133, 255, 0.3);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2), inset 2px 2px 4px rgba(0,0,0,0.2);
}
.conv-item.active { 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 0 12px rgba(82, 133, 255, 0.2), inset 2px 2px 4px rgba(0,0,0,0.2);
}
.conv-item .conv-icon { color: var(--text-secondary); font-size: 14px; flex-shrink: 0; }
.conv-item .conv-title {
  flex: 1; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 600;
  transition: all var(--transition);
}
.conv-item:hover .conv-title { color: #fff; }
.conv-item .conv-actions {
  display: none; gap: 2px; flex-shrink: 0;
}
.conv-item:hover .conv-actions, .conv-item.active .conv-actions { display: flex; }
.conv-action-btn {
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  padding: 4px; border-radius: 4px; font-size: 11px; transition: all var(--transition);
  font-family: inherit;
}
.conv-action-btn:hover { 
  color: #fff; 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  box-shadow: 0 0 4px rgba(82, 133, 255, 0.15);
}
.conv-action-btn.danger:hover { color: var(--danger); }

.sidebar-footer {
  padding: 10px 12px;
  border-top: 2px solid var(--border);
  background: linear-gradient(to bottom, var(--surface), var(--panel));
}
.mode-select {
  width: 100%;
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  text-transform: uppercase;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235285ff' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
  transition: all var(--transition);
}
.mode-select:hover {
  border-color: rgba(82, 133, 255, 0.6);
  box-shadow: 0 0 4px rgba(82, 133, 255, 0.15);
}
.mode-select:focus {
  outline: none;
  border-color: rgba(82, 133, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(82, 133, 255, 0.1), inset 2px 2px 4px rgba(0,0,0,0.2);
}

/* ── Main Area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg);
}

/* ── Header ── */
.main-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
  gap: 10px;
  flex-shrink: 0;
}
.btn-toggle-sidebar {
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  border: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer; font-size: 18px; padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-family: inherit;
}
.btn-toggle-sidebar:hover { 
  color: #fff; 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.18);
}

.header-title {
  flex: 1; 
  font-size: 14px; 
  font-weight: 700;
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #5285ff;
  text-shadow: 0 0 4px rgba(82, 133, 255, 0.15);
}

.status-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  border: 2px solid var(--border);
  text-transform: uppercase;
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
}
.status-dot {
  width: 8px; height: 8px; 
  border-radius: 4px;
  background: var(--success);
  box-shadow: 0 0 4px var(--success);
  transition: all var(--transition);
}
.status-badge.thinking .status-dot {
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  box-shadow: 0 0 6px rgba(82, 133, 255, 0.25);
}
.status-badge.thinking .status-label {
  font-weight: 700;
}

/* ── Messages ── */
.messages {
  flex: 1; 
  overflow-y: auto; 
  padding: 20px 16px;
  scroll-behavior: smooth;
  background: radial-gradient(circle at center, rgba(82, 133, 255, 0.02), transparent 70%);
}
.messages-inner {
  max-width: 780px;
  margin: 0 auto;
}

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; padding: 40px;
  background: radial-gradient(circle at center, rgba(82, 133, 255, 0.03), transparent 70%);
}
.empty-state .empty-icon {
  font-size: 48px; margin-bottom: 16px;
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  -webkit-background-clip: text; 
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 8px rgba(82, 133, 255, 0.2);
}
.empty-state h2 { 
  font-size: 22px; 
  font-weight: 700; 
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #5285ff;
  text-shadow: 0 0 6px rgba(82, 133, 255, 0.15);
}
.empty-state p { 
  color: var(--text-secondary); 
  font-size: 14px; 
  max-width: 400px;
  font-family: inherit;
}

/* Bubbles */
.bubble { 
  margin-bottom: 20px; 
  animation: fadeInUp 300ms ease-out;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble .msg-wrapper {
  display: flex; gap: 12px; align-items: flex-start;
}

/* Hide avatar icons in message bubbles */
.bubble .msg-wrapper .avatar {
  display: none !important;
}

.bubble .msg {
  flex: 1;
  min-width: 0;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 17px;
  line-height: 1.75;
  position: relative;
  font-family: inherit;
}

.role-user .msg {
  background: #323232d9;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2), inset 2px 2px 4px rgba(0,0,0,0.1);
  margin-right: auto;
  text-align: right;
}

.role-assistant .msg {
  background: transparent;
  padding-left: 0;
  text-align: left;
}

.role-assistant .msg .msg-content { padding: 0 4px; }

/* Message streaming effects */
.role-assistant .msg-content {
  position: relative;
}
.role-assistant .msg-content::selection {
  background: rgba(82, 133, 255, 0.3);
}

/* Message content styling */
.msg p { margin: 0 0 0.5em; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0.3em 0 0.3em 1.4em; padding: 0; }
.msg li { margin: 0.15em 0; }
.msg blockquote {
  border-left: 4px solid rgba(82, 133, 255, 0.4);
  margin: 0.5em 0; 
  padding: 0.3em 0.8em;
  color: var(--text-secondary);
  background: rgba(82, 133, 255, 0.03);
  border-radius: 0 6px 6px 0;
}
/* ── Syntax Highlighting Fixes ── */
.msg pre {
  background: #0d0d12;
  border: 1px solid rgba(82, 133, 255, 0.2);
  padding: 12px; 
  border-radius: var(--radius-sm);
  overflow-x: auto; 
  margin: 0.5em 0;
  font-size: 14px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.25);
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  line-height: 1.5;
  text-align: left;
}
.msg pre code {
  background: none;
  padding: 0;
  border: none;
  color: inherit;
  font-size: inherit;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  line-height: inherit;
  white-space: pre;
  box-shadow: none;
}
/* Ensure highlight.js theme colors are preserved */
.msg pre .hljs {
  color: #d6deeb;
}
.msg pre .hljs-keyword {
  color: #c678dd;
}
.msg pre .hljs-function {
  color: #61afef;
}
.msg pre .hljs-string {
  color: #98c379;
}
.msg pre .hljs-number,
.msg pre .hljs-literal,
.msg pre .hljs-variable,
.msg pre .hljs-template-variable,
.msg pre .hljs-attribute {
  color: #d19a66;
}
.msg pre .hljs-comment {
  color: #5c6370;
  font-style: italic;
}
.msg pre .hljs-doctag {
  color: #5c6370;
}
.msg pre .hljs-title {
  color: #61afef;
}
.msg pre .hljs-tag {
  color: #e06c6b;
}
.msg pre .hljs-name {
  color: #e06c6b;
}
.msg pre .hljs-attr {
  color: #e06c6b;
}
.msg pre .hljs-boolean {
  color: #c678dd;
}
.msg pre .hljs-regexp {
  color: #98c379;
}
.msg pre .hljs-symbol,
.msg pre .hljs-builtin {
  color: #56b6c2;
}
.msg pre .hljs-bullet {
  color: #56b6c2;
}
.msg pre .hljs-addition {
  color: #98c379;
}
.msg pre .hljs-deletion {
  color: #e06c6b;
}
.msg pre .hljs-link {
  color: #61afef;
}
.msg pre .hljs-quote {
  color: #5c6370;
}

.msg code {
  background: rgba(82, 133, 255, 0.05);
  padding: 2px 6px; 
  border-radius: 4px;
  font-size: 14px;
  border: 1px solid rgba(82, 133, 255, 0.15);
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
}
.msg table { 
  border-collapse: collapse; 
  margin: 0.5em 0; 
  width: 100%; 
  border: 1px solid rgba(82, 133, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
}
.msg th, .msg td { 
  border: 1px solid rgba(82, 133, 255, 0.15); 
  padding: 8px 10px; 
  text-align: left; 
  font-size: 12px;
  font-family: inherit;
}
.msg th { 
  background: linear-gradient(to bottom, rgba(82, 133, 255, 0.08), rgba(0, 0, 0, 0.4));
  font-weight: 700;
}
.msg td { 
  background: rgba(0, 0, 0, 0.18);
}
.msg a { 
  color: #5285ff; 
  text-decoration: none;
  font-weight: 700;
  transition: all var(--transition);
}
.msg a:hover { 
  text-decoration: underline;
  color: #7a8ba3;
  text-shadow: 0 0 4px rgba(82, 133, 255, 0.15);
}

.copy-btn {
  position: absolute; 
  top: 8px; 
  right: 8px;
  z-index: 10;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  border: 1px solid rgba(82, 133, 255, 0.2);
  color: var(--text-secondary); 
  border-radius: var(--radius-sm);
  padding: 4px 8px; 
  cursor: pointer; 
  font-size: 10px;
  font-family: inherit;
  opacity: 0; 
  transition: opacity var(--transition), transform var(--transition);
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
  text-transform: uppercase;
}
.msg:hover .copy-btn { opacity: 1; }
.copy-btn:hover { 
  color: #fff; 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  border-color: transparent;
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.25);
  transform: translateY(-1px);
}

/* ── Code Block Copy Button ── */
.code-block {
  position: relative;
}
.code-block .code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 11;
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  border: 1px solid rgba(82, 133, 255, 0.2);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
  text-transform: uppercase;
  pointer-events: none;
}
/* Code block copy button - sticky mode (fixed to viewport below header) */
.code-block .code-copy-btn.sticky {
  position: fixed;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 1;
  pointer-events: auto;
  transition: opacity var(--transition), box-shadow var(--transition);
}
.code-block:hover .code-copy-btn {
  opacity: 1;
  pointer-events: auto;
}
.code-block .code-copy-btn:hover {
  color: #fff;
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  border-color: transparent;
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.25);
  transform: translateY(-1px);
}
.code-block .code-copy-btn.copied {
  color: #6c8b7a;
  border-color: rgba(108, 139, 122, 0.4);
  background: linear-gradient(to bottom, var(--panel), var(--surface));
}

/* ── Composer ── */
.composer {
  flex-shrink: 0;
  padding: 16px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  border-top: 2px solid var(--border);
}
.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  position: relative;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  border: 2px solid rgba(82, 133, 255, 0.2);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 18px;
  transition: all var(--transition);
  box-shadow: inset 3px 3px 6px rgba(0,0,0,0.2);
}
.composer-inner:focus-within {
  border-color: rgba(82, 133, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(82, 133, 255, 0.15), inset 2px 2px 4px rgba(0,0,0,0.2);
}

.composer textarea {
  flex: 1;
  background: none; 
  color: var(--text);
  border: none; 
  outline: none;
  font-size: 14px; 
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  min-height: 24px;
  padding: 6px 0;
  font-weight: 600;
}
.composer textarea::placeholder { 
  color: var(--text-secondary);
  opacity: 0.7;
}

.btn-send {
  width: 38px; height: 38px;
  border: 2px solid rgba(82, 133, 255, 0.2);
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  color: #5285ff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
}
.btn-send:hover { 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff;
  transform: scale(1.05);
  box-shadow: 0 0 10px rgba(82, 133, 255, 0.22);
}
.btn-send:disabled { 
  opacity: 0.4; 
  cursor: not-allowed; 
  transform: none;
}

.btn-send[data-state="stop"] {
  background: linear-gradient(to bottom, var(--danger), var(--danger-hover));
  color: #fff;
  border-color: rgba(139, 108, 108, 0.3);
  animation: pulseStop 1s ease-in-out infinite;
}

.btn-send[data-state="stop"]:hover {
  background: linear-gradient(135deg, #8b6c6c 0%, #c0392b 100%);
  border-color: rgba(192, 57, 43, 0.3);
  box-shadow: 0 0 12px rgba(192, 57, 43, 0.25);
}

@keyframes pulseStop {
  0%, 100% { box-shadow: 0 0 6px rgba(192, 57, 43, 0.15); }
  50% { box-shadow: 0 0 14px rgba(192, 57, 43, 0.35); }
}

/* ── HTML Editor Panel ── */
.editor-panel {
  display: none;
  flex-direction: column;
  width: 500px; 
  min-width: 300px; 
  max-width: 50vw;
  border-left: 2px solid rgba(82, 133, 255, 0.2);
  background: linear-gradient(to bottom, var(--panel), var(--bg));
  box-shadow: inset 4px 0 8px rgba(0,0,0,0.3);
}
.editor-panel.visible { display: flex; }

.editor-panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 2px solid rgba(82, 133, 255, 0.2);
  font-size: 13px; 
  font-weight: 700;
  text-transform: uppercase;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  color: #5285ff;
}
.editor-panel-header .btn-close-editor {
  margin-left: auto;
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  cursor: pointer; 
  font-size: 16px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.editor-panel-header .btn-close-editor:hover {
  color: var(--danger);
  background: linear-gradient(135deg, rgba(139, 108, 108, 0.1), rgba(139, 108, 108, 0.05));
}

.editor-wrapper { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  overflow: hidden; 
}
.editor-code {
  flex: 1; 
  margin: 0;
  border: none; 
  border-bottom: 1px solid rgba(82, 133, 255, 0.2);
  padding: 12px; 
  overflow: auto;
  font-size: 14px; 
  background: var(--bg);
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  color: #e0e0e8;
}
.editor-resizer {
  height: 6px; 
  background: linear-gradient(to right, var(--border), rgba(82, 133, 255, 0.3), var(--border));
  cursor: row-resize; 
  flex-shrink: 0;
}
.editor-preview {
  flex: 1; 
  border: none; 
  background: #fff;
}
.editor-toolbar {
  display: flex; 
  gap: 6px; 
  padding: 10px 16px;
  border-top: 2px solid rgba(82, 133, 255, 0.2);
  align-items: center;
  background: linear-gradient(to bottom, var(--surface), var(--panel));
}
.editor-toolbar button {
  padding: 6px 12px; 
  font-size: 11px;
  background: linear-gradient(to bottom, var(--panel), var(--surface)); 
  border: 2px solid rgba(82, 133, 255, 0.2);
  color: var(--text); 
  border-radius: var(--radius-sm);
  cursor: pointer; 
  transition: all var(--transition);
  font-family: inherit;
  font-weight: 600;
  text-transform: uppercase;
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
}
.editor-toolbar button:hover { 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 6px rgba(82, 133, 255, 0.2);
}
.editor-toolbar button.active { 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.25);
}

/* ── Panel Resizer ── */
.panel-resizer {
  width: 6px; 
  cursor: col-resize;
  background: linear-gradient(to bottom, var(--border), rgba(82, 133, 255, 0.3), var(--border));
  flex-shrink: 0;
  transition: all var(--transition);
}
.panel-resizer:hover { 
  background: linear-gradient(180deg, #5285ff, #7a8ba3);
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.35);
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; 
    top: 0; 
    left: 0; 
    height: 100%;
    box-shadow: 0 0 16px rgba(0,0,0,0.5);
    background: var(--bg);
  }
  .sidebar.collapsed { transform: translateX(-100%); }
  .sidebar-overlay {
    display: none; 
    position: fixed; 
    inset: 0;
    background: rgba(0,0,0,.8); 
    z-index: 99;
    background: linear-gradient(90deg, rgba(0,0,0,0.95), rgba(0,0,0,0.7));
  }
  .sidebar-overlay.visible { display: block; }
  .editor-panel { display: none !important; }
  .main-header { padding: 0 10px; }
  .messages { padding: 16px 12px; }
  .composer { padding: 12px; }
  .composer-inner { padding: 6px 6px 6px 14px; }
}

/* ── Rename dialog ── */
.rename-dialog {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fadeIn 200ms ease-out;
  background: linear-gradient(180deg, rgba(0,0,0,0.92), rgba(0,0,0,0.75));
}
@keyframes fadeIn { 
  from { opacity: 0; } 
  to { opacity: 1; } 
}
.rename-dialog-box {
  background: linear-gradient(to bottom, var(--surface), var(--panel));
  border: 2px solid rgba(82, 133, 255, 0.3);
  border-radius: var(--radius-md);
  padding: 24px;
  width: 380px; 
  max-width: 90vw;
  box-shadow: 0 16px 32px rgba(0,0,0,0.6), 0 0 24px rgba(82, 133, 255, 0.12);
  position: relative;
  overflow: hidden;
}
.rename-dialog-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: var(--radius-md);
  border: 1px solid rgba(82, 133, 255, 0.2);
  pointer-events: none;
  background: linear-gradient(135deg, rgba(82, 133, 255, 0.05), transparent 50%);
}
.rename-dialog-box h3 { 
  margin-bottom: 12px; 
  font-size: 16px; 
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #5285ff;
  text-shadow: 0 0 4px rgba(82, 133, 255, 0.15);
}
.rename-dialog-box input {
  width: 100%; 
  padding: 10px 12px;
  background: var(--bg); 
  border: 2px solid rgba(82, 133, 255, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text); 
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  outline: none;
  text-transform: uppercase;
  transition: all var(--transition);
}
.rename-dialog-box input:focus { 
  border-color: rgba(82, 133, 255, 0.8);
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.25);
}
.rename-dialog-actions {
  display: flex; 
  gap: 8px; 
  justify-content: flex-end; 
  margin-top: 16px;
}
.rename-dialog-actions button {
  padding: 8px 16px; 
  border-radius: var(--radius-sm);
  border: 2px solid rgba(82, 133, 255, 0.2); 
  cursor: pointer;
  font-size: 12px; 
  font-weight: 600;
  font-family: inherit;
  transition: all var(--transition);
  text-transform: uppercase;
}
.rename-dialog-actions .btn-cancel { 
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  color: var(--text);
}
.rename-dialog-actions .btn-cancel:hover { 
  background: linear-gradient(135deg, rgba(82, 133, 255, 0.1), rgba(122, 139, 163, 0.05));
  border-color: rgba(82, 133, 255, 0.5);
}
.rename-dialog-actions .btn-confirm { 
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff; 
  border-color: transparent;
  box-shadow: 0 0 8px rgba(82, 133, 255, 0.25);
}
.rename-dialog-actions .btn-confirm:hover { 
  box-shadow: 0 0 12px rgba(82, 133, 255, 0.35);
}

/* ── Thinking Dots Placeholder ── */
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
}
.thinking-dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  box-shadow: 0 0 6px rgba(82, 133, 255, 0.25);
  animation: dotPulse 1.4s infinite ease-in-out;
}
.thinking-dots .dot:nth-child(1) { animation-delay: 0s; }
.thinking-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% {
    transform: scale(0.55);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── Gear Spin Animation (Active Tool Indicator) ── */
@keyframes gearSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.tool-section summary i.fa-gear.spinning {
  animation: gearSpin 1s linear infinite;
  display: inline-block;
}

.image-attachments {
  position: absolute;
  bottom: 100%;
  left: 18px;
  right: 56px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  pointer-events: none;
}

.image-attachments:empty {
  margin-bottom: 0;
}

.attachment-chip {
  position: relative;
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(82, 133, 255, 0.3);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 200ms ease-out;
  flex-shrink: 0;
}

.attachment-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment-chip .attachment-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #5285ff;
}

.attachment-chip .attachment-filename {
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  font-size: 8px;
  color: var(--text-secondary);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(0,0,0,0.6);
  padding: 1px 3px;
  border-radius: 2px;
}

.attachment-chip .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(139, 108, 108, 0.85);
  color: #fff;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
  padding: 0;
}

.attachment-chip:hover .remove-btn {
  opacity: 1;
}

.attachment-chip .remove-btn:hover {
  background: var(--danger);
}

.btn-attach-image {
  width: 38px;
  height: 38px;
  border: 2px solid rgba(82, 133, 255, 0.2);
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
}

.btn-attach-image:hover {
  color: #5285ff;
  border-color: rgba(82, 133, 255, 0.5);
  background: linear-gradient(135deg, rgba(82, 133, 255, 0.1), rgba(122, 139, 163, 0.05));
}

/* ── Mic Button ── */
.btn-mic {
  width: 38px; height: 38px;
  border: 2px solid rgba(82, 133, 255, 0.2);
  border-radius: var(--radius-sm);
  background: linear-gradient(to bottom, var(--panel), var(--surface));
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.2);
}
.btn-mic:hover {
  background: linear-gradient(135deg, #5285ff 0%, #7a8ba3 100%);
  color: #fff;
  transform: scale(1.05);
}
.btn-mic.recording {
  background: linear-gradient(to bottom, var(--danger), var(--danger-hover));
  color: #fff;
  border-color: rgba(139, 108, 108, 0.3);
  animation: pulseStop 1s ease-in-out infinite;
}
.btn-mic.recording:hover {
  background: linear-gradient(135deg, #8b6c6c 0%, #c0392b 100%);
}

/* ── Drag & Drop Overlay ── */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: fadeIn 150ms ease-out;
}

.drop-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 64px;
  border: 3px dashed rgba(82, 133, 255, 0.7);
  border-radius: var(--radius-xl);
  background: rgba(33, 33, 33, 0.9);
  box-shadow: 0 0 40px rgba(82, 133, 255, 0.25);
  color: #fff;
  text-align: center;
}

.drop-overlay-content i {
  font-size: 56px;
  color: #5285ff;
  text-shadow: 0 0 16px rgba(82, 133, 255, 0.4);
}

.drop-overlay-content span {
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-shadow: 0 0 8px rgba(82, 133, 255, 0.3);
}

/* Highlight chat messages area while dragging */
.messages.drag-over {
  outline: 3px dashed rgba(82, 133, 255, 0.5);
  outline-offset: -3px;
}


/* ── Tool Sections (Collapsible) ── */
.tool-section {
  margin: 8px 0 8px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--transition);
}
.tool-section:hover {
  border-color: rgba(82, 133, 255, 0.4);
}
.tool-section summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  list-style: none;
  transition: background var(--transition), color var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tool-section summary::-webkit-details-marker {
  display: none;
}
.tool-section summary::before {
  content: '\f013';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 11px;
  color: #5285ff;
  transition: transform var(--transition);
  flex-shrink: 0;
}
.tool-section[open] summary::before {
  transform: rotate(180deg);
}
.tool-section summary:hover {
  background: rgba(82, 133, 255, 0.06);
  color: var(--text);
}
.tool-content {
  padding: 0 12px 12px 12px;
}
.tool-content pre {
  margin: 0;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  color: var(--text-secondary);
}
.tool-content pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
  font-family: inherit;
  white-space: pre;
  color: inherit;
}

/* ── Image Messages ── */
.image-container {
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  max-width: 100%;
}
.image-container-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}
.image-download-btn {
  background: none;
  border: 1px solid rgba(82, 133, 255, 0.3);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  transition: all var(--transition);
}
.image-download-btn:hover {
  color: #5285ff;
  border-color: rgba(82, 133, 255, 0.6);
  background: rgba(82, 133, 255, 0.08);
}
.image-container img {
  display: block;
  max-width: 100%;
  max-height: 512px;
  object-fit: contain;
  cursor: pointer;
  margin: 0;
}
.image-container img:hover {
  opacity: 0.95;
}
.image-container img:active {
  transform: scale(0.99);
}
