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

:root {
  --bg: #0f0f10;
  --bg2: #1a1a1c;
  --bg3: #242426;
  --border: #2e2e32;
  --text: #e8e8ea;
  --text-muted: #8a8a94;
  --accent: #E8621A;
  --accent-dim: rgba(232,98,26,0.15);
  --accent-hover: #f07130;
  --user-bubble: #1e2433;
  --sidebar-w: 260px;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  --transition: 0.15s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
body { display: flex; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
  color: var(--text);
}

.new-chat-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.new-chat-btn:hover {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--accent);
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 14px 14px 6px;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg3) transparent;
}
.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-track { background: transparent; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }

.loading-convs {
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  group: true;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--accent-dim); }

.conv-item-title {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition);
}
.conv-item:hover .conv-item-title,
.conv-item.active .conv-item-title { color: var(--text); }

.conv-item-delete {
  opacity: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  font-size: 14px;
  line-height: 1;
}
.conv-item:hover .conv-item-delete { opacity: 1; }
.conv-item-delete:hover { background: rgba(239,68,68,0.2); color: #ef4444; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.model-badge {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}
.sidebar-footer-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Main ────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.sidebar-toggle {
  display: none;
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  overflow-y: auto;
}

.empty-icon { margin-bottom: 20px; }

.empty-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 40px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 600px;
}

.suggestion-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.suggestion-card:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.suggestion-icon { font-size: 20px; }

.suggestion-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}
.suggestion-card:hover .suggestion-text { color: var(--text); }

/* ── Chat area ───────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg3) transparent;
}
.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

.messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Message ─────────────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 16px;
  padding: 20px 0;
}

.message + .message {
  border-top: 1px solid var(--border);
}

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

.message.user .msg-avatar {
  background: var(--user-bubble);
  color: var(--text);
  border: 1px solid var(--border);
}

.message.assistant .msg-avatar {
  background: var(--accent);
  color: white;
}

.msg-content {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}

.message.user .msg-content {
  color: var(--text);
}

/* ── Markdown styles ─────────────────────────────────────────────────────── */
.msg-content p { margin-bottom: 12px; }
.msg-content p:last-child { margin-bottom: 0; }

.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5 {
  margin: 20px 0 10px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.msg-content h1 { font-size: 22px; }
.msg-content h2 { font-size: 19px; }
.msg-content h3 { font-size: 16px; }

.msg-content ul, .msg-content ol {
  margin: 10px 0;
  padding-left: 24px;
}
.msg-content li { margin-bottom: 6px; }

.msg-content strong { color: var(--text); font-weight: 700; }
.msg-content em { font-style: italic; color: #c8c8d0; }

.msg-content code {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--mono);
  font-size: 13px;
  color: #e8a87c;
}

.msg-content pre {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin: 14px 0;
}
.msg-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--text);
}

.msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin: 14px 0;
  color: var(--text-muted);
  font-style: italic;
}

.msg-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.msg-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 14px;
}
.msg-content th, .msg-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.msg-content th {
  background: var(--bg3);
  font-weight: 600;
}
.msg-content tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* Copy button */
.msg-actions {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--transition);
}
.message:hover .msg-actions { opacity: 1; }

.msg-copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}
.msg-copy-btn:hover { background: var(--bg3); color: var(--text); }
.msg-copy-btn.copied { border-color: #22c55e; color: #22c55e; }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-message .msg-content {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.input-area {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-area > * { max-width: 760px; margin-left: auto; margin-right: auto; }

.attachments-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px 5px 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.attachment-chip svg { flex-shrink: 0; }
.attachment-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  margin-left: 4px;
  transition: color var(--transition);
}
.attachment-chip button:hover { color: #ef4444; }

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color var(--transition);
}
.input-box:focus-within { border-color: var(--accent); }

.attach-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  margin-bottom: 2px;
}
.attach-btn:hover { background: var(--bg3); color: var(--accent); }

.message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.message-input::placeholder { color: var(--text-muted); }
.message-input::-webkit-scrollbar { width: 3px; }
.message-input::-webkit-scrollbar-thumb { background: var(--bg3); }

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: all var(--transition);
}
.send-btn:disabled { background: var(--bg3); color: var(--text-muted); cursor: default; }
.send-btn:not(:disabled):hover { background: var(--accent-hover); transform: scale(1.03); }

.input-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

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

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
  .sidebar-toggle { display: flex; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .messages { padding: 24px 16px 12px; }
  .input-area { padding: 12px 16px 16px; }
  .empty-state { padding: 60px 16px 40px; }
}

/* ── File upload area overlay ────────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(232,98,26,0.15);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  pointer-events: none;
}
.drop-overlay.active { display: flex; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
