:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-accent: #e9eefb;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-strong: #ffffff;
  --text: #121826;
  --muted: #5f6b85;
  --border: rgba(18, 24, 38, 0.08);
  --shadow: 0 18px 50px rgba(18, 24, 38, 0.12);
  --user-bubble: linear-gradient(135deg, #2563eb, #1d4ed8);
  --bot-bubble: #edf2ff;
  --bot-text: #182038;
  --focus: #2563eb;
  --composer: rgba(255, 255, 255, 0.92);
  --ring: rgba(37, 99, 235, 0.18);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-accent: #111a33;
  --surface: rgba(16, 22, 40, 0.88);
  --surface-strong: #111827;
  --text: #e8edf8;
  --muted: #93a1bd;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  --bot-bubble: #1b2742;
  --bot-text: #edf3ff;
  --composer: rgba(15, 23, 42, 0.94);
  --ring: rgba(96, 165, 250, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.12), transparent 24%),
    linear-gradient(180deg, var(--bg), var(--bg-accent));
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 18px;
  overflow: hidden;
}

.app {
  width: min(100%, 980px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.app::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 36%);
  pointer-events: none;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.18);
  position: relative;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.32);
  flex: none;
}

.title-wrap {
  min-width: 0;
}

.title {
  margin: 0;
  font-size: clamp(1.1rem, 1vw + 1rem, 1.45rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.chip,
.icon-button,
.send-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
}

.chip {
  padding: 9px 14px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.88rem;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(18, 24, 38, 0.08);
}

.icon-button:hover,
.send-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(18, 24, 38, 0.12);
}

.icon-button:focus-visible,
.send-button:focus-visible,
.composer input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 6px var(--ring);
  border-color: var(--focus);
}

.chat-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 18px 10px;
}


.messages {
  list-style: none;
  margin: 0;
  padding: 4px 6px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  flex: 1;
  min-height: 0;
}

.messages::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(99, 115, 129, 0.35);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.message-row {
  display: flex;
  width: 100%;
  animation: fadeUp 220ms ease both;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.bot {
  justify-content: flex-start;
}

.bubble {
  max-width: min(74%, 640px);
  padding: 12px 14px;
  border-radius: 20px;
  box-shadow: 0 12px 26px rgba(18, 24, 38, 0.08);
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.user .bubble {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 8px;
}

.bot .bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border-bottom-left-radius: 8px;
  border: 1px solid var(--border);
}

.meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 7px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 18px 14px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.12));
  position: sticky;
  bottom: 0;
  z-index: 1;
}

.composer-shell {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--composer);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 10px 24px rgba(18, 24, 38, 0.06);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.composer-shell:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 6px var(--ring), 0 10px 24px rgba(18, 24, 38, 0.08);
  transform: translateY(-1px);
}

.composer input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: clamp(0.98rem, 0.9vw + 0.85rem, 1.05rem);
  outline: none;
}

.composer input::placeholder {
  color: var(--muted);
}

.hint {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
  padding-left: 6px;
}

.send-button {
  height: 48px;
  padding: 0 18px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: 0;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 14px 26px rgba(37, 99, 235, 0.24);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.footer-note {
  position: absolute;
  right: 20px;
  bottom: 66px;
  color: var(--muted);
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  backdrop-filter: blur(10px);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  body {
    padding: 0;
  }

  .app {
    width: 100%;
    min-height: 100dvh;
    border-radius: 0;
  }

  .header,
  .chat-area,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chip {
    display: none;
  }

  .bubble {
    max-width: 86%;
  }

  .footer-note {
    display: none;
  }
}
