/* ==========================================================================
   MyBot 工业诊断工作台
   原生 CSS / 无外部依赖 / 深色默认与亮色主题
   ========================================================================== */

:root {
  color-scheme: dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;

  --bg-canvas: #0b1016;
  --bg-base: #0f151d;
  --bg-elevated: #141c26;
  --bg-panel: #111923;
  --bg-panel-raised: #18222e;
  --bg-hover: #1b2734;
  --bg-active: #202e3d;
  --bg-input: #0e151d;

  --border-subtle: #202b38;
  --border-default: #2b3948;
  --border-strong: #3a4a5c;

  --text-primary: #edf2f6;
  --text-secondary: #b2bfcc;
  --text-muted: #82909f;
  --text-faint: #617080;

  --accent: #ef9b42;
  --accent-hover: #f4aa5c;
  --accent-active: #dd8730;
  --accent-soft: rgba(239, 155, 66, 0.12);
  --accent-border: rgba(239, 155, 66, 0.34);
  --accent-contrast: #1d1308;

  --status-alarm: #ef665f;
  --status-warning: #e8b84e;
  --status-normal: #42b883;
  --status-info: #4e9fd1;
  --status-private: #a27add;
  --status-offline: #798594;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.16);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.24);
  --shadow-focus: 0 0 0 3px rgba(239, 155, 66, 0.18);

  --radius-sm: 5px;
  --radius-md: 7px;
  --radius-lg: 9px;

  --header-height: 68px;
  --side-width: 340px;
  --content-max: 1480px;
  --transition: 160ms cubic-bezier(0.2, 0, 0, 1);
}

[data-theme="light"] {
  color-scheme: light;

  --bg-canvas: #e9edf0;
  --bg-base: #f3f5f6;
  --bg-elevated: #ffffff;
  --bg-panel: #f8f9fa;
  --bg-panel-raised: #ffffff;
  --bg-hover: #eef1f3;
  --bg-active: #e5eaee;
  --bg-input: #ffffff;

  --border-subtle: #dce1e5;
  --border-default: #cdd4da;
  --border-strong: #aeb9c2;

  --text-primary: #17212b;
  --text-secondary: #43515f;
  --text-muted: #667483;
  --text-faint: #8995a0;

  --accent: #b86617;
  --accent-hover: #a85c12;
  --accent-active: #914d0e;
  --accent-soft: rgba(184, 102, 23, 0.09);
  --accent-border: rgba(184, 102, 23, 0.28);
  --accent-contrast: #ffffff;

  --status-alarm: #c94743;
  --status-warning: #a97808;
  --status-normal: #25845f;
  --status-info: #2477a8;
  --status-private: #7850ad;
  --status-offline: #75808b;

  --shadow-xs: 0 1px 2px rgba(24, 35, 45, 0.06);
  --shadow-sm: 0 4px 14px rgba(24, 35, 45, 0.08);
  --shadow-md: 0 14px 34px rgba(24, 35, 45, 0.11);
  --shadow-focus: 0 0 0 3px rgba(184, 102, 23, 0.15);
}

* {
  box-sizing: border-box;
}

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

html {
  background: var(--bg-canvas);
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  color: var(--text-primary);
  background: var(--bg-base);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

button {
  border: 0;
}

button,
a,
input,
textarea,
[tabindex] {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled),
a,
[tabindex] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

code,
kbd,
.source-id,
.source-score,
.kb-item-id,
.kb-detail-id,
.score-num {
  font-family: var(--font-mono);
}

::selection {
  color: var(--text-primary);
  background: var(--accent-soft);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--border-strong);
  background-clip: padding-box;
}

/* ---------- Generic controls ---------- */

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: background-color var(--transition), border-color var(--transition),
              color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  color: var(--accent-contrast);
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.btn-primary:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn-ghost {
  color: var(--text-secondary);
  border-color: var(--border-default);
  background: transparent;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
}

.icon-btn {
  display: inline-flex;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-muted);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: transparent;
  transition: color var(--transition), border-color var(--transition), background-color var(--transition);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.section-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

