:root {
  --db-blue: #0a2fd6;

  --bg: #f3f4f7;
  --bg-soft: #e9ebf0;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --border: #e2e4ea;
  --border-strong: #d2d5dd;
  --text: #1b1d24;
  --text-2: #565b67;
  --muted: #868b97;

  --accent: #0a2fd6;
  --accent-text: #0a2fd6;
  --accent-soft: #e9edfd;
  --chat-overlay: rgba(243, 244, 247, 0.85);

  --r: 12px;
  --r-lg: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --maxw: 760px;
  --sidebar-w: 270px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-modal: 0 20px 60px rgba(20, 22, 40, 0.22);
  --shadow-pop: 0 12px 34px rgba(20, 22, 40, 0.18);
}

[data-theme="dark"] {
  --bg: #1a1a1c;
  --bg-soft: #202022;
  --surface: #232326;
  --surface-2: #2a2a2e;
  --border: #34343a;
  --border-strong: #43434b;
  --text: #ececee;
  --text-2: #a6a6ae;
  --muted: #74747d;

  --accent: #7d97ff;
  --accent-text: #95a9ff;
  --accent-soft: rgba(125, 151, 255, 0.14);
  --chat-overlay: rgba(26, 26, 28, 0.84);

  --shadow-modal: 0 24px 70px rgba(0, 0, 0, 0.6);
  --shadow-pop: 0 14px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; -webkit-font-smoothing: antialiased; overflow: hidden; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: transparent; border-radius: 20px; }
*:hover::-webkit-scrollbar-thumb { background: var(--border-strong); }

input, textarea, select, button { font-family: inherit; color: inherit; font-size: inherit; }
input:focus, textarea:focus, select:focus { outline: none; }
select { cursor: pointer; }

