:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1d2230;
  --line: #272d3a;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --accent-ink: #ffffff;
  --bubble-bot: #1d2230;
  --bubble-user: #5b8cff;
  --danger: #ff8a8a;
  --radius: 18px;
  --maxw: 720px;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--panel);
}

/* Header */
.chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.chat__avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-ink);
  background: linear-gradient(135deg, #5b8cff, #8a5bff);
}

.chat__title h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.chat__title p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* Messages */
.chat__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: pop .18s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg--bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg--user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--accent-ink);
  border-bottom-right-radius: 6px;
}

.msg--error {
  align-self: flex-start;
  background: #2a1d22;
  border: 1px solid #54323a;
  color: var(--danger);
  border-bottom-left-radius: 6px;
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 14px 16px;
  background: var(--bubble-bot);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-bottom-left-radius: 6px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite ease-in-out both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Composer */
.chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.chat__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
}
.chat__input:focus {
  border-color: var(--accent);
}
.chat__input::placeholder { color: var(--muted); }

.chat__send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.chat__send:hover { transform: scale(1.05); }
.chat__send:active { transform: scale(0.95); }
.chat__send:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 480px) {
  .msg { max-width: 88%; }
}
