:root {
  --bg: #FAF9F5;
  --surface: #FFFFFF;
  --ink: #2B3A4A;
  --ink-2: #576373;
  --muted: #98999B;
  --border: #E9E6DE;
  --border-soft: #F1EFE9;

  --primary: #3E5C82;
  --primary-ink: #2F4767;
  --primary-soft: #EEF2F7;

  --ok: #47795B;
  --warn: #A0762F;
  --warn-bg: #FCF7EC;
  --gray: #8A8478;
  --gray-bg: #F5F3EE;

  --r: 8px;
  --r-s: 6px;

  --font-display: Georgia, "Times New Roman", "Source Han Serif SC", "Noto Serif SC", SimSun, serif;

  font-size: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

/* auth gate */

.auth-gate {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.auth-gate[hidden] { display: none !important; }

.auth-card {
  width: 360px; max-width: calc(100vw - 40px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 32px 30px 28px;
  box-shadow: 0 12px 40px rgba(43, 58, 74, .08);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 44px; height: 44px; font-size: 22px; }
.auth-brand-name { font-family: var(--font-display); font-size: 16px; color: var(--ink); text-align: center; }

.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--gray-bg); border-radius: var(--r-s); padding: 3px; }
.auth-tab {
  flex: 1; border: none; background: none;
  padding: 8px; border-radius: 5px;
  font: inherit; font-size: 13.5px; color: var(--muted);
  cursor: pointer;
}
.auth-tab.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(43,58,74,.06); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-input {
  border: 1px solid var(--border);
  border-radius: var(--r-s);
  padding: 11px 13px;
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface);
  outline: none;
}
.auth-input:focus { border-color: var(--primary); }
.auth-error { font-size: 12.5px; color: var(--warn); min-height: 16px; line-height: 1.3; }
.auth-submit {
  border: none; background: var(--primary); color: #fff;
  border-radius: var(--r-s); padding: 11px;
  font: inherit; font-size: 14px; cursor: pointer;
  transition: background .15s;
}
.auth-submit:hover { background: var(--primary-ink); }
.auth-submit:disabled { opacity: .6; cursor: default; }

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

.icon { width: 16px; height: 16px; flex: none; }

.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  min-width: 880px;
}

/* ---------- sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding: 26px 14px 14px;
  gap: 22px;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px; }

.brand-mark {
  width: 36px; height: 36px;
  border-radius: var(--r);
  background: var(--primary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 18px;
  display: grid; place-items: center;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
}

.new-chat-side {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  font: inherit;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.new-chat-side:hover { border-color: var(--primary); color: var(--primary-ink); }
.new-chat-side .icon { width: 16px; height: 16px; color: var(--muted); }
.new-chat-side:hover .icon { color: var(--primary); }

.side-nav { display: flex; flex-direction: column; gap: 2px; }

.course-picker {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  font-family: var(--font-display);
  font-size: 14.5px;
  cursor: pointer;
  color: var(--ink);
  transition: border-color .15s;
}
.course-picker:hover { border-color: var(--primary); }
.course-picker .icon { color: var(--primary); }
.course-picker .chevron { margin-left: auto; color: var(--muted); }

.nav-group { display: flex; flex-direction: column; gap: 3px; }

.nav-label {
  font-size: 12px; color: var(--muted);
  padding: 0 12px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-radius: var(--r-s);
  color: var(--ink-2);
  text-decoration: none;
  transition: background .12s;
}
.nav-item:hover { background: var(--gray-bg); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 600;
}
.nav-item .icon { color: var(--muted); }
.nav-item.active .icon { color: var(--primary); }
.nav-text { flex: 1; }
.nav-count { font-size: 12px; color: var(--muted); font-weight: 400; }

.sidebar-footer {
  position: relative;
  margin-top: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px;
  border-top: 1px solid var(--border-soft);
  border-radius: var(--r-s);
  color: var(--muted);
  cursor: pointer;
}
.sidebar-footer:hover { background: var(--gray-bg); }
.teacher-name { flex: 1; color: var(--ink); }

.footer-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 5px;
  box-shadow: 0 6px 20px rgba(43, 58, 74, .08);
  display: flex; flex-direction: column; gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(5px);
  transition: opacity .16s, transform .16s, visibility .16s;
  z-index: 5;
}
.sidebar-footer:hover .footer-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.footer-menu::after {
  content: "";
  position: absolute;
  top: 100%; left: 0; right: 0;
  height: 10px;
}

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px;
  flex: none;
}
.avatar-teacher { background: var(--primary); color: #fff; }
.avatar-agent { background: var(--primary-soft); color: var(--primary); }

/* ---------- chat ---------- */

