:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #182230;
  background: #eef1f5;
  --surface: #ffffff;
  --surface-muted: #f5f7fa;
  --line: #dfe4ea;
  --muted: #667384;
  --accent: #234b72;
  --visitor: #e3edf7;
  --assistant: #f0f3f6;
  --danger: #9b3f3f;
}

* { box-sizing: border-box; }
body { min-height: 100svh; margin: 0; padding: 1rem; background: var(--background, #eef1f5); }
button, textarea { font: inherit; }
button { cursor: pointer; }

.chat-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 38rem);
  height: min(48rem, calc(100svh - 2rem));
  min-height: 28rem;
  margin: auto;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: 0 1.5rem 4rem rgb(25 39 56 / 12%);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--line);
}
.identity-mark {
  display: grid;
  flex: 0 0 2.5rem;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  color: white;
  background: var(--accent);
  border-radius: .85rem;
  font-size: 1.25rem;
  font-weight: 700;
}
.identity-copy { min-width: 0; }
.eyebrow { margin: 0 0 .12rem; color: var(--muted); font-size: .67rem; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
h1 { margin: 0; overflow: hidden; font-size: 1rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.assistant-line { display: flex; align-items: center; gap: .28rem; margin: .22rem 0 0; overflow: hidden; color: var(--muted); font-size: .76rem; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: .43rem; height: .43rem; flex: 0 0 .43rem; background: #4f8a69; border-radius: 50%; }

.conversation {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  min-height: 0;
  padding: 1.1rem 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.message {
  max-width: min(84%, 30rem);
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  color: #243142;
  font-size: .91rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.customer { align-self: flex-end; color: #17334d; background: var(--visitor); border-color: #cdddec; border-bottom-right-radius: .3rem; }
.message.assistant { align-self: flex-start; background: var(--assistant); border-bottom-left-radius: .3rem; }
.message.error { color: var(--danger); background: #fff7f7; border-color: #e8caca; }

.typing { display: inline-flex; align-items: center; gap: .26rem; min-height: 2.45rem; padding-right: 1rem; }
.typing span { width: .38rem; height: .38rem; background: var(--muted); border-radius: 50%; animation: typing-pulse 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .16s; }
.typing span:nth-child(3) { animation-delay: .32s; }
@keyframes typing-pulse { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-.18rem); } }

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: .6rem;
  padding: .75rem 1rem 1rem;
  background: linear-gradient(transparent, var(--surface) 26%);
}
.composer textarea {
  min-height: 2.7rem;
  max-height: 8rem;
  flex: 1;
  resize: none;
  overflow-y: auto;
  padding: .68rem .8rem;
  color: inherit;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: .8rem;
  outline: none;
  line-height: 1.35;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(35 75 114 / 16%); }
.composer button {
  display: grid;
  place-items: center;
  width: 2.7rem;
  height: 2.7rem;
  flex: 0 0 2.7rem;
  color: white;
  background: var(--accent);
  border: 0;
  border-radius: .8rem;
  font-size: 1.35rem;
  line-height: 1;
}
.composer button:hover { filter: brightness(1.08); }
.composer button:disabled { cursor: wait; opacity: .55; }
.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; }

@media (max-width: 640px) {
  body { padding: 0; }
  .chat-shell { width: 100%; height: 100svh; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { padding: .85rem 1rem; }
  .conversation { padding: 1rem .8rem; }
  .composer { padding: .65rem .8rem max(.7rem, env(safe-area-inset-bottom)); }
  .message { max-width: 90%; font-size: .88rem; }
}

@media (prefers-reduced-motion: reduce) {
  .conversation { scroll-behavior: auto; }
  .typing span { animation: none; }
}

@media (prefers-color-scheme: dark) {
  :root { color: #edf2f7; background: #111820; --surface: #1a222d; --surface-muted: #222d39; --line: #344252; --muted: #a9b6c5; --accent: #79a6d1; --visitor: #23425c; --assistant: #242e3a; --danger: #f0a4a4; }
  body { background: #111820; }
  .identity-mark { color: #12202e; }
  .message { color: #edf2f7; }
  .message.customer { color: #e9f3fc; border-color: #315b7d; }
  .message.error { color: var(--danger); background: #3a2529; border-color: #704247; }
}
