:root {
  --indigo: #4F46E5;
  --indigo-dim: #EEEDFD;
  --cyan: #06B6D4;
  --cyan-dim: #E4F9FC;
  --ink: #1B1E2B;
  --ink-soft: #565A6E;
  --line: #E4E4EF;
  --paper: #FBFBFD;
  --panel: #FFFFFF;
  --radius: 10px;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; }

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

/* ---------- Sidebar ---------- */

.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  min-width: 0;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 20px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-soft);
}

.rail-section { margin-bottom: 22px; }
.rail-section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.rail-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.doc-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--paper);
}

.doc-name {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 8px;
}

.doc-actions { display: flex; gap: 6px; }

.rail-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--indigo);
  background: var(--indigo);
  color: white;
  cursor: pointer;
  text-align: center;
}
.rail-btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}
.rail-btn:hover { filter: brightness(0.97); }

.section-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.section-list li {
  font-size: 13px;
  color: var(--ink-soft);
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  line-height: 1.4;
}

.section-list li:hover {
  background: var(--indigo-dim);
  color: var(--indigo);
}

.rail-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #D0D0DE;
  flex-shrink: 0;
}
.dot.ok { background: var(--cyan); }
.dot.bad { background: #E04F5F; }

/* ---------- Main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px 18px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}

.topbar-title h1 {
  font-size: 20px;
  margin: 0 0 3px;
  letter-spacing: -0.01em;
}
.topbar-title p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.mode-toggle {
  display: flex;
  background: var(--indigo-dim);
  border-radius: 999px;
  padding: 3px;
  flex-shrink: 0;
}

.mode-btn {
  border: none;
  background: transparent;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--indigo);
  border-radius: 999px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--indigo);
  color: white;
}

/* ---------- Thread ---------- */

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty {
  margin: auto;
  text-align: center;
  max-width: 420px;
  color: var(--ink-soft);
}
.empty h2 {
  color: var(--ink);
  font-size: 17px;
  margin-bottom: 6px;
}
.empty p { font-size: 13.5px; line-height: 1.6; margin-bottom: 16px; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.suggestion-chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.suggestion-chip:hover { border-color: var(--indigo); color: var(--indigo); }

.msg {
  display: flex;
  gap: 10px;
  max-width: 640px;
  animation: rise 0.22s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  margin-top: 2px;
}
.msg.assistant .avatar { background: var(--indigo); }
.msg.user .avatar { background: var(--ink-soft); }

.bubble-wrap { display: flex; flex-direction: column; min-width: 0; }
.msg.user .bubble-wrap { align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top-left-radius: 3px;
}
.msg.user .bubble {
  background: var(--indigo);
  color: white;
  border-top-right-radius: 3px;
}

/* Rendered markdown inside assistant bubbles */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 8px; padding-left: 20px; }
.bubble li { margin-bottom: 3px; }
.bubble strong { font-weight: 700; color: var(--ink); }
.bubble code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--indigo-dim);
  padding: 1px 5px;
  border-radius: 4px;
}
.bubble pre {
  background: #F3F3FA;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0 8px;
}
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--indigo); }
.bubble h1, .bubble h2, .bubble h3 { margin: 4px 0 8px; font-size: 1em; font-weight: 700; }

/* Emoji reaction row under assistant messages */
.reactions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.reaction-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.reaction-btn:hover { border-color: var(--indigo); }
.reaction-btn.popped { animation: pop 0.35s ease; }
.reaction-btn .count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-left: 3px;
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.5) rotate(-8deg); }
  100% { transform: scale(1); }
}

.meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-top: 5px;
  padding: 0 3px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.meta .tag {
  background: var(--cyan-dim);
  color: #0A7C93;
  padding: 1px 6px;
  border-radius: 5px;
}

.copy-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 0;
}
.copy-btn:hover { color: var(--indigo); }

.typing {
  display: inline-flex;
  gap: 3px;
  padding: 4px 0;
}
.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* ---------- Composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 32px 22px;
  border-top: 1px solid var(--line);
}

#composerInput {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14.5px;
  max-height: 160px;
  outline: none;
  background: var(--panel);
}
#composerInput:focus { border-color: var(--indigo); }

#sendBtn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--indigo);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
#sendBtn:disabled { background: var(--line); color: var(--ink-soft); cursor: not-allowed; }

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .topbar { padding: 16px 18px; }
  .thread { padding: 20px 18px; }
  .composer { padding: 12px 18px 18px; }
}