.chat { display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 48px 16px;
}
.chat-title {
  display: flex; align-items: baseline; gap: 14px;
  font-family: var(--font-display);
  font-size: 17px;
}

.status-online {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 12px; color: var(--ok);
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  display: inline-block;
}
.dot-breathe { animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-s);
  padding: 6px 14px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary-ink); }

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 48px 12px;
  display: flex; flex-direction: column; gap: 26px;
}

.msg {
  width: 100%;
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}

.time-divider {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.msg { display: flex; gap: 12px; animation: rise .35s ease both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg-teacher { justify-content: flex-end; }
.msg-teacher .bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--r);
  border-top-right-radius: 2px;
  padding: 10px 16px;
  max-width: 60%;
  line-height: 1.7;
}

.msg-agent { align-items: flex-start; }
.msg-agent .avatar-agent .icon { width: 17px; height: 17px; }

.agent-reply { min-width: 0; }
.agent-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.agent-meta time { margin-left: 6px; }
.agent-intro { line-height: 1.8; margin-bottom: 14px; }

.evidence {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r);
  padding: 14px 18px;
  margin-bottom: 10px;
  animation: rise .35s ease both;
}
.evidence-confirmed { border-left-color: var(--ok); }
.evidence-inferred  { border-left-color: var(--warn); }
.evidence-unknown   { border-left-color: var(--gray); }
.evidence:nth-of-type(1) { animation-delay: .05s; }
.evidence:nth-of-type(2) { animation-delay: .15s; }
.evidence:nth-of-type(3) { animation-delay: .25s; }

.evidence-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 13px;
  margin-bottom: 10px;
}
.evidence-confirmed .evidence-head { color: var(--ok); }
.evidence-inferred  .evidence-head { color: var(--warn); }
.evidence-unknown   .evidence-head { color: var(--gray); }

.evidence ul { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.evidence li {
  display: flex; align-items: baseline; gap: 9px;
  line-height: 1.7; color: var(--ink-2);
}
.evidence li::before {
  content: "";
  width: 4px; height: 4px; border-radius: 50%;
  flex: none;
  position: relative; top: -3px;
  background: var(--muted);
}
.evidence li > span { flex: 1; }

.evidence-link {
  border: none; background: none;
  font-family: inherit; font-size: 12.5px;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
  padding: 0;
}
.evidence-link:hover { text-decoration: underline; }

.agent-actions {
  display: flex; align-items: center; gap: 9px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.agent-actions-label { font-size: 12px; color: var(--muted); }

.action-chip {
  border: 1px solid var(--border);
  color: var(--primary-ink);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.action-chip:hover { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- composer ---------- */

.composer {
  padding: 12px 48px 28px;
}

.quick-chips, .attach-chips, .input-row {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}

.quick-chips { display: flex; gap: 9px; margin-bottom: 12px; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--ink-2);
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary-ink); }

.input-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 7px;
  transition: border-color .15s;
}
.input-row:focus-within { border-color: var(--primary); }

.input {
  flex: 1;
  border: none; outline: none;
  font: inherit; color: var(--ink);
  background: none;
  padding: 9px 0;
}
.input::placeholder { color: var(--muted); }

.btn-send {
  width: 38px; height: 38px;
  border: none; border-radius: var(--r-s);
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .15s;
}
.btn-send:hover { background: var(--primary-ink); }

/* ---------- right panel ---------- */

.panel {
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  min-width: 0;
}

.panel-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 24px 24px 16px;
}
.panel-title { font-family: var(--font-display); font-size: 16px; }

.class-select {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  max-width: 180px;
}
.class-select:focus { outline: none; }
.panel-refresh { font-size: 12px; color: var(--muted); }

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 24px;
  display: flex; flex-direction: column; gap: 14px;
}

.student-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  transition: border-color .15s;
}
.student-card:hover { border-color: var(--primary); }

.student-head { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; }
.student-name { font-family: var(--font-display); font-size: 15.5px; }

.student-status {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px;
}
.student-status.is-online { color: var(--ok); }
.student-status.is-offline { color: var(--muted); }

.student-agent {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--muted);
}

.task-name {
  display: flex; justify-content: space-between; align-items: baseline;
  color: var(--ink-2); font-size: 13px;
  margin-bottom: 8px;
}
.task-pct { font-size: 12px; color: var(--muted); }

.progress {
  height: 4px;
  background: var(--border-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .6s ease;
}

.student-note {
  margin-top: 11px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}
.student-note.is-warn { color: var(--warn); }

.panel-footer {
  padding: 14px 24px 20px;
}
.panel-footer .btn-ghost { width: 100%; }

/* interactions */

.evidence li.evidence-detail-li { display: block; animation: rise .25s ease both; }
.evidence li.evidence-detail-li::before { content: none; }

.evidence-detail {
  display: flex; flex-direction: column; gap: 5px;
  background: var(--gray-bg);
  border-radius: var(--r-s);
  padding: 10px 14px;
  margin: 3px 0 4px 13px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-2);
}
.evidence-detail .detail-note { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  right: 24px; bottom: 28px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r);
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 10;
}
.toast.show { opacity: 1; transform: none; }

.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 60%, 100% { opacity: .25; }
  30% { opacity: 1; }
}

/* scenario cards */

.plan-card, .report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--r);
  padding: 4px 18px;
  margin-bottom: 4px;
}

.plan-group { padding: 13px 0; }
.plan-group + .plan-group { border-top: 1px solid var(--border-soft); }
.plan-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 600; font-size: 13.5px;
  color: var(--primary-ink);
  margin-bottom: 5px;
}
.plan-count { font-size: 12px; font-weight: 400; color: var(--muted); }
.plan-group p { line-height: 1.7; color: var(--ink-2); font-size: 13px; }

.stat-row {
  display: flex; gap: 34px;
  padding: 14px 0 12px;
  border-bottom: 1px solid var(--border-soft);
}
.stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 400;
  color: var(--ink);
}
.stat span { font-size: 12px; color: var(--muted); }

.report-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 9px;
  padding: 13px 0;
}
.report-list li {
  display: flex; align-items: baseline; gap: 9px;
  line-height: 1.7; color: var(--ink-2); font-size: 13px;
}
.report-list li::before {
  content: "";
  width: 4px; height: 4px; border-radius: 50%;
  flex: none;
  position: relative; top: -3px;
  background: var(--muted);
}
.report-list li > span { flex: 1; }
.report-list li.evidence-detail-li { display: block; }
.report-list li.evidence-detail-li::before { content: none; }

@keyframes flash {
  0% { border-color: var(--primary); background: var(--primary-soft); }
  100% { border-color: var(--border); background: var(--surface); }
}
.student-card { cursor: pointer; }
.student-card.flash { animation: flash 1.8s ease both; }

/* drawer */

.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(43, 58, 74, .18);
  opacity: 0;
  transition: opacity .2s;
  z-index: 20;
}
.drawer-mask.open { opacity: 1; }
.drawer-mask:not(.open) { pointer-events: none; }

.drawer {
  position: absolute; top: 0; right: 0;
  width: 420px; height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(24px);
  transition: transform .22s ease;
}
.drawer-mask.open .drawer { transform: none; }

.drawer-head {
  display: flex; align-items: baseline; gap: 12px;
  padding: 24px 26px 16px;
}
.drawer-name { font-family: var(--font-display); font-size: 19px; }
.drawer-tag { font-size: 12px; color: var(--muted); flex: 1; }
.drawer-close {
  border: none; background: none;
  font-size: 22px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
}
.drawer-close:hover { color: var(--ink); }

.drawer-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 0 26px;
  display: flex; flex-direction: column; gap: 20px;
}

.drawer-sec h3 {
  font-size: 12px; font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}
.drawer-sec > p {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 15px;
  line-height: 1.7;
  font-size: 13px;
  color: var(--ink-2);
}

.log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 15px;
}
.log-item {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 0;
  font-size: 13px;
}
.log-item + .log-item { border-top: 1px solid var(--border-soft); }
.log-time { font-size: 12px; color: var(--muted); flex: none; }
.log-who {
  flex: none;
  font-size: 12px;
  color: var(--ink-2);
}
.log-who.is-agent { color: var(--primary); }
.log-item p { flex: 1; line-height: 1.65; color: var(--ink-2); }

.drawer-foot { padding: 16px 26px 22px; }

/* live chat */

.agent-reply { max-width: 680px; }

.md { line-height: 1.8; color: var(--ink-2); max-width: 560px; }
.md p { margin-bottom: 8px; }
.md p:last-child { margin-bottom: 0; }
.md h4 {
  font-size: 13.5px; font-weight: 600;
  color: var(--ink);
  margin: 14px 0 6px;
}
.md h4:first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 20px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.md code {
  background: var(--gray-bg);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12.5px;
}
.md pre {
  background: var(--gray-bg);
  border-radius: var(--r-s);
  padding: 10px 14px;
  overflow-x: auto;
  margin-bottom: 8px;
}
.md pre code { background: none; padding: 0; }
.md b { color: var(--ink); }

.chat-scroll:empty { position: relative; }
.chat-scroll:empty::after {
  content: attr(data-empty);
  position: absolute;
  top: 42%; left: 0; right: 0;
  padding: 0 48px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1.6;
  color: var(--muted);
}

/* kb page (chat + library panes) */

.chat[hidden], .kb-page[hidden], .kb-layout[hidden] { display: none; }

.kb-layout { display: flex; min-width: 0; }
.kb-chat-pane { flex: 1; min-width: 0; border-right: 1px solid var(--border); }

.kb-library {
  width: 320px; flex: none;
  display: flex; flex-direction: column;
  min-width: 0;
}
.kb-lib-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 20px 22px 14px;
}
.kb-lib-title { font-family: var(--font-display); font-size: 16px; }
.kb-lib-count { font-size: 12px; color: var(--muted); }

.kb-lib-list {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 0 18px 20px;
  display: flex; flex-direction: column; gap: 9px;
}

.lib-card {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color .14s, background .14s, box-shadow .14s;
}
.lib-card:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 1px 3px rgba(43, 58, 74, .06);
}
.lib-card-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  margin-bottom: 5px;
}
.lib-card-title .icon-s { color: var(--primary); flex: none; }
.lib-card-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-card-preview {
  font-size: 12px; line-height: 1.55; color: var(--muted);
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.lib-card-meta { margin-top: 7px; font-size: 11.5px; color: var(--muted); }

.lib-empty {
  font-size: 13px; color: var(--muted); line-height: 1.7;
  padding: 20px 4px; text-align: center;
}

.lib-flash { animation: flash 1.8s ease both; }

/* document modal */

.doc-mask {
  position: fixed; inset: 0;
  background: rgba(43, 58, 74, .22);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  padding: 40px;
}
.doc-mask[hidden] { display: none; }

.doc-modal {
  width: 720px; max-width: 100%;
  max-height: 86vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 20px 60px rgba(43, 58, 74, .18);
  display: flex; flex-direction: column;
}

.doc-modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.doc-title-input {
  flex: 1;
  border: 1px solid transparent;
  background: none;
  font-family: var(--font-display);
  font-size: 17px; color: var(--ink);
  padding: 5px 8px;
  border-radius: var(--r-s);
  outline: none;
}
.doc-title-input:not([readonly]) {
  border-color: var(--border);
  background: var(--surface);
}
.doc-modal-actions { display: flex; gap: 4px; flex: none; }
.doc-btn {
  width: 32px; height: 32px;
  border: none; background: none;
  display: grid; place-items: center;
  border-radius: var(--r-s);
  color: var(--muted); cursor: pointer;
  transition: background .14s, color .14s;
}
.doc-btn:hover { background: var(--gray-bg); color: var(--ink); }
.doc-btn-danger:hover { background: var(--warn-bg); color: var(--warn); }
.doc-btn.armed { background: var(--warn-bg); color: var(--warn); width: auto; padding: 0 10px; font-size: 12px; }

.doc-meta { padding: 10px 22px 0; font-size: 12px; color: var(--muted); }

.doc-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 22px 20px; }
.doc-content {
  font: 13px/1.85 Consolas, "Microsoft YaHei", sans-serif;
  color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
  margin: 0;
}
.doc-content-edit {
  width: 100%; min-height: 46vh;
  border: 1px solid var(--border);
  border-radius: var(--r-s);
  padding: 12px 14px;
  font: 13px/1.8 Consolas, "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--surface);
  outline: none; resize: vertical;
}
.doc-content-edit:focus { border-color: var(--primary); }

