:root {
  color-scheme: dark;
  --bg: #111827;
  --panel: #182233;
  --panel-light: #202d41;
  --border: #344258;
  --text: #f8fafc;
  --muted: #a7b0bf;
  --accent: #7c6cf2;
  --accent-hover: #8e80f5;
  --user: #3d63a8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: 220px minmax(0, 760px);
  gap: 20px;
  width: min(1020px, calc(100% - 32px));
  height: calc(100vh - 32px);
  margin: 16px auto;
}

.sidebar,
.chat {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
}

.new-chat,
.send,
.stop {
  border: 0;
  border-radius: 10px;
  color: white;
  background: var(--accent);
  font: inherit;
  cursor: pointer;
}

.new-chat { padding: 10px; }

.new-chat:hover,
.send:hover { background: var(--accent-hover); }

.model {
  margin-top: auto;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.messages {
  overflow-y: auto;
  padding: 24px 20px;
  scroll-behavior: smooth;
}

.message {
  max-width: 82%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant {
  background: var(--panel-light);
  border-bottom-left-radius: 4px;
}

.message.user {
  margin-left: auto;
  background: var(--user);
  border-bottom-right-radius: 4px;
}

.message.error { background: #702b3a; }

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}

textarea {
  min-height: 44px;
  max-height: 150px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #111a27;
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

textarea:focus { border-color: var(--accent); }

.send {
  width: 44px;
  height: 44px;
  font-size: 18px;
}

.send:disabled {
  cursor: wait;
  opacity: 0.65;
}

.typing {
  display: inline-flex;
  gap: 4px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1s infinite alternate;
}

.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    width: 100%;
    height: 100vh;
    margin: 0;
  }
  .sidebar { display: none; }
  .chat { border: 0; border-radius: 0; }
}
