:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1b1f24; --muted: #66707c; --border: #e3e6ea;
  --accent: #2557d6; --accent-soft: #e8eefc; --user: #2557d6; --user-text: #fff; --warn: #fff6dd;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --surface: #1a1e24; --text: #e6e9ed; --muted: #9aa4af; --border: #2b313a;
    --accent: #7aa2ff; --accent-soft: #1f2a44; --user: #2f5fd8; --warn: #3a3218; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid;
  place-items: center; font-weight: 700; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.ghost { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 5px 10px;
  font-size: 13px; text-decoration: none; }
.ghost:hover { background: var(--accent-soft); }

.chat { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.welcome, .messages { max-width: 820px; margin: 0 auto; }
.welcome { text-align: center; padding-top: 8vh; }
.welcome h1 { font-size: 26px; margin: 0 0 8px; }
.banner { background: var(--warn); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  margin: 16px auto; font-size: 13px; max-width: 600px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.suggestion { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; }
.suggestion:hover { border-color: var(--accent); }

.msg { margin: 0 0 18px; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; max-width: 100%; width: 100%; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.bubble table { border-collapse: collapse; margin: 6px 0; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.cite { display: inline-block; min-width: 18px; padding: 0 4px; margin: 0 1px; font-size: 11px; line-height: 16px;
  text-align: center; border-radius: 4px; background: var(--accent-soft); color: var(--accent); text-decoration: none;
  vertical-align: 2px; cursor: pointer; }
.typing { color: var(--muted); }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.sources { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.sources summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.source { display: block; padding: 8px 10px; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px;
  text-decoration: none; color: inherit; font-size: 13px; }
.source:hover, .source.flash { border-color: var(--accent); }
.source .t { font-weight: 600; }
.source .m { color: var(--muted); font-size: 12px; }
.source .s { color: var(--muted); font-size: 12px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin-right: 6px; }

.composer { display: flex; gap: 8px; max-width: 820px; width: calc(100% - 32px); margin: 8px auto 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; }
.composer textarea { flex: 1; border: 0; resize: none; background: transparent; color: var(--text); font: inherit;
  padding: 6px 8px; max-height: 200px; outline: none; }
.composer button { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 0 18px; }
.composer button:disabled { opacity: .5; cursor: default; }

.persona { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.persona select { font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; }
.level-badge, .lvl { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.lvl { margin-left: 8px; font-size: 11px; }
.lvl-1 { background: var(--accent-soft); color: var(--accent); }
.lvl-2 { background: #e6f4ea; color: #1e7a3c; }
.lvl-3 { background: #fdecea; color: #b3261e; }
@media (prefers-color-scheme: dark) {
  .lvl-2 { background: #173322; color: #7fd69a; }
  .lvl-3 { background: #3a1a18; color: #ff9b90; }
}
.access-note { font-size: 13px; color: var(--muted); max-width: 600px; margin: 8px auto 0; }

@media (max-width: 640px) {
  .persona { order: -1; width: 100%; justify-content: flex-end; }
  .topbar { padding: 8px 16px; }
  #sync-info, #user-name { display: none; }
  .bubble { max-width: 100%; }
}
