:root {
  color-scheme: light;
  --accent: #1a4480;
  --accent-2: #2962b8;
  --ink: #1e2026;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #ebeef3;
  --panel: #ffffff;
  --bubble-bot: #ffffff;
  --bubble-user: #1a4480;
  --bubble-user-ink: #ffffff;
  --typing: #c9cdd5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(26, 68, 128, .10), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(26, 68, 128, .08), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

.page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-shell {
  width: min(720px, 100%);
  height: min(820px, calc(100vh - 48px));
  min-height: 560px;
  background: var(--panel);
  border-radius: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  box-shadow: 0 30px 80px rgba(20, 30, 50, .14);
  overflow: hidden;
}

/* === Header === */
.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
}

.peer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.peer-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
  flex-shrink: 0;
}

.peer-avatar-fallback { font-size: 18px; }

.peer-meta { line-height: 1.2; }

.peer-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.peer-status {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 0 2px rgba(46, 204, 113, .25);
}

/* === Messages === */
.messages {
  padding: 18px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background:
    radial-gradient(900px 500px at 50% 0%, rgba(26, 68, 128, .04), transparent 70%),
    #f4f6fa;
}

.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 6px;
}

.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; }

.row.same-author { margin-top: 2px; }

.row .row-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.row .row-avatar-spacer { width: 28px; flex-shrink: 0; }

.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 16px;
  line-height: 1.4;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(20, 30, 50, .04);
}

.row.bot .bubble {
  background: var(--bubble-bot);
  color: var(--ink);
  border-top-left-radius: 6px;
}

.row.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-top-right-radius: 6px;
}

.row.same-author.bot .bubble { border-top-left-radius: 16px; }
.row.same-author.user .bubble { border-top-right-radius: 16px; }

/* Typing indicator */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

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

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* === Composer === */
.chat-form {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  align-items: end;
  background: #fff;
}

textarea#messageInput {
  resize: none;
  min-width: 0;
  min-height: 44px;
  max-height: 160px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
  background: #f4f6fa;
  transition: border-color .15s, background .15s;
}

textarea#messageInput:focus {
  border-color: var(--accent);
  background: #fff;
}

#sendBtn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .1s;
}

#sendBtn:hover:not(:disabled) { background: var(--accent-2); }
#sendBtn:active:not(:disabled) { transform: scale(0.95); }
#sendBtn:disabled { opacity: .45; cursor: default; }

/* === Mobile === */
@media (max-width: 640px) {
  .page { padding: 0; }
  .chat-shell {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border-radius: 0;
  }
  .bubble { max-width: 86%; font-size: 16px; }
}
