:root {
  --bg: #0f1117;
  --sidebar-bg: #171923;
  --panel: #1e2230;
  --border: #2a2f3f;
  --text: #e8eaf0;
  --text-dim: #9aa1b5;
  --accent: #6366f1;
  --accent-hover: #4f52d8;
  --user-bubble: #6366f1;
  --error: #f87171;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

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

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.new-chat-btn:hover {
  background: #262b3d;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.settings-btn:hover {
  background: var(--panel);
  color: var(--text);
}

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

/* Main area */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.topbar h2 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
}

.status {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status.hidden {
  display: none;
}

.status.thinking {
  color: var(--accent);
}

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

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

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

.welcome {
  text-align: center;
  margin: auto;
  max-width: 520px;
}

.welcome h3 {
  font-size: 26px;
  margin-bottom: 10px;
}

.welcome p {
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 20px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.chip:hover {
  border-color: var(--accent);
  background: #262b3d;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 85%;
}

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

.msg.assistant {
  align-self: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.msg.user .avatar {
  background: var(--user-bubble);
  color: #fff;
}

.msg.assistant .avatar {
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.msg.assistant.error .bubble {
  background: rgba(248, 113, 113, 0.12);
  border-color: var(--error);
  color: var(--error);
}

.sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.sources details {
  margin-top: 6px;
}

.sources summary {
  cursor: pointer;
  color: var(--accent);
}

.sources blockquote {
  margin-top: 6px;
  padding: 8px;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  white-space: pre-wrap;
}

/* Input area */
.input-area {
  padding: 16px 24px 8px;
  border-top: 1px solid var(--border);
}

#chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  max-width: 800px;
  margin: 0 auto;
  transition: border-color 0.2s;
}

#chat-form:focus-within {
  border-color: var(--accent);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
}

#chat-input::placeholder {
  color: var(--text-dim);
}

#send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 0 4px;
}

/* Scrollbar */
.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: #3a4156;
}

/* Responsive */
@media (max-width: 720px) {
  .sidebar {
    display: none;
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  width: 420px;
  max-width: 90vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

#key-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn {
  padding: 9px 18px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.key-hint {
  margin-bottom: 0 !important;
}

.key-hint.error {
  color: var(--error);
}
