:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #4c8dff;
  --accent2: #2f6fd6;
  --line: #2a3140;
  --client: #243044;
  --bot: #1f3d2e;
  --danger: #ff8a80;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.875rem; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login__card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}
.login__card h1 { margin: 0 0 8px; font-size: 1.35rem; }
.login__card p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }
.login__card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  margin-bottom: 12px;
}
.login__card button, .reply button, .ghost {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}
.login__card button, .reply button {
  background: var(--accent);
  border-color: var(--accent2);
  font-weight: 600;
}
.login__err { color: var(--danger); margin-top: 12px; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}
.chat-list { overflow: auto; flex: 1; }
.chat-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.chat-item:hover, .chat-item.active { background: var(--panel2); }
.chat-item__top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.chat-item__name { font-weight: 600; }
.chat-item__stage { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.chat-item__preview { color: var(--muted); font-size: 0.875rem; line-height: 1.35; }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: #3a2a14;
  color: #ffc971;
  margin-left: 6px;
}

.main { min-width: 0; display: flex; flex-direction: column; }
.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread__head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.thread__head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.thread__meta { color: var(--muted); font-size: 0.875rem; }
.thread__actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.banner {
  padding: 10px 20px;
  background: #3a2a14;
  color: #ffc971;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}
.messages {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: min(720px, 85%);
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { align-self: flex-start; background: var(--client); }
.msg.assistant { align-self: flex-end; background: var(--bot); }
.msg__meta { font-size: 0.72rem; color: var(--muted); margin-bottom: 4px; }
.reply {
  border-top: 1px solid var(--line);
  padding: 16px 20px;
  background: var(--panel);
}
.reply textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font: inherit;
}
.reply__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { max-height: 38vh; }
}
