:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --background: #d9e6e2;
  --header: #145c4a;
  --header-text: #ffffff;
  --incoming: #ffffff;
  --outgoing: #d7f5dc;
  --text: #17211e;
  --muted: #68746f;
  --accent: #17785f;
  --border: #d7dfdc;
  --danger: #8f2f2f;
}

* {
  box-sizing: border-box;
}

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

body {
  align-items: center;
  background:
    radial-gradient(circle at 15% 10%, rgb(255 255 255 / 55%), transparent 35%),
    var(--background);
  color: var(--text);
  display: flex;
  justify-content: center;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.chat-shell {
  background: #efeae2;
  box-shadow: 0 20px 70px rgb(20 50 42 / 20%);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: min(900px, 100dvh);
  max-width: 760px;
  overflow: hidden;
  width: 100%;
}

.chat-header {
  align-items: center;
  background: var(--header);
  color: var(--header-text);
  display: flex;
  gap: 12px;
  min-height: 72px;
  padding: 12px 16px;
}

.avatar {
  align-items: center;
  background: #e5fff6;
  border: 2px solid rgb(255 255 255 / 55%);
  border-radius: 50%;
  color: var(--header);
  display: flex;
  flex: 0 0 46px;
  font-size: 1.25rem;
  font-weight: 750;
  height: 46px;
  justify-content: center;
}

.profile {
  min-width: 0;
}

.profile h1 {
  font-size: 1.05rem;
  margin: 0 0 3px;
}

.profile p {
  font-size: 0.78rem;
  margin: 0;
  opacity: 0.82;
}

.new-chat {
  background: transparent;
  border: 1px solid rgb(255 255 255 / 45%);
  border-radius: 999px;
  color: white;
  font-size: 0.78rem;
  margin-left: auto;
  padding: 8px 12px;
}

.new-chat:hover,
.new-chat:focus-visible {
  background: rgb(255 255 255 / 12%);
}

.new-chat:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.messages {
  background-image:
    linear-gradient(rgb(239 234 226 / 92%), rgb(239 234 226 / 92%)),
    radial-gradient(circle, #96ada5 1px, transparent 1px);
  background-size: auto, 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 20px clamp(12px, 4vw, 28px);
  scroll-behavior: smooth;
}

.message {
  border-radius: 10px;
  box-shadow: 0 1px 2px rgb(18 45 37 / 12%);
  line-height: 1.45;
  max-width: min(84%, 560px);
  padding: 9px 12px 7px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.ana {
  align-self: flex-start;
  background: var(--incoming);
  border-top-left-radius: 2px;
}

.message.user {
  align-self: flex-end;
  background: var(--outgoing);
  border-top-right-radius: 2px;
}

.message-text {
  font-size: 0.95rem;
}

.message-meta {
  color: var(--muted);
  font-size: 0.68rem;
  margin-top: 5px;
  text-align: right;
}

.sources {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.73rem;
  margin-top: 8px;
  padding-top: 7px;
}

.sources summary {
  cursor: pointer;
  font-weight: 650;
}

.sources ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.typing {
  align-items: center;
  display: flex;
  gap: 4px;
  min-height: 22px;
}

.typing span {
  animation: blink 1.2s infinite;
  background: #81918b;
  border-radius: 50%;
  height: 6px;
  width: 6px;
}

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

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

@keyframes blink {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.error-bar {
  align-items: center;
  background: #fff0f0;
  color: var(--danger);
  display: flex;
  font-size: 0.82rem;
  gap: 12px;
  justify-content: space-between;
  padding: 8px 14px;
}

.error-bar button {
  background: white;
  border: 1px solid #d49a9a;
  border-radius: 6px;
  color: var(--danger);
  padding: 5px 8px;
}

.composer {
  align-items: flex-end;
  background: #f7f8f7;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  padding: 10px 12px;
}

.composer textarea {
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  max-height: 120px;
  min-height: 44px;
  outline: none;
  padding: 11px 15px;
  resize: none;
  width: 100%;
}

.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(23 120 95 / 12%);
}

.composer button {
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  color: white;
  min-height: 44px;
  padding: 0 18px;
}

.composer button:disabled,
.composer textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

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

@media (min-width: 761px) {
  .chat-shell {
    border-radius: 14px;
    height: min(900px, calc(100dvh - 40px));
  }
}

@media (max-width: 420px) {
  .new-chat {
    font-size: 0;
    height: 38px;
    padding: 0;
    width: 38px;
  }

  .new-chat::after {
    content: "+";
    font-size: 1.35rem;
  }

  .message {
    max-width: 90%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .messages {
    scroll-behavior: auto;
  }

  .typing span {
    animation: none;
  }
}