.spinner {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Application frame ---------- */

.app-page {
  background:
    radial-gradient(circle at 68% 0%, rgba(239, 155, 66, 0.035), transparent 30%),
    var(--bg-base);
}

[data-theme="light"] .app-page {
  background:
    radial-gradient(circle at 68% 0%, rgba(184, 102, 23, 0.045), transparent 30%),
    var(--bg-base);
}

.app-shell {
  display: flex;
  width: 100%;
  height: 100dvh;
  min-width: 0;
  flex-direction: column;
}

.app-header {
  position: relative;
  z-index: 30;
  display: grid;
  min-height: var(--header-height);
  flex: 0 0 var(--header-height);
  grid-template-columns: minmax(235px, 1fr) auto minmax(310px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-xs);
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: inline-flex;
  width: 37px;
  height: 37px;
  flex: 0 0 37px;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.brand-mark svg {
  width: 25px;
  height: 25px;
  stroke-width: 1.8;
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.25;
}

.brand-copy strong {
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.brand-copy > span {
  overflow: hidden;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-base);
}

.tab {
  position: relative;
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  color: var(--text-muted);
  border-radius: 6px;
  background: transparent;
  font-size: 12px;
  font-weight: 620;
  transition: color var(--transition), background-color var(--transition), box-shadow var(--transition);
}

.tab svg {
  width: 15px;
  height: 15px;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.tab.active {
  color: var(--text-primary);
  background: var(--bg-panel-raised);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16), inset 0 0 0 1px var(--border-subtle);
}

.tab.active::after {
  position: absolute;
  right: 13px;
  bottom: -4px;
  left: 13px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  content: "";
}

.header-tools {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.header-divider {
  width: 1px;
  height: 26px;
  margin: 0 2px;
  background: var(--border-subtle);
}

.kb-health {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border: 2px solid var(--status-normal);
  border-radius: 50%;
  background: var(--status-normal);
  box-shadow: 0 0 0 3px rgba(66, 184, 131, 0.1);
}

.kb-health.is-offline .status-dot,
.side-context.is-offline .status-dot {
  border-color: var(--status-offline);
  background: var(--status-offline);
  box-shadow: 0 0 0 3px rgba(121, 133, 148, 0.1);
}

.kb-health-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.kb-health-copy > span {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 650;
}

.kb-health-copy small {
  overflow: hidden;
  max-width: 190px;
  margin-top: 3px;
  color: var(--text-faint);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  border-radius: 50%;
  background: var(--bg-panel-raised);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
}

.user-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.25;
}

.user-copy small {
  color: var(--text-faint);
  font-size: 9px;
  letter-spacing: 0.05em;
}

.user-copy > span {
  overflow: hidden;
  max-width: 130px;
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-toggle .theme-icon-light {
  display: none;
}

[data-theme="light"] .theme-toggle .theme-icon-dark {
  display: none;
}

[data-theme="light"] .theme-toggle .theme-icon-light {
  display: block;
}

.app-main {
  position: relative;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.view {
  display: none;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.view.active {
  display: block;
}

/* ---------- 智能体模块页面 ----------
   模块视图直接复用诊断页的 .diagnostic-layout / .chat-main / .chat-inner /
   .welcome / .composer 骨架，因此排版与诊断页天然一致。 */

/* ---------- Diagnostic workspace ---------- */

.diagnostic-layout {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) var(--side-width);
}

.chat-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background:
    linear-gradient(rgba(255, 255, 255, 0.008) 1px, transparent 1px),
    var(--bg-base);
  background-size: 100% 32px;
}

.chat-scroll {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-inner {
  width: min(100%, 900px);
  min-height: 100%;
  margin: 0 auto;
  padding: 42px clamp(24px, 4vw, 56px) 32px;
}

.welcome {
  display: flex;
  flex-direction: column;
  gap: 28px;
  animation: enter-up 320ms cubic-bezier(0.2, 0, 0, 1) both;
}

@keyframes enter-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-heading {
  max-width: 720px;
}

.welcome-heading h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: clamp(27px, 3vw, 36px);
  font-weight: 720;
  line-height: 1.2;
  letter-spacing: -0.035em;
}

.welcome-heading p {
  max-width: 650px;
  margin: 12px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.75;
}

.capability-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.capability-card {
  display: flex;
  min-width: 0;
  min-height: 112px;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition), background-color var(--transition), transform var(--transition);
}

.capability-card:hover {
  border-color: var(--border-default);
  background: var(--bg-panel-raised);
  transform: translateY(-1px);
}

.capability-icon {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid currentColor;
  border-radius: 7px;
}

.capability-icon svg {
  width: 18px;
  height: 18px;
}

.capability-icon.alarm {
  color: var(--status-alarm);
  background: rgba(239, 102, 95, 0.08);
}

.capability-icon.guide {
  color: var(--status-info);
  background: rgba(78, 159, 209, 0.08);
}

.capability-icon.action {
  color: var(--accent);
  background: var(--accent-soft);
}

.capability-card h3 {
  margin: 1px 0 5px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 680;
}

.capability-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.65;
}

.quick-start {
  padding-top: 2px;
}

.quick-start-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.quick-start-head > span {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 680;
  letter-spacing: 0.04em;
}

.quick-start-head small {
  color: var(--text-faint);
  font-size: 10px;
}

.example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.example-chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 10px;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  border-radius: 7px;
  background: var(--bg-panel);
  font-size: 11px;
  text-align: left;
  transition: color var(--transition), border-color var(--transition), background-color var(--transition), transform var(--transition);
}

