:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2128;
  --border: #2d333b;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #7c6df2;
  --accent-2: #4f8ef7;
  --user-bubble: linear-gradient(135deg, #7c6df2, #4f8ef7);
  --radius: 14px;
}

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

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

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

/* ===== Sidebar ===== */
.sidebar {
  width: 290px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  transition: transform .25s ease;
}

.sidebar-header { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 10px; }
.sidebar-header h1 { font-size: 17px; }
.subtitle { font-size: 12px; color: var(--text-dim); }

.btn-new {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; padding: 11px;
  border-radius: var(--radius); cursor: pointer;
  font-size: 14px; font-weight: 600;
  transition: opacity .15s;
}
.btn-new:hover { opacity: .85; }

.settings { display: flex; flex-direction: column; gap: 12px; }
.settings label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); }
.settings input, .settings select, .settings textarea {
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: 10px;
  font-size: 13px; outline: none; resize: vertical;
  transition: border-color .15s;
}
.settings input:focus, .settings select:focus, .settings textarea:focus { border-color: var(--accent); }
.settings input[type="range"] { padding: 0; accent-color: var(--accent); }
.checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; cursor: pointer; }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.icon-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 6px 10px;
  border-radius: 8px; transition: background .15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #3fb950; }
.dot.busy { background: #d29922; animation: pulse 1s infinite; }
.dot.error { background: #f85149; }
@keyframes pulse { 50% { opacity: .4; } }

/* ===== Chat ===== */
.chat {
  flex: 1; overflow-y: auto; padding: 24px 8%;
  display: flex; flex-direction: column; gap: 18px;
  scroll-behavior: smooth;
}

.welcome {
  margin: auto; text-align: center; color: var(--text-dim);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.welcome img { width: 64px; border-radius: 16px; opacity: .8; }
.welcome h2 { color: var(--text); }

.message { display: flex; gap: 12px; max-width: 85%; animation: slideIn .25s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } }

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

.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.user-avatar { background: #2d333b; }
.bot-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

.bubble {
  padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.6; font-size: 14px; position: relative;
  overflow-wrap: break-word; min-width: 0;
}
.user-message .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.bot-message .bubble { background: var(--bg-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.bubble pre {
  background: #0a0d12; padding: 12px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0; font-size: 13px;
  border: 1px solid var(--border);
}
.bubble code { font-family: 'Consolas', monospace; font-size: 13px; }
.bubble p code { background: #2d333b; padding: 2px 6px; border-radius: 4px; }
.bubble a { color: var(--accent-2); }

.msg-meta {
  display: flex; gap: 8px; align-items: center;
  font-size: 11px; color: var(--text-dim); margin-top: 6px;
}
.copy-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 11px; padding: 2px 6px; border-radius: 5px;
}
.copy-btn:hover { background: var(--bg-3); color: var(--text); }

/* ===== Typing ===== */
.typing {
  display: none; align-items: center; gap: 12px;
  padding: 0 8% 8px;
}
.dots span {
  display: inline-block; width: 7px; height: 7px; margin: 0 2px;
  background: var(--text-dim); border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 30% { transform: translateY(-6px); } }

/* ===== Composer ===== */
.composer { padding: 14px 8% 20px; }
.error {
  display: none; background: rgba(248,81,73,.12);
  border: 1px solid rgba(248,81,73,.4); color: #f85149;
  padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 10px;
}
.input-wrap {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 16px; padding: 10px 12px;
  transition: border-color .15s;
}
.input-wrap:focus-within { border-color: var(--accent); }
#messageInput {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 14px; resize: none;
  max-height: 180px; line-height: 1.5; font-family: inherit;
}
#sendButton, #stopButton {
  width: 40px; height: 40px; border-radius: 12px; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all .15s;
}
#sendButton { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
#sendButton:hover:not(:disabled) { transform: scale(1.05); }
#sendButton:disabled { opacity: .4; cursor: not-allowed; }
#stopButton { background: #f85149; color: #fff; }
.hidden { display: none !important; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; z-index: 100; height: 100%;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .chat, .composer { padding-left: 4%; padding-right: 4%; }
  .typing { padding-left: 4%; }
  .message { max-width: 95%; }
}
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }