:root {
  --paper: #f6f3ec;
  --paper-deep: #ece7dc;
  --surface: #fffefb;
  --surface-muted: #f7f8f7;
  --ink: #162332;
  --ink-soft: #435365;
  --muted: #687586;
  --line: #d9ddd9;
  --line-strong: #bec7c5;
  --navy: #173750;
  --navy-hover: #214a69;
  --navy-pale: #eaf0f3;
  --vermilion: #a53d2d;
  --vermilion-dark: #7f2c21;
  --vermilion-pale: #f8ebe7;
  --success: #26614c;
  --success-pale: #e7f1ec;
  --warning: #805919;
  --warning-pale: #fff3d6;
  --danger: #9c2f2a;
  --danger-pale: #fcebea;
  --shadow-sm: 0 1px 2px rgb(22 35 50 / 6%), 0 5px 18px rgb(22 35 50 / 4%);
  --shadow-md: 0 14px 45px rgb(22 35 50 / 13%);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --sidebar-width: 280px;
  --reading-width: 860px;
  --focus-ring: 0 0 0 3px rgb(65 119 154 / 28%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.65;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #41779a;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3,
.sidebar-brand strong {
  font-family: "Songti SC", SimSun, "Noto Serif CJK SC", serif;
  letter-spacing: 0.015em;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.65rem, 3vw, 2.25rem);
  line-height: 1.28;
}

h2 {
  font-size: 1.2rem;
  line-height: 1.4;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  transform: translateY(-160%);
  border-radius: var(--radius-sm);
  background: var(--navy);
  color: white;
}

.skip-link:focus {
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--muted);
}

.compact {
  margin: 4px 8px;
  font-size: 0.875rem;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--vermilion);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.button {
  min-height: 44px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 650;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.button-primary {
  background: var(--navy);
  color: white;
}

.button-primary:hover:not(:disabled) {
  background: var(--navy-hover);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--navy);
  color: var(--navy);
}

.button-danger {
  background: var(--danger);
  color: white;
}

.button-danger:hover:not(:disabled) {
  background: #7c2521;
}

.button-block {
  width: 100%;
}

.icon-button,
.avatar-button,
.text-button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
}

.icon-button:hover,
.text-button:hover {
  background: rgb(23 55 80 / 8%);
}

.text-button {
  min-width: auto;
  color: var(--muted);
  font-size: 0.8rem;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(320px, 0.92fr) minmax(420px, 1.08fr);
  background: var(--paper);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background:
    linear-gradient(rgb(19 49 71 / 94%), rgb(19 49 71 / 94%)),
    repeating-linear-gradient(45deg, transparent, transparent 20px, rgb(255 255 255 / 4%) 20px, rgb(255 255 255 / 4%) 21px);
  color: #eef3f5;
}

.login-brand p {
  margin-top: 20px;
  color: #c8d6dd;
  letter-spacing: 0.14em;
}

.brand-seal {
  display: inline-grid;
  width: 116px;
  height: 116px;
  place-items: center;
  border: 2px solid rgb(255 255 255 / 72%);
  outline: 1px solid rgb(255 255 255 / 32%);
  outline-offset: 5px;
  background: var(--vermilion);
  color: white;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 4rem;
  line-height: 1;
  box-shadow: 0 14px 40px rgb(0 0 0 / 18%);
}

.login-card {
  width: min(100%, 470px);
  align-self: center;
  justify-self: center;
  padding: 48px;
}

.login-intro {
  margin-bottom: 30px;
  color: var(--ink-soft);
}

.stack-form,
.modal-card {
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 650;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: #8c9ba2;
}

.field small {
  color: var(--muted);
  font-size: 0.78rem;
}

.form-error {
  min-height: 1.55em;
  margin: -5px 0 0;
  color: var(--danger);
  font-size: 0.86rem;
}

.security-note {
  margin: 25px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.mobile-header {
  display: none;
}

.sidebar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  padding: 20px 16px 14px;
  border-right: 1px solid #d6d9d6;
  background: #eeebe3;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  min-height: 58px;
  margin-bottom: 18px;
  gap: 13px;
}

.sidebar-brand > div {
  display: grid;
  flex: 1;
}

.sidebar-brand strong {
  font-size: 1rem;
}

.sidebar-brand span:not(.brand-seal) {
  color: var(--muted);
  font-size: 0.78rem;
}

.brand-seal-small {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  border-width: 1px;
  outline: 0;
  font-size: 1.65rem;
  box-shadow: none;
}

.drawer-close {
  display: none;
}

.new-chat-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  gap: 8px;
}

.primary-nav {
  display: grid;
  gap: 3px;
}

.nav-item {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}

.nav-item > span:first-child {
  display: inline-grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  font-family: "Songti SC", SimSun, serif;
  font-size: 0.78rem;
}

.nav-item:hover,
.nav-item.is-active {
  background: rgb(23 55 80 / 8%);
  color: var(--navy);
}

.nav-item.is-active {
  font-weight: 700;
}

.nav-item.is-active > span:first-child {
  border-color: var(--navy);
  background: var(--navy);
  color: white;
}

.history-section {
  display: flex;
  min-height: 120px;
  flex: 1;
  flex-direction: column;
  margin-top: 22px;
  overflow: hidden;
}

.section-heading,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2 {
  margin: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.history-list {
  overflow-y: auto;
  margin-top: 6px;
  scrollbar-color: #b6b9b4 transparent;
  scrollbar-width: thin;
}

.history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: center;
  border-radius: var(--radius-sm);
}

.history-entry.is-active {
  background: rgb(23 55 80 / 9%);
}

.history-open {
  display: grid;
  min-width: 0;
  min-height: 50px;
  align-content: center;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}

.history-open strong,
.history-open span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-open strong {
  font-size: 0.84rem;
  font-weight: 600;
}

.history-open span {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-delete {
  width: 36px;
  min-width: 36px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
}

.history-delete:hover {
  background: var(--danger-pale);
  color: var(--danger);
}

.account-panel {
  display: flex;
  align-items: center;
  padding-top: 13px;
  border-top: 1px solid var(--line-strong);
  gap: 10px;
}

.account-avatar,
.avatar-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  place-items: center;
  border: 1px solid #9c4f42;
  border-radius: 50%;
  background: var(--vermilion-pale);
  color: var(--vermilion-dark);
  font-family: "Songti SC", SimSun, serif;
  font-weight: 700;
}

.account-copy {
  display: grid;
  min-width: 0;
  flex: 1;
}

.account-copy strong,
.account-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-copy strong {
  font-size: 0.84rem;
}

.account-copy span {
  color: var(--muted);
  font-size: 0.72rem;
}

.workspace {
  min-width: 0;
  background: var(--surface);
}

.workspace-view {
  min-height: 100vh;
}

.view-header {
  display: flex;
  min-height: 110px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 28px clamp(24px, 4vw, 58px) 22px;
  border-bottom: 1px solid var(--line);
  gap: 24px;
}

.view-header h1 {
  margin: 0;
  font-size: 1.65rem;
}

.view-header p {
  max-width: 720px;
  margin: 8px 0 0;
  color: var(--muted);
}

.chat-view {
  display: grid;
  height: 100vh;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.knowledge-badge,
.status-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid #b8d0c5;
  border-radius: 999px;
  background: var(--success-pale);
  color: var(--success);
  font-size: 0.76rem;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--success);
}

.chat-stage {
  overflow-y: auto;
  padding: 30px clamp(24px, 4vw, 58px) 18px;
  scroll-behavior: smooth;
}

.welcome-panel,
.messages,
.answer-progress,
.composer-wrap {
  width: min(100%, var(--reading-width));
  margin-right: auto;
  margin-left: auto;
}

.welcome-panel {
  padding: clamp(20px, 5vh, 58px) 0 16px;
  text-align: center;
}

.welcome-seal {
  width: 64px;
  height: 64px;
  border: 0;
  outline: 0;
  font-size: 2.3rem;
  box-shadow: var(--shadow-sm);
}

.welcome-panel h2 {
  margin: 23px 0 10px;
  font-size: clamp(1.3rem, 3vw, 1.65rem);
}

.welcome-panel > p {
  max-width: 650px;
  margin: 0 auto 30px;
  color: var(--ink-soft);
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  text-align: left;
}