.example-chip:hover {
  color: var(--text-primary);
  border-color: var(--accent-border);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.example-chip:active {
  transform: translateY(0);
}

.example-chip code {
  color: var(--accent);
  font-size: 11px;
}

.chip-type {
  padding-right: 8px;
  color: var(--text-faint);
  border-right: 1px solid var(--border-default);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.example-chip.alarm-code {
  border-color: rgba(239, 102, 95, 0.24);
}

.example-chip.alarm-code .chip-type {
  color: var(--status-alarm);
}

/* ---------- Messages ---------- */

.msg {
  display: grid;
  width: 100%;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.msg-avatar {
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  border-radius: 7px;
  background: var(--bg-panel-raised);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 750;
  box-shadow: var(--shadow-xs);
}

.msg.assistant .msg-avatar {
  color: var(--accent-contrast);
  border-color: var(--accent);
  background: var(--accent);
}

.msg-body {
  min-width: 0;
}

.msg-role {
  margin: 0 0 7px 2px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 680;
  letter-spacing: 0.04em;
}

.bubble {
  min-width: 0;
  padding: 14px 16px;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 3px var(--radius-lg) var(--radius-lg) var(--radius-lg);
  background: var(--bg-panel);
  box-shadow: var(--shadow-xs);
  font-size: 14px;
  line-height: 1.78;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  color: var(--text-secondary);
  border-color: var(--border-default);
  background: var(--bg-panel-raised);
}

.msg.assistant .bubble {
  border-color: var(--border-default);
  background: var(--bg-elevated);
}

.bubble.error {
  color: var(--status-alarm);
  border-color: rgba(239, 102, 95, 0.3);
  background: rgba(239, 102, 95, 0.07);
}

.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }

.bubble p {
  margin: 0 0 13px;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 22px 0 10px;
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.4;
}

.bubble h1 { font-size: 22px; }
.bubble h2 { font-size: 19px; }
.bubble h3 { font-size: 16px; }
.bubble h4 { font-size: 14px; }

.bubble ul,
.bubble ol {
  margin: 10px 0 15px;
  padding-left: 23px;
}

.bubble li {
  margin: 5px 0;
  padding-left: 3px;
}

.bubble li::marker {
  color: var(--accent);
}

.bubble strong {
  color: var(--text-primary);
  font-weight: 700;
}

.bubble a {
  color: var(--status-info);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.bubble code {
  padding: 2px 5px;
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 4px;
  background: var(--accent-soft);
  font-size: 0.88em;
}

.bubble pre {
  max-width: 100%;
  margin: 15px 0;
  padding: 14px 16px;
  overflow-x: auto;
  color: #d8e1e8;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: #090e14;
}

.bubble pre code {
  padding: 0;
  color: inherit;
  border: 0;
  background: transparent;
  font-size: 12px;
  line-height: 1.65;
}

.bubble blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  color: var(--text-secondary);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
}

.bubble blockquote p {
  margin: 0;
}

.bubble table {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 15px 0;
  overflow-x: auto;
  border-spacing: 0;
  border-collapse: separate;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: 12px;
}

.bubble thead,
.bubble tbody {
  display: table;
  width: 100%;
  min-width: 520px;
  table-layout: auto;
}

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

.bubble th {
  color: var(--text-secondary);
  background: var(--bg-panel-raised);
  font-size: 11px;
  font-weight: 700;
}

.bubble tr:last-child td {
  border-bottom: 0;
}

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

.msg-meta {
  margin: -16px 0 24px 44px;
  color: var(--text-faint);
  font-size: 10px;
  font-family: var(--font-mono);
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 20px;
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing 1.1s ease-in-out infinite;
}

.typing i:nth-child(2) { animation-delay: 120ms; }
.typing i:nth-child(3) { animation-delay: 240ms; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Composer ---------- */

.composer-wrap {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  padding: 14px clamp(24px, 4vw, 56px) 18px;
  border-top: 1px solid var(--border-subtle);
  background: linear-gradient(to bottom, rgba(15, 21, 29, 0.72), var(--bg-base) 24%);
}

[data-theme="light"] .composer-wrap {
  background: linear-gradient(to bottom, rgba(243, 245, 246, 0.72), var(--bg-base) 24%);
}

.composer {
  width: min(100%, 788px);
  margin: 0 auto;
}

.composer-main {
  display: grid;
  min-height: 66px;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 10px 10px 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.13), var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}

.composer-main:focus-within {
  border-color: var(--accent);
  background: var(--bg-input);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12), var(--shadow-focus);
}

.composer-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 9px;
  color: var(--text-faint);
}

.composer-icon svg {
  width: 19px;
  height: 19px;
}

.composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 190px;
  padding: 10px 0;
  resize: none;
  overflow-y: auto;
  color: var(--text-primary);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  line-height: 1.65;
}

.composer textarea::placeholder {
  color: var(--text-faint);
}

.send-btn {
  min-width: 90px;
  min-height: 44px;
  align-self: end;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 0;
  color: var(--text-faint);
  font-size: 10px;
}

.composer-footer kbd {
  padding: 1px 4px;
  color: var(--text-muted);
  border: 1px solid var(--border-default);
  border-bottom-color: var(--border-strong);
  border-radius: 3px;
  background: var(--bg-panel);
  font-size: 9px;
}

/* 继续：来源面板、响应式布局、辅助状态 */

/* ---------- Sources panel ---------- */

.side-panel {
  position: relative;
  z-index: 10;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
}

.side-panel-header {
  display: flex;
  min-height: 78px;
  align-items: center;
  gap: 10px;
  padding: 17px 17px 15px;
  border-bottom: 1px solid var(--border-subtle);
}

.side-panel-header > div {
  min-width: 0;
  flex: 1 1 auto;
}

.side-panel-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.source-count {
  display: inline-flex;
  min-width: 25px;
  height: 25px;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  color: var(--text-muted);
  border: 1px solid var(--border-default);
  border-radius: 13px;
  background: var(--bg-base);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

.source-count.has-items {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.side-close {
  display: none;
}

.side-context {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 13px 14px 0;
  padding: 10px 11px;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-base);
  font-size: 10px;
  line-height: 1.55;
}

.side-context .status-dot {
  margin-top: 4px;
}

.side-scroll {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 12px 18px;
}

.source-item {
  margin-bottom: 8px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  transition: border-color var(--transition), background-color var(--transition);
}

.source-item:hover,
.source-item.open {
  border-color: var(--border-default);
}

.source-item.open {
  background: var(--bg-panel-raised);
}

.source-head {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  color: inherit;
  background: transparent;
  text-align: left;
}

.source-head-top {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.source-id {
  overflow: hidden;
  color: var(--accent);
  font-size: 10px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-kind {
  flex: 0 0 auto;
  padding: 2px 6px;
  color: var(--text-muted);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  background: var(--bg-base);
  font-size: 9px;
  line-height: 1.45;
}

.source-kind.kind-alarm {
  color: var(--status-alarm);
  border-color: rgba(239, 102, 95, 0.26);
  background: rgba(239, 102, 95, 0.08);
}

.source-kind.kind-manual {
  color: var(--status-info);
  border-color: rgba(78, 159, 209, 0.26);
  background: rgba(78, 159, 209, 0.08);
}

.source-kind.kind-guide {
  color: var(--status-normal);
  border-color: rgba(66, 184, 131, 0.26);
  background: rgba(66, 184, 131, 0.08);
}

.source-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 620;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.source-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
}

.score-bar {
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--bg-active);
}

.score-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.score-num {
  color: var(--text-faint);
  font-size: 9px;
}

.source-detail {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border-subtle);
}

.source-item.open .source-detail {
  display: block;
  animation: enter-up 180ms ease-out both;
}

.source-summary {
  padding-top: 10px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.65;
}

.source-path {
  margin-top: 8px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.kb-stats {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-base);
}

.kb-stat {
  padding: 12px 14px;
}

.kb-stat + .kb-stat {
  border-left: 1px solid var(--border-subtle);
}

.kb-stat-label {
  color: var(--text-faint);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.kb-stat-value {
  margin-top: 2px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
}

.side-panel-toggle {
  display: none;
}

/* ---------- Empty states ---------- */

.side-empty {
  display: flex;
  min-height: 260px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 30px 22px;
  color: var(--text-muted);
  text-align: center;
}

.side-empty.compact {
  min-height: 180px;
  padding: 24px 16px;
}

.empty-icon {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--text-faint);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  background: var(--bg-base);
}

.empty-icon svg {
  width: 22px;
  height: 22px;
}

.empty-icon.spinner {
  width: 25px;
  height: 25px;
  margin-bottom: 16px;
  border-width: 2px;
}

.side-empty strong {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 680;
}

.side-empty p {
  max-width: 310px;
  margin: 7px 0 0;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.7;
}

.side-empty code {
  margin-top: 14px;
  padding: 4px 8px;
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 5px;
  background: var(--accent-soft);
  font-size: 10px;
}

.side-empty.error strong {
  color: var(--status-alarm);
}

.empty-guide {
  width: 100%;
  max-width: 265px;
  margin-top: 24px;
  padding-top: 17px;
  border-top: 1px solid var(--border-subtle);
  text-align: left;
}

.empty-guide > div {
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}

.empty-guide span {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
}

.empty-guide p {
  margin: 0;
  color: var(--text-muted);
  font-size: 10px;
}

/* ---------- Knowledge base ---------- */

.page-heading {
  width: min(100%, var(--content-max));
  margin: 0 auto;
  padding: 28px 28px 18px;
}

.page-heading h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: 26px;
  font-weight: 730;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.page-heading p {
  margin: 7px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.kb-wrap {
  display: grid;
  width: min(100%, var(--content-max));
  height: calc(100% - 99px);
  min-height: 0;
  margin: 0 auto;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.35fr);
  gap: 16px;
  padding: 0 28px 26px;
}

.kb-left,
.kb-detail {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  box-shadow: var(--shadow-xs);
}

.kb-left {
  display: flex;
  flex-direction: column;
}

.kb-toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  padding: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-field {
  display: grid;
  min-width: 0;
  height: 38px;
  flex: 1 1 auto;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.search-field svg {
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 12px;
}

.search-field input::placeholder {
  color: var(--text-faint);
}

.search-field kbd {
  padding: 1px 5px;
  color: var(--text-faint);
  border: 1px solid var(--border-default);
  border-radius: 3px;
  background: var(--bg-base);
  font-size: 9px;
}

.kb-results-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-base);
  font-size: 10px;
  font-weight: 680;
}

.kb-results-head small {
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 500;
}

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

.kb-item {
  margin-bottom: 7px;
  padding: 12px 13px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  transition: border-color var(--transition), background-color var(--transition), transform var(--transition);
}

.kb-item:hover {
  border-color: var(--border-default);
  background: var(--bg-panel-raised);
}

.kb-item.active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.kb-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kb-item-id {
  color: var(--accent);
  font-size: 10px;
  font-weight: 650;
}

.kb-item-score {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 9px;
}

.kb-item-title {
  margin-top: 7px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
}

.kb-item-summary {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.kb-detail {
  overflow-y: auto;
  padding: 22px;
}

.kb-placeholder {
  display: flex;
  min-height: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.kb-placeholder strong {
  color: var(--text-secondary);
  font-size: 14px;
}

.kb-placeholder p {
  max-width: 340px;
  margin: 7px 0 0;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.7;
}

.kb-detail-inner {
  max-width: 760px;
}

.kb-detail-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kb-detail-id {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.kb-kind {
  padding: 2px 7px;
  color: var(--text-muted);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  background: var(--bg-base);
  font-size: 9px;
}

.kb-detail-inner h2 {
  margin: 10px 0 0;
  color: var(--text-primary);
  font-size: 21px;
  font-weight: 720;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.kb-path {
  margin-top: 7px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.kb-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
}

.kb-section h3 {
  margin: 0 0 9px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
}

.kb-section p,
.kb-section ul {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.8;
}

.kb-section ul {
  padding-left: 20px;
}

.kb-section li {
  margin: 4px 0;
}

.kb-section li::marker {
  color: var(--accent);
}

/* ---------- History ---------- */

.history-wrap {
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

.history-inner {
  width: min(100%, 880px);
  min-height: 100%;
  margin: 0 auto;
  padding: 0 28px 40px;
}

.history-day-label {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 11px 0 9px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-base);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.history-day + .history-day {
  margin-top: 22px;
}

.history-item {
  margin-top: 16px;
}

.history-item .msg-avatar {
  grid-row: 1;
}

.history-time {
  margin: 0 0 6px 2px;
  color: var(--text-faint);
  font-size: 9px;
}

.history-item .bubble {
  font-size: 13px;
}

/* ---------- Authentication page ---------- */

.login-page {
  display: grid;
  width: 100%;
  min-height: 100dvh;
  place-items: center;
  overflow-y: auto;
  background:
    radial-gradient(circle at 22% 18%, rgba(239, 155, 66, 0.09), transparent 28%),
    radial-gradient(circle at 78% 82%, rgba(78, 159, 209, 0.055), transparent 30%),
    var(--bg-base);
}

.login-shell {
  display: grid;
  width: min(100% - 32px, 900px);
  min-height: 540px;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
}

.login-brand {
  position: relative;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  overflow: hidden;
  padding: 38px;
  border-right: 1px solid var(--border-subtle);
  background:
    linear-gradient(145deg, rgba(239, 155, 66, 0.06), transparent 48%),
    var(--bg-panel);
}

.login-brand::after {
  position: absolute;
  right: -110px;
  bottom: -130px;
  width: 330px;
  height: 330px;
  border: 1px solid var(--accent-border);
  border-radius: 50%;
  box-shadow:
    0 0 0 34px rgba(239, 155, 66, 0.025),
    0 0 0 70px rgba(239, 155, 66, 0.018);
  content: "";
}

.login-brand-head {
  display: flex;
  align-items: center;
  gap: 11px;
}

.login-brand-head .brand-mark {
  width: 40px;
  height: 40px;
  flex-basis: 40px;
}

.login-brand-head strong {
  color: var(--text-primary);
  font-size: 19px;
  letter-spacing: -0.02em;
}

.login-brand-copy {
  position: relative;
  z-index: 1;
  max-width: 460px;
  margin: auto 0;
  padding: 40px 0;
}

.login-brand-copy .section-kicker {
  margin-bottom: 12px;
}

.login-brand-copy h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: clamp(29px, 4vw, 42px);
  font-weight: 730;
  line-height: 1.18;
  letter-spacing: -0.045em;
}

.login-brand-copy > p {
  max-width: 410px;
  margin: 18px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.85;
}

.login-features {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 28px;
}

.login-feature {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-muted);
  font-size: 11px;
}

.login-feature span {
  display: inline-flex;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  background: var(--accent-soft);
}

.login-feature span svg {
  width: 13px;
  height: 13px;
}

.login-brand-foot {
  position: relative;
  z-index: 1;
  color: var(--text-faint);
  font-size: 10px;
}

.login-form-panel {
  display: flex;
  justify-content: center;
  flex-direction: column;
  padding: 42px clamp(28px, 5vw, 58px);
  background: var(--bg-elevated);
}

.login-form-head h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 23px;
  font-weight: 720;
  letter-spacing: -0.025em;
}

.login-form-head p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 11px;
}

.login-form {
  margin-top: 28px;
}

.form-field + .form-field {
  margin-top: 16px;
}

.form-field label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 650;
}

