@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a25;
  --bg-glass: rgba(18, 18, 26, 0.7);
  --bg-glass-hover: rgba(26, 26, 37, 0.85);
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text-primary: #e8e8ed;
  --text-secondary: #8e8ea0;
  --text-muted: #56566a;
  --accent: #6c5ce7;
  --accent-hover: #7f6ff0;
  --accent-glow: rgba(108, 92, 231, 0.25);
  --accent-secondary: #00cec9;
  --user-bubble: linear-gradient(135deg, #6c5ce7 0%, #a855f7 100%);
  --danger: #ff6b6b;
  --success: #00cec9;
  --warning: #fdcb6e;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.container { display:flex; height:100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(20px);
  animation: slideInLeft 0.4s ease;
  z-index: 10;
}

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

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  letter-spacing: -0.5px;
}

.logo-icon {
  width: 32px; height: 32px;
  background: var(--user-bubble);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 20px var(--accent-glow);
}

.new-chat-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: rgba(108, 92, 231, 0.1);
  border: 1px solid rgba(108, 92, 231, 0.2);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.new-chat-btn:hover {
  background: rgba(108, 92, 231, 0.2);
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-1px);
}

.sidebar-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  padding: 0 4px;
}

.recent-item {
  padding: 10px 12px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.recent-item:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
}

.recent-item.active {
  background: rgba(108, 92, 231, 0.12);
  color: var(--accent);
}

.recent-item .delete-btn {
  display: none;
  background: none; border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.recent-item:hover .delete-btn { display: block; }

.empty-state {
  text-align: center;
  padding: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.stats-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.context-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.context-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-secondary) 100%);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  min-height: 36px;
}

.status-left, .status-right { display:flex; align-items:center; gap:12px; }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse 2s infinite;
}

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

.status-dot.offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

.model-badge {
  background: var(--bg-tertiary);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
}

.model-badge:hover {
  background: rgba(108, 92, 231, 0.15);
  border-color: var(--accent);
}

/* ── Welcome Screen ── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px;
  animation: fadeIn 0.6s ease;
}

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

.greeting {
  font-size: 36px;
  font-weight: 300;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -1px;
}

.greeting-sub {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 40px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 500px;
  width: 100%;
  margin-bottom: 30px;
}

.action-card {
  padding: 16px;
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: left;
  display: flex; align-items: center; gap: 10px;
}

.action-card:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.action-card .icon {
  font-size: 18px;
  flex-shrink: 0;
}

.auth-box {
  max-width: 500px;
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
  margin-bottom: 20px;
  animation: fadeIn 0.4s ease 0.2s both;
}

.auth-box p { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }

.auth-btn {
  background: var(--user-bubble);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: var(--transition);
}

.auth-btn:hover { transform: scale(1.03); box-shadow: 0 0 25px var(--accent-glow); }

/* ── Chat ── */
.chat-container {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.chat-container.active { display: flex; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 0;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  animation: msgIn 0.3s ease;
}

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

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

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
}

.message.user .msg-avatar { background: var(--user-bubble); color: white; }
.message.assistant .msg-avatar { background: var(--bg-tertiary); color: var(--accent-secondary); }

.msg-body { flex: 1; min-width: 0; }

.msg-content {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

.message.user .msg-content {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-content {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-actions {
  display: flex; gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}

.message:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: var(--transition);
  font-family: inherit;
  display: flex; align-items: center; gap: 4px;
}

.msg-action-btn:hover { background: var(--bg-glass-hover); color: var(--text-secondary); }

/* Thinking block */
.thinking-block {
  background: rgba(108, 92, 231, 0.06);
  border: 1px solid rgba(108, 92, 231, 0.15);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}

.thinking-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  user-select: none;
}

.thinking-header .spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--accent-glow);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.thinking-body {
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}

.thinking-body.open { display: block; }

/* Typing indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  max-width: 800px;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 13px;
}

.typing-indicator.active { display: flex; }

.typing-dots { display: flex; gap: 4px; }
.typing-dot {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input Area ── */
.input-area {
  padding: 16px 20px 20px;
  max-width: 840px;
  margin: 0 auto;
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  transition: var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-wrapper textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 150px;
  line-height: 1.5;
}

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

.input-controls { display: flex; align-items: center; gap: 4px; padding-right: 4px; }

.ctrl-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  font-size: 16px;
}

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

.ctrl-btn.research-active { color: var(--accent-secondary); background: rgba(0, 206, 201, 0.1); }

.send-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: var(--user-bubble);
  border: none;
  color: white;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  font-size: 16px;
}

.send-btn:hover { transform: scale(1.05); box-shadow: 0 0 15px var(--accent-glow); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Model Picker Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 480px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.25s ease;
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

.modal-search {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.modal-search:focus { border-color: var(--accent); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.model-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 8px 4px;
}

.model-option {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
}

.model-option:hover { background: var(--bg-glass-hover); color: var(--text-primary); }
.model-option.selected { background: rgba(108,92,231,0.12); color: var(--accent); }

.model-option .model-ctx {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Artifact/Code block ── */
.artifact-canvas {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 10px 0;
  overflow: hidden;
}

.artifact-header {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-secondary);
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.artifact-actions { display: flex; gap: 6px; }

.artifact-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  transition: var(--transition);
}

.artifact-btn:hover { background: var(--bg-tertiary); color: var(--text-secondary); }
.artifact-btn.view-btn { border-color: var(--accent-secondary); color: var(--accent-secondary); }
.artifact-btn.view-btn:hover { background: var(--accent-secondary); color: white; }

.artifact-code {
  padding: 12px;
  overflow-x: auto;
  max-height: 400px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.artifact-code pre { margin: 0; }
.artifact-code code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  color: var(--text-primary);
  white-space: pre;
  line-height: 1.6;
}

/* ── Markdown rendering ── */
.msg-content h1,.msg-content h2,.msg-content h3 {
  margin: 12px 0 6px;
  font-weight: 600;
}
.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 16px; }
.msg-content h3 { font-size: 14px; }
.msg-content ul, .msg-content ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg-content li { margin: 3px 0; }
.msg-content strong { font-weight: 600; }
.msg-content em { font-style: italic; }
.msg-content code:not(pre code) {
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Consolas', monospace;
}
.msg-content a { color: var(--accent); text-decoration: underline; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 240px; }
  .greeting { font-size: 26px; }
  .action-grid { grid-template-columns: 1fr; }
  .modal { width: 95%; }
}
