:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #252937;
  --bg-hover: #2f3447;
  --text-primary: #e4e6ed;
  --text-secondary: #9ba1b5;
  --text-muted: #6b7188;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.4);
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --border: #2a2f40;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 18px;
  overflow-y: auto;
}

.sidebar-header h1 {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

.sidebar h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.lang-panel, .voice-panel {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.lang-switch {
  display: flex;
  gap: 6px;
}

.lang-btn {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

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

.lang-btn.active {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
  border-color: var(--accent);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 0;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 36px;
  height: 20px;
  appearance: none;
  background: var(--bg-hover);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-row input[type="checkbox"]:checked {
  background: var(--accent);
}

.toggle-row input[type="checkbox"]::after {
  content: '';
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(16px);
}

.model-select {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.model-select:hover,
.model-select:focus {
  border-color: var(--accent);
}

.model-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.stats-panel .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-value {
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.status-idle { color: var(--text-muted); }
.status-working { color: var(--accent); animation: pulse 1.5s infinite; }
.status-done { color: var(--success); }
.status-error { color: var(--error); }

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

.sidebar-actions {
  margin-top: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  width: 100%;
}

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, #10b981, #059669);
}

.message.system .message-avatar {
  background: var(--bg-tertiary);
}

.message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-content {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.1));
  border-color: rgba(99, 102, 241, 0.3);
}

.message.assistant .message-content {
  background: var(--bg-tertiary);
}

.message.system-message .message-content {
  background: var(--bg-secondary);
  border-color: var(--border);
  max-width: 600px;
}

.message .hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 8px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.message-meta .provider-tag {
  background: var(--bg-hover);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.cursor-blink::after {
  content: '▍';
  animation: blink 1s infinite;
  color: var(--accent);
  margin-left: 2px;
}

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

/* Voice controls */
.voice-controls {
  padding: 16px 24px 24px;
  background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.interim-display {
  min-height: 28px;
  font-size: 14px;
  color: var(--accent);
  text-align: center;
  padding: 4px 16px;
  width: 100%;
  max-width: 500px;
  transition: opacity 0.3s;
  opacity: 0;
}

.interim-display.visible,
#interimDisplay:not(:empty) {
  opacity: 1;
}

.voice-buttons {
  display: flex;
  gap: 16px;
  align-items: center;
}

.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.mic-btn:hover {
  transform: scale(1.05);
}

.mic-btn:active {
  transform: scale(0.95);
}

.mic-btn.recording {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 30px rgba(239, 68, 68, 0.5);
  animation: recording-pulse 1.2s infinite;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 4px 30px rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 4px 40px rgba(239, 68, 68, 0.8); }
}

.stop-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.stop-btn:hover {
  background: var(--error);
}

.text-input-row {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 500px;
  align-items: center;
}

.text-input-row input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 18px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.text-input-row input:hover,
.text-input-row input:focus {
  border-color: var(--accent);
}

.text-input-row .btn-primary {
  padding: 10px 20px;
  border-radius: 20px;
}

.waveform {
  display: flex;
  gap: 4px;
  height: 32px;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.waveform.active {
  opacity: 1;
}

.wave-bar {
  width: 4px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite alternate;
  animation-delay: var(--delay);
}

@keyframes wave {
  0% { height: 6px; }
  100% { height: 28px; }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  color: var(--text-primary);
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 1000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

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