:root {
  --blue: #1769ff;
  --blue-2: #4388ff;
  --blue-50: #f1f6ff;
  --blue-100: #e5efff;
  --navy: #061a46;
  --text: #18345f;
  --muted: #7488aa;
  --line: #dfe8f5;
  --line-strong: #cbdaf0;
  --surface: #ffffff;
  --page: #f8fbff;
  --green: #16b982;
  --sidebar-width: 184px;
  --reference-width: 482px;
  --topbar-height: 61px;
  --shadow-soft: 0 8px 30px rgba(36, 84, 145, .07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: visible;
  color: var(--text);
  background: var(--page);
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; }
button { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(560px, 1fr) var(--reference-width);
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at 36% 0%, rgba(90, 151, 255, .07), transparent 30%), #fff;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { background: var(--blue-50); color: var(--blue); }

/* Sidebar */
.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 10px 10px;
  border-right: 1px solid var(--line);
  background: rgba(251, 253, 255, .97);
  overflow: visible;
  transition: width .25s ease, transform .25s ease;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; min-height: 43px; margin: 0 5px 12px; }
.brand { display: flex; align-items: center; height: 39px; text-decoration: none; white-space: nowrap; }
.brand-mark {
  display: block;
  flex: 0 0 auto;
  width: 63px;
  height: auto;
  margin-right: 0;
}
.brand-k { display: none; width: 32px; height: auto; }
.collapse-button { width: 30px; height: 30px; border-radius: 8px; color: #536f96; }
.collapse-glyph { width: 18px; height: 18px; transition: transform .18s ease; }

.new-chat-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #17345f;
  background: transparent;
  font-size: 14px;
  font-weight: 620;
  cursor: pointer;
  transition: .18s ease;
}
.new-chat-button:hover { color: var(--blue); background: #f3f7fe; }
.new-chat-button.active { color: var(--blue); border-color: #dce8fa; background: linear-gradient(90deg, #eaf2ff, #f5f8ff); }

.primary-nav { display: grid; gap: 4px; margin-top: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #17345f;
  font-size: 14px;
  font-weight: 620;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: .15s ease;
}
.nav-item svg { flex: 0 0 auto; }
.new-chat-button svg, .nav-item svg { width:18px; height:18px; stroke-width:1.7; }
.nav-item:hover { color: var(--blue); background: #f3f7fe; }
.nav-item.active { color: var(--blue); border-color: #dce8fa; background: linear-gradient(90deg, #eaf2ff, #f5f8ff); }
.nav-divider { display: block; height: 1px; margin: 12px 4px; background: var(--line); }

.history-section { min-height: 0; margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--line); overflow: hidden; }
.section-title { display: flex; align-items: center; gap: 13px; padding: 0 18px 11px; color: #102b58; font-size: 15px; font-weight: 600; }
.history-list { display: grid; gap: 1px; }
.history-item {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding: 9px 14px 9px 47px;
  border: 0;
  background: transparent;
  color: #61789e;
  font-size: 13px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.history-item::before { content: ""; position: absolute; left: 21px; top: 50%; width: 4px; height: 4px; border-radius: 50%; background: #5475a7; transform: translateY(-50%); }
.history-item:hover, .history-item.current { color: var(--blue); background: #f3f7fe; }
.profile-card {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  margin-top: auto;
  padding: 7px 9px;
  border: 1px solid #e8eff8;
  border-radius: 9px;
  background: linear-gradient(135deg, #f5f9ff, #edf4ff);
  text-align: left;
  cursor: pointer;
}
.avatar, .user-avatar { position: relative; display: inline-block; flex: 0 0 auto; width: 39px; height: 39px; border-radius: 50%; background:#e1edff; box-shadow:inset 0 0 0 1px rgba(255,255,255,.9); }
.avatar::before, .user-avatar::before { content:""; position:absolute; top:7px; left:50%; width:10px; height:10px; border-radius:50%; background:#2f82f7; transform:translateX(-50%); }
.avatar::after, .user-avatar::after { content:""; position:absolute; bottom:5px; left:50%; width:22px; height:13px; border-radius:12px 12px 7px 7px; background:#2f82f7; transform:translateX(-50%); }
.profile-card .avatar { width:30px; height:30px; }
.profile-card .avatar::before { top:5px; width:8px; height:8px; }
.profile-card .avatar::after { bottom:4px; width:17px; height:10px; border-radius:9px 9px 6px 6px; }
.profile-copy { display: grid; gap: 2px; min-width: 0; }
.profile-copy strong { color: #17345f; font-size: 13px; }
.profile-copy small { color: #7d90ac; font-size: 11px; }
.profile-card > svg { width: 13px; margin-left: auto; }

/* Main workspace */
.workspace { position: relative; display: grid; grid-template-rows: var(--topbar-height) minmax(0, 1fr) auto; min-width: 0; height: 100vh; background: rgba(255,255,255,.87); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 24px 0 30px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.85); backdrop-filter: blur(14px); }
.topbar-title { display: flex; align-items: center; min-width: 0; }
.topbar-title h1 { margin: 0; color: #071c47; font-size: 23px; line-height: 1; letter-spacing: -.6px; }
.topbar-title > span { margin-left: 20px; color: #7a8fb2; font-size: 14px; white-space: nowrap; }
.mobile-menu { display: none; margin-right: 8px; }
.topbar-actions { display: flex; gap: 10px; }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 82px; height: 39px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; color: #17345f; font-size: 14px; font-weight: 600; cursor: pointer; transition: .15s ease; }
.secondary-button:hover { border-color: #9dbcf0; color: var(--blue); box-shadow: 0 5px 15px rgba(35,88,164,.08); }
.secondary-button.blue { color: var(--blue); }
.secondary-button svg { width: 18px; }
.references-toggle { display: none; }
.references-toggle b { display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 50%; background: var(--blue-100); font-size: 12px; }

.conversation { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 15px 28px 22px 30px; scrollbar-width: thin; scrollbar-color: #c7d5e9 transparent; }
.conversation::-webkit-scrollbar, .references-list::-webkit-scrollbar { width: 6px; }
.conversation::-webkit-scrollbar-thumb, .references-list::-webkit-scrollbar-thumb { border-radius: 6px; background: #c7d5e9; }
.chat-turn { margin-bottom: 36px; padding-bottom: 24px; border-bottom: 1px solid #edf2f8; }
.conversation { scroll-behavior: auto; overflow-anchor: none; }
.retrieval-card[hidden] { display: none; }
.conversation > .question-row, .conversation > .answer, .conversation > .retrieval-card, .chat-turn { max-width: 860px; margin-left: auto; margin-right: auto; }
.composer { max-width: 860px; margin-left: auto; margin-right: auto; }
.question-row { display: flex; align-items: flex-start; justify-content: flex-end; gap: 10px; margin-bottom: 9px; }
.question-stack { display: grid; justify-items: end; }
.question-bubble { max-width: 670px; padding: 13px 18px; border-radius: 9px 9px 2px 9px; color: #17345f; background: linear-gradient(135deg, #e7f1ff, #f0f6ff); font-size: 14px; font-weight: 600; line-height: 1.5; }
.question-stack time { margin-top: 2px; color: #91a2bc; font-size: 11px; }
.user-avatar { width: 38px; height: 38px; }

.retrieval-card { display: grid; grid-template-columns: 50px minmax(0,1fr) minmax(170px, 44%); gap: 14px; align-items: start; margin-bottom: 13px; padding: 14px 17px; border: 1px solid #d8e6fa; border-radius: 12px; background: linear-gradient(135deg, rgba(247,250,255,.96), rgba(255,255,255,.98)); box-shadow: 0 8px 24px rgba(41, 87, 153, .05); }
.retrieval-icon { display: grid; place-items: center; width: 47px; height: 47px; border-radius: 50%; color: var(--blue); background: #e9f2ff; }
.retrieval-icon svg { width: 28px; height: 28px; stroke-width: 2; }
.retrieval-heading { display: flex; align-items: center; gap: 7px; }
.retrieval-heading strong { color: #0e2a59; font-size: 15px; }
.retrieval-heading svg { width: 17px; height: 17px; color: var(--green); }
.retrieval-content p { margin: 5px 0 8px; color: #7b8ead; font-size: 12px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-row span { padding: 4px 11px; border-radius: 999px; color: #4b71a8; background: #eef4fd; font-size: 11px; }
.retrieval-side { display: grid; grid-template-columns: 1fr 35px; align-items: center; align-self: stretch; gap: 8px; }
.retrieval-side button { grid-column: 1 / -1; justify-self: end; padding: 0; border: 0; color: var(--blue); background: none; font-size: 12px; font-weight: 600; cursor: pointer; }
.progress { height: 4px; overflow: hidden; border-radius: 3px; background: #e9f0f9; }
.progress i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), #438fff); }
.retrieval-side small { color: var(--blue); font-size: 11px; }

.answer { color: #26446f; }
.assistant-row { display: flex; align-items: center; gap: 9px; margin: 6px 0 5px; }
.ai-avatar { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: var(--blue); background: linear-gradient(135deg, #deecff, #f4f8ff); font-size: 17px; font-weight: 900; font-style: italic; }
.assistant-row strong { color: #092553; font-size: 15px; }
.assistant-row time { color: #94a5bf; font-size: 11px; }
.answer-body { padding-left: 60px; font-size: 14px; line-height: 1.75; }
.answer-body > p { margin: 0 0 7px; }
.answer-body :is(h1,h2,h3,h4,h5,h6) { margin: 16px 0 7px; font-size: 16px; color: #19324d; }
.answer-body pre { padding: 14px; overflow-x: auto; border-radius: 8px; background: #eef3f7; white-space: pre; }
.answer-body pre code { padding: 0; background: transparent; }
.answer-body ul, .answer-body ol { margin: 6px 0 10px 20px; padding: 0; }
.answer-body li { margin: 4px 0; }
.answer-body code { padding: 1px 5px; border-radius: 4px; background: #eef3f7; font-family: ui-monospace, monospace; font-size: .92em; }
.answer-body a { color: #1769aa; text-decoration: underline; }
.answer-body .markdown-table-scroll { max-width: 100%; overflow-x: auto; margin: 14px 0; border: 1px solid #dce5ee; border-radius: 8px; }
.answer-body table { width: 100%; min-width: 480px; border-collapse: collapse; font-size: inherit; line-height: 1.7; }
.answer-body th, .answer-body td { min-width: 110px; padding: 11px 14px; border-right: 1px solid #dce5ee; border-bottom: 1px solid #dce5ee; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.answer-body th { background: #eef3f8; color: #19324d; font-weight: 600; }
.answer-body tr:last-child td { border-bottom: 0; }
.answer-body :is(th, td):last-child { border-right: 0; }
.answer-body tbody tr:nth-child(even) { background: #f8fafc; }
.answer-body .align-center { text-align: center; }
.answer-body .align-right { text-align: right; }
.answer-section { margin: 5px 0; }
.answer-section h2 { margin: 0 0 1px; color: #073b91; font-size: 15px; line-height: 1.55; }
.answer-section h2 span { color: var(--blue); }
.answer-section p { margin: 0; padding-left: 22px; }
.citation { position: relative; display: inline; margin: 0 1px; padding: 1px 4px; border: 0; border-radius: 3px; color: var(--blue); background: #e8f1ff; font-size: 11px; line-height: 1.4; vertical-align: 1px; cursor: pointer; }
.citation:hover, .citation.active { color: #fff; background: var(--blue); }
.citation-popover { position: absolute; z-index: 50; left: 50%; bottom: calc(100% + 9px); display: none; width: 280px; padding: 9px 11px; border: 1px solid #cfe0f8; border-radius: 8px; color: #23446f; background: #fff; box-shadow: 0 8px 24px rgba(26,66,125,.18); font-size: 12px; font-weight: 400; line-height: 1.5; text-align: left; white-space: normal; transform: translateX(-50%); pointer-events: none; }
.citation-popover::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 9px; height: 9px; border-right: 1px solid #cfe0f8; border-bottom: 1px solid #cfe0f8; background: #fff; transform: translateX(-50%) rotate(45deg); }
.citation:hover .citation-popover, .citation:focus-visible .citation-popover { display: block; }
@media (max-width: 700px) { .citation-popover { position: fixed; left: 12px; right: 12px; bottom: 14px; width: auto; transform: none; pointer-events: none; } .citation-popover::after { display: none; } }

.insight-card { margin-top: 9px; padding: 11px 13px 12px; border: 1px solid #cfe0fa; border-radius: 11px; background: linear-gradient(135deg, #edf5ff 0%, #f7faff 100%); }
.insight-title { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bulb-dot { display: grid; place-items: center; width: 19px; height: 19px; border-radius: 50%; color: white; background: linear-gradient(135deg, #1670ff, #6aa1ff); font-size: 8px; }
.insight-title strong { color: #0d397d; font-size: 15px; }
.insight-title small { color: #8a9db8; font-size: 11px; }
.insight-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.insight-item { display: flex; gap: 9px; min-width: 0; padding: 10px; border: 1px solid rgba(214,226,244,.9); border-radius: 8px; background: rgba(255,255,255,.75); }
.feature-icon { display: grid; place-items: center; flex: 0 0 auto; width: 29px; height: 29px; border-radius: 8px; color: var(--blue); background: #e7f0ff; font-size: 18px; }
.insight-item strong { color: #12396f; font-size: 13px; }
.insight-item p { margin: 3px 0 0; color: #7087a8; font-size: 10px; line-height: 1.5; }

.composer-wrap { padding: 0 28px 8px 18px; background: linear-gradient(to top, #fff 75%, rgba(255,255,255,.4)); }
.composer { padding: 8px 10px 9px 14px; border: 1px solid #d3e0f2; border-radius: 13px; background: rgba(255,255,255,.98); box-shadow: 0 8px 24px rgba(33, 79, 143, .08); }
.composer textarea { display: block; width: 100%; min-height: 25px; max-height: 120px; padding: 2px 4px; resize: none; border: 0; outline: 0; color: #15335e; background: transparent; font-size: 14px; line-height: 1.5; }
.composer textarea::placeholder { color: #a5b4ca; }
.composer-tools { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.tool-group { display: flex; align-items: center; gap: 7px; min-width: 0; }
.circle-tool, .mode-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; border: 1px solid #dce6f4; border-radius: 18px; color: #24466f; background: #fff; font-size: 12px; cursor: pointer; }
.circle-tool { width: 32px; padding: 0; }
.circle-tool svg, .mode-button svg { width: 16px; height: 16px; }
.mode-button { padding: 0 12px; }
.mode-button.active, .mode-button:hover { color: var(--blue); border-color: #c8dbfa; background: #f3f7ff; }
.source-button .chevron { width: 13px; }
.send-button { display: grid; place-items: center; flex: 0 0 auto; width: 44px; height: 44px; border: 0; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #1769ff, #4b8fff); box-shadow: 0 8px 20px rgba(23,105,255,.25); cursor: pointer; transition: .15s ease; }
.send-button:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(23,105,255,.32); }
.send-button:disabled { opacity: .5; cursor: wait; }
.ai-notice { margin: 4px 0 0; color: #a5b2c5; font-size: 10px; text-align: center; }

/* References */
.references-panel { position: relative; z-index: 20; display: grid; grid-template-rows: 61px 50px minmax(0,1fr) 70px; min-width: 0; height: 100vh; border-left: 1px solid var(--line); background: #fbfdff; transition: transform .25s ease, opacity .25s ease; }
.references-header { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-bottom: 1px solid var(--line); background: #fff; }
.reference-tabs { display: flex; align-self: stretch; gap: 30px; }
.reference-tab { position: relative; border: 0; color: #4c6287; background: transparent; font-size: 15px; font-weight: 600; cursor: pointer; }
.reference-tab span { display: inline-grid; place-items: center; min-width: 25px; height: 25px; margin-left: 4px; border-radius: 50%; color: var(--blue); background: #e3eeff; font-size: 12px; }
.reference-tab.active { color: #0b2d66; }
.reference-tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--blue); }
.references-header .icon-button { color: #6f84a5; }
.reference-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 0 20px; color: #6b82a5; }
.reference-toolbar button { display: inline-flex; align-items: center; gap: 7px; border: 0; color: inherit; background: transparent; font-size: 12px; cursor: pointer; }
.reference-toolbar svg { width: 15px; height: 15px; }
.references-list { min-height: 0; overflow-y: auto; padding: 0 14px 15px 10px; }
.reference-card { position: relative; display: grid; grid-template-columns: 43px minmax(0,1fr); gap: 8px; margin-bottom: 8px; padding: 13px 10px 10px 6px; border: 1px solid #dce7f4; border-radius: 10px; background: #fff; box-shadow: 0 3px 12px rgba(35,78,137,.035); transition: .18s ease; }
.reference-card:hover, .reference-card.highlight { border-color: #a8c8f9; box-shadow: 0 8px 22px rgba(26,89,180,.09); }
.reference-card.highlight { border: 2px solid #1769ff; background: linear-gradient(135deg,#eaf3ff,#ffffff); box-shadow: 0 0 0 4px rgba(23,105,255,.18), 0 12px 30px rgba(23,105,255,.18); transform: translateX(-3px); }
.reference-card.highlight .reference-index { color:#fff; background:#1769ff; font-weight:800; }
.reference-card.highlight h3 a { color:#0b55c7; font-weight:800; }
.reference-card.highlight::after { content:'当前引用'; position:absolute; top:8px; right:10px; padding:3px 7px; border-radius:10px; color:#fff; background:#1769ff; font-size:10px; font-weight:700; }
.reference-card.selected { background: linear-gradient(135deg, #f5f9ff, #fff); }
.reference-card.selected::before { content: ""; position: absolute; left: -1px; top: 0; bottom: 0; width: 3px; border-radius: 10px 0 0 10px; background: var(--blue); }
.reference-index { display: grid; place-items: center; align-self: start; width: 34px; height: 34px; margin-left: 2px; border-radius: 50%; color: var(--blue); background: #eaf2ff; font-size: 16px; font-weight: 700; }
.reference-main { min-width: 0; }
.reference-open { position: absolute; top: 9px; right: 9px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; color: var(--blue); background: #edf5ff; }
.reference-open svg { width: 16px; height: 16px; }
.reference-open:hover, .reference-open:focus-visible { background: #dceaff; outline: 2px solid #a8c8f9; }
.reference-card:has(.reference-open) .reference-main h3 { padding-right: 32px; }
.reference-main h3 { margin: 0 0 6px; color: #10264f; font-family: Arial, "Microsoft YaHei", sans-serif; font-size: 14px; line-height: 1.33; }
.reference-cn { margin: 0 0 7px; color: #6f84a5; font-size: 12px; line-height: 1.45; }
.reference-meta { display: flex; flex-wrap: wrap; gap: 4px 7px; color: #61799f; font-size: 11px; }
.reference-doi { margin: 6px 0 8px; color: #7890b3; font-size: 10px; }
.reference-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reference-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; border: 1px solid #cfe0f8; border-radius: 6px; color: var(--blue); background: #fff; font-size: 12px; font-weight: 600; cursor: pointer; }
.reference-actions button:hover { background: var(--blue-50); }
.reference-actions svg { width: 15px; height: 15px; }
.related-questions { min-height: 0; overflow: auto; padding: 8px 18px; }
.related-questions button { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 54px; padding: 0 13px; border: 0; border-bottom: 1px solid var(--line); color: #21436f; background: transparent; text-align: left; cursor: pointer; }
.related-questions button:hover { color: var(--blue); background: var(--blue-50); }
.reference-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 11px 16px 14px; border-top: 1px solid var(--line); background: #fff; }
.reference-footer button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #d3e0f1; border-radius: 8px; color: #17345f; background: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.reference-footer button:hover { color: var(--blue); border-color: #acc8f2; }
.reference-footer svg { width: 17px; }

.mobile-overlay { position: fixed; z-index: 25; inset: 0; display: none; background: rgba(7,24,53,.28); backdrop-filter: blur(2px); }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 32px; transform: translate(-50%, 15px); padding: 10px 18px; border-radius: 9px; color: #fff; background: rgba(8, 28, 62, .92); box-shadow: 0 10px 30px rgba(5,24,56,.2); font-size: 13px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.app-shell.sidebar-collapsed { --sidebar-width: 64px; }
.sidebar-collapsed .new-chat-button span, .sidebar-collapsed .nav-item span, .sidebar-collapsed .profile-copy, .sidebar-collapsed .profile-card > svg { display: none; }
.sidebar-collapsed .brand-row { justify-content: center; margin-left: 0; margin-right: 0; }
.sidebar-collapsed .brand-mark { display: none; }
.sidebar-collapsed .brand-k { display: block; }
.sidebar-collapsed .collapse-button { position: absolute; right: -12px; top: 14px; z-index: 3; width: 24px; height: 24px; border: 1px solid #dbe5f2; border-radius: 50%; background: #fff; box-shadow: 0 4px 12px rgba(29,69,126,.1); }
.sidebar-collapsed .collapse-glyph { display: inline-block; transform: rotate(180deg); }
.sidebar-collapsed .new-chat-button, .sidebar-collapsed .nav-item { justify-content: center; width:40px; min-height:40px; height:40px; margin-inline:auto; padding:0; gap:0; border-radius:10px; }
.sidebar-collapsed .new-chat-button svg, .sidebar-collapsed .nav-item svg { width:19px; height:19px; stroke-width:1.7; }
.sidebar-collapsed .profile-card { justify-content:center; width:40px; min-height:40px; margin-right:auto; margin-left:auto; padding:4px 0; }
.sidebar-collapsed .profile-card .avatar { width:30px; height:30px; }
.sidebar-collapsed .profile-card .avatar::before { top:5px; width:8px; height:8px; }
.sidebar-collapsed .profile-card .avatar::after { bottom:4px; width:17px; height:10px; }
.sidebar-collapsed [data-label] { position: relative; }
.sidebar-collapsed [data-label]::after { content: attr(data-label); position: absolute; z-index: 100; top: 50%; left: calc(100% + 11px); width: max-content; max-width: 180px; padding: 7px 10px; border-radius: 7px; color: #fff; background: rgba(10,29,58,.94); box-shadow: 0 8px 24px rgba(8,28,58,.2); font-size: 12px; font-weight: 500; line-height: 1.3; opacity: 0; pointer-events:none; transform: translate(-4px,-50%); transition: .15s; }
.sidebar-collapsed [data-label]:hover::after, .sidebar-collapsed [data-label]:focus-visible::after { opacity: 1; transform: translate(0,-50%); }

@media (max-width: 1390px) {
  :root { --reference-width: 420px; --sidebar-width: 184px; }
  .conversation { padding-left: 22px; padding-right: 20px; }
  .topbar { padding-left: 23px; padding-right: 18px; }
  .answer-body { padding-left: 54px; }
  .insight-item { padding: 8px; }
}

@media (max-width: 1180px) {
  :root { --sidebar-width: 126px; }
  .app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .references-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(470px, 92vw); transform: translateX(101%); box-shadow: -12px 0 40px rgba(20,53,98,.15); }
  .app-shell.references-open .references-panel { z-index: 30; transform: translateX(0); }
  .app-shell.references-open + .mobile-overlay { display: block; }
  .references-toggle { display: inline-flex; }
}

@media (max-width: 820px) {
  :root { --sidebar-width: 260px; }
  body { overflow: hidden; }
  .app-shell { display: block; }
  .workspace { width: 100%; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 260px; transform: translateX(-101%); box-shadow: 12px 0 40px rgba(20,53,98,.15); }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-open + .mobile-overlay { display: block; }
  .collapse-button { display: none; }
  .mobile-menu { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .topbar-title > span { display: none; }
  .topbar-title h1 { font-size: 19px; }
  .secondary-button span { display: none; }
  .secondary-button { min-width: 40px; padding: 0 10px; }
  .references-toggle { padding: 0 9px; }
  .references-toggle span { display: inline; }
  .conversation { padding: 12px 14px 18px; }
  .retrieval-card { grid-template-columns: 42px 1fr; }
  .retrieval-side { grid-column: 2; }
  .answer-body { padding-left: 0; }
  .insight-grid { grid-template-columns: 1fr; }
  .insight-title small { display: none; }
  .composer-wrap { padding: 0 12px 7px; }
}

@media (max-width: 560px) {
  .question-bubble { font-size: 13px; }
  .retrieval-card { padding: 12px; }
  .retrieval-side { grid-template-columns: 1fr 30px; }
  .answer-body { font-size: 13px; line-height: 1.7; }
  .answer-section p { padding-left: 0; }
  .mode-button span, .source-button .chevron { display: none; }
  .mode-button { width: 34px; padding: 0; }
  .references-toggle span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* Unified readable typography. Adjust these variables to tune the Q&A page. */
:root{--kz-font-micro:11px;--kz-font-small:12px;--kz-font-body:14px;--kz-font-title:16px}
.question-stack time,.retrieval-side small,.assistant-row time,.citation,.insight-title small,.reference-meta{font-size:var(--kz-font-micro)}
.profile-copy small,.retrieval-content p,.tag-row span,.retrieval-side button,.circle-tool,.mode-button,.reference-toolbar button,.reference-cn,.reference-actions button{font-size:var(--kz-font-small)}
.history-item,.insight-item strong,.reference-footer button,.question-bubble,.answer-body{font-size:var(--kz-font-body)}
.insight-item p,.ai-notice,.reference-doi{font-size:var(--kz-font-micro)}
.task-steps { list-style: none; padding: 0 2px 2px; margin: 14px 0 10px; display: grid; gap: 7px; max-height: 180px; overflow-y: auto; scroll-behavior: smooth; scrollbar-width: thin; }
.task-steps li { display: flex; align-items: center; gap: 10px; min-height: 28px; padding: 4px 8px 4px 5px; border-radius: 9px; font-size: 13px; color: #7b8798; animation: task-step-in .28s ease both; transition: background .25s ease, color .25s ease; }
.task-steps .step-marker { position: relative; display: inline-grid; place-items: center; flex: 0 0 18px; width: 18px; height: 18px; border: 1px solid #cbd5e1; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700; }
.task-steps .step-marker[data-status="running"] { border-color: #5b8def; border-top-color: transparent; animation: task-spin .75s linear infinite; }
.task-steps .step-marker[data-status="completed"] { border-color: #65b891; background: #65b891; }
.task-steps .step-marker[data-status="failed"] { border-color: #d97878; background: #d97878; }
.task-steps .step-state { margin-left: auto; font-size: 11px; color: #a0aabb; white-space: nowrap; }
.task-steps li[data-status="running"] { color: #2458a6; background: #f1f6ff; font-weight: 600; }
.task-steps li[data-status="completed"] { color: #697789; }
.task-steps li[data-status="failed"] { color: #a83e3e; background: #fff5f5; }
.task-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; text-align: left; }
.task-toggle:focus-visible { outline: 2px solid #7da5e8; outline-offset: 4px; border-radius: 4px; }
.task-toggle strong { letter-spacing: -.01em; }
.task-caret { display: inline-block; color: #93a0b2; font-size: 17px; line-height: 1; transition: transform .24s ease; }
#retrievalCard.is-collapsed .task-caret { transform: rotate(-90deg); }
#retrievalCard.is-collapsed .task-steps, #retrievalCard.is-collapsed .retrieval-content p, #retrievalCard.is-collapsed .retrieval-side { display: none; }
#retrievalCard[hidden] { display: none; }
#retrievalCard { display: block; padding: 10px 0 14px; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
#retrievalCard .retrieval-icon { display: none; }
#retrievalCard .retrieval-heading { color: #687586; font-size: 13px; }
#retrievalCard .retrieval-heading strong { font-weight: 500; }
#retrievalCard .task-steps { margin: 12px 0 8px 7px; padding-left: 12px; border-left: 1px solid #e4e9f0; }
#retrievalCard .task-steps li { background: transparent; padding: 3px 4px; line-height: 1.6; }
#retrievalCard .task-steps .step-state { display: none; }
#retrievalCard .task-steps li[data-status="running"] { color: #344963; font-weight: 500; }
#retrievalCard .retrieval-side { margin: 4px 0 0 24px; }
#retrievalCard .retrieval-side button { color: #8b97a6; font-size: 11px; }
#retrievalCard .retrieval-content p { max-height: 320px; overflow: auto; white-space: pre-wrap; line-height: 1.7; }
@keyframes task-step-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes task-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .task-steps li, .task-steps .step-marker[data-status="running"] { animation: none; } }
