:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6a737d;
  --border: #e5e7eb;
  --user: #2563eb;
  --user-text: #ffffff;
  --assistant: #f3f4f6;
  --assistant-text: #1f2328;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

[data-theme='dark'] {
  --bg: #0f172a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  --user: #3b82f6;
  --user-text: #ffffff;
  --assistant: #1f2937;
  --assistant-text: #e5e7eb;
  --error: #fecaca;
  --error-bg: #7f1d1d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  z-index: 1;
}

.topbar h1 {
  font-size: 16px;
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.ghost-btn,
.primary-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.ghost-btn:hover,
.icon-btn:hover {
  background: var(--bg);
}

.primary-btn {
  background: var(--user);
  color: var(--user-text);
  border-color: var(--user);
  padding: 8px 16px;
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
  font-size: 15px;
  box-shadow: var(--shadow);
}

.bubble pre,
.bubble code {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
    monospace;
  font-size: 13.5px;
}

.bubble pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
}

.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.assistant {
  align-self: flex-start;
  background: var(--assistant);
  color: var(--assistant-text);
  border-bottom-left-radius: 4px;
}

.assistant .meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.assistant .meta button {
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
}

.error {
  align-self: stretch;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}

.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--assistant);
  border-radius: 14px;
  color: var(--muted);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.2s infinite ease-in-out;
}

.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.3;
  }
  40% {
    opacity: 1;
  }
}

.composer {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}

.composer textarea:focus {
  outline: 2px solid var(--user);
  outline-offset: 1px;
}

@media (max-width: 600px) {
  .bubble {
    max-width: 95%;
  }
  .topbar h1 {
    font-size: 15px;
  }
  .primary-btn {
    padding: 8px 12px;
  }
}
