:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #273449;
  --ink-2: #5a6b85;
  --line: #e6eaf3;
  --brand: #4a6cf7;
  --brand-soft: #edf1ff;
  --ok: #1fa36a;
  --ok-soft: #e6f7ef;
  --warn: #d9822b;
  --warn-soft: #fdf1e3;
  --bad: #e34d59;
  --bad-soft: #fdecee;
}

html.dark {
  --bg: #10141d;
  --panel: #1a2130;
  --ink: #e8ecf5;
  --ink-2: #99a5be;
  --line: #2b3448;
  --brand: #6d8bff;
  --brand-soft: #242e4c;
  --ok: #35c183;
  --ok-soft: #163328;
  --warn: #e6a14b;
  --warn-soft: #3a2d1a;
  --bad: #f06a74;
  --bad-soft: #3d2026;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

/* sidebar */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 18px;
  min-height: 0;
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #4a6cf7, #7d5ef0);
  color: #fff; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--ink-2); }
.side-section { border-top: 1px solid var(--line); padding-top: 12px; flex-shrink: 0; }
.side-label { font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.stat-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.stat-row span { color: var(--ink-2); }

.side-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

/* chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.chat-header {
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.chat-header h1 { font-size: 17px; }
.header-sub { font-size: 12px; color: var(--ink-2); }
.messages { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; min-height: 0; overscroll-behavior: contain; }

.msg { display: flex; gap: 10px; max-width: 860px; width: 100%; }
.msg.user { flex-direction: row-reverse; align-self: flex-end; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #4a6cf7, #7d5ef0);
}
.msg.user .avatar { background: #34435c; }
.bubble {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 16px; font-size: 14px; line-height: 1.7; min-width: 0;
}
.msg.user .bubble { background: #e5edff; color: var(--ink); border: 1px solid #d8e2fb; white-space: pre-wrap; }
html.dark .msg.user .bubble { background: #26335c; border-color: #33406f; }
.verdict {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; margin-bottom: 6px;
}
.verdict.covered { background: var(--ok-soft); color: var(--ok); }
.verdict.weak { background: var(--warn-soft); color: var(--warn); }
.verdict.unknown { background: var(--bad-soft); color: var(--bad); }
.answer-text { white-space: pre-wrap; word-break: break-word; }
.answer-text p { margin: 6px 0; }
.answer-text ol, .answer-text ul { margin: 6px 0; padding-left: 20px; }
.answer-text li { margin: 3px 0; }
.answer-text code { background: var(--brand-soft); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.answer-text .md-h { font-weight: 700; color: var(--ink); margin-top: 10px; }

.cites { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.cite {
  font-size: 12.5px; color: var(--ink-2); margin: 4px 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  border-left: 3px solid var(--brand);
}
.cite summary { cursor: pointer; padding: 6px 10px; font-weight: 600; color: var(--ink); }
.cite .cite-body { padding: 0 10px 8px; line-height: 1.6; }
.cite .cite-meta { color: var(--ink-2); font-size: 11.5px; margin-top: 4px; }

.practice { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.practice-title { font-size: 12px; color: var(--ink-2); font-weight: 600; margin-bottom: 6px; }
.pq {
  font-size: 12.5px; background: var(--brand-soft); border-radius: 8px;
  padding: 7px 10px; margin: 5px 0; color: var(--ink);
  display: block; width: 100%; text-align: left; border: 1px solid transparent;
  cursor: pointer; font-family: inherit; transition: border-color .15s, background .15s;
}
.pq:hover { border-color: var(--brand); background: #e6ecff; }
.pq .pq-head { font-weight: 700; font-size: 11.5px; color: var(--brand); }
.pq .pq-snip { margin-top: 3px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pq .pq-go { margin-top: 4px; font-size: 11px; color: var(--brand); font-weight: 600; }

.welcome { text-align: center; color: var(--ink-2); margin-top: 18vh; font-size: 14px; }
.welcome b { color: var(--ink); }
/* composer */
.composer { padding: 12px 22px 8px; background: var(--panel); border-top: 1px solid var(--line); }
.composer-box {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 8px;
}
.composer textarea {
  flex: 1; border: none; outline: none; resize: none; background: transparent;
  font-size: 14px; line-height: 1.5; font-family: inherit; color: var(--ink);
  max-height: 120px; padding: 6px 8px;
}
.composer-hint { font-size: 11px; color: var(--ink-2); padding: 6px 4px 2px; }

/* buttons */
.btn {
  border: none; border-radius: 10px; padding: 10px 18px; font-size: 14px;
  cursor: pointer; font-family: inherit; transition: opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.small { padding: 7px 12px; font-size: 12.5px; }
.btn.ghost:hover { background: var(--brand-soft); }

/* modal */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 28, 46, .45);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-mask.open { display: flex; }
.modal {
  width: min(640px, 92vw); max-height: 86vh; overflow: auto;
  background: var(--panel); border-radius: 16px; padding: 0;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head .close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--ink-2); line-height: 1; }
.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { font-size: 12.5px; color: var(--ink-2); display: flex; flex-direction: column; gap: 5px; }
.modal-body input {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-size: 13.5px; outline: none; color: var(--ink);
}
.modal-body input:focus { border-color: var(--brand); }
.modal-body .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.modal-tip {
  font-size: 12px; color: var(--ink-2); background: var(--brand-soft);
  border-radius: 10px; padding: 10px 12px; line-height: 1.7;
}
.modal-tip code { background: var(--panel); padding: 1px 5px; border-radius: 4px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}
.typing { display: inline-block; width: 6px; height: 16px; background: var(--brand); margin-left: 2px; vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* practice modal */
.practice-modal { width: min(760px, 94vw); }
.practice-foot { display: flex; justify-content: space-between; }
.q-content { font-size: 14.5px; line-height: 1.8; color: var(--ink); }
.q-img { max-width: 100%; display: block; margin: 8px 0; border-radius: 8px; border: 1px solid var(--line); }
.fml { vertical-align: middle; max-height: 40px; }
.q-options { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.opt-row {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 13.5px;
  transition: border-color .15s, background .15s;
}
.opt-row:hover { border-color: var(--brand); }
.opt-row input { margin-top: 3px; }
.opt-key { font-weight: 700; color: var(--ink); min-width: 16px; }
.opt-text { line-height: 1.6; }
.opt-row.correct { background: var(--ok-soft); border-color: var(--ok); }
.opt-row.wrong { background: var(--bad-soft); border-color: var(--bad); }
.result-box { margin-top: 12px; }
.result { font-weight: 700; padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
.result.ok { background: var(--ok-soft); color: var(--ok); }
.result.fail { background: var(--bad-soft); color: var(--bad); }
.explain {
  margin-top: 8px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; font-size: 13px; line-height: 1.7; color: var(--ink-2);
}
.q-loading { color: var(--ink-2); font-size: 13px; padding: 10px 0; }

/* brand / theme / menu */
.theme-btn { margin-left: auto; }
.menu-btn { display: none; }
.btn.icon {
  padding: 8px; font-size: 16px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 10px; cursor: pointer;
}
.btn.icon:hover, .theme-btn:hover { background: var(--brand-soft); }
.chat-header > div { flex: 1; min-width: 0; }
.chat-header .menu-btn { margin-right: 10px; flex: none; }

/* system status */
.status-line { display: flex; gap: 9px; align-items: flex-start; padding: 5px 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c3cdde; flex: none; margin-top: 6px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(31, 163, 106, .16); }
.dot.off { background: var(--bad); }
.status-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.status-text b { font-size: 13px; font-weight: 600; color: var(--ink); }
.status-text small { font-size: 11.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* welcome examples */
.welcome { max-width: 560px; margin-left: auto; margin-right: auto; }
.example-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.example-q {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: border-color .15s, color .15s, background .15s;
}
.example-q:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* message actions + pending */
.msg { animation: rise .22s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg-actions { display: flex; gap: 6px; margin-top: 8px; }
.msg-action {
  border: 1px solid var(--line); background: transparent; color: var(--ink-2);
  border-radius: 7px; padding: 3px 10px; font-size: 11.5px; cursor: pointer;
  font-family: inherit; transition: border-color .15s, color .15s;
}
.msg-action:hover { border-color: var(--brand); color: var(--brand); }
.pending-dots { display: flex; gap: 5px; padding: 4px 2px; }
.pending-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); opacity: .3; animation: blink 1s infinite; }
.pending-dots i:nth-child(2) { animation-delay: .2s; }
.pending-dots i:nth-child(3) { animation-delay: .4s; }
.pending-hint { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #8a8f98; }

/* send spinner */
.spinner {
  width: 13px; height: 13px; border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff; border-radius: 50%; display: inline-block;
  vertical-align: -2px; margin-right: 6px; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* settings test */
.test-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.test-result { font-size: 12.5px; color: var(--ink-2); }
.test-result.ok { color: var(--ok); }
.test-result.fail { color: var(--bad); }

/* practice modal */
.pq-head-row { display: flex; align-items: center; gap: 10px; }
.pq-progress {
  font-size: 12px; font-weight: 600; color: var(--brand);
  background: var(--brand-soft); border-radius: 999px; padding: 3px 10px;
}
.pq-hint { padding: 2px 20px 14px; font-size: 11.5px; color: var(--ink-2); }

/* dark tweaks */
html.dark .modal-body input { background: var(--bg); color: var(--ink); border-color: var(--line); }
html.dark .pq:hover { background: #28335a; }
html.dark ::-webkit-scrollbar { width: 10px; height: 10px; }
html.dark ::-webkit-scrollbar-thumb { background: #333d56; border-radius: 5px; }
html.dark ::-webkit-scrollbar-track { background: transparent; }

/* responsive drawer */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: 260px; z-index: 40;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 8px 0 30px rgba(20, 28, 46, .25); }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; z-index: 35;
    background: rgba(20, 28, 46, .45);
  }
  .chat-header { padding: 12px 14px; }
  .messages { padding: 16px 14px; }
  .composer { padding: 10px 14px 8px; }
  .header-sub { display: none; }
}

/* lan tip (sidebar footer) */
.lan-tip {
  font-size: 11.5px; color: var(--ink-2); word-break: break-all;
  background: var(--brand-soft); border-radius: 8px; padding: 7px 9px; line-height: 1.5;
}

/* phones */
@media (max-width: 480px) {
  .chat-header { padding: 10px 12px; gap: 8px; }
  .chat-header h1 { font-size: 15px; }
  .chat-header #btnReload { padding: 6px 10px; font-size: 12px; }
  .messages { padding: 12px 10px; gap: 12px; }
  .avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 12px; }
  .msg { gap: 8px; }
  .bubble { padding: 10px 12px; font-size: 13.5px; }
  .cite summary { padding: 9px 12px; }
  .cite .cite-body { padding: 0 12px 10px; }
  .pq { padding: 10px 12px; }
  .msg-action { padding: 5px 12px; font-size: 12.5px; }
  .composer { padding: 8px 10px 6px; }
  .composer-box { padding: 6px; gap: 8px; }
  .composer textarea { font-size: 16px; }
  .composer-hint { font-size: 10.5px; }
  .example-grid { gap: 7px; }
  .example-q { flex: 1 1 46%; padding: 9px 10px; font-size: 12.5px; }
  .modal-mask.open { align-items: stretch; }
  .modal { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .modal-head { padding: 12px 16px; }
  .modal-body { padding: 12px 16px; }
  .modal-body input { font-size: 16px; }
  .modal-foot { padding: 12px 16px; }
  .btn, .example-q, .pq, .msg-action, .opt-row { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .toast { bottom: 16px; font-size: 12.5px; }
  .side-footer { flex-direction: row; }
  .side-footer .btn { flex: 1; }
}

/* short windows: compact sidebar instead of scrolling */
@media (max-height: 620px) {
  .sidebar { gap: 10px; padding: 12px 12px; }
  .side-section { padding-top: 8px; }
  .status-line { padding: 3px 0; }
  .lan-tip { display: none; }
}


/* image lightbox */
.img-view {
  position: fixed; inset: 0; z-index: 120; display: none;
  align-items: center; justify-content: center;
  background: rgba(8, 12, 22, .88); cursor: zoom-out;
}
.img-view.open { display: flex; }
.img-view img {
  max-width: 96vw; max-height: 94vh; object-fit: contain;
  border-radius: 8px; background: #fff; box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}

/* katex tweaks */
.katex { font-size: 1.02em; }
.katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
html.dark .katex { color: var(--ink); }

/* subject filter */
.subject-list { display: flex; flex-wrap: wrap; gap: 6px; }
.subj-chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  border-radius: 999px; padding: 5px 11px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: border-color .15s, color .15s, background .15s;
}
.subj-chip:hover { border-color: var(--brand); color: var(--brand); }
.subj-chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.subj-tag {
  display: inline-block; font-size: 11px; background: var(--brand); color: #fff;
  border-radius: 999px; padding: 1px 8px; font-weight: 600;
}

/* clickable citation cards */
.cite:hover { border-color: var(--brand); }

/* stop button */
.btn.stop {
  display: none; background: var(--bad); color: #fff; font-weight: 600;
  align-items: center; justify-content: center;
}
.btn.stop.show { display: inline-flex; }
.btn.stop:hover { opacity: .88; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 90;
  transform: translateX(-50%) translateY(10px);
  background: #273449; color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: 0 8px 24px rgba(20, 28, 46, .25); max-width: 82vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
html.dark .toast { background: #36415f; }
textarea#input { transition: height .12s ease; }



/* 图片输入与预览 */
.img-btn { padding: 10px 10px; font-size: 17px; align-self: flex-end; background: transparent; line-height: 1; }
.img-btn:hover { filter: brightness(.92); }
.img-previews { display: none; flex-wrap: wrap; gap: 8px; padding: 0 4px 10px; }
.img-preview { position: relative; width: 76px; height: 76px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); }
.img-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-remove { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border: none; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; padding: 0; }
.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-imgs img { max-width: 172px; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); display: block; }

/* 深度思考过程展示 */
.think-box { margin: 0 0 8px; border: 1px dashed var(--line); border-radius: 10px; padding: 7px 10px; font-size: 12px; color: var(--ink-2); background: var(--panel); }
.think-head { display: flex; align-items: center; gap: 8px; }
.think-len { opacity: .75; }
.think-toggle { margin-left: auto; color: var(--brand); cursor: pointer; user-select: none; }
.think-content { margin-top: 6px; white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow-y: auto; line-height: 1.55; }
