:root {
  --bg: #212121;
  --sidebar-bg: #171717;
  --main-bg: #212121;
  --bubble-user: #2f2f2f;
  --bubble-assistant: transparent;
  --border: #2f2f2f;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --accent: #10a37f;
  --hover: #2a2a2a;
  --danger: #ef4146;
}

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

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

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: width 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 0; overflow: hidden; border-right: none; }

.sidebar-top { padding: 10px; }

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

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  transition: background 0.12s;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item:hover { background: var(--hover); color: var(--text); }
.conv-item.active { background: var(--hover); color: var(--text); }
.conv-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-item .del {
  display: none;
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 2px; border-radius: 4px; flex-shrink: 0;
}
.conv-item:hover .del { display: flex; }
.conv-item .del:hover { color: var(--danger); background: rgba(255,255,255,0.05); }

.sidebar-bottom { padding: 10px; border-top: 1px solid var(--border); }
.workspace-info {
  font-size: 12px; color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
}
.icon-btn {
  background: transparent; border: none; color: var(--text);
  cursor: pointer; padding: 6px; border-radius: 6px; display: flex;
}
.icon-btn:hover { background: var(--hover); }
.model-badge {
  font-weight: 600; font-size: 15px;
}

/* ---------- Chat ---------- */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.messages {
  max-width: 768px;
  margin: 0 auto;
  padding: 24px 20px 120px;
}

.welcome {
  max-width: 768px;
  margin: 0 auto;
  padding: 15vh 20px 0;
  text-align: center;
  color: var(--text);
}
.welcome-logo {
  font-size: 48px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #d97757, #c44d3e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome h1 { font-size: 28px; font-weight: 600; margin-bottom: 10px; }
.welcome p { color: var(--text-dim); font-size: 15px; }

.msg {
  margin-bottom: 24px;
  display: flex;
  gap: 14px;
}
.msg.user { justify-content: flex-end; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; color: #fff;
}
.msg.assistant .avatar { background: linear-gradient(135deg, #d97757, #c44d3e); }
.msg .body {
  max-width: 85%;
  min-width: 0;
}
.msg.user .body {
  background: var(--bubble-user);
  padding: 10px 16px;
  border-radius: 18px;
}
.msg.assistant .body { padding-top: 2px; }

.msg .body p { margin: 0 0 10px; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body ul, .msg .body ol { margin: 0 0 10px 20px; }
.msg .body h1, .msg .body h2, .msg .body h3 { margin: 16px 0 8px; }
.msg .body a { color: #7ab7ff; }
.msg .body code {
  background: #0d0d0d; padding: 2px 6px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em;
}
.msg .body pre {
  background: #0d0d0d; padding: 14px; border-radius: 10px;
  overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--border);
}
.msg .body pre code { background: none; padding: 0; font-size: 13px; }
.msg .body table { border-collapse: collapse; margin: 8px 0; }
.msg .body th, .msg .body td { border: 1px solid var(--border); padding: 6px 10px; }
.msg .body blockquote {
  border-left: 3px solid var(--border); padding-left: 12px;
  color: var(--text-dim); margin: 8px 0;
}

/* code block header */
.code-wrap { position: relative; margin: 0 0 12px; }
.code-wrap .code-head {
  display: flex; justify-content: space-between; align-items: center;
  background: #1a1a1a; border: 1px solid var(--border); border-bottom: none;
  border-radius: 10px 10px 0 0; padding: 6px 12px; font-size: 12px; color: var(--text-dim);
}
.code-wrap pre { border-radius: 0 0 10px 10px; margin: 0; border-top: none; }
.code-wrap .copy-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 12px;
}
.code-wrap .copy-btn:hover { color: var(--text); }

/* tool blocks */
.tool-block {
  margin: 6px 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #181818;
  overflow: hidden;
}
.tool-block .tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
  background: #1f1f1f; color: var(--text-dim);
  user-select: none;
}
.tool-block .tool-head:hover { color: var(--text); }
.tool-block .tool-icon { color: var(--accent); }
.tool-block .tool-name { font-family: ui-monospace, monospace; font-weight: 600; }
.tool-block .tool-chevron { margin-left: auto; transition: transform 0.15s; }
.tool-block.open .tool-chevron { transform: rotate(90deg); }
.tool-block .tool-body {
  display: none; padding: 10px 12px; font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow-y: auto;
  border-top: 1px solid var(--border);
}
.tool-block.open .tool-body { display: block; }
.tool-block.error .tool-head .tool-icon { color: var(--danger); }

.cursor {
  display: inline-block; width: 8px; height: 16px;
  background: var(--accent); margin-left: 2px;
  animation: blink 1s steps(2) infinite; vertical-align: text-bottom;
}
@keyframes blink { 50% { opacity: 0; } }

.typing-dots span {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim); margin: 0 2px;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Composer ---------- */
.composer-wrap {
  max-width: 768px; margin: 0 auto; width: 100%;
  padding: 0 20px 16px; flex-shrink: 0;
}
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 8px 8px 16px;
}
.composer:focus-within { border-color: #4a4a4a; }
#input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 15px; font-family: inherit;
  resize: none; max-height: 200px; line-height: 1.5; padding: 6px 0;
}
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--text); color: #000; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: opacity 0.15s;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn:not(:disabled):hover { opacity: 0.85; }
.composer-hint {
  text-align: center; font-size: 12px; color: var(--text-dim);
  margin-top: 8px;
}

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 20; height: 100%; transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); width: 260px; }
  .messages, .composer-wrap { padding-left: 12px; padding-right: 12px; }
}
