:root {
  color-scheme: dark;
  --bg: #0f1014;
  --panel: #17181d;
  --panel-soft: #202126;
  --border: #34363d;
  --text: #f2f3f5;
  --muted: #a7adb7;
  --user: #2563eb;
  --user-strong: #1d4ed8;
  --ai: #1f2937;
  --accent: #14b8a6;
  --danger: #f87171;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: radial-gradient(circle at top left, #123b3a 0, transparent 32rem), var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: min(920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 4px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  line-height: 1.1;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: rgba(23, 24, 29, 0.76);
  font-size: 0.86rem;
}

.status-pill.is-loading {
  color: var(--accent);
}

.status-pill.is-error {
  color: var(--danger);
}

.chat-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(23, 24, 29, 0.9);
  box-shadow: var(--shadow);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 22px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 86%;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-ai {
  align-self: flex-start;
}

.avatar {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 0.74rem;
  font-weight: 800;
}

.message-user .avatar {
  color: #dbeafe;
  background: var(--user-strong);
  border-color: rgba(219, 234, 254, 0.2);
}

.bubble {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--ai);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-user .bubble {
  border-color: rgba(219, 234, 254, 0.24);
  background: var(--user);
}

.bubble p {
  margin: 0;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 14px;
  background: rgba(13, 17, 23, 0.92);
}

textarea {
  width: 100%;
  max-height: 160px;
  min-height: 48px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel-soft);
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16);
}

button {
  min-width: 84px;
  height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: white;
  background: var(--user);
  cursor: pointer;
  font-weight: 700;
}

button:hover:not(:disabled) {
  background: var(--user-strong);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .app-header {
    align-items: flex-start;
    padding-bottom: 12px;
  }

  .status-pill {
    max-width: 42%;
    text-align: center;
  }

  .messages {
    padding: 14px;
  }

  .message {
    max-width: 96%;
  }

  .avatar {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
  }

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

  button {
    width: 100%;
  }
}
