:root {
  color-scheme: light;
  --bg: oklch(97.5% 0.006 245);
  --surface: oklch(99% 0.004 245);
  --panel: oklch(94.5% 0.008 245);
  --text: oklch(23% 0.018 250);
  --muted: oklch(47% 0.02 250);
  --line: oklch(86% 0.012 245);
  --accent: oklch(47% 0.12 230);
  --accent-hover: oklch(40% 0.13 230);
  --accent-text: oklch(98% 0.004 245);
  --error: oklch(46% 0.16 28);
  --focus: oklch(62% 0.14 230);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0;
  margin: 0 0 0.05rem;
}

h1 {
  font-size: 1.18rem;
  line-height: 1.2;
  margin: 0;
}

.status-pill {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.86rem;
  gap: 0.45rem;
  min-height: 2rem;
  padding: 0 0.75rem;
}

.status-dot {
  background: oklch(62% 0.14 150);
  border-radius: 999px;
  display: inline-block;
  height: 0.5rem;
  width: 0.5rem;
}

.status-pill.error .status-dot {
  background: var(--error);
}

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

.messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: min(72ch, 100%);
  padding: 0.85rem 1rem;
}

.message.user {
  align-self: flex-end;
  background: oklch(93.5% 0.025 230);
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
}

.message.error {
  border-color: oklch(72% 0.08 28);
  color: var(--error);
}

.message-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.28rem;
}

.message p {
  margin: 0;
  overflow-wrap: anywhere;
}

.composer {
  align-items: end;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
}

textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  min-height: 2.75rem;
  max-height: 12rem;
  outline: none;
  padding: 0.68rem 0.8rem;
  resize: none;
  width: 100%;
}

textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px oklch(62% 0.14 230 / 18%);
}

button {
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 700;
  min-height: 2.75rem;
  min-width: 5.25rem;
  padding: 0 1rem;
}

button:hover {
  background: var(--accent-hover);
}

button:focus-visible {
  outline: 3px solid oklch(62% 0.14 230 / 30%);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.sr-only {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-pill {
    align-self: flex-start;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