.doc-modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border-soft);
}

.kb-page { display: flex; flex-direction: column; min-width: 0; }

.btn-back {
  border: none; background: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--r-s);
  color: var(--muted);
  cursor: pointer;
  align-self: center;
}
.btn-back:hover { color: var(--ink); background: var(--gray-bg); }
.btn-back .icon { width: 17px; height: 17px; }

.kb-count {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 12px; color: var(--muted);
}

.btn-upload { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.btn-upload .icon-s { color: var(--primary); }

.kb-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 8px 48px 32px;
}

.kb-list {
  display: flex; flex-direction: column; gap: 10px;
  max-width: 720px;
}

.kb-doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 18px;
  cursor: pointer;
  transition: border-color .15s;
}
.kb-doc:hover { border-color: var(--primary); }

.kb-doc-line { display: flex; align-items: center; gap: 12px; }
.kb-item-title { flex: 1; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.kb-item-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.kb-del {
  border: none; background: none;
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted);
  cursor: pointer;
  padding: 3px;
  border-radius: var(--r-s);
}
.kb-del:hover { color: var(--warn); }
.kb-del-confirm { font-size: 12px; color: var(--warn); }
.kb-del.is-armed { color: var(--warn); background: var(--warn-bg); padding: 3px 8px; }

.kb-doc-preview[hidden] { display: none; }
.kb-doc-preview {
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.kb-doc-content {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--gray-bg);
  border-radius: var(--r-s);
  font: 12.5px/1.7 Consolas, "Microsoft YaHei", monospace;
  color: var(--ink-2);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 420px;
  overflow-y: auto;
}

.card-empty { font-size: 13px; color: var(--muted); padding: 4px 2px; }

/* attachments */

.btn-attach {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-s);
  color: var(--muted);
  cursor: pointer;
  flex: none;
  transition: color .15s, background .15s;
}
.btn-attach:hover { color: var(--primary); background: var(--gray-bg); }
.btn-attach .icon { width: 17px; height: 17px; }

.is-drop { outline: 2px dashed var(--primary); outline-offset: -10px; border-radius: var(--r-s); }

