/* ── Reset & Variables ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --bg2: #16161d;
  --bg3: #1e1e28;
  --border: #2a2a38;
  --text: #e8e8f0;
  --text2: #8888a8;
  --accent: #7c6af5;
  --accent2: #a89df8;
  --user-bg: #1a1a2e;
  --assist-bg: #16161d;
  --code-bg: #0d0d15;
  --green: #4ade80;
  --red: #f87171;
  font-size: 15px;
}

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

/* ── Layout ─────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100dvh;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-icon { font-size: 28px; }
.brand-name { font-weight: 700; font-size: 1rem; color: var(--text); }
.brand-sub { font-size: 0.72rem; color: var(--text2); }

.btn-new {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-new:hover { background: var(--accent2); }

.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.sidebar-label { font-size: 0.7rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; }

.system-prompt {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.8rem;
  padding: 8px;
  resize: vertical;
  min-height: 80px;
  max-height: 180px;
  font-family: inherit;
  line-height: 1.4;
}
.system-prompt:focus { outline: none; border-color: var(--accent); }
.system-prompt::placeholder { color: var(--text2); }

.file-list-sidebar { display: flex; flex-direction: column; gap: 4px; }

.sidebar-file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg3);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.75rem;
  color: var(--text2);
}
.sidebar-file-item .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.sidebar-file-item .remove-file {
  cursor: pointer;
  color: var(--text2);
  background: none;
  border: none;
  font-size: 0.85rem;
  padding: 0 2px;
  line-height: 1;
}
.sidebar-file-item .remove-file:hover { color: var(--red); }

.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg3);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--accent2);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn-upload:hover { border-color: var(--accent); background: var(--bg); }

.file-hint { font-size: 0.7rem; color: var(--text2); }

.sidebar-footer { margin-top: auto; }
.model-badge {
  display: inline-block;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.7rem;
  color: var(--text2);
  font-family: monospace;
}

.model-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.8rem;
  padding: 7px 10px;
  width: 100%;
  cursor: pointer;
}
.model-select:focus { outline: none; border-color: var(--accent); }

/* ── Main chat ───────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

/* ── Welcome ─────────────────────────────────────────────── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
  gap: 16px;
}
.welcome-icon { font-size: 52px; }
.welcome h1 { font-size: 1.6rem; font-weight: 700; }
.welcome p { color: var(--text2); max-width: 460px; line-height: 1.6; }

.welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}
.example-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text2);
  font-size: 0.8rem;
  padding: 9px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.example-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── Message bubbles ─────────────────────────────────────── */
.msg {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.2s ease;
}
.msg:last-child { border-bottom: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg.user .msg-avatar { background: var(--accent); }
.msg.assistant .msg-avatar { background: var(--bg3); border: 1px solid var(--border); }

.msg-body { flex: 1; min-width: 0; }
.msg-role { font-size: 0.7rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.msg-content { line-height: 1.7; color: var(--text); }

.msg.user .msg-content {
  background: var(--user-bg);
  border-radius: 12px;
  padding: 10px 14px;
  display: inline-block;
  max-width: 100%;
  word-break: break-word;
}

/* ── Markdown content ────────────────────────────────────── */
.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { margin: 8px 0 8px 20px; }
.msg-content li { margin-bottom: 4px; }
.msg-content strong { color: var(--text); }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 14px 0 8px; }

.msg-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}
.msg-content code {
  font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
  font-size: 0.82rem;
}
.msg-content :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.82rem;
}

/* ── Copy button on code blocks ──────────────────────────── */
.code-wrap { position: relative; }
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text2);
  font-size: 0.7rem;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.code-wrap:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); }

/* ── File attachments in message ─────────────────────────── */
.msg-files { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: var(--text2);
}

/* ── Download file cards ─────────────────────────────────── */
.download-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 10px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}
.download-card:hover { background: var(--bg); }
.download-icon { font-size: 22px; }
.download-info .dname { font-weight: 600; font-size: 0.88rem; }
.download-info .ddesc { font-size: 0.75rem; color: var(--text2); margin-top: 2px; }
.download-arrow { margin-left: auto; color: var(--accent); font-size: 1.1rem; }

/* ── Typing indicator ────────────────────────────────────── */
.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 0;
}
.dot {
  width: 7px; height: 7px;
  background: var(--text2);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input area ──────────────────────────────────────────── */
.input-area {
  border-top: 1px solid var(--border);
  background: var(--bg2);
  padding: 12px 20px 16px;
}

.uploaded-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  color: var(--text2);
}
.preview-chip .rm {
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 0.85rem;
  padding: 0 2px;
  line-height: 1;
}
.preview-chip .rm:hover { color: var(--red); }

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.user-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  padding: 10px 14px;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
  overflow-y: auto;
  transition: border-color 0.15s;
}
.user-input:focus { outline: none; border-color: var(--accent); }
.user-input::placeholder { color: var(--text2); }

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  width: 42px;
  height: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn:hover { background: var(--accent2); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint { font-size: 0.68rem; color: var(--text2); margin-top: 6px; }

/* ── Error toast ─────────────────────────────────────────── */
.error-msg {
  background: rgba(248,113,113,0.12);
  border: 1px solid #f87171;
  border-radius: 8px;
  color: #f87171;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.85rem;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { width: 200px; padding: 12px; }
  .messages { padding: 16px 12px; }
  .input-area { padding: 10px 12px 14px; }
  .welcome h1 { font-size: 1.2rem; }
  .welcome-examples { flex-direction: column; }
}
@media (max-width: 480px) {
  .sidebar { display: none; }
}