.input-wrap {
  position: relative;
}

.input-wrap > svg {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
  transform: translateY(-50%);
}

.form-field input {
  width: 100%;
  height: 44px;
  padding: 0 13px 0 39px;
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: 0;
  background: var(--bg-input);
  font-size: 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-field input::placeholder {
  color: var(--text-faint);
}

.form-field input:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  display: inline-flex;
  width: 31px;
  height: 31px;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-faint);
  border-radius: 5px;
  background: transparent;
  transform: translateY(-50%);
}

.password-toggle:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.password-toggle svg {
  width: 16px;
  height: 16px;
}

.password-toggle .eye-off {
  display: none;
}

.password-toggle.is-visible .eye-on {
  display: none;
}

.password-toggle.is-visible .eye-off {
  display: block;
}

.form-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 15px;
  color: var(--text-muted);
  font-size: 10px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.checkbox-label input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.login-submit {
  width: 100%;
  height: 44px;
  margin-top: 22px;
}

.login-submit .spinner {
  width: 14px;
  height: 14px;
}

.login-error {
  display: none;
  margin-top: 15px;
  padding: 10px 12px;
  color: var(--status-alarm);
  border: 1px solid rgba(239, 102, 95, 0.28);
  border-radius: var(--radius-md);
  background: rgba(239, 102, 95, 0.07);
  font-size: 10px;
  line-height: 1.6;
}

.login-error.is-visible {
  display: block;
}

.login-security {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
  color: var(--text-faint);
  font-size: 9px;
}

.login-security svg {
  width: 12px;
  height: 12px;
}

.login-footer {
  margin-top: 32px;
  color: var(--text-faint);
  font-size: 9px;
  text-align: center;
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
    gap: 14px;
    padding: 0 14px;
  }

  .brand-copy > span,
  .kb-health-copy,
  .user-copy {
    display: none;
  }

  .kb-health {
    margin-right: 2px;
  }

  .kb-health::after {
    color: var(--text-faint);
    content: "KB";
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
  }

  .diagnostic-layout {
    grid-template-columns: minmax(0, 1fr) 310px;
  }

  :root {
    --side-width: 310px;
  }

  .kb-wrap {
    grid-template-columns: minmax(290px, 0.85fr) minmax(380px, 1.15fr);
  }
}

@media (max-width: 920px) {
  .app-header {
    grid-template-columns: auto 1fr auto;
  }

  .brand-copy {
    display: none;
  }

  .tabs {
    justify-self: center;
  }

  .header-tools {
    gap: 7px;
  }

  .kb-health,
  .header-divider {
    display: none;
  }

  .diagnostic-layout {
    display: block;
  }

  .chat-main {
    height: 100%;
  }

  .side-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(88vw, 360px);
    visibility: hidden;
    border-left: 1px solid var(--border-default);
    box-shadow: -16px 0 42px rgba(0, 0, 0, 0.28);
    transform: translateX(100%);
    transition: visibility var(--transition), transform var(--transition);
  }

  .side-panel.is-open {
    visibility: visible;
    transform: translateX(0);
  }

  .side-close {
    display: inline-flex;
  }

  .side-panel-toggle {
    position: absolute;
    right: 17px;
    bottom: 114px;
    z-index: 8;
    display: inline-flex;
    height: 36px;
    align-items: center;
    gap: 7px;
    padding: 0 11px;
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-panel-raised);
    box-shadow: var(--shadow-sm);
    font-size: 10px;
    font-weight: 650;
  }

  .side-panel-toggle svg {
    width: 15px;
    height: 15px;
  }

  .kb-wrap {
    height: calc(100% - 99px);
    grid-template-columns: minmax(270px, 0.85fr) minmax(340px, 1.15fr);
    padding: 0 18px 20px;
  }

  .page-heading {
    padding: 24px 18px 16px;
  }
}