.progress-track { height: 6px; background: var(--gray-bg, #eee); border-radius: 3px; margin: 16px 18px 18px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .6s ease; }

.admin-modal { max-width: 560px; }
.admin-title { font-family: var(--font-display); font-size: 17px; }
.admin-using { display: flex; align-items: center; gap: 12px; padding: 12px 22px 0; color: var(--muted); font-size: 13px; }
.admin-keys { padding: 10px 22px; display: flex; flex-direction: column; gap: 8px; }
.admin-key-row { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--r-s); font-size: 13.5px; }
.ak-label { font-weight: 600; }
.ak-meta { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ak-active { color: var(--primary); font-weight: 600; font-size: 12.5px; }
.ak-del.armed { color: #b4423a; }
.admin-form { display: flex; flex-direction: column; gap: 8px; padding: 6px 22px 20px; }
.admin-form-foot { display: flex; justify-content: flex-end; gap: 10px; }
.admin-health { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 22px 0; font-size: 12.5px; color: var(--muted); }
.health-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.health-ok { background: #3fa46a; }
.health-bad { background: #c0492f; }
.health-unknown { background: var(--border); }
.health-rate { margin-left: auto; }

.grade-list, .history-list, .kb-list { max-height: 420px; overflow-y: auto; overscroll-behavior: contain; }
.grade-list::-webkit-scrollbar, .history-list::-webkit-scrollbar, .kb-list::-webkit-scrollbar { width: 8px; }
.grade-list::-webkit-scrollbar-thumb, .history-list::-webkit-scrollbar-thumb, .kb-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.attach-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.attach-chips:not(:empty) { margin-bottom: 9px; }

.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.attach-chip .icon-s { color: var(--primary); }

.attach-remove {
  border: none; background: none;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 14px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.attach-remove:hover { background: var(--gray-bg); color: var(--ink); }

/* clarifying choice question */

.choice-box {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px;
  max-width: 420px;
}
.choice-opt {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r);
  padding: 10px 14px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.choice-opt:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.choice-opt:disabled { opacity: .5; cursor: default; }
.choice-opt.is-other { color: var(--ink-2); border-style: dashed; }
.choice-box.chosen .choice-opt { border-style: solid; }

.choice-input-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--primary);
  border-radius: var(--r);
  padding: 5px 6px 5px 14px;
  background: var(--surface);
}
.choice-input {
  flex: 1; border: none; outline: none;
  font: inherit; background: none; color: var(--ink);
  padding: 5px 0;
}
.choice-input::placeholder { color: var(--muted); }
.choice-go {
  width: 30px; height: 30px; flex: none;
  border: none; border-radius: var(--r-s);
  background: var(--primary); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.choice-go:hover { background: var(--primary-ink); }

.choice-card { max-width: 480px; margin-top: 12px; }
.choice-list { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; }
.choice-card.chosen .choice-opt { border-style: solid; }
.choice-opt.picked {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}
.choice-foot { display: flex; justify-content: flex-end; }

.bubble-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bubble-file {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .14);
  border-radius: var(--r-s);
  padding: 4px 10px;
  font-size: 12.5px;
}

/* data cards (agent tool output) */

.cards-wrap { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.data-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 18px 12px;
  max-width: 560px;
}

.data-card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.data-card-title { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.data-card-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.data-card-foot {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  color: var(--muted);
}

.icon-s { width: 13px; height: 13px; flex: none; }

.roster-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.roster-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  color: var(--ink-2);
}
.roster-chip.is-done .icon-s { color: var(--ok); }
.roster-chip.is-pending { color: var(--warn); background: var(--warn-bg); border-color: transparent; }

.grade-list { display: flex; flex-direction: column; }
.grade-row + .grade-row { border-top: 1px solid var(--border-soft); }

.grade-line {
  display: grid;
  grid-template-columns: 52px 1fr 40px 40px 16px;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
}
.grade-line.is-expandable { cursor: pointer; }
.grade-name { font-size: 13.5px; color: var(--ink); }
.grade-pass { font-size: 12px; color: var(--muted); text-align: right; }
.grade-badge {
  font-size: 13px;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.grade-badge.is-full { color: var(--ok); }
.grade-badge.is-missing { font-size: 12px; color: var(--warn); white-space: nowrap; }
.grade-chev { color: var(--muted); display: flex; justify-content: flex-end; }
.grade-line .chev { transition: transform .15s; }
.grade-line.open .chev { transform: rotate(180deg); }

.progress-bar.is-full { background: var(--ok); }

.grade-detail {
  list-style: none;
  display: flex; flex-direction: column; gap: 5px;
  margin: 0 0 11px 64px;
  font-size: 12.5px;
  color: var(--muted);
}
.grade-detail[hidden] { display: none; }
.grade-line .progress, .grade-line .progress-bar { display: block; }
.grade-detail li { display: flex; align-items: baseline; gap: 8px; }
.grade-detail code {
  background: var(--gray-bg);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--ink-2);
}
.grade-detail .grade-error-line { color: var(--warn); }

/* batch grade card */

.dim-detail li { display: grid; grid-template-columns: 110px 46px 1fr; gap: 8px; align-items: baseline; }
.dim-detail .dim-name { color: var(--ink); }
.dim-detail .dim-score { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.dim-detail .dim-reason { color: var(--muted); }
.dim-detail .dim-summary {
  display: block;
  margin-top: 4px; padding-top: 7px;
  border-top: 1px solid var(--border-soft);
  color: var(--ink-2);
}

.flag-chip {
  margin-left: 7px;
  font-size: 11px;
  color: var(--warn);
  background: var(--warn-bg);
  border-radius: 999px;
  padding: 1px 8px;
  vertical-align: 1px;
}

.batch-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.history-name-wide { font-weight: 600; color: var(--ink); flex: 1; }

.history-list { display: flex; flex-direction: column; }
.history-row {
  display: flex; align-items: baseline; gap: 14px;
  padding: 8px 0;
  font-size: 12.5px;
  color: var(--ink-2);
}
.history-row + .history-row { border-top: 1px solid var(--border-soft); }
.history-name { font-weight: 600; color: var(--ink); flex: none; width: 48px; }
.history-assignment { flex: 1; }
.history-date { color: var(--muted); white-space: nowrap; }

.kb-item-block { display: block; }
.kb-item-preview { margin-top: 6px; font-size: 12.5px; line-height: 1.6; color: var(--ink-2); }
