:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #202938;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --accent: #4fa3ff;
  --danger: #ff5b5b;
  --border: #2f394c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header,
main,
footer {
  width: min(1200px, 94vw);
  margin: 0 auto;
}

header {
  margin-top: 1.5rem;
}

h1,
h2 {
  margin: 0 0 0.8rem 0;
}

.muted {
  color: var(--muted);
}

main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin: 1rem auto 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.card-chat {
  grid-column: 1 / -1;
}

.row {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

.row.wrap {
  align-items: center;
}

label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

input,
textarea,
button {
  background: var(--surface-2);
  border: 1px solid #3a4558;
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

input,
textarea {
  width: 100%;
}

button {
  cursor: pointer;
  border-color: #466086;
}

button:hover {
  border-color: var(--accent);
}

button.danger {
  border-color: #7b3b3b;
}

button.danger:hover {
  border-color: var(--danger);
}

.out {
  background: #0a0f16;
  border: 1px solid #2a3242;
  border-radius: 8px;
  min-height: 110px;
  max-height: 250px;
  overflow: auto;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.chat-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1rem;
}

.threads-pane,
.messages-pane {
  background: #0f151f;
  border: 1px solid #263145;
  border-radius: 10px;
  padding: 0.9rem;
}

.thread-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
  max-height: 430px;
  overflow: auto;
}

.thread-empty {
  color: var(--muted);
  font-size: 0.95rem;
}

.thread-item {
  border: 1px solid #2f3b52;
  border-radius: 8px;
  background: #141d2b;
  padding: 0.55rem;
  display: grid;
  gap: 0.35rem;
}

.thread-item.active {
  border-color: var(--accent);
  background: #162538;
}

.thread-select {
  all: unset;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

.thread-item small {
  color: var(--muted);
  font-size: 0.78rem;
}

.messages-list {
  min-height: 300px;
  max-height: 520px;
  overflow: auto;
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  padding-right: 0.2rem;
}

.message-empty {
  color: var(--muted);
  padding: 0.65rem;
}

.message {
  border: 1px solid #2f3b52;
  border-radius: 10px;
  padding: 0.65rem;
  background: #101a28;
}

.message header {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
}

.message-user {
  border-color: #355681;
}

.message-assistant {
  border-color: #3e6b4e;
}

.message-system {
  border-color: #69543a;
}

.composer textarea {
  resize: vertical;
  min-height: 90px;
}

footer {
  margin-bottom: 1.5rem;
}

@media (max-width: 960px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }
}
