*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bot-bubble: #eef2ff;
  --user-bubble: #2563eb;
  --user-text: #ffffff;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 40%);
  color: var(--text);
}

.chat-app {
  width: min(720px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chat-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-header__brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.chat-header__logo {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.875rem;
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 1.125rem;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.chat-header__status {
  margin: 0.125rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.chat-messages {
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg);
}

.message {
  display: flex;
}

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

.message__bubble {
  max-width: min(85%, 28rem);
  padding: 0.875rem 1rem;
  border-radius: 1rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message--bot .message__bubble {
  background: var(--bot-bubble);
  color: var(--text);
  border-bottom-left-radius: 0.35rem;
}

.message--user .message__bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 0.35rem;
}

.message--typing .message__bubble {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}

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

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

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

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

  40% {
    transform: translateY(-0.35rem);
    opacity: 1;
  }
}

.chat-input {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input textarea {
  flex: 1;
  resize: none;
  min-height: 3rem;
  max-height: 8rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  font: inherit;
  line-height: 1.4;
  background: var(--bg);
}

.chat-input textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.chat-input button {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.chat-input button:hover:not(:disabled) {
  background: var(--primary-dark);
}

.chat-input button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-input button svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: currentColor;
}

@media (max-width: 640px) {
  .chat-app {
    min-height: 100dvh;
    box-shadow: none;
  }

  .chat-messages,
  .chat-header,
  .chat-input {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
