:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #10131a;
  --muted: #6b7280;
  --accent: #4c6fff;
  --accent-soft: #e8edff;
  --bubble-user: #4c6fff;
  --bubble-user-text: #ffffff;
  --bubble-bot: #ffffff;
  --line: rgba(16, 19, 26, 0.08);
  --shadow: 0 8px 24px rgba(16, 19, 26, 0.08);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b24;
    --text: #eef1f7;
    --muted: #9aa3b2;
    --accent: #7c93ff;
    --accent-soft: #1d2540;
    --bubble-user: #4c6fff;
    --bubble-bot: #1a1f2a;
    --line: rgba(255, 255, 255, 0.08);
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

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

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 10px;
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
  z-index: 5;
}

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

.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #4c6fff, #8a5bff);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.brand-name { font-weight: 700; letter-spacing: 0.2px; }

.who { color: var(--muted); font-size: 13px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 10px; align-items: flex-end; }
.msg.user { justify-content: flex-end; }

.avatar {
  width: 28px; height: 28px; flex: 0 0 28px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #4c6fff, #8a5bff);
  color: #fff; font-size: 14px; font-weight: 700;
}

.bubble {
  background: var(--bubble-bot);
  border-radius: var(--radius);
  border-bottom-left-radius: 6px;
  padding: 12px 15px;
  box-shadow: var(--shadow);
  max-width: min(86%, 620px);
  line-height: 1.45;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-radius: var(--radius);
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 18px rgba(76, 111, 255, 0.28);
}

.bubble h4 { margin: 0 0 8px; font-size: 15px; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 6px 0 10px; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.bubble code { background: var(--accent-soft); border-radius: 6px; padding: 1px 5px; font-size: 13px; }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.35; animation: pulse 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.sources { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.sources summary { cursor: pointer; color: var(--muted); font-size: 13px; outline: none; }
.sources ol { margin: 8px 0 0; padding-left: 20px; }
.sources li { margin: 6px 0; font-size: 13.5px; }
.sources a { color: var(--accent); text-decoration: none; }
.sources .host { color: var(--muted); font-size: 12px; margin-left: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform 0.12s ease, background 0.12s ease;
}
.chip:hover { transform: translateY(-1px); background: var(--accent-soft); }
.chip[disabled] { opacity: 0.5; cursor: default; transform: none; }

.composer {
  position: sticky;
  bottom: 0;
  padding: 8px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 78%, transparent);
  z-index: 5;
}

.suggest { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.suggest::-webkit-scrollbar { display: none; }
.suggest button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.suggest button:hover { background: var(--accent-soft); }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 6px 6px 6px 14px;
  box-shadow: var(--shadow);
}

#input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.35;
  resize: none;
  max-height: 140px;
  padding: 7px 0;
  outline: none;
}
#input::placeholder { color: var(--muted); }

.send {
  flex: 0 0 38px;
  width: 38px; height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.12s ease;
}
.send:disabled { opacity: 0.45; cursor: default; }
.send:not(:disabled):hover { transform: translateY(-1px); }

.footline { text-align: center; color: var(--muted); font-size: 11px; margin-top: 9px; letter-spacing: 0.3px; }

.notice {
  margin: 0 0 12px;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
}

.error { color: #e04b4b; }

@media (max-width: 420px) {
  .bubble { font-size: 15px; }
  .chat { padding: 6px 12px 16px; }
}