@media (max-width: 720px) {
  :root {
    --header-height: 60px;
  }

  .app-header {
    display: flex;
    padding: 0 12px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .tabs {
    min-width: 0;
    flex: 1 1 auto;
    justify-content: center;
  }

  .tab {
    min-height: 32px;
    padding: 0 9px;
  }

  .tab svg {
    display: none;
  }

  .tab.active::after {
    right: 8px;
    left: 8px;
  }

  .user-identity,
  .logoutBtn span {
    display: none;
  }

  .logoutBtn {
    width: 34px;
    min-height: 34px;
    padding: 0;
  }

  .logoutBtn svg {
    width: 16px;
    height: 16px;
  }

  .chat-inner {
    padding: 28px 16px 24px;
  }

  .welcome {
    gap: 22px;
  }

  .welcome-heading h1 {
    font-size: 28px;
  }

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

  .capability-card {
    min-height: 86px;
  }

  .quick-start-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .example-chips {
    flex-direction: column;
  }

  .example-chip {
    width: 100%;
  }

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

  .msg-avatar {
    width: 27px;
    height: 27px;
  }

  .bubble {
    padding: 12px 13px;
    font-size: 13px;
  }

  .msg-meta {
    margin-left: 37px;
  }

  .composer-wrap {
    padding: 10px 12px 12px;
  }

  .composer-main {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
    padding: 8px;
  }

  .composer-icon {
    display: none;
  }

  .composer textarea {
    min-height: 42px;
    padding: 9px 4px;
  }

  .send-btn {
    min-width: 42px;
    width: 42px;
    padding: 0;
  }

  .send-btn .send-label {
    display: none;
  }

  .composer-footer > span:last-child {
    display: none;
  }

  .composer-footer {
    justify-content: flex-end;
  }

  .side-panel-toggle {
    right: 12px;
    bottom: 96px;
  }

  .page-heading {
    padding: 20px 14px 14px;
  }

  .page-heading h1 {
    font-size: 23px;
  }

  .kb-wrap {
    display: block;
    height: calc(100% - 91px);
    padding: 0 14px 16px;
  }

  .kb-left,
  .kb-detail {
    height: 100%;
  }

  .kb-detail {
    display: none;
  }

  .kb-wrap.show-detail .kb-left {
    display: none;
  }

  .kb-wrap.show-detail .kb-detail {
    display: block;
  }

  .kb-toolbar {
    flex-wrap: wrap;
  }

  .search-field {
    flex-basis: 100%;
  }

  .kb-detail {
    padding: 17px;
  }

  .history-inner {
    padding: 0 16px 30px;
  }

  .login-page {
    display: block;
  }

  .login-shell {
    display: block;
    width: min(100% - 24px, 520px);
    min-height: 0;
    margin: 24px auto;
  }

  .login-brand {
    min-height: 300px;
    padding: 26px;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
  }

  .login-brand-copy {
    padding: 35px 0 15px;
  }

  .login-brand-copy h1 {
    font-size: 31px;
  }

  .login-features {
    margin-top: 20px;
  }

  .login-form-panel {
    padding: 30px 26px 34px;
  }
}

@media (max-width: 440px) {
  .login-shell {
    width: 100%;
    margin: 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .login-brand {
    padding: 23px 20px;
  }

  .login-features {
    grid-template-columns: 1fr;
  }

  .login-form-panel {
    padding: 28px 20px 34px;
  }

  .form-options {
    align-items: flex-start;
    flex-direction: column;
  }

  .theme-toggle {
    display: none;
  }
}

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


/* ---------- 面板底部统计：始终贴在面板底部且完整可见 ---------- */
.side-panel > .side-empty,
.side-panel > .source-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.kb-stats {
  flex: 0 0 auto;
  margin-top: auto;
}


/* ---------- 空状态：紧凑有呼吸感，不把输入框推离视线 ---------- */
.chat-inner {
  justify-content: flex-start;
}

.welcome {
  max-width: 100%;
  padding-top: 6px;
}

.chat-scroll {
  display: flex;
  flex-direction: column;
}

.chat-scroll > .chat-inner {
  flex: 0 0 auto;
}

.welcome-heading h1 {
  font-size: 34px;
  line-height: 1.18;
}

.capability-grid {
  gap: 14px;
}

.quick-start {
  margin-top: 4px;
}


/* ==========================================================================
   移动端登录页适配（放在最后，覆盖上面 720 / 440 两档）
   背景：390×844 的手机视口下登录按钮落在 y=812..856，viewport 只有 844，
   按钮被挤出首屏，用户看不到也点不到 —— 手机上“登录不了”的直接原因。
   另外输入框 font-size < 16px 会触发 iOS 聚焦自动放大，同样会把按钮顶出屏幕。
   ========================================================================== */
@media (max-width: 720px) {
  .login-page {
    align-items: flex-start;
    min-height: 100%;
    padding: 0;
  }

  .login-shell {
    display: block;
    width: 100%;
    max-width: 480px;
    min-height: 0;
    margin: 0 auto;
    border: 0;
    border-radius: 0;
  }

  /* 品牌区退化为紧凑页头：不再占掉半屏 */
  .login-brand {
    min-height: 0;
    padding: 20px 22px 18px;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
  }

  .login-brand-copy {
    padding: 14px 0 0;
  }

  .login-brand-copy h1 {
    font-size: 25px;
    line-height: 1.25;
  }

  .login-brand-copy > p {
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.55;
  }

  .login-features,
  .login-brand-foot {
    display: none;
  }

  .login-form-panel {
    padding: 24px 22px 28px;
  }

  .login-form-head h2 {
    font-size: 20px;
  }

  .login-form {
    margin-top: 20px;
  }

  /* 16px 是 iOS 不自动缩放输入框的临界字号 */
  .form-field input {
    height: 46px;
    font-size: 16px;
  }

  .login-submit {
    height: 48px;
    margin-top: 20px;
    font-size: 14px;
  }

  .login-footer {
    padding-bottom: 18px;
    font-size: 11px;
  }
}

/* 矮屏手机（横屏或小屏）：进一步压缩，保证按钮仍在首屏 */
@media (max-width: 720px) and (max-height: 700px) {
  .login-brand-copy > p,
  .login-security {
    display: none;
  }

  .login-brand {
    padding: 16px 22px 14px;
  }

  .login-form-panel {
    padding: 18px 22px 22px;
  }

  .login-form {
    margin-top: 16px;
  }
}


/* ==========================================================================
   数智化转型模块（bizdoc）：咨询问答 + 业务单元文档生成
   颜色一律走 CSS 变量，深浅两套主题都能保持与其它页面一致的对比度。
   ========================================================================== */
.module-tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 20px;
  padding: 4px;
  border-radius: 12px;
  background: var(--bg-hover);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

/* 模块页签与面板都放在 .chat-inner 内，和诊断页的欢迎区同一层级，
   因此宽度、内边距、居中方式完全由 .chat-inner 的既有规则决定。 */
.bizdoc-scroll > .chat-inner {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* 页签紧跟欢迎区 */
.chat-inner > .module-tabs {
  margin-top: 22px;
}

/* 生成文档面板：底部留白，别贴着输入框 */
.chat-inner > .module-panel {
  padding-bottom: 28px;
}

.module-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-family: inherit;
  padding: 9px 18px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.module-tab:hover {
  color: var(--text-primary);
}

.module-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.module-panel {
  display: none;
}

.module-panel.active {
  display: block;
}

/* 生成文档面板：底部留白，别贴着输入框 */

/* ---- 咨询问答 ----
   骨架与故障诊断页一致（.chat-scroll / .chat-inner / .composer / .msg），
   这里只补 bizdoc 特有的对话记录区。
   注意：颜色一律走变量，不要硬编码，否则浅色主题会白底白字。 */

/* 中间滚动区：欢迎区 + 页签 + 面板都在里面，输入框固定在底部 */
.bizdoc-scroll {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 对话记录区 */
.bizdoc-chat-scroll {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 聊过之后才有内容区高度 */
.bizdoc-chat-scroll:not(:empty) {
  min-height: 220px;
  padding-top: 4px;
}

/* ---- 生成文档 ---- */
.bizdoc-form {
  max-width: 720px;
}

.bizdoc-form .form-field {
  margin-bottom: 16px;
}

.bizdoc-form .form-field label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.bizdoc-form .form-field input,
.bizdoc-form .form-field textarea,
.bizdoc-form .form-field select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
}

.bizdoc-form .form-field textarea {
  resize: vertical;
  min-height: 132px;
}

.bizdoc-form .form-field input:focus,
.bizdoc-form .form-field textarea:focus,
.bizdoc-form .form-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.bizdoc-form .form-field .req {
  color: var(--status-alarm);
  margin-left: 3px;
}

.bizdoc-form .form-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.6;
}

.bizdoc-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.bizdoc-submit {
  appearance: none;
  border: 0;
  border-radius: 11px;
  padding: 13px 30px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-contrast);
}

.bizdoc-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.bizdoc-result {
  margin-top: 22px;
  padding: 18px 20px;
  border-radius: 12px;
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
}

.bizdoc-result.ok {
  border-color: var(--status-normal);
  background: var(--bg-panel-raised);
}

.bizdoc-result.warn {
  border-color: var(--status-warning);
  background: var(--bg-panel-raised);
}

.bizdoc-result.err {
  border-color: var(--status-alarm);
  background: var(--bg-panel-raised);
}

.bizdoc-result h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--text-primary);
}

.bizdoc-result ul {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-secondary);
}

.bizdoc-download {
  display: inline-block;
  margin-top: 14px;
  appearance: none;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.bizdoc-download:hover {
  background: var(--accent-border);
}

@media (max-width: 720px) {
  .bizdoc-form .form-row {
    grid-template-columns: 1fr;
  }
}

