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

:root {
  --bg: #1a1a1a;
  --bg2: #242424;
  --bg3: #2e2e2e;
  --border: #3a3a3a;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #7c6af7;
  --accent-hover: #9585ff;
  --user-bubble: #2d2b55;
  --assistant-bubble: #242424;
  --error: #ff6b6b;
  --radius: 12px;
  --sidebar-width: 240px;
  --topbar-height: 52px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }

/* ===== Login Page ===== */
.login-page {
  display: flex; align-items: center; justify-content: center; height: 100vh;
}
.login-container {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 48px 40px; width: 320px; text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-title { font-size: 22px; font-weight: 600; margin-bottom: 32px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 15px; padding: 12px 16px; outline: none;
  transition: border-color .2s;
}
.login-form input:focus { border-color: var(--accent); }
.login-error { color: var(--error); font-size: 13px; }
.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
  border: none; border-radius: 8px; cursor: pointer; font-size: 14px;
  font-weight: 500; padding: 10px 18px; transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--bg3); }

/* ===== App Layout ===== */
.chat-page { overflow: hidden; }
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  align-items: center; background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; flex-shrink: 0; height: var(--topbar-height); justify-content: space-between;
  padding: 0 16px;
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }

.main { display: flex; flex: 1; overflow: hidden; }

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

.session-item {
  align-items: center; border-radius: 8px; cursor: pointer; display: flex;
  justify-content: space-between; padding: 10px 12px; transition: background .15s;
}
.session-item:hover { background: var(--bg3); }
.session-item.active { background: var(--bg3); }
.session-title { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-delete {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 16px;
  opacity: 0; padding: 0 4px; transition: opacity .15s;
}
.session-item:hover .session-delete { opacity: 1; }
.session-delete:hover { color: var(--error); }

/* ===== Chat Area ===== */
.chat-area { display: flex; flex: 1; flex-direction: column; overflow: hidden; }

.messages {
  flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
.welcome-msg { color: var(--text-dim); text-align: center; margin: auto; }

.message { display: flex; flex-direction: column; max-width: 80%; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  border-radius: var(--radius); padding: 12px 16px; word-break: break-word;
}
.message.user .bubble { background: var(--user-bubble); color: var(--text); }
.message.assistant .bubble { background: var(--assistant-bubble); border: 1px solid var(--border); }

/* Markdown inside bubbles */
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: #111; border-radius: 8px; margin: 8px 0; overflow-x: auto; padding: 12px;
}
.bubble code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 13px; }
.bubble p code {
  background: #333; border-radius: 4px; padding: 2px 6px;
}
.bubble ul, .bubble ol { margin: 8px 0 8px 20px; }
.bubble blockquote {
  border-left: 3px solid var(--accent); color: var(--text-dim); margin: 8px 0; padding-left: 12px;
}

.typing-cursor::after { animation: blink 1s step-end infinite; content: '▋'; }
@keyframes blink { 50% { opacity: 0; } }

/* ===== Input Area ===== */
.input-area {
  align-items: flex-end; background: var(--bg2); border-top: 1px solid var(--border);
  display: flex; gap: 10px; padding: 12px 16px;
}
#message-input {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; color: var(--text);
  flex: 1; font-family: inherit; font-size: 15px; max-height: 160px; outline: none;
  padding: 10px 14px; resize: none; transition: border-color .2s;
}
#message-input:focus { border-color: var(--accent); }
#message-input:disabled { opacity: .5; }

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

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .sidebar { width: 180px; }
  .message { max-width: 95%; }
}
