:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #1f2328;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #374151;
  --accent-contrast: #ffffff;
  --user-bubble: #374151;
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --bot-text: #1f2328;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --radius: 16px;
  --max-width: 780px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1f22;
    --surface: #2b2d31;
    --text: #e6e6e6;
    --text-muted: #9ca3af;
    --border: #3a3c42;
    --accent: #d1d5db;
    --accent-contrast: #1e1f22;
    --user-bubble: #4b5563;
    --user-text: #f9fafb;
    --bot-bubble: #2b2d31;
    --bot-text: #e6e6e6;
    --error-bg: #3b1f1f;
    --error-text: #fca5a5;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
}

.header h1 { margin: 0; font-size: 1.15rem; }
.subtitle { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

.reset {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.reset:hover { border-color: var(--accent); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.bot { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.message.bot .bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.error .bubble {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: transparent;
}

.typing .bubble { display: flex; gap: 4px; align-items: center; padding: 14px 16px; }
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  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.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  margin-top: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.composer:focus-within { border-color: var(--accent); }

.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 6px 8px;
  max-height: 200px;
}

.composer button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

.hint {
  margin: 8px 0 12px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}