/* ---------- Brand mark ---------- */
.mark { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 7px; background: var(--db-blue); display: grid; place-items: center; }
.mark.sm { width: 26px; height: 26px; border-radius: 6px; }
.mark.lg { width: 52px; height: 52px; border-radius: 12px; }
.db-square { width: 15px; height: 15px; position: relative; border: 2px solid #fff; }
.mark.sm .db-square { width: 13px; height: 13px; border-width: 1.7px; }
.mark.lg .db-square { width: 26px; height: 26px; border-width: 2.6px; }
.db-square .db-slash { position: absolute; inset: 0; }
.db-square .db-slash::after { content: ""; position: absolute; left: 50%; top: 50%; width: 2.6px; height: 19px; background: #fff; transform: translate(-50%, -50%) rotate(45deg); }
.mark.sm .db-square .db-slash::after { width: 2.2px; height: 16px; }
.mark.lg .db-square .db-slash::after { width: 4px; height: 34px; }

.brand { display: flex; align-items: center; gap: 9px; }
.brand-word, .loader-word { font-weight: 700; letter-spacing: -0.01em; font-size: 17px; }
.brand-word span, .loader-word span { color: var(--accent-text); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: var(--r); padding: 11px 18px; font-size: 14.5px; font-weight: 600; cursor: pointer; transition: background 0.15s, border-color 0.15s, opacity 0.15s; background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { opacity: 0.9; }
.btn.ghost { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.ghost.danger { color: #d4374a; border-color: transparent; }
.btn.ghost.danger:hover { background: rgba(212, 55, 74, 0.08); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: none; background: transparent; color: var(--text-2); cursor: pointer; display: grid; place-items: center; font-size: 16px; transition: background 0.15s, color 0.15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Loader ---------- */
.loader { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); transition: opacity 0.4s ease, visibility 0.4s; }
.loader.fade { opacity: 0; visibility: hidden; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loader .mark.lg { animation: pulse 1.8s ease-in-out infinite; }
.loader-word { font-size: 22px; }
.loader-bar { width: 160px; height: 3px; border-radius: 10px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.loader-bar-fill { width: 0%; height: 100%; background: var(--accent); transition: width 0.3s ease; }

/* ---------- Onboarding ---------- */
.onboarding { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; background: var(--bg-soft); overflow-y: auto; animation: fade 0.3s ease; }
.ob-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 36px 34px; }
.ob-card .mark { margin-bottom: 20px; }
.ob-card h1 { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; }
.ob-lead { color: var(--text-2); margin-top: 10px; margin-bottom: 24px; line-height: 1.6; font-size: 14.5px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 7px; }
.field input, .field select { width: 100%; padding: 12px 13px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 14.5px; transition: border-color 0.15s, box-shadow 0.15s; color: var(--text); }
.field input:focus, .field select:focus { border-color: var(--muted); box-shadow: none; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ob-card .btn.primary { margin-top: 8px; padding: 13px; }
.ob-note { display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ---------- App layout ---------- */
.app { display: flex; height: 100vh; animation: fade 0.3s ease; }
.sidebar { width: var(--sidebar-w); flex: 0 0 auto; background: var(--bg-soft); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px 10px; gap: 8px; transition: margin-left 0.28s var(--ease); }
.app.collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); }
.sidebar-top { display: flex; align-items: center; padding: 4px 6px 2px; }

.new-chat { display: flex; align-items: center; gap: 9px; padding: 11px 13px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500; transition: background 0.15s, border-color 0.15s; }
.new-chat:hover { background: var(--surface-2); }
.new-chat i { font-size: 12px; color: var(--text-2); }
.newchat-row { display: flex; gap: 6px; }
.newchat-row .new-chat { flex: 1; }
.newchat-import { width: 42px; height: 42px; flex: 0 0 auto; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); }
.newchat-import:hover { background: var(--surface-2); }
.ctx-menu { position: fixed; z-index: 130; width: 172px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r); box-shadow: var(--shadow-pop); padding: 5px; animation: pop 0.14s var(--ease); }
.ctx-item { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent; color: var(--text); font-size: 13.5px; padding: 9px 11px; border-radius: 8px; cursor: pointer; text-align: left; transition: background 0.15s; }
.ctx-item i { width: 15px; text-align: center; color: var(--text-2); font-size: 12px; }
.ctx-item:hover { background: var(--surface-2); }
.ctx-item.danger { color: #d4374a; }
.ctx-item.danger i { color: #d4374a; }
.ctx-item.danger:hover { background: rgba(212, 55, 74, 0.1); }

.chat-search { position: relative; margin-bottom: 2px; }
.chat-search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
.chat-search input { width: 100%; padding: 8px 10px 8px 32px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--text); }
.chat-search input:focus { border-color: var(--muted); }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-group { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 12px 8px 4px; }
.chat-group:first-child { padding-top: 4px; }
.chat-item { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 9px; cursor: pointer; color: var(--text-2); font-size: 13.5px; transition: background 0.15s, color 0.15s; }
.chat-item:hover { background: var(--surface-2); color: var(--text); }
.chat-item.active { background: var(--surface-2); color: var(--text); font-weight: 500; }
.chat-item .ci-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-actions { display: flex; flex: 0 0 auto; }
.ci-act { opacity: 0; width: 24px; height: 24px; border-radius: 6px; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; transition: opacity 0.15s, color 0.15s, background 0.15s; }
.chat-item:hover .ci-act { opacity: 1; }
.ci-act:hover { background: var(--bg-soft); color: var(--text); }
.ci-act.del-act:hover { color: #d4374a; }
.ci-rename { flex: 1; min-width: 0; border: 1px solid var(--accent); border-radius: 7px; background: var(--surface); color: var(--text); font-size: 13.5px; padding: 5px 8px; box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-empty { color: var(--muted); font-size: 12.5px; text-align: center; padding: 24px 10px; }
.clear-history { display: none; margin: 4px 2px 0; padding: 8px; border: none; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; border-radius: 8px; transition: background 0.15s, color 0.15s; }
.clear-history:hover { background: var(--surface-2); color: #d4374a; }

.sidebar-bottom { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 8px; }
.side-link { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; border: none; background: transparent; cursor: pointer; color: var(--text-2); font-size: 13.5px; transition: background 0.15s, color 0.15s; }
.side-link:hover { background: var(--surface-2); color: var(--text); }
.side-link i { width: 16px; text-align: center; font-size: 14px; }
.profile-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r); border: none; background: transparent; cursor: pointer; margin-top: 2px; transition: background 0.15s; }
.profile-card:hover { background: var(--surface-2); }
.profile-meta { display: flex; flex-direction: column; text-align: left; overflow: hidden; line-height: 1.3; }
.profile-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-role { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar { width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; overflow: hidden; }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.avatar.xs { width: 20px; height: 20px; font-size: 10.5px; }
.avatar.lg { width: 56px; height: 56px; font-size: 22px; }
.avatar img, .avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sidebar-scrim { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.scroll-btn { position: absolute; right: 24px; bottom: 100px; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; box-shadow: var(--shadow-md); display: grid; place-items: center; z-index: 6; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s var(--ease), color 0.15s, background 0.15s; }
.scroll-btn.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
.scroll-btn:hover { color: var(--text); background: var(--surface-2); }
.topbar { height: 54px; flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.top-title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.top-actions #topProfile { margin-left: 8px; }

/* ---------- Chat / welcome ---------- */
.chat { flex: 1; overflow-y: auto; }
.main.has-bg { background-image: linear-gradient(var(--chat-overlay), var(--chat-overlay)), var(--chat-bg-img); background-size: cover; background-position: center; background-repeat: no-repeat; }
.main.has-bg.anim { background-size: 340% 340%; animation: bgShift 24s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .main.has-bg.anim { animation: none; background-size: cover; } }
.welcome { max-width: var(--maxw); margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 48px 24px; }
.welcome-head { text-align: center; }
.context-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--accent-text); background: var(--accent-soft); padding: 6px 12px; border-radius: 20px; margin-bottom: 16px; }
.welcome-title { font-size: clamp(26px, 4vw, 33px); font-weight: 700; letter-spacing: -0.025em; }
.welcome-sub { color: var(--text-2); font-size: 16px; margin-top: 8px; }

.explore { margin-top: 32px; }
.explore-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding-bottom: 2px; }
.explore-tab { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 22px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; transition: background 0.15s, color 0.15s, border-color 0.15s; }
.explore-tab:hover { color: var(--text); border-color: var(--muted); }
.explore-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.explore-tab i { font-size: 12px; }

.explore-list { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.explore-item { display: flex; align-items: flex-start; gap: 12px; padding: 15px 16px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); cursor: pointer; text-align: left; font-size: 14px; color: var(--text); transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s; }
.explore-item:hover { background: var(--surface-2); border-color: var(--border-strong); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20, 22, 40, 0.06); }
.explore-item .ei-ico { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 8px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: 13px; }
.explore-item .ei-q { flex: 1; line-height: 1.45; padding-top: 4px; }
.explore-item .ei-arrow { display: none; }

/* ---------- Messages ---------- */
.messages { max-width: var(--maxw); margin: 0 auto; padding: 24px 24px 12px; display: none; flex-direction: column; gap: 22px; }
.chat.has-messages .welcome { display: none; }
.chat.has-messages .messages { display: flex; }
.msg { display: flex; flex-direction: column; animation: rise 0.35s var(--ease); }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--surface-2); border-radius: 16px; padding: 11px 15px; max-width: 85%; line-height: 1.55; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.msg-head .mini { width: 20px; height: 20px; border-radius: 5px; background: var(--db-blue); display: grid; place-items: center; }
.msg-head .mini .db-square { width: 10px; height: 10px; border-width: 1.4px; }
.msg-head .mini .db-square .db-slash::after { width: 1.8px; height: 13px; }

.bubble { font-size: 15px; line-height: 1.7; color: var(--text); }
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h2.md-h { font-size: 15px; font-weight: 700; margin: 18px 0 8px; }
.bubble ul, .bubble ol { margin: 0 0 12px; padding-left: 22px; display: flex; flex-direction: column; gap: 5px; }
.bubble li::marker { color: var(--muted); }
.bubble strong { font-weight: 600; }
.bubble code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; font-size: 13px; font-family: ui-monospace, "Cascadia Code", monospace; }
.bubble blockquote { border-left: 3px solid var(--border-strong); padding: 2px 0 2px 14px; margin: 0 0 12px; color: var(--text-2); }
.bubble .md-table { width: 100%; border-collapse: collapse; margin: 4px 0 14px; font-size: 13.5px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.bubble .md-table th { background: var(--surface-2); text-align: left; padding: 9px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.bubble .md-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.bubble .md-table tr:last-child td { border-bottom: none; }

/* sources */
.sources { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.sources-label { font-size: 11.5px; color: var(--muted); font-weight: 500; margin-right: 2px; }
.source-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border-strong); padding: 6px 11px; border-radius: 20px; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.source-chip:hover { background: var(--surface-2); border-color: var(--muted); }
.source-chip i { color: var(--accent-text); font-size: 11px; }

.related { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.related-q { font-size: 12.5px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); padding: 7px 13px; border-radius: 20px; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.related-q:hover { background: var(--surface-2); border-color: var(--muted); }

.msg-actions { margin-top: 10px; display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.msg.bot:hover .msg-actions { opacity: 1; }
.msg-act { width: 28px; height: 28px; border-radius: 7px; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; transition: background 0.15s, color 0.15s; }
.msg-act:hover { background: var(--surface-2); color: var(--text); }
.msg-act.active { color: var(--accent-text); }
.msg-act.ok { color: #22a06b; }
.msg.user .msg-actions { justify-content: flex-end; }
.msg.user .bubble:hover ~ .msg-actions,
.msg.user .msg-atts:hover ~ .msg-actions,
.msg.user .ver-nav:hover ~ .msg-actions,
.msg.user .msg-actions:hover { opacity: 1; }
.edit-box { width: 100%; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; padding: 8px 10px 10px 16px; box-shadow: var(--shadow-md); animation: rise 0.22s var(--ease); }
.edit-ta { width: 100%; border: none; outline: none; background: transparent; color: var(--text); font-size: 15px; line-height: 1.6; padding: 9px 0 6px; resize: none; min-height: 50px; }
.edit-actions { display: flex; align-items: center; gap: 8px; }
.edit-hint { font-size: 11.5px; color: var(--muted); margin-right: auto; display: inline-flex; align-items: center; gap: 6px; }
.edit-hint i { color: var(--accent-text); }
.edit-actions .btn { padding: 8px 15px; font-size: 13px; border-radius: 12px; }
.ver-nav { display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; font-size: 12px; color: var(--muted); align-self: flex-end; }
.ver-btn { width: 22px; height: 22px; border: none; background: transparent; color: var(--text-2); border-radius: 6px; cursor: pointer; font-size: 10px; display: grid; place-items: center; transition: background 0.15s, color 0.15s; }
.ver-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.ver-btn:disabled { opacity: 0.35; cursor: default; }
.md-hr { border: none; border-top: 1px solid var(--border-strong); margin: 14px 0; }
.bubble em { font-style: italic; }
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.cursor-blink { display: inline-block; width: 7px; height: 15px; background: var(--accent); margin-left: 2px; vertical-align: text-bottom; animation: caret 1s step-end infinite; }

.prerun { display: flex; flex-direction: column; gap: 9px; padding: 2px 0; }
.pr-step { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-2); animation: rise 0.3s var(--ease); }
.pr-step.done { color: var(--muted); }
.pr-step i { font-size: 12px; }
.pr-ico { width: 18px; display: grid; place-items: center; flex: 0 0 auto; color: var(--accent-text); font-size: 11px; }
.pr-spin { width: 13px; height: 13px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }

.video-embed { position: relative; width: 100%; padding-top: 56.25%; margin: 8px 0 4px; border-radius: var(--r); overflow: hidden; background: #000; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.md-image { display: block; margin: 8px 0 4px; cursor: zoom-in; }
.md-image img, .bubble img.md-img { max-width: 100%; border-radius: var(--r); display: block; }
.bubble img.md-img { margin: 6px 0; cursor: zoom-in; }

.msg-atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 7px; }
.msg-att { display: inline-flex; align-items: center; gap: 7px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 11px; font-size: 12px; color: var(--text); cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.msg-att:hover { background: var(--surface); border-color: var(--border-strong); }
.msg-att i { color: var(--accent-text); }
.msg-att.img { padding: 4px 11px 4px 5px; }
.msg-att .att-thumb { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }

.av-wrap { display: inline-flex; position: relative; }
.av-card { position: absolute; top: calc(100% + 8px); width: 232px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 14px; opacity: 0; pointer-events: none; transform: translateY(-6px) scale(0.98); transform-origin: top; transition: opacity 0.18s, transform 0.18s var(--ease); z-index: 40; }
.av-card::before { content: ""; position: absolute; left: 0; right: 0; top: -12px; height: 14px; }
.av-wrap:hover .av-card { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
.msg.bot .av-card { left: 0; transform-origin: top left; }
.msg.user .av-card { right: 0; transform-origin: top right; }
.av-card-top { display: flex; align-items: center; gap: 12px; }
.av-card-id { min-width: 0; }
.av-card-name { font-size: 15px; font-weight: 700; }
.av-card-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-card-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); margin-top: 12px; }
.av-card-row i { color: var(--accent-text); width: 14px; text-align: center; flex: 0 0 auto; }
.av-card-hint { font-size: 12px; color: var(--muted); margin-top: 9px; line-height: 1.5; }
.av-card-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; width: 100%; margin-top: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 12.5px; padding: 8px; border-radius: 9px; cursor: pointer; transition: background 0.15s; }
.av-card-btn:hover { background: var(--surface-2); }
.preview-img { max-width: 100%; max-height: 68vh; border-radius: var(--r); display: block; margin: 0 auto; }
.preview-cap { text-align: center; color: var(--text-2); font-size: 13px; margin-top: 12px; }
.preview-file { text-align: center; padding: 28px 12px; }
.preview-file-ic { width: 66px; height: 66px; border-radius: 16px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: 28px; margin: 0 auto 14px; }
.preview-file-name { font-weight: 600; font-size: 15px; word-break: break-word; }
.preview-file-note { color: var(--muted); font-size: 13px; margin-top: 8px; line-height: 1.5; }

.web-results { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.web-results-head { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 9px 13px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.web-result { display: block; padding: 11px 13px; border-bottom: 1px solid var(--border); text-decoration: none; transition: background 0.15s; }
.web-result:last-child { border-bottom: none; }
.web-result:hover { background: var(--surface-2); }
.wr-top { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.wr-fav { width: 16px; height: 16px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: 8px; }
.wr-domain { font-size: 11.5px; color: var(--muted); }
.wr-title { font-size: 13.5px; font-weight: 600; color: var(--accent-text); line-height: 1.35; }
.wr-snip { font-size: 12.5px; color: var(--text-2); line-height: 1.45; margin-top: 3px; }

.code-block { margin: 10px 0; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; background: var(--surface-2); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.code-lang { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.code-copy { border: none; background: transparent; color: var(--text-2); font-size: 11.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 7px; transition: background 0.15s, color 0.15s; }
.code-copy:hover { background: var(--surface-2); color: var(--text); }
.code-copy.ok { color: #22a06b; }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code-block code { font-family: ui-monospace, "Cascadia Code", "SF Mono", monospace; font-size: 12.5px; line-height: 1.6; color: var(--text); white-space: pre; background: none; border: none; padding: 0; }
.tok-str { color: #b3541e; }
.tok-com { color: var(--muted); font-style: italic; }
[data-theme="dark"] .tok-str { color: #e5a06a; }

#micBtn.active { color: #e23d4b; background: rgba(226, 61, 75, 0.12); animation: recpulse 1.3s infinite; }
@keyframes recpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(226, 61, 75, 0.4); } 50% { box-shadow: 0 0 0 6px rgba(226, 61, 75, 0); } }

/* source popover */
.src-pop { position: fixed; z-index: 130; width: 290px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r); box-shadow: var(--shadow-pop); padding: 14px 15px; animation: pop 0.16s var(--ease); }
.src-pop-head { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; }
.src-pop-head i { color: var(--accent-text); }
.src-pop-body { font-size: 12.5px; color: var(--text-2); line-height: 1.55; margin-top: 9px; }
.src-pop-foot { font-size: 11px; color: var(--muted); margin-top: 11px; display: flex; align-items: center; gap: 6px; }
.src-pop-foot .dot { width: 6px; height: 6px; border-radius: 50%; background: #22a06b; }

/* ---------- Composer ---------- */
.composer-wrap { flex: 0 0 auto; padding: 6px 24px 14px; }
.composer-wrap > * { max-width: var(--maxw); margin-left: auto; margin-right: auto; }
.composer { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 8px; background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: 24px; transition: border-color 0.15s, box-shadow 0.15s; }
.composer:focus-within { border-color: var(--muted); box-shadow: none; }
.composer-main { display: flex; align-items: center; gap: 2px; }
.composer-tool { width: 33px; height: 33px; flex: 0 0 auto; border-radius: 50%; border: none; background: transparent; color: var(--text-2); cursor: pointer; font-size: 14px; display: grid; place-items: center; transition: background 0.2s var(--ease), color 0.2s, transform 0.2s var(--ease); }
.composer-tool i { transition: transform 0.2s var(--ease); display: block; }
.composer-tool:hover { background: var(--surface-2); color: var(--text); }
.composer-tool:hover i { transform: scale(1.12); }
.composer-tool:active { transform: scale(0.86); }
.composer-tool.active { background: var(--accent-soft); color: var(--accent-text); }

[data-tooltip] { position: relative; }
[data-tooltip]::after { content: attr(data-tooltip); position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(-4px); background: var(--text); color: var(--bg); font-size: 11.5px; font-weight: 500; padding: 5px 9px; border-radius: 7px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.16s, transform 0.16s var(--ease); z-index: 60; box-shadow: var(--shadow-pop); }
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.attachments { display: none; flex-wrap: wrap; gap: 6px; padding: 4px 4px 2px; }
.att-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 6px 6px 10px; font-size: 12.5px; max-width: 240px; }
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-ico { color: var(--accent-text); }
.att-chip { cursor: pointer; }
.att-chip .att-thumb { width: 20px; height: 20px; border-radius: 5px; object-fit: cover; flex: 0 0 auto; }
.att-status { display: grid; place-items: center; width: 14px; height: 14px; }
.att-chip.done .att-status i { color: #22a06b; font-size: 12px; }
.att-spin { width: 13px; height: 13px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin 0.7s linear infinite; }
.att-x { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; padding: 0 2px; line-height: 1; }
.att-x:hover { color: #d4374a; }
.composer textarea { flex: 1; border: none; background: transparent; resize: none; font-size: 15px; line-height: 1.5; padding: 9px 2px; max-height: 170px; color: var(--text); }
.composer textarea::placeholder { color: var(--muted); }
.send-btn { width: 42px; height: 42px; flex: 0 0 auto; border-radius: 50%; border: none; cursor: pointer; background: var(--accent); color: #fff; font-size: 15px; display: grid; place-items: center; box-shadow: 0 3px 10px rgba(10, 47, 214, 0.28); transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease), background 0.2s, color 0.2s; }
.send-btn i { transition: transform 0.28s var(--ease); }
.send-btn:hover:not(:disabled) { transform: scale(1.09); box-shadow: 0 6px 18px rgba(10, 47, 214, 0.42); }
.send-btn:hover:not(:disabled) i { transform: translateY(-2px); }
.send-btn:active:not(:disabled) { transform: scale(0.9); transition-duration: 0.12s; }
.send-btn:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; box-shadow: none; transform: scale(0.86); }
.send-btn.stop { background: var(--text); color: var(--bg); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25); }
.composer-foot { font-size: 11.5px; color: var(--muted); text-align: center; margin-top: 9px; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(20, 22, 40, 0.32); backdrop-filter: blur(3px); animation: fade 0.2s ease; }
.modal-card { width: 100%; max-width: 440px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-modal); animation: pop 0.25s var(--ease); max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-card.wide { max-width: 560px; }
.modal-card.sm { max-width: 400px; }
.modal-card.sm .modal-foot { justify-content: flex-end; }
.dialog-msg { font-size: 14px; color: var(--text-2); line-height: 1.55; }
.dialog-input { width: 100%; margin-top: 14px; padding: 11px 13px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 14.5px; color: var(--text); }
.dialog-input:focus { border-color: var(--muted); box-shadow: none; }
.btn.danger-solid { background: #d4374a; color: #fff; }
.btn.danger-solid:hover { opacity: 0.9; }

.avatar-edit { position: relative; border: none; background: transparent; padding: 0; cursor: pointer; border-radius: 50%; flex: 0 0 auto; }
.avatar-edit-badge { position: absolute; right: -2px; bottom: -2px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 10px; border: 2px solid var(--surface); }

.bg-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.bg-swatch.custom { border-style: dashed; color: var(--text-2); }
.bg-swatch { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border-strong); cursor: pointer; background: var(--surface); color: var(--muted); display: grid; place-items: center; font-size: 12px; transition: box-shadow 0.15s, transform 0.15s; }
.bg-swatch:hover { transform: translateY(-2px); }
.bg-swatch.selected { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.bg-url { width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 13.5px; color: var(--text); }
.bg-url:focus { border-color: var(--muted); box-shadow: none; }
.bg-url.active { border-color: var(--accent); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; }
.profile-hero { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; }
.profile-hero-name { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.profile-hero-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.search { position: relative; margin-bottom: 16px; }
.search i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }
.search input { width: 100%; padding: 11px 13px 11px 38px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 14px; }
.search input:focus { border-color: var(--muted); box-shadow: none; }
.glossary-list { display: flex; flex-direction: column; gap: 8px; }
.gloss-item { padding: 13px 14px; border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.gloss-item:hover { background: var(--surface-2); border-color: var(--border-strong); }
.gloss-top { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.gloss-term { font-size: 14.5px; font-weight: 700; }
.gloss-full { font-size: 12.5px; color: var(--text-2); }
.gloss-cat { margin-left: auto; font-size: 11px; color: var(--muted); }
.gloss-def { font-size: 13px; color: var(--text-2); line-height: 1.5; margin-top: 6px; }
.gloss-empty { text-align: center; color: var(--muted); padding: 28px; font-size: 14px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 16px); z-index: 140; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Studio (authoring tool) ---------- */
.studio-body { overflow: hidden; }
.studio { display: flex; flex-direction: column; height: 100vh; }
.studio-top { height: 58px; flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.studio-top .brand-word { font-size: 16px; }
.studio-kicker { font-size: 11px; font-weight: 600; color: var(--accent-text); background: var(--accent-soft); padding: 4px 9px; border-radius: 20px; }
.studio-top .spacer { flex: 1; }
.studio-main { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.studio-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--bg-soft); }
.studio-list-top { padding: 14px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--border); }
.studio-entries { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.studio-entry { padding: 11px 12px; border-radius: var(--r); border: 1px solid transparent; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.studio-entry:hover { background: var(--surface-2); }
.studio-entry.active { background: var(--surface); border-color: var(--border-strong); }
.studio-entry-q { font-size: 13.5px; font-weight: 500; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-entry-meta { display: flex; align-items: center; gap: 7px; margin-top: 6px; }
.se-badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.se-badge.std { background: var(--surface-2); color: var(--muted); }
.se-badge.own { background: var(--accent-soft); color: var(--accent-text); }
.se-cat { font-size: 11px; color: var(--muted); }
.studio-editor { overflow-y: auto; padding: 26px clamp(20px, 5vw, 56px); }
.studio-editor-inner { max-width: 720px; margin: 0 auto; }
.studio-editor h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.studio-editor .hint { color: var(--text-2); font-size: 13.5px; margin-top: 6px; margin-bottom: 22px; line-height: 1.5; }
.se-field { margin-bottom: 16px; }
.se-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; }
.se-field input, .se-field select, .se-field textarea { width: 100%; padding: 11px 13px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 14px; color: var(--text); transition: border-color 0.15s, box-shadow 0.15s; }
.se-field input:focus, .se-field select:focus, .se-field textarea:focus { border-color: var(--muted); box-shadow: none; }
.se-field textarea { resize: vertical; min-height: 180px; line-height: 1.6; font-family: inherit; }
.se-field .sub { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.se-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.se-preview { border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; background: var(--surface); margin-top: 6px; }
.se-preview-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 10px; }
.se-actions { display: flex; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }
.se-actions .spacer { flex: 1; }
.studio-empty { color: var(--muted); text-align: center; padding: 60px 20px; font-size: 14px; }
.studio-intro { position: relative; background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; margin-bottom: 24px; animation: rise 0.35s var(--ease); }
.studio-intro h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.studio-intro h3 i { color: var(--accent-text); }
.studio-intro p { font-size: 13.5px; color: var(--text-2); margin-top: 7px; }
.studio-intro ol { font-size: 13.5px; color: var(--text-2); margin: 9px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.studio-intro b { color: var(--text); font-weight: 600; }
.studio-intro-x { position: absolute; top: 10px; right: 10px; width: 26px; height: 26px; border: none; background: transparent; color: var(--muted); cursor: pointer; border-radius: 7px; transition: background 0.15s, color 0.15s; }
.studio-intro-x:hover { background: var(--surface); color: var(--text); }
.editor-titlebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.md-help { font-size: 12.5px; color: var(--muted); line-height: 1.55; margin-bottom: 9px; }
.md-help code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; font-size: 11.5px; }
.md-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 5px 6px; border: 1px solid var(--border-strong); border-bottom: none; border-radius: var(--r) var(--r) 0 0; background: var(--surface-2); }
.md-toolbar button { width: 30px; height: 30px; border: none; background: transparent; color: var(--text-2); border-radius: 7px; cursor: pointer; font-size: 13px; display: grid; place-items: center; transition: background 0.15s, color 0.15s; }
.md-toolbar button:hover { background: var(--surface); color: var(--text); }
.md-sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 4px; }
.se-field textarea#fAnswer { min-height: 260px; border-top-left-radius: 0; border-top-right-radius: 0; }

/* ---------- Impact dashboard ---------- */
.modal-card.impact { max-width: 680px; }
.seg { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 18px; }
.seg-btn { border: none; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: background 0.18s, color 0.18s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.impact-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.istat { border: 1px solid var(--border); border-radius: var(--r); padding: 13px 14px; background: var(--surface); transition: transform 0.18s var(--ease), box-shadow 0.18s; }
.istat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.istat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.istat-ico { width: 30px; height: 30px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: 13px; }
.istat-delta { font-size: 11px; font-weight: 700; color: #22a06b; background: rgba(34, 160, 107, 0.12); padding: 2px 7px; border-radius: 12px; }
.istat-num { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.istat-label { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.impact-charts { display: grid; grid-template-columns: 1.3fr 1fr; gap: 12px; margin-top: 14px; }
.impact-chart { border: 1px solid var(--border); border-radius: var(--r); padding: 14px; background: var(--surface); }
.impact-chart-head { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 14px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 110px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 26px; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg, var(--accent), var(--accent-text)); position: relative; cursor: pointer; transition: filter 0.15s, transform 0.15s; min-height: 6px; }
.bar:hover { filter: brightness(1.12); transform: scaleY(1.02); }
.bar::after { content: attr(data-v); position: absolute; top: -22px; left: 50%; transform: translateX(-50%) scale(0.9); background: var(--text); color: var(--bg); font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s; white-space: nowrap; }
.bar:hover::after { opacity: 1; transform: translateX(-50%) scale(1); }
.bar-lbl { font-size: 11px; color: var(--muted); }

.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { width: 96px; height: 96px; border-radius: 50%; flex: 0 0 auto; position: relative; }
.donut::before { content: ""; position: absolute; inset: 24%; background: var(--surface); border-radius: 50%; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.leg { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); cursor: default; }
.leg-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.leg-name { flex: 1; }
.leg-val { font-weight: 600; color: var(--text); }
.impact-assume { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--r); padding: 14px; background: var(--surface); }
.assume-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.assume-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 12.5px; padding: 8px 11px; background: var(--surface-2); border-radius: 9px; }
.assume-k { color: var(--muted); white-space: nowrap; }
.assume-v { color: var(--text); font-weight: 600; text-align: right; }
.impact-calc { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 560px) { .assume-grid { grid-template-columns: 1fr; } }

.impact-note { margin-top: 14px; background: var(--accent-soft); border-radius: var(--r); padding: 13px 15px; font-size: 13px; color: var(--text-2); line-height: 1.6; display: flex; gap: 10px; align-items: flex-start; }
.impact-note i { color: var(--accent-text); margin-top: 3px; flex: 0 0 auto; }
.impact-note span { flex: 1; }
.impact-note b { color: var(--text); font-weight: 700; }

@media (max-width: 640px) {
  .impact-stats { grid-template-columns: repeat(2, 1fr); }
  .impact-charts { grid-template-columns: 1fr; }
}

/* ---------- Docs page ---------- */
.docs-body { overflow-y: auto; height: auto; min-height: 100%; }
.docs-top { position: sticky; top: 0; z-index: 10; height: 58px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg); }
.docs-top .brand { text-decoration: none; color: var(--text); }
.docs-top .spacer { flex: 1; }
.docs-main { display: grid; grid-template-columns: 230px 1fr; max-width: 1040px; margin: 0 auto; gap: 36px; padding: 28px 24px 80px; }
.docs-toc { position: sticky; top: 86px; align-self: start; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 110px); overflow-y: auto; }
.docs-toc a { font-size: 13px; color: var(--text-2); text-decoration: none; padding: 7px 11px; border-radius: 8px; border-left: 2px solid transparent; transition: background 0.15s, color 0.15s, border-color 0.15s; }
.docs-toc a:hover { background: var(--surface-2); color: var(--text); }
.docs-toc a.active { color: var(--accent-text); border-left-color: var(--accent); background: var(--accent-soft); }
.docs-content { min-width: 0; max-width: 720px; }
.doc-sec { margin-bottom: 38px; scroll-margin-top: 80px; }
.doc-sec h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.doc-sec h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 12px; }
.doc-lead { font-size: 16px; color: var(--text-2); line-height: 1.65; margin: 12px 0; }
.doc-sec p { color: var(--text-2); line-height: 1.65; margin: 10px 0; }
.doc-sec ul, .doc-sec ol { color: var(--text-2); line-height: 1.7; margin: 10px 0; padding-left: 22px; display: flex; flex-direction: column; gap: 7px; }
.doc-sec b { color: var(--text); font-weight: 600; }
.doc-sec code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; font-family: ui-monospace, monospace; }
.doc-sec pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; margin: 8px 0; overflow-x: auto; }
.doc-sec pre code { background: none; border: none; padding: 0; }
.doc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; margin: 10px 0; color: var(--text-2); line-height: 1.6; }
.doc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
.doc-grid .doc-card { margin: 0; }
.doc-ic { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: 15px; margin-bottom: 9px; }
.doc-grid .doc-card b { display: block; color: var(--text); margin-bottom: 4px; }
.doc-grid .doc-card p { margin: 0; font-size: 13px; }
.doc-note { font-size: 13px; color: var(--muted); border-left: 3px solid var(--border-strong); padding-left: 12px; }
.doc-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13.5px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.doc-table th { background: var(--surface-2); text-align: left; padding: 9px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.doc-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text-2); }
.doc-table tr:last-child td { border-bottom: none; }
.docs-foot { color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--border); padding-top: 18px; margin-top: 30px; }
@media (max-width: 760px) { .docs-main { grid-template-columns: 1fr; } .docs-toc { display: none; } .doc-grid { grid-template-columns: 1fr; } }

/* ---------- Password gate ---------- */
.gate { position: fixed; inset: 0; z-index: 9999; display: grid; place-items: center; background: var(--bg-soft); padding: 24px; }
.gate-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 34px 30px; text-align: center; box-shadow: var(--shadow-pop); }
.gate-card .mark.lg { margin: 0 auto 18px; }
.gate-card h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.gate-card h1 span { color: var(--accent-text); }
.gate-card p { color: var(--text-2); font-size: 14px; margin: 10px 0 22px; line-height: 1.55; }
.gate-card input { width: 100%; padding: 13px 14px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 15px; color: var(--text); }
.gate-card input:focus { border-color: var(--accent); }
.gate-err { display: none; color: #d4374a; font-size: 12.5px; margin-top: 10px; }
.gate-card .btn.primary { margin-top: 16px; padding: 13px; }
.gate-foot { color: var(--muted); font-size: 12px; margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.gate-card.shake { animation: shake 0.4s; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Animations ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.92); opacity: 0.7; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes bgShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 70; margin-left: calc(var(--sidebar-w) * -1); }
  .app.sidebar-open .sidebar { margin-left: 0; }
  .app.collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); }
  .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(20, 22, 40, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .app.sidebar-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .welcome { justify-content: flex-start; padding-top: 36px; }
  .explore-list { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