.suggestion {
  min-height: 112px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.suggestion:hover {
  border-color: #91a4af;
  background: var(--navy-pale);
  transform: translateY(-1px);
}

.suggestion strong,
.suggestion span {
  display: block;
}

.suggestion strong {
  margin-bottom: 6px;
  color: var(--vermilion-dark);
  font-size: 0.8rem;
}

.suggestion span {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.5;
}

.messages {
  display: grid;
  gap: 28px;
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: start;
  gap: 14px;
}

.message-avatar {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  font-family: "Songti SC", SimSun, serif;
  font-size: 0.85rem;
  font-weight: 700;
}

.message-user .message-avatar {
  border: 1px solid var(--line-strong);
  background: var(--paper-deep);
  color: var(--ink-soft);
}

.message-assistant .message-avatar {
  background: var(--navy);
  color: white;
}

.message-system .message-avatar {
  background: var(--danger-pale);
  color: var(--danger);
}

.message-content {
  min-width: 0;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  gap: 12px;
}

.message-meta strong {
  font-size: 0.86rem;
}

.copy-button {
  min-height: 36px;
  padding: 5px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.76rem;
}

.copy-button:hover {
  background: var(--navy-pale);
  color: var(--navy);
}

.message-text {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.78;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.markdown-body {
  white-space: normal;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-table-wrap {
  margin: 0 0 0.9em;
}

.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.25em 0 0.55em;
  color: var(--ink);
  line-height: 1.45;
}

.markdown-body h2 {
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--line);
  font-size: 1.13rem;
}

.markdown-body h3 {
  font-size: 1.02rem;
}

.markdown-body h4 {
  font-family: inherit;
  font-size: 0.96rem;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.55em;
}

.markdown-body li {
  padding-left: 0.18em;
}

.markdown-body li + li {
  margin-top: 0.35em;
}

.markdown-body strong {
  color: var(--navy);
  font-weight: 750;
}

.markdown-body a {
  color: var(--navy-hover);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.markdown-body blockquote {
  padding: 0.75em 1em;
  border-left: 3px solid var(--vermilion);
  background: var(--vermilion-pale);
  color: var(--ink-soft);
}

.markdown-body code {
  padding: 0.12em 0.35em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
}

.markdown-body pre {
  max-width: 100%;
  padding: 13px 15px;
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #132431;
  color: #f4f7f8;
}

.markdown-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 0.84rem;
  white-space: pre;
}

.markdown-body hr {
  margin: 1.15em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.citation-reference {
  display: inline;
  min-height: 0;
  padding: 0 0.08em;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--vermilion-dark);
  font: inherit;
  font-weight: 750;
  line-height: inherit;
  white-space: nowrap;
}

.citation-reference:hover {
  background: var(--vermilion-pale);
}

.markdown-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.88rem;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 11px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th:last-child,
.markdown-body td:last-child {
  border-right: 0;
}

.markdown-body tbody tr:last-child td {
  border-bottom: 0;
}

.markdown-body th {
  background: var(--navy-pale);
  color: var(--navy);
  font-weight: 700;
}

.markdown-body .align-center {
  text-align: center;
}

.markdown-body .align-right {
  text-align: right;
}

.message-user .message-text {
  padding: 12px 15px;
  border-radius: 3px var(--radius-md) var(--radius-md) var(--radius-md);
  background: var(--navy-pale);
}

.message-system .message-text {
  padding: 12px 15px;
  border-left: 3px solid var(--danger);
  background: var(--danger-pale);
  color: var(--danger);
}

.sources-section {
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.sources-summary {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  list-style: none;
  cursor: pointer;
}

.sources-summary::-webkit-details-marker,
.source-heading::-webkit-details-marker {
  display: none;
}

.sources-summary::after {
  margin-left: auto;
  color: var(--navy);
  content: "展开";
  font-size: 0.76rem;
  font-weight: 650;
}

.sources-section[open] > .sources-summary {
  border-bottom: 1px solid var(--line);
  background: var(--navy-pale);
}

.sources-section[open] > .sources-summary::after {
  content: "收起";
}

.sources-summary-title {
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 700;
}

.sources-count {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--paper-deep);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}

.sources-summary-hint {
  color: var(--muted);
  font-size: 0.76rem;
}

.source-list {
  display: grid;
  padding: 10px;
  gap: 8px;
}

.source-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.source-card.is-revealed {
  border-color: var(--vermilion);
  box-shadow: 0 0 0 3px rgb(165 61 45 / 12%);
}

.source-heading {
  display: flex;
  min-height: 46px;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  list-style: none;
  cursor: pointer;
}

.source-heading::after {
  flex: 0 0 auto;
  align-self: center;
  margin-left: 2px;
  color: var(--muted);
  content: "+";
  font-size: 1rem;
  font-weight: 500;
}

.source-card[open] > .source-heading {
  background: var(--paper);
}

.source-card[open] > .source-heading::after {
  content: "−";
}

.citation-number {
  flex: 0 0 auto;
  color: var(--vermilion);
  font-weight: 750;
}

.source-title {
  min-width: 0;
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.source-meta,
.source-score {
  color: var(--muted);
  font-size: 0.75rem;
}

.source-meta {
  margin-left: auto;
  white-space: nowrap;
}

.source-detail {
  padding: 13px 14px 14px;
  border-top: 1px solid var(--line);
}

.source-location {
  display: grid;
  margin: 0 0 13px;
  gap: 6px;
}

.source-location > div {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 9px;
}

.source-location dt,
.source-location dd {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.55;
}

.source-location dt {
  color: var(--muted);
}

.source-location dd {
  color: var(--ink-soft);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.source-excerpt-label {
  margin: 0 0 7px;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.source-excerpt {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.source-detail .source-excerpt {
  margin: 0;
  padding: 11px 12px;
  border-left: 3px solid var(--line-strong);
  background: var(--surface-muted);
  white-space: normal;
}

.source-detail .source-excerpt p {
  margin: 0 0 0.7em;
}

.source-detail .source-excerpt p:last-child {
  margin-bottom: 0;
}

.source-section-heading {
  margin: 0.9em 0 0.45em;
  color: var(--navy);
  font-family: inherit;
  font-size: 0.84rem;
}

.source-inline-label {
  margin-right: 0.55em;
  color: var(--navy);
}

.source-keywords {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin: 0.8em 0;
  gap: 6px;
}

.source-keywords strong {
  margin-right: 2px;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.source-keywords span {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.74rem;
}

.source-detail > .source-score {
  display: block;
  margin-top: 9px;
  text-align: right;
}

.answer-progress {
  padding: 14px 0 4px 52px;
  color: var(--muted);
  font-size: 0.86rem;
}

.thinking-dots {
  display: inline-flex;
  margin-right: 7px;
  gap: 3px;
}

.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--navy);
  animation: thinking 1.2s ease-in-out infinite;
}

.thinking-dots i:nth-child(2) {
  animation-delay: 120ms;
}

.thinking-dots i:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes thinking {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.composer-wrap {
  padding: 14px 0 12px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.composer:focus-within {
  border-color: #6f8999;
  box-shadow: var(--focus-ring);
}

.composer textarea {
  max-height: 190px;
  resize: none;
  padding: 8px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.55;
}

.send-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--navy);
  color: white;
  font-size: 1.25rem;
  font-weight: 700;
}

.send-button:hover:not(:disabled) {
  background: var(--navy-hover);
}

.composer-note {
  margin: 6px 4px 0;
  color: var(--muted);
  font-size: 0.73rem;
  text-align: center;
}

.content-column {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 30px clamp(24px, 4vw, 58px) 60px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  align-items: end;
  gap: 16px;
}

.search-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.result-summary {
  margin: 25px 0 13px;
  color: var(--muted);
  font-size: 0.86rem;
}

.search-results {
  display: grid;
  gap: 12px;
}

.search-result {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.search-result header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.search-result h2 {
  margin: 0;
  color: var(--navy);
  font-family: inherit;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.search-result .source-excerpt {
  margin: 12px 0;
  font-size: 0.93rem;
}

.empty-state,
.error-state {
  padding: 34px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  text-align: center;
}

.error-state {
  border-color: #dbb3af;
  background: var(--danger-pale);
  color: var(--danger);
}

.admin-view {
  background: var(--surface-muted);
}

.admin-grid {
  display: grid;
  max-width: 1220px;
  margin: 0 auto;
  padding: 30px clamp(24px, 4vw, 58px) 60px;
  grid-template-columns: minmax(300px, 0.85fr) minmax(380px, 1.15fr);
  gap: 18px;
}

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.panel-header {
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.status-list {
  margin: 0;
}

.status-list > div {
  display: grid;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  grid-template-columns: minmax(120px, 0.7fr) minmax(0, 1.3fr);
  gap: 12px;
}

.status-list dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.status-list dd {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.status-pill.is-warning {
  border-color: #e2c37b;
  background: var(--warning-pale);
  color: var(--warning);
}

.status-pill.is-error {
  border-color: #dfaba8;
  background: var(--danger-pale);
  color: var(--danger);
}

.admin-user-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.admin-user-form .field:nth-child(4),
.admin-user-form .button {
  grid-column: 1 / -1;
}

.users-panel {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
}

.user-identity {
  display: grid;
}

.user-identity span {
  color: var(--muted);
  font-size: 0.75rem;
}

.role-badge,
.account-status {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--navy-pale);
  color: var(--navy);
  font-size: 0.74rem;
  white-space: nowrap;
}

.account-status.is-inactive {
  background: var(--danger-pale);
  color: var(--danger);
}

.table-action {
  min-height: 36px;
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--navy);
  font-size: 0.76rem;
  white-space: nowrap;
}

.table-action:hover:not(:disabled) {
  border-color: var(--navy);
  background: var(--navy-pale);
}

.table-action.is-danger {
  border-color: #d6aaa6;
  color: var(--danger);
}

.table-action.is-danger:hover:not(:disabled) {
  background: var(--danger-pale);
}

.modal {
  width: min(calc(100% - 32px), 500px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  box-shadow: var(--shadow-md);
}

.modal::backdrop {
  background: rgb(13 25 36 / 58%);
  backdrop-filter: blur(2px);
}

.modal-card {
  padding: 30px;
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.modal-card h2 {
  margin-bottom: -7px;
}

.modal-card > p:not(.form-error) {
  margin-bottom: 2px;
  color: var(--ink-soft);
}

.modal-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 50%;
  background: var(--vermilion-pale);
  color: var(--vermilion-dark);
  font-size: 0.76rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  display: grid;
  width: min(calc(100% - 40px), 380px);
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border: 1px solid #b8d0c5;
  border-radius: var(--radius-sm);
  background: var(--success-pale);
  color: var(--success);
  box-shadow: var(--shadow-md);
  font-size: 0.86rem;
}

.toast.is-error {
  border-color: #dfaba8;
  background: var(--danger-pale);
  color: var(--danger);
}

.noscript-message {
  position: fixed;
  z-index: 2000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--surface);
  color: var(--danger);
  text-align: center;
}

@media (max-width: 1000px) {
  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .suggestion {
    min-height: 86px;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .users-panel {
    grid-column: 1;
  }
}

@media (max-width: 768px) {
  .login-shell {
    display: block;
  }

  .login-brand {
    min-height: 220px;
    padding: 32px;
  }

  .login-brand .brand-seal {
    width: 80px;
    height: 80px;
    font-size: 2.8rem;
  }

  .login-brand p {
    margin-bottom: 0;
  }

  .login-card {
    padding: 36px 24px 50px;
  }

  .app-shell {
    display: block;
    padding-top: 58px;
  }

  .mobile-header {
    position: fixed;
    z-index: 25;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    height: 58px;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    border-bottom: 1px solid var(--line);
    background: rgb(255 254 251 / 96%);
  }

  .mobile-brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    font-family: "Songti SC", SimSun, serif;
    font-weight: 700;
  }

  .mobile-brand > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mini-seal {
    display: inline-grid;
    width: 27px;
    height: 27px;
    flex: 0 0 27px;
    place-items: center;
    background: var(--vermilion);
    color: white;
    font-size: 0.84rem;
  }

  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, var(--sidebar-width));
    height: 100vh;
    transform: translateX(-105%);
    box-shadow: var(--shadow-md);
    transition: transform 160ms ease;
  }

  body.drawer-open {
    overflow: hidden;
  }

  body.drawer-open .sidebar {
    transform: translateX(0);
  }

  .drawer-scrim {
    position: fixed;
    z-index: 35;
    inset: 0;
    background: rgb(13 25 36 / 46%);
  }

  .drawer-close {
    display: inline-grid;
    place-items: center;
  }

  .workspace-view,
  .chat-view {
    min-height: calc(100vh - 58px);
    height: calc(100vh - 58px);
  }

  .view-header {
    min-height: 90px;
    padding: 20px 20px 16px;
  }

  .view-header h1 {
    font-size: 1.42rem;
  }

  .knowledge-badge {
    display: none;
  }

  .chat-stage {
    padding: 22px 16px 14px;
  }

  .welcome-panel {
    padding-top: 18px;
  }

  .welcome-panel > p {
    margin-bottom: 20px;
  }

  .composer-wrap {
    padding: 10px 14px 8px;
  }

  .composer-note {
    display: none;
  }

  .content-column,
  .admin-grid {
    padding: 22px 16px 40px;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .result-count-field {
    max-width: 140px;
  }

  .admin-view {
    height: auto;
  }

  .admin-user-form {
    grid-template-columns: 1fr;
  }

  .admin-user-form .field:nth-child(4),
  .admin-user-form .button {
    grid-column: 1;
  }
}

@media (max-width: 480px) {
  .login-brand {
    min-height: 185px;
  }

  .login-brand p {
    font-size: 0.78rem;
  }

  .message {
    grid-template-columns: 31px minmax(0, 1fr);
    gap: 9px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.72rem;
  }

  .source-heading {
    flex-wrap: wrap;
  }

  .source-meta {
    margin-left: auto;
  }

  .sources-summary-hint {
    display: none;
  }

  .source-location > div {
    grid-template-columns: 1fr;
    gap: 1px;
  }

  .search-input-row {
    grid-template-columns: 1fr;
  }

  .search-input-row .button {
    width: 100%;
  }

  .panel {
    padding: 17px;
  }

  .modal-card {
    padding: 24px 20px;
  }
}

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

@media (forced-colors: active) {
  .status-dot,
  .brand-seal,
  .mini-seal {
    border: 1px solid CanvasText;
  }
}
