:root {
  --bg: #FAF8F3;
  --surface: #ffffff;
  --surface-2: #efeadd;
  --sidebar: #F3EFE5;
  --sidebar-text: #1B1F1D;
  --sidebar-muted: #5F6762;
  --sidebar-hover: rgba(27, 31, 29, 0.07);
  --text: #1B1F1D;
  --muted: #5F6762;
  --border: #E6E1D5;
  --accent: #0F6B57;
  --accent-hover: #0B5645;
  --accent-text: #ffffff;
  --gold: #e0a22b;
  --user-bubble: #EFEBE0;
  --user-text: #1B1F1D;
  --danger: #b3261e;
  --ok: #16794c;
  --ok-bg: #e4f4ea;
  --bad-bg: #fbe9e7;
  --shadow: 0 8px 30px rgba(20, 40, 30, 0.12);
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --surface: #18201c;
    --surface-2: #202a25;
    --sidebar: #0a0f0d;
    --sidebar-text: #e3ebe6;
    --sidebar-muted: #8aa397;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --text: #e6ece8;
    --muted: #93a39a;
    --border: #2a3630;
    --accent: #2fb594;
    --accent-hover: #4ccaa9;
    --accent-text: #06231b;
    --gold: #f2b84b;
    --user-bubble: #26312c;
    --user-text: #ffffff;
    --danger: #ff8a80;
    --ok: #62d79a;
    --ok-bg: #12301f;
    --bad-bg: #3a1b18;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; max-width: 100%; overflow-x: hidden; }
@supports (height: 100dvh) { html, body, .shell { height: 100dvh; } }
*, *::before, *::after { min-width: 0; }
button, .btn, .chip, .round, .icon-btn, .avatar, svg.i { min-width: auto; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }
.hidden { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
a { color: var(--accent); }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); text-decoration: none; font-weight: 600; color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { background: none; border: none; font-size: 20px; padding: 6px 10px; border-radius: 8px; color: inherit; }
.icon-btn:hover { background: var(--sidebar-hover); }
.link-btn { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 8px 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
input[type='text'], input[type='email'], input[type='password'], select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); min-height: 44px;
}
.form-error { color: var(--danger); margin: 0 0 12px; min-height: 0; font-size: 14px; }
.form-error:empty { display: none; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.demo-note {
  background: color-mix(in srgb, var(--gold) 22%, transparent); border: 1px solid var(--gold);
  border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 0 0 14px;
}
.mobile-only { display: none !important; }
.scrim { display: none; }

/* ---------- auth ---------- */
.auth-page { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
  background: var(--sidebar); color: var(--sidebar-text); padding: 56px 8%;
  display: flex; flex-direction: column; justify-content: center; gap: 20px;
}
svg.i { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.auth-hero h1 { font-size: clamp(30px, 4vw, 46px); letter-spacing: -0.02em; }
.auth-hero p { color: var(--sidebar-muted); font-size: 18px; margin: 0; max-width: 34em; }
.hero-points { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.hero-points li::before { content: '✓'; color: var(--gold); font-weight: 700; margin-right: 10px; }
.auth-card { padding: 48px 8%; display: flex; flex-direction: column; justify-content: center; max-width: 520px; width: 100%; margin: 0 auto; }
.auth-card h2 { font-size: 26px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { border-radius: 8px; }
.boot-error, .noscript { padding: 40px; text-align: center; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100%; overflow: hidden; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column;
  padding: 14px 12px; gap: 12px; min-height: 0;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; }
.new-chat { width: 100%; background: var(--surface); border-color: var(--border); color: var(--sidebar-text); }
.new-chat:hover { background: var(--sidebar-hover); }
.chat-list { flex: 1; overflow-y: auto; min-height: 0; }
.group-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--sidebar-muted); margin: 14px 8px 6px; font-weight: 600; }
.empty-list { color: var(--sidebar-muted); font-size: 14px; padding: 8px; }
.chat-item { display: flex; align-items: center; border-radius: 9px; }
.chat-item:hover, .chat-item.active { background: var(--sidebar-hover); }
.chat-open {
  flex: 1; min-width: 0; text-align: left; background: none; border: none; color: inherit;
  padding: 9px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px;
}
.chat-act { background: none; border: none; color: var(--sidebar-muted); padding: 6px 6px; opacity: 0; font-size: 14px; border-radius: 6px; }
.chat-item:hover .chat-act, .chat-item:focus-within .chat-act { opacity: 1; }
.chat-act:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }
.sidebar-foot { position: relative; border-top: 1px solid var(--border); padding-top: 10px; }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: none; color: inherit; text-align: left; padding: 8px; border-radius: 10px; }
.user-btn:hover { background: var(--sidebar-hover); }
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong, .user-meta small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--sidebar-muted); }
.avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--gold); color: #2b1d00; display: grid; place-items: center; font-weight: 700; }
.user-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.user-menu button { background: none; border: none; text-align: left; padding: 10px 12px; border-radius: 8px; }
.user-menu button:hover { background: var(--surface-2); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg); }
.topbar .icon-btn { color: var(--text); }
.chat-title { font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cert-btn { background: var(--gold); border-color: var(--gold); color: #2b1d00; }
.cert-btn:hover { background: #eab444; }

.messages { flex: 1; overflow-y: auto; padding: 24px 20px 8px; scroll-behavior: smooth; }
.messages > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.msg { display: flex; gap: 12px; margin-bottom: 22px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); color: var(--user-text); border-radius: 18px 18px 4px 18px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .col { min-width: 0; flex: 1; }
.avatar.bot { background: var(--surface-2); font-size: 18px; }
.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0.6em 0; }
.prose h3, .prose h4, .prose h5 { margin: 1.2em 0 0.4em; }
.prose h2 { margin: 1.2em 0 0.4em; font-size: 1.25em; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0.5em 0; }
.prose li { margin: 0.25em 0; }
.prose code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 0.92em; }
.prose pre { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 0.6em 0; padding: 2px 14px; border-left: 3px solid var(--gold); color: var(--muted); }
.table-wrap { overflow-x: auto; margin: 0.8em 0; }
.prose table { border-collapse: collapse; min-width: 60%; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.msg-error { color: var(--danger); font-weight: 600; }
.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

.sources { margin-top: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 14px; font-size: 14px; }
.sources summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.sources ul { list-style: none; padding: 0; margin: 6px 0 4px; display: grid; gap: 6px; }
.src-kind { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); color: var(--muted); border-radius: 6px; padding: 1px 7px; margin-right: 8px; }
.sources small { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.chip:hover { background: var(--surface-2); }
.chip.accent { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 20%, transparent); font-weight: 600; }

.empty { text-align: center; padding: 8vh 0 0; }
.empty h2 { font-size: clamp(24px, 4vw, 34px); letter-spacing: -0.02em; }
.empty p { color: var(--muted); max-width: 34em; margin: 12px auto 22px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; }
.suggestion { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; font-weight: 600; text-align: left; }
.suggestion:hover { border-color: var(--accent); }

.composer { padding: 8px 20px 14px; }
.composer > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow); }
.composer-box:focus-within { border-color: var(--accent); }
.composer-input { flex: 1; border: none; outline: none; resize: none; background: transparent; max-height: 200px; padding: 8px 0; line-height: 1.45; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--accent); color: var(--accent-text); font-size: 16px; flex: none; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn.stop { background: var(--danger); color: #fff; }
.fineprint { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--bg); color: var(--text); border-radius: 18px; width: min(520px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 20px; }
.modal-head .icon-btn:hover { background: var(--surface-2); }
.modal-body { padding: 18px 20px 20px; overflow-y: auto; }
.spinner { width: 32px; height: 32px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.quiz-loading { text-align: center; padding: 20px 0; color: var(--muted); }
.quiz-intro { margin-top: 0; color: var(--muted); }
.q { border: 1px solid var(--border); border-radius: 12px; margin: 0 0 14px; padding: 12px 16px 8px; background: var(--surface); }
.q legend { font-weight: 600; float: left; width: 100%; padding: 0; margin: 0 0 6px; }
.q legend + .opt { clear: both; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 6px; border-radius: 8px; cursor: pointer; }
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: 5px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.quiz-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; bottom: -20px; background: var(--bg); padding: 12px 0 4px; }
.quiz-progress { color: var(--muted); font-size: 14px; }
.result-head { display: flex; gap: 16px; align-items: center; padding: 16px; border-radius: 14px; margin-bottom: 14px; }
.result-head.pass { background: var(--ok-bg); }
.result-head.fail { background: var(--bad-bg); }
.result-head p { margin: 4px 0 0; }
.score { font-size: 34px; font-weight: 800; min-width: 84px; text-align: center; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.review { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; border: 1px solid var(--border); background: var(--surface); }
.review.ok { border-left: 4px solid var(--ok); }
.review.bad { border-left: 4px solid var(--danger); }
.review p { margin: 3px 0; }
.review-q { font-weight: 600; }
.review-a.good { color: var(--ok); }
.review-e { color: var(--muted); font-size: 14px; }
.cert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.cert-list li { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.cert-list small { display: block; color: var(--muted); }
.cert-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.settings .quiz-foot { position: static; padding-top: 8px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 24px; }
  .auth-hero p { font-size: 16px; }
  .auth-card { padding: 28px 24px 40px; }
  .shell { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid !important; }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar-open .sidebar { transform: none; }
  .scrim { display: none; }
  .sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 30; }
  .chat-act { opacity: 1; }
  .suggestions { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
  .messages { padding: 16px 14px 4px; }
  .composer { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); }
  .msg.user .bubble { max-width: 92%; }
  .avatar.bot { display: none; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 18px 18px 0 0; max-height: 92vh; }
  .result-head { flex-direction: column; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- v2: Claude-like flat chat, icons, voice, trust UI ---------- */
.auth-hero { background: var(--sidebar); border-right: 1px solid var(--border); }
.auth-hero .hero-points li::before { color: var(--accent); }
.btn { gap: 8px; }
.icon-btn { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; }
.icon-btn:hover { background: var(--surface-2); }
.user-menu button { display: flex; align-items: center; gap: 10px; }
.avatar { background: var(--accent); color: #fff; }
.cert-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
.cert-btn:hover { background: var(--accent-hover); }
.msg.assistant .col { min-width: 0; flex: 1; }
.msg { margin-bottom: 26px; }
.prose pre { background: #1d2420; color: #e9efe9; border-radius: 12px; }
.prose pre code { color: inherit; }

.greeting { font-size: clamp(28px, 4.5vw, 40px); font-weight: 500; letter-spacing: -0.02em; font-family: Newsreader, Georgia, 'Times New Roman', serif; }
.slide-word { display: inline-block; opacity: 0; transform: translateY(14px); animation: slideIn 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) forwards; white-space: pre; }
@keyframes slideIn { to { opacity: 1; transform: none; } }
.empty .sub { color: var(--muted); max-width: 34em; margin: 10px auto 26px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; text-align: left; }
.tile { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; font-weight: 600; min-height: 96px; }
.tile .i { color: var(--accent); }
.tile:hover { border-color: var(--accent); }

.composer-box { flex-direction: column; align-items: stretch; gap: 4px; border-radius: 24px; padding: 12px 12px 10px 20px; }
.composer-input { padding: 4px 0 6px; font-size: 16px; }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1 1 auto; }
.chip-select { width: auto; min-height: 36px; padding: 4px 28px 4px 12px; border-radius: 999px; background: var(--bg); font-size: 13px; max-width: 150px; text-overflow: ellipsis; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: grid; place-items: center; flex: none; padding: 0; }
.round:hover { background: var(--surface-2); }
.round.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.round.primary:hover { background: var(--accent-hover); }
.round.primary:disabled { background: #D9D5C8; border-color: #D9D5C8; cursor: not-allowed; }
.round.stop { background: var(--danger); border-color: var(--danger); color: #fff; }
.round:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-box:has(.voice-row:not(.hidden)) { border-color: var(--accent); border-width: 1.5px; }
.voice-row { display: flex; align-items: center; gap: 12px; padding: 4px 0 8px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #C0392B; flex: none; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.rec-time { font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; min-width: 44px; }
.wave { flex: 1 1 auto; height: 36px; display: flex; align-items: center; gap: 3px; overflow: hidden; }
.wave i { width: 3px; height: 4px; border-radius: 2px; background: var(--accent); flex: none; transition: height 0.05s; }
.quick-chips { display: flex; gap: 8px; margin-bottom: 8px; overflow-x: auto; padding-bottom: 2px; }
.quick-chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; min-height: 36px; }

.source-cards { display: grid; gap: 8px; margin-top: 14px; }
.src-head { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; margin: 0; color: var(--accent); }
.source-card { display: flex; align-items: center; gap: 10px; padding: 11px 14px; min-height: 44px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text); font-size: 14px; }
.source-card:hover { border-color: var(--accent); }
.source-card .src-title { flex: 1 1 auto; min-width: 0; }
.source-card small { color: var(--muted); }
.source-card .i:last-child { color: var(--muted); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin: 12px 0 0; padding: 9px 12px; border-radius: 10px; }
.check p { margin: 0; display: flex; gap: 8px; align-items: center; }
.check.ok { background: var(--ok-bg); color: var(--ok); }
.check.bad { background: var(--bad-bg); color: var(--danger); display: block; }
.check ul { margin: 6px 0 0; padding-left: 22px; }
.checking { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.spinner.sm { width: 14px; height: 14px; border-width: 2px; margin: 0; }
.fact { margin-top: 12px; }
.claims { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
.claim { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; }
.claim small { color: var(--muted); }
.claim .verdict { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.claim.supported { border-left: 4px solid var(--ok); } .claim.supported .verdict { color: var(--ok); }
.claim.doubtful { border-left: 4px solid #B45309; } .claim.doubtful .verdict { color: #B45309; }
.claim.wrong { border-left: 4px solid var(--danger); } .claim.wrong .verdict { color: var(--danger); }

.cert-dialog { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; }
.cert-paper { background: #FFFDF7; color: #1B1F1D; border: 3px double #C9A24B; padding: 28px 22px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.cert-paper h3 { font-family: Newsreader, Georgia, serif; font-size: 30px; font-weight: 500; }
.cert-paper .seal { width: 48px; height: 48px; border-radius: 50%; background: #F2DFA6; color: #6B4A0A; border: 2px solid #C9A24B; display: grid; place-items: center; }
.cert-org { font-size: 12px; font-weight: 600; letter-spacing: 0.3em; color: var(--accent); margin: 6px 0 0; }
.cert-sub { font-style: italic; color: #5F6762; margin: 10px 0 0; }
.cert-name { font-family: Newsreader, Georgia, serif; font-size: 30px; border-bottom: 1px solid #C9A24B; padding: 0 18px 2px; margin: 0; }
.cert-topic { font-size: 22px; font-weight: 600; color: var(--accent); margin: 0; }
.cert-id { font-family: ui-monospace, Consolas, monospace; font-size: 13px; margin-top: 12px; }
.cert-note { font-size: 11px; color: #5F6762; max-width: 36em; }
.cert-side { display: flex; flex-direction: column; gap: 18px; }
.cert-side h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.cert-side .row { display: flex; gap: 10px; }
.cert-side .row .btn { flex: 1; }
.cert-side .grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.cert-side .btn.block { margin-top: 10px; }
.share-text { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin: 0 0 12px; overflow-wrap: anywhere; }
.modal.wide { width: min(960px, 100%); }
.course-view { max-width: 70ch; }

#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; color: #000; background: #fff; padding: 0; font-size: 12pt; }
  #print-root pre { background: #f3f3f3; color: #000; border: 1px solid #ccc; white-space: pre-wrap; }
  #print-root h2 { break-after: avoid; }
  .print-foot { margin-top: 24pt; font-size: 9pt; color: #555; }
}
@media (max-width: 860px) {
  .tiles { grid-template-columns: 1fr; }
  .cert-dialog { grid-template-columns: 1fr; }
  .chip-select { max-width: 112px; }
}

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle { position: absolute; right: 2px; top: 0; bottom: 0; width: 44px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; border-radius: 10px; }
.pw-toggle:hover { color: var(--text); }
.forgot { margin: -6px 0 10px; padding: 4px 0; text-decoration: none; font-weight: 600; font-size: 14px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 14px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.google-box { display: flex; justify-content: center; min-height: 0; margin-bottom: 8px; }

/* ---------- phone fixes: nothing may be wider than the screen ---------- */
.composer, .composer > *, .composer-box, .composer-bar, .messages, .main, .msg, .msg .col, .prose { max-width: 100%; }
.composer-bar { flex-wrap: nowrap; }
.chip-select { flex: 1 1 0; width: 0; min-width: 0; max-width: 170px; text-overflow: ellipsis; }
.prose pre { overflow-x: auto; max-width: 100%; }
.prose table { display: block; overflow-x: auto; max-width: 100%; }
.prose img { max-width: 100%; height: auto; }
.prose p, .prose li, .bubble { overflow-wrap: anywhere; }
@media (max-width: 520px) {
  .composer-box { padding: 10px 10px 8px 16px; }
  .composer-bar { gap: 6px; }
  .round { width: 40px; height: 40px; }
  .chip-select { max-width: none; padding-left: 10px; padding-right: 22px; font-size: 13px; }
  .tile { min-height: 72px; padding: 12px 14px; flex-direction: row; align-items: center; }
  .greeting { font-size: 26px; }
  .cert-btn span { display: none; }
  .cert-btn { padding: 8px 10px; }
}
@media (max-width: 520px) {
  .composer-bar .grow { display: none; }
  .composer-bar .chip-select { flex: 1 1 0; padding: 4px 18px 4px 10px; font-size: 13px; background-position: right 6px center; }
}

.working { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.working .typing { padding: 4px 0; }
.status-text { animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.src-num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft, #E2EFEA); color: var(--accent); font-size: 12px; font-weight: 700; display: grid; place-items: center; flex: none; }
.src-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); flex: none; }
.suggest-frame { width: 100%; height: 64px; border: 0; margin-top: 10px; border-radius: 12px; background: transparent; color-scheme: light dark; }
@media (prefers-reduced-motion: reduce) { .typing i, .status-text, .slide-word { animation: none; opacity: 1; transform: none; } }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2, #EFEBE0); overflow: hidden; width: min(360px, 100%); margin: 10px auto 4px; }
.bar i { display: block; height: 100%; width: 5%; background: var(--accent); transition: width 0.6s; }
.modal .tiles .tile strong { font-size: 16px; }

.modal .tiles .tile { flex-direction: column; align-items: flex-start; gap: 4px; min-height: 0; }

/* ---- v4: pictures, long messages, jump arrow, citations, compact sources ---- */
.hidden { display: none !important; }
.msgs-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.msgs-wrap .messages { flex: 1; min-height: 0; }
.jump { position: absolute; right: 16px; bottom: 12px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow); display: grid; place-items: center; z-index: 5; }
.jump:hover { border-color: var(--accent); color: var(--accent); }

.msg.user .ucol { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 85%; min-width: 0; }
.msg.user .ucol .bubble { max-width: 100%; }
.bubble.clamp { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.linkbtn { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 14px; padding: 2px 4px; cursor: pointer; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.pic-note { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; }

.attach-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0 8px; }
.pending { position: relative; width: 64px; height: 64px; }
.pending img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.pending .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: grid; place-items: center; padding: 0; }
.composer-input { overflow-y: auto; }

.cites { white-space: nowrap; }
.cite { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin: 0 1px 0 2px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--accent); font-size: 11px; font-weight: 700; line-height: 1; vertical-align: 0.15em; cursor: pointer; }
.cite:hover, .cite:focus-visible { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.cite-pop { position: fixed; z-index: 60; width: min(320px, calc(100vw - 24px)); display: grid; gap: 4px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; }
.cite-pop strong { font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.cite-pop small { color: var(--muted); }
.cite-pop .cite-kind { text-transform: uppercase; letter-spacing: 0.05em; font-size: 11px; }
.cite-pop .btn { margin-top: 8px; justify-self: start; text-decoration: none; }

.srcs { margin-top: 12px; font-size: 14px; }
.srcs summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-weight: 600; }
.srcs summary::-webkit-details-marker { display: none; }
.srcs summary:hover, .srcs[open] summary { border-color: var(--accent); color: var(--accent); }
.srcs ol { margin: 10px 0 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 2px; }
.srcs li { counter-increment: s; }
.srcs li a { display: grid; grid-template-columns: 24px 1fr; column-gap: 8px; align-items: baseline; padding: 7px 8px; border-radius: 10px; color: var(--text); text-decoration: none; }
.srcs li a::before { content: counter(s); grid-row: span 2; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); color: var(--accent); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.srcs li a:hover { background: var(--surface-2); }
.srcs .src-title { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srcs small { color: var(--muted); }

.memory-box { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.memory-box textarea { width: 100%; resize: vertical; }
.check-row { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.check-row input { width: 18px; height: 18px; }
@media (max-width: 600px) { .jump { bottom: 8px; right: 12px; } .msg.user .ucol { max-width: 92%; } }

/* ---- v4: attached files and projects ---- */
.attach-wrap { position: relative; display: inline-flex; }
.attach-menu { position: absolute; right: 0; bottom: calc(100% + 8px); min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; display: grid; gap: 2px; z-index: 20; }
.attach-menu button { display: flex; align-items: center; gap: 10px; background: none; border: none; color: var(--text); text-align: left; padding: 10px 12px; border-radius: 10px; font-size: 15px; cursor: pointer; }
.attach-menu button:hover, .attach-menu button:focus-visible { background: var(--surface-2); }
.pending.file { width: auto; height: auto; max-width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 36px 10px 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); color: var(--accent); }
.pending.file .file-info { display: grid; min-width: 0; color: var(--text); }
.pending.file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.pending.file small { color: var(--muted); font-size: 12.5px; }
.pending.file .x { top: 6px; right: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--accent); font-size: 14px; }
.file-chip span { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-bar { display: flex; align-items: center; gap: 10px; margin: 0 auto 8px; max-width: 760px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--accent); font-size: 14px; }
.project-bar .pb-text { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-bar .pb-text strong { color: var(--text); }
