:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1d1c1a; --muted: #5d5a54; --line: #dedad2;
  --accent: #8a1c1c; --accent-ink: #ffffff; --soft: #efece6; --cite: #8a1c1c;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); -webkit-text-size-adjust: 100%; }
body.chat { display: flex; flex-direction: column; min-height: 100dvh; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: rgba(246, 245, 242, .94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.short { display: none; }
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .01em; }
.mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.ghost:hover { background: var(--soft); }

.login-box { max-width: 420px; margin: 8vh auto; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.login-box h1 { font-size: 22px; line-height: 1.3; margin: 0 0 8px; }
.login-box form { display: grid; gap: 14px; margin-top: 18px; }
.login-box label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.login-box input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.login-box button[type=submit] { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 11px; font-weight: 600; }
.err { color: #a11; min-height: 1.2em; margin: 0; font-size: 14px; }
.ai-note { color: var(--muted); font-size: 14px; margin: 0; }
.ai-note.small { font-size: 12.5px; text-align: center; margin-top: 6px; }

.thread { flex: 1; width: 100%; max-width: 780px; margin: 0 auto; padding: 24px 20px 12px; }
.welcome h1 { font-size: 26px; line-height: 1.25; margin: 6vh 0 10px; }
.welcome p { color: var(--muted); margin: 0 0 18px; }
.examples { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.ex { width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; color: var(--ink); line-height: 1.45; }
.ex:hover { border-color: #c9c3b8; }

.msg { margin: 0 0 22px; overflow-wrap: anywhere; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user p { margin: 0; max-width: 85%; background: var(--soft); border-radius: 14px; padding: 10px 14px; }
.msg.bot .answer > :first-child { margin-top: 0; }
.msg.bot h3 { font-size: 17px; margin: 18px 0 6px; }
.msg.bot ul, .msg.bot ol { padding-left: 22px; margin: 6px 0 10px; }
.msg.bot li { margin: 3px 0; }
.msg.bot li.sub { margin-left: 22px; list-style-type: circle; }
.msg.bot p { margin: 0 0 10px; }
.msg.bot code { background: var(--soft); padding: 1px 5px; border-radius: 4px; font-size: 14px; }
.msg.error p { color: #8a1111; background: #fbecec; border: 1px solid #efc9c9; border-radius: 10px; padding: 10px 14px; }
.cite { display: inline-block; min-width: 18px; padding: 0 5px; margin: 0 1px; border-radius: 9px; background: #f1e3e3; color: var(--cite);
  font-size: 11.5px; line-height: 18px; text-align: center; text-decoration: none; vertical-align: 2px; font-weight: 600; }
.thinking { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: .25 } 50% { opacity: 1 } }

.sources { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.sources summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; }
.sources ol { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.sources li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.4; }
.sources .n { flex: none; width: 22px; height: 22px; border-radius: 6px; background: var(--soft); display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.sources a { text-decoration: none; font-weight: 550; }
.sources a:hover { text-decoration: underline; }
.sources .meta { display: block; color: var(--muted); font-size: 12.5px; }
.ed10 { color: #8a5a00; font-weight: 600; }

.composer { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 82%, rgba(246, 245, 242, 0)); padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer form { max-width: 780px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 14px; box-shadow: 0 2px 10px rgba(0, 0, 0, .05); }
.composer textarea { flex: 1; min-width: 0; border: 0; outline: none; resize: none; font: inherit; line-height: 1.5; padding: 6px 0; background: transparent; color: var(--ink); max-height: 220px; }
#send { flex: none; background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 8px 14px; font-weight: 600; }
#send:disabled { opacity: .5; cursor: default; }

@media (max-width: 560px) {
  .top { padding: 8px 12px; }
  .brand span:last-child { font-size: 15px; }
  .ghost { padding: 5px 9px; font-size: 13px; }
  .long { display: none; }
  .short { display: inline; }
  .actions { flex-wrap: nowrap; }
  .thread { padding: 16px 14px 8px; }
  .welcome h1 { font-size: 22px; margin-top: 3vh; }
  .login-box { margin: 4vh 14px; padding: 22px; }
}
