:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #eef3fb;
  --line: #dbe3ef;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --user: #e0edff;
  --assistant: #ffffff;
  --error: #ffe4e6;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.send-button {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.icon-button svg,
.send-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover,
.send-button:hover {
  border-color: #c6d4ea;
}

.icon-button:disabled,
.send-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.thread {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
}

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

.bubble {
  max-width: min(72ch, 100%);
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--assistant);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
  overflow-wrap: anywhere;
}

.message--user .bubble {
  background: var(--user);
  border-color: #cfe0ff;
}

.message--error .bubble {
  background: var(--error);
  border-color: #fecdd3;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.bubble.typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #94a3b8;
  animation: pulse 1.1s infinite ease-in-out;
}

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

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

@keyframes pulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(245, 247, 251, 0.96);
}

.composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 168px;
  resize: none;
  padding: 11px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer textarea:focus,
.icon-button:focus-visible,
.send-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.send-button {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.send-button:hover {
  background: var(--accent-strong);
}

.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) {
  .topbar {
    padding-inline: 12px;
  }

  .message-list {
    padding: 12px;
  }

  .composer {
    padding-inline: 12px;
  }

  .bubble {
    max-width: 100%;
  }
}
