/**
 * 所在层次：服务端渲染视图层
 * 主要职责：负责维护前端页面样式，统一视觉表现与布局规则。
 * 维护提示：维护时应同时检查关联模板、静态资源与控制器传入数据，避免页面渲染出现结构错位。
 */

/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --bg: #eef2ff;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --accent-light: #eff6ff;
  --accent-mid: #dbeafe;
  --accent-pill: rgba(37, 99, 235, 0.09);
  --fill: rgba(37, 99, 235, 0.06);
  --fill-focus: rgba(37, 99, 235, 0.11);
  --sidebar-bg: #1a3065;
  --sidebar-text: rgba(255, 255, 255, 0.85);
  --sidebar-muted: rgba(255, 255, 255, 0.44);
  --sidebar-active: rgba(255, 255, 255, 0.13);
  --sidebar-hover: rgba(255, 255, 255, 0.07);
  --navbar-h: 54px;
  --sidebar-w: 214px;
  --radius: 14px;
  --radius-sm: 9px;
  --scrollbar-thumb: #d1d5db;
  --scrollbar-thumb-hover: #c4cbd4;
}

/* ── Global ─────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Shared thin scrollbars ─────────────────────────────────────────────── */

.admin-layout .sidebar,
.admin-layout .ai-settings-panel,
.admin-layout .react-agent-sidebar,
.admin-layout .react-agent-trace,
.admin-layout .task-runner-sidebar,
.admin-layout .task-runner-trace,
.admin-layout .companion-messages,
.admin-layout .companion-session-list,
.admin-layout .companion-form textarea {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.admin-layout ::-webkit-scrollbar {
  width: 3px !important;
  height: 3px !important;
}

.admin-layout ::-webkit-scrollbar-track {
  background: transparent !important;
}

.admin-layout ::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb) !important;
  border-radius: 4px !important;
}

.admin-layout ::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover) !important;
}

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

/* ── Navbar ──────────────────────────────────────────────────────────────── */

.navbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--navbar-h);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.navbar-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

.navbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

/* ── Admin shell ─────────────────────────────────────────────────────────── */

.admin-layout {
  background: var(--bg);
}

.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--navbar-h));
}

.admin-content {
  padding: 32px 36px 48px;
  min-width: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  gap: 2px;
  position: sticky;
  top: var(--navbar-h);
  height: calc(100vh - var(--navbar-h));
  overflow-y: auto;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--sidebar-text);
  transition:
    background 0.14s,
    color 0.14s;
  line-height: 1;
}

.sidebar a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar a.active,
.sidebar a[aria-current='page'] {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-muted);
  padding: 12px 12px 4px;
}

.sidebar-spacer {
  flex: 1;
}

.signout-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--sidebar-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition:
    background 0.14s,
    color 0.14s;
  margin-top: 4px;
}

.signout-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

/* ── Flash messages ──────────────────────────────────────────────────────── */

.flash-success,
.flash-error,
.flash-info {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  margin-bottom: 18px;
}

.flash-success {
  background: #d1fae5;
  color: #065f46;
}
.flash-error {
  background: #fee2e2;
  color: #991b1b;
}
.flash-info {
  background: var(--accent-mid);
  color: #1e40af;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.14s,
    opacity 0.14s;
  white-space: nowrap;
}

.primary-button:hover {
  background: var(--accent-dim);
}
.primary-button:active {
  opacity: 0.88;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.14s,
    color 0.14s;
  white-space: nowrap;
}

.ghost-button:hover {
  background: var(--accent-pill);
  color: var(--accent);
}

.ghost-button:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ── Form elements ───────────────────────────────────────────────────────── */

.ai-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ai-field span,
.ai-field > label > span {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ai-field input,
.ai-field textarea {
  padding: 10px 14px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  resize: vertical;
  transition: background 0.15s;
  outline: none;
}

.ai-field input:focus,
.ai-field textarea:focus {
  background: var(--fill-focus);
}

.ai-field input::placeholder,
.ai-field textarea::placeholder {
  color: var(--faint);
}

.ai-inline-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}

.ai-inline-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.69rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.badge-green {
  background: #d1fae5;
  color: #065f46;
}
.badge-blue {
  background: var(--accent-mid);
  color: #1e40af;
}
.badge-gray {
  background: #f1f5f9;
  color: #475569;
}

/* eyebrow / label */
.eyebrow {
  font-size: 0.71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 0 0 6px;
}

/* ── Dashboard ───────────────────────────────────────────────────────────── */

.dash-header {
  margin-bottom: 36px;
}

.dash-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 0 0 6px;
}

.dash-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.dash-section {
  margin-bottom: 36px;
}

.dash-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
  margin: 0 0 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card span {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
}

.stat-card strong {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  word-break: break-all;
}

.dash-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.dash-action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  transition: background 0.14s;
}

.dash-action-card:hover {
  background: var(--accent-light);
}

.dash-action-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
  transition: background 0.14s;
}

.dash-action-card:hover .dash-action-icon {
  background: var(--accent-mid);
}

.dash-action-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.dash-action-label strong {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}

.dash-action-label span {
  font-size: 0.76rem;
  color: var(--muted);
}

/* ── AI Panel (shared shell) ─────────────────────────────────────────────── */

.ai-panel {
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
}

.ai-panel-head h2 {
  margin: 0 0 2px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.ai-panel-head p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── AI Workbench ─────────────────────────────────────────────────────────── */

.ai-workbench {
  padding: 0;
}

.ai-workbench-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  height: calc(100vh - var(--navbar-h) - 64px);
}

.ai-console-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.ai-provider-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 22px 12px;
}

.ai-provider-label {
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  white-space: nowrap;
}

.ai-provider-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-provider-pill {
  padding: 3px 11px;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 600;
  background: var(--accent-pill);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.14s;
}

.ai-provider-pill.is-selected {
  background: var(--accent);
  color: #fff;
}
.ai-provider-pill.is-loading {
  color: var(--faint);
  background: #f1f5f9;
}
.ai-provider-pill:hover:not(.is-selected):not(.is-loading) {
  background: var(--accent-mid);
}

.ai-token-note {
  margin: 0;
  padding: 0 22px 12px;
  font-size: 0.76rem;
  color: var(--faint);
  line-height: 1.5;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-message {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 82%;
}

.ai-message-user {
  align-self: flex-end;
}
.ai-message-assistant {
  align-self: flex-start;
}

.ai-message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--faint);
  padding: 0 4px;
}

.ai-message-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
}

/* ── Markdown prose inside message bubbles ─────────────────────────── */
.ai-message-bubble p,
.ra-card-body p,
.li-generate-body p {
  margin: 0 0 8px;
}
.ai-message-bubble p:last-child,
.ra-card-body p:last-child,
.li-generate-body p:last-child {
  margin: 0;
}

.ai-message-bubble h1,
.ai-message-bubble h2,
.ai-message-bubble h3,
.ai-message-bubble h4,
.ai-message-bubble h5,
.ai-message-bubble h6,
.ra-card-md h1,
.ra-card-md h2,
.ra-card-md h3,
.li-generate-body h1,
.li-generate-body h2,
.li-generate-body h3 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.3;
}

.ai-message-bubble ul,
.ai-message-bubble ol,
.ra-card-md ul,
.ra-card-md ol,
.li-generate-body ul,
.li-generate-body ol {
  margin: 6px 0;
  padding-left: 20px;
}

.ai-message-bubble li,
.ra-card-md li,
.li-generate-body li {
  margin: 2px 0;
}

.ai-message-bubble code,
.ra-card-md code,
.li-generate-body code {
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 0.82em;
  background: rgba(37, 99, 235, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

.ai-message-user .ai-message-bubble code {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.ai-message-bubble pre,
.ra-card-md pre,
.li-generate-body pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.82em;
  line-height: 1.55;
}

.ai-message-bubble pre code,
.ra-card-md pre code,
.li-generate-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.ai-message-bubble blockquote,
.ra-card-md blockquote,
.li-generate-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--muted);
}

.ai-message-bubble strong,
.ai-message-bubble b,
.ra-card-md strong,
.li-generate-body strong {
  font-weight: 600;
}

.ai-message-bubble hr,
.ra-card-md hr,
.li-generate-body hr {
  border: none;
  border-top: 1px solid var(--accent-mid);
  margin: 10px 0;
}

.ai-message-bubble a {
  color: var(--accent);
  text-decoration: underline;
}
.ai-message-user .ai-message-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

.ai-message-user .ai-message-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
}

.ai-message-assistant .ai-message-bubble {
  background: var(--fill);
  color: var(--ink);
  border-radius: 14px 14px 14px 4px;
}

.ai-message-featured .ai-message-bubble {
  background: var(--accent-light);
  color: var(--ink);
}

.ai-starter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 22px 0;
}

.ai-starter-chip {
  padding: 5px 13px;
  border-radius: 99px;
  background: var(--accent-pill);
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.14s;
}

.ai-starter-chip:hover {
  background: var(--accent-mid);
}

.ai-composer {
  padding: 14px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ai-submit-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-tip {
  font-size: 0.75rem;
  color: var(--faint);
}

.ai-settings-panel {
  height: 100%;
  overflow-y: auto;
}

.ai-settings-stack {
  padding: 4px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── ReAct Agent page ────────────────────────────────────────────────────── */

.react-agent-page {
  padding: 0;
}

.react-agent-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - var(--navbar-h) - 64px);
}

.react-agent-sidebar {
  position: sticky;
  top: calc(var(--navbar-h) + 32px);
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  overflow-y: auto;
}

.react-agent-samples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 22px 12px;
}

.react-agent-tools {
  padding: 14px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.react-agent-tools-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin: 0 0 6px;
}

.react-tool-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  background: var(--fill);
  border-radius: var(--radius-sm);
}

.react-tool-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
}

.react-tool-desc {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ReAct trace panel */
.react-agent-trace-panel {
  height: 100%;
}

.react-agent-legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.react-agent-trace {
  flex: 1;
  overflow-y: auto;
  padding: 8px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.react-agent-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 24px;
  color: var(--faint);
  text-align: center;
  flex: 1;
}

.react-agent-empty p {
  margin: 0;
  font-size: 0.84rem;
}

/* ── Task Runner page ───────────────────────────────────────────────────── */

.task-runner-page {
  padding: 0;
}

.task-runner-page .react-agent-grid {
  grid-template-columns: minmax(348px, 380px) minmax(0, 1fr);
}

.task-runner-sidebar,
.task-runner-trace-panel {
  min-height: 0;
}

.task-runner-sidebar {
  overflow-x: hidden;
  padding-right: 10px;
}

.task-runner-sidebar .ai-panel-head,
.task-runner-sidebar .react-agent-samples,
.task-runner-sidebar .ai-composer,
.task-runner-sidebar .react-agent-tools {
  padding-right: 16px;
}

.task-runner-actions-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.task-runner-page .ai-composer-foot {
  flex-wrap: wrap;
  align-items: flex-start;
}

.task-runner-submit-group {
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.task-runner-sidebar .primary-button,
.task-runner-sidebar .ghost-button {
  flex-shrink: 0;
}

.task-runner-switches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.task-runner-tools {
  border-top: 1px solid rgba(148, 163, 184, 0.14);
}

.task-tool-item {
  gap: 6px;
}

.task-tool-row,
.task-tool-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.task-tool-meta {
  font-size: 0.72rem;
  color: var(--faint);
}

.task-tool-risk {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.task-tool-risk-low {
  background: #dbeafe;
  color: #1d4ed8;
}
.task-tool-risk-medium,
.task-tool-risk-moderate {
  background: #fef3c7;
  color: #b45309;
}
.task-tool-risk-high {
  background: #fee2e2;
  color: #b91c1c;
}

.task-runner-session-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--accent-pill);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
}

.task-runner-trace {
  gap: 12px;
}

.task-trace-step {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  position: relative;
}

.task-trace-step + .task-trace-step::before {
  content: '';
  position: absolute;
  left: 17px;
  top: -12px;
  height: 12px;
  width: 2px;
  background: linear-gradient(to bottom, transparent, rgba(37, 99, 235, 0.18));
}

.task-trace-node {
  position: relative;
  display: flex;
  justify-content: center;
  padding-top: 14px;
}

.task-trace-node::after {
  content: '';
  position: absolute;
  top: 24px;
  bottom: -14px;
  width: 2px;
  background: linear-gradient(to bottom, rgba(37, 99, 235, 0.18), transparent);
}

.task-trace-step:last-child .task-trace-node::after {
  display: none;
}

.task-trace-node-core {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent);
  position: relative;
  z-index: 1;
}

.task-trace-card {
  margin: 8px 0 0;
  background: var(--fill);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.task-trace-step-task .task-trace-card {
  background: rgba(239, 246, 255, 0.92);
}
.task-trace-step-session .task-trace-card {
  background: rgba(248, 250, 252, 0.94);
}
.task-trace-step-step .task-trace-card {
  background: rgba(238, 242, 255, 0.94);
}
.task-trace-step-plan .task-trace-card {
  background: rgba(224, 242, 254, 0.88);
}
.task-trace-step-confirm .task-trace-card {
  background: rgba(255, 247, 237, 0.96);
}
.task-trace-step-done .task-trace-card {
  background: rgba(240, 253, 244, 0.92);
}
.task-trace-step-final .task-trace-card {
  background: rgba(219, 234, 254, 0.9);
}
.task-trace-step-failed .task-trace-card,
.task-trace-step-error .task-trace-card,
.task-trace-step-stopped .task-trace-card {
  background: rgba(254, 242, 242, 0.96);
}

.task-trace-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 8px;
}

.task-trace-head strong {
  font-size: 0.88rem;
  line-height: 1.45;
}

.task-trace-meta {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--faint);
}

.task-trace-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.task-trace-badge-task {
  background: #dbeafe;
  color: #1d4ed8;
}
.task-trace-badge-session {
  background: #e2e8f0;
  color: #334155;
}
.task-trace-badge-plan {
  background: #bfdbfe;
  color: #1e3a8a;
}
.task-trace-badge-confirm {
  background: #fed7aa;
  color: #c2410c;
}
.task-trace-badge-step {
  background: #e0e7ff;
  color: #3730a3;
}
.task-trace-badge-done {
  background: #d1fae5;
  color: #047857;
}
.task-trace-badge-final {
  background: #c7d2fe;
  color: #3730a3;
}
.task-trace-badge-failed,
.task-trace-badge-error,
.task-trace-badge-stopped {
  background: #fee2e2;
  color: #b91c1c;
}

.task-confirm-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.task-confirm-tool {
  padding: 12px 14px;
  border: 1px solid rgba(251, 146, 60, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.86);
}

.task-confirm-tool-head {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.task-confirm-tool p {
  margin: 8px 0 0;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--faint);
}

.task-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.task-trace-body {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.84rem;
  line-height: 1.65;
  color: var(--ink);
  word-break: break-word;
}

.task-trace-copy {
  white-space: pre-wrap;
}

.task-trace-context {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  white-space: pre-wrap;
}

.task-trace-md > :first-child {
  margin-top: 0;
}

.task-trace-md > :last-child {
  margin-bottom: 0;
}

.task-trace-code {
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.6;
}

.task-trace-error {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
  white-space: pre-wrap;
}

.task-plan-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.task-plan-item {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.52);
}

.task-plan-item-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.task-plan-item-head strong {
  display: block;
  margin-bottom: 4px;
}

.task-plan-item-head p,
.task-step-outline p {
  margin: 0;
  color: var(--muted);
}

.task-plan-index {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  font-weight: 700;
  flex-shrink: 0;
}

.task-plan-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.task-plan-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 99px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  font-size: 0.73rem;
  font-weight: 600;
}

.task-plan-pill code {
  background: transparent;
  padding: 0;
}

.task-step-outline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Timeline steps ──────────────────────────────────────────────────────── */

.ra-timeline-step {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 0 14px;
  position: relative;
}

.ra-timeline-step + .ra-timeline-step::before {
  content: '';
  position: absolute;
  left: 17px;
  top: -12px;
  height: 12px;
  width: 2px;
  background: linear-gradient(to bottom, transparent, rgba(37, 99, 235, 0.18));
}

.ra-step-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 14px;
}

.ra-node-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-mid);
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.ra-timeline-step:last-child .ra-step-node::after {
  display: none;
}

.ra-step-node::after {
  content: '';
  position: absolute;
  top: 24px;
  bottom: -14px;
  width: 2px;
  background: linear-gradient(to bottom, rgba(37, 99, 235, 0.18), transparent);
}

.ra-node-glow {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.12);
  top: 7px;
}

.ra-step-card {
  margin: 8px 0 14px;
  background: var(--fill);
  border-radius: var(--radius);
  overflow: hidden;
}

.ra-step-thought .ra-step-card {
  background: rgba(239, 246, 255, 0.9);
}
.ra-step-action .ra-step-card {
  background: rgba(238, 242, 255, 0.9);
}
.ra-step-observation .ra-step-card {
  background: rgba(240, 253, 244, 0.9);
}
.ra-step-answer .ra-step-card {
  background: rgba(219, 234, 254, 0.85);
}

.ra-step-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 8px;
}

.ra-meta {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--faint);
}

.ra-step-body {
  padding: 0 14px 12px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

/* RA badges */
.ra-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.ra-badge-thought {
  background: #dbeafe;
  color: #1e40af;
}
.ra-badge-action {
  background: #e0e7ff;
  color: #3730a3;
}
.ra-badge-observation {
  background: #d1fae5;
  color: #065f46;
}
.ra-badge-answer {
  background: #bfdbfe;
  color: #1e3a8a;
}
.ra-badge-error {
  background: #fee2e2;
  color: #991b1b;
}

/* streaming */
.ra-step-streaming .ra-step-card {
  background-image: linear-gradient(
    270deg,
    rgba(37, 99, 235, 0.06),
    rgba(99, 102, 241, 0.05),
    rgba(37, 99, 235, 0.06)
  );
  background-size: 300% 100%;
  animation: ra-aurora 2.8s ease infinite;
}

@keyframes ra-aurora {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.ra-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  border-radius: 1px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: ra-cursor-blink 0.9s ease-in-out infinite;
}

@keyframes ra-cursor-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* ── LlamaIndex ──────────────────────────────────────────────────────────── */

.li-page {
  padding: 0;
}

.li-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - var(--navbar-h) - 64px);
}

.li-sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}

.li-form {
  padding: 0 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.li-docs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.li-doc-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.li-doc-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
}

.li-doc-textarea {
  padding: 9px 12px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.84rem;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: background 0.14s;
}

.li-doc-textarea:focus {
  background: var(--fill-focus);
}
.li-doc-textarea::placeholder {
  color: var(--faint);
}

.li-add-doc {
  align-self: flex-start;
  font-size: 0.78rem;
}

.li-divider {
  height: 1px;
  background: rgba(37, 99, 235, 0.08);
  margin: 4px 0;
}

.li-query-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.li-query-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
}

.li-sample-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.li-query-input {
  padding: 10px 12px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: background 0.14s;
}

.li-query-input:focus {
  background: var(--fill-focus);
}
.li-query-input::placeholder {
  color: var(--faint);
}

/* LlamaIndex pipeline panel */
.li-pipeline-panel {
  height: 100%;
}

.li-legend {
  display: flex;
  gap: 6px;
}

.li-pipeline {
  flex: 1;
  overflow-y: auto;
  padding: 8px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.li-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 24px;
  color: var(--faint);
  text-align: center;
  flex: 1;
}

.li-empty p {
  margin: 0;
  font-size: 0.84rem;
}

/* Pipeline step */
.li-step {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 0 14px;
}

.li-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 14px;
}

.li-node-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-mid);
  flex-shrink: 0;
}

.li-node-index .li-node-dot {
  background: #a7f3d0;
}
.li-node-retrieve .li-node-dot {
  background: #bfdbfe;
}
.li-node-generate .li-node-dot {
  background: #c7d2fe;
}
.li-node-error .li-node-dot {
  background: #fca5a5;
}

.li-card {
  margin: 8px 0 8px;
  background: var(--fill);
  border-radius: var(--radius);
  overflow: hidden;
}

.li-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 8px;
}

.li-meta {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--faint);
}

.li-card-body {
  padding: 0 14px 12px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--ink);
}

.li-generate-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.li-sources {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.li-source-item {
  padding: 8px 10px;
  background: var(--surface);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.li-source-score {
  font-size: 0.7rem;
  color: var(--faint);
  margin-left: 4px;
}

/* LI badges */
.li-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.li-badge-index {
  background: #d1fae5;
  color: #065f46;
}
.li-badge-retrieve {
  background: var(--accent-mid);
  color: #1e40af;
}
.li-badge-generate {
  background: #e0e7ff;
  color: #3730a3;
}
.li-badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.li-step-error .li-card {
  background: rgba(254, 226, 226, 0.5);
}

/* ── Docs (Swagger iframe) ───────────────────────────────────────────────── */

.docs-frame-wrap {
  margin: -32px -36px -48px;
  height: calc(100vh - var(--navbar-h));
}

.docs-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Prompt Manager ───────────────────────────────────────────────────────── */

.pm-page {
  padding: 0;
}

.pm-layout {
  display: grid;
  grid-template-columns: 210px 1fr;
  height: calc(100vh - var(--navbar-h) - 64px);
}

/* Projects panel */
.pm-projects-panel {
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  position: sticky;
  top: 0;
  height: 100%;
  overflow-y: auto;
}

.pm-projects-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 12px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
}

.pm-new-btn {
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pm-projects-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pm-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  border-radius: 0;
  transition:
    background 0.12s,
    color 0.12s;
}

.pm-project-item:hover {
  background: var(--accent-pill);
  color: var(--ink);
}

.pm-project-item.pm-project-active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.pm-project-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-project-count {
  background: var(--accent-pill);
  color: var(--accent);
  border-radius: 99px;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 1px 7px;
  flex-shrink: 0;
}

/* Cards section */
.pm-cards-section {
  background: var(--bg);
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-width: 0;
}

.pm-cards-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pm-cards-heading {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink);
  flex: 1;
  letter-spacing: -0.01em;
}

.pm-search {
  padding: 7px 13px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  outline: none;
  width: 210px;
  transition: background 0.14s;
}

.pm-search:focus {
  background: var(--accent-light);
}

.pm-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
  align-content: start;
}

/* Prompt card */
.pm-card {
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.14s;
}

.pm-card:hover {
  background: var(--accent-light);
}

.pm-card-head {
  padding: 13px 15px 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.pm-card-title {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  word-break: break-all;
  line-height: 1.4;
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
}

.pm-card-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.pm-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pm-badge-builtin {
  background: #fef9c3;
  color: #854d0e;
}
.pm-badge-shared {
  background: #d1fae5;
  color: #065f46;
}
.pm-badge-module {
  background: var(--accent-mid);
  color: #1e40af;
}
.pm-badge-readonly {
  background: #f1f5f9;
  color: #64748b;
}

.pm-card-body {
  padding: 0 15px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pm-card-desc {
  font-size: 0.77rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pm-card-preview {
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--fill);
  border-radius: 7px;
  padding: 7px 9px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 58px;
  overflow: hidden;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.pm-card-foot {
  padding: 8px 15px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.pm-icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--faint);
  transition:
    background 0.13s,
    color 0.13s;
}

.pm-icon-btn:hover {
  background: var(--accent-pill);
  color: var(--accent);
}
.pm-icon-btn.pm-delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Empty state */
.pm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 24px;
  color: var(--faint);
  text-align: center;
}

.pm-empty svg {
  opacity: 0.3;
}
.pm-empty p {
  margin: 0;
  font-size: 0.86rem;
}

/* Pagination */
.pm-pagination,
.sm-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 24px;
}
.pm-page-btn,
.sm-page-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}
.pm-page-btn:hover:not(:disabled),
.sm-page-btn:hover:not(:disabled) {
  background: var(--hover);
}
.pm-page-btn:disabled,
.sm-page-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.pm-page-info,
.sm-page-info {
  font-size: 0.82rem;
  color: var(--faint);
  min-width: 56px;
  text-align: center;
}

/* Modal */
.pm-modal-backdrop,
.pm-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(10, 20, 60, 0.38);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pm-modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 660px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.pm-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
}

.pm-modal-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.pm-modal-close {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--faint);
  transition:
    background 0.13s,
    color 0.13s;
}

.pm-modal-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

.pm-modal-form {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pm-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pm-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pm-field-grow {
  flex: 1;
}

.pm-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
}

.pm-hint {
  font-weight: 400;
  color: var(--faint);
  margin-left: 4px;
}

.pm-hint code {
  background: var(--fill);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.74rem;
}

.pm-input {
  padding: 9px 13px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.86rem;
  color: var(--ink);
  outline: none;
  transition: background 0.14s;
}

.pm-input:focus {
  background: var(--fill-focus);
}
.pm-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.pm-input::placeholder {
  color: var(--faint);
}

.pm-textarea {
  padding: 10px 13px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  font-size: 0.82rem;
  color: var(--ink);
  resize: vertical;
  min-height: 180px;
  outline: none;
  line-height: 1.6;
  transition: background 0.14s;
}

.pm-textarea:focus {
  background: var(--fill-focus);
}

.pm-key-preview {
  font-size: 0.76rem;
  color: var(--muted);
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  background: var(--fill);
  border-radius: 7px;
  padding: 6px 11px;
  min-height: 26px;
}

.pm-key-preview:empty {
  display: none;
}

.pm-modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* Confirm dialog */
.pm-confirm-backdrop {
  z-index: 600;
}

.pm-confirm-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 26px;
  width: 100%;
  max-width: 370px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.pm-confirm-msg {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
}

.pm-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.pm-danger-btn {
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.14s;
  font-family: inherit;
}

.pm-danger-btn:hover {
  background: #b91c1c;
}

/* ── Schema Manager ──────────────────────────────────────────────────────── */

.sm-page {
  padding: 0;
}

.sm-layout {
  display: grid;
  grid-template-columns: 210px 1fr;
  height: calc(100vh - var(--navbar-h) - 64px);
}

/* Projects panel */
.sm-projects-panel {
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  position: sticky;
  top: 0;
  height: 100%;
  overflow-y: auto;
}

.sm-projects-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 12px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
}

.sm-new-btn {
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sm-projects-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sm-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  border-radius: 0;
  transition:
    background 0.12s,
    color 0.12s;
}

.sm-project-item:hover {
  background: var(--accent-pill);
  color: var(--ink);
}

.sm-project-item.sm-project-active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.sm-project-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sm-project-count {
  background: var(--accent-pill);
  color: var(--accent);
  border-radius: 99px;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 1px 7px;
  flex-shrink: 0;
}

/* Cards section */
.sm-cards-section {
  background: var(--bg);
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-width: 0;
}

.sm-cards-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sm-cards-heading {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink);
  flex: 1;
  letter-spacing: -0.01em;
}

.sm-search {
  padding: 7px 13px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  outline: none;
  width: 210px;
  transition: background 0.14s;
}

.sm-search:focus {
  background: var(--accent-light);
}

.sm-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
  align-content: start;
}

/* Schema card */
.sm-card {
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.14s;
}

.sm-card:hover {
  background: var(--accent-light);
}

.sm-card-head {
  padding: 13px 15px 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.sm-card-title {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  word-break: break-all;
  line-height: 1.4;
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
}

.sm-card-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.sm-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sm-badge-shared {
  background: #d1fae5;
  color: #065f46;
}
.sm-badge-module {
  background: var(--accent-mid);
  color: #1e40af;
}
.sm-badge-strict {
  background: #fef9c3;
  color: #854d0e;
}

.sm-card-body {
  padding: 0 15px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sm-card-desc {
  font-size: 0.77rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sm-card-preview {
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--fill);
  border-radius: 7px;
  padding: 7px 9px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 72px;
  overflow: hidden;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  margin: 0;
}

.sm-card-foot {
  padding: 8px 15px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

/* Empty state */
.sm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 24px;
  color: var(--faint);
  text-align: center;
}

.sm-empty svg {
  opacity: 0.3;
}
.sm-empty p {
  margin: 0;
  font-size: 0.86rem;
}

/* Modal */
.sm-modal-backdrop,
.sm-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(10, 20, 60, 0.38);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.sm-modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 660px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sm-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
}

.sm-modal-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.sm-modal-close {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--faint);
  transition:
    background 0.13s,
    color 0.13s;
}

.sm-modal-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

.sm-modal-form {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sm-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sm-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.sm-field-grow {
  flex: 1;
}
.sm-field-inline {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.sm-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
}

.sm-hint {
  font-weight: 400;
  color: var(--faint);
  margin-left: 4px;
}

.sm-input {
  padding: 9px 13px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.86rem;
  color: var(--ink);
  outline: none;
  transition: background 0.14s;
}

.sm-input:focus {
  background: var(--fill-focus);
}
.sm-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.sm-input::placeholder {
  color: var(--faint);
}

.sm-textarea {
  padding: 10px 13px;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  font-size: 0.82rem;
  color: var(--ink);
  resize: vertical;
  min-height: 180px;
  outline: none;
  line-height: 1.6;
  width: 100%;
  transition: background 0.14s;
}

.sm-textarea:focus {
  background: var(--fill-focus);
}

.sm-json-textarea {
  font-size: 0.8rem;
  line-height: 1.55;
}

.sm-schema-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sm-json-error {
  font-size: 0.76rem;
  color: #dc2626;
  min-height: 16px;
  margin: 0;
}

.sm-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--muted);
}
.sm-toggle input {
  display: none;
}
.sm-toggle-track {
  width: 34px;
  height: 18px;
  border-radius: 99px;
  background: var(--fill-focus);
  flex-shrink: 0;
  position: relative;
  transition: background 0.2s;
}
.sm-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition:
    transform 0.2s,
    background 0.2s;
}
.sm-toggle input:checked ~ .sm-toggle-track {
  background: var(--accent);
}
.sm-toggle input:checked ~ .sm-toggle-track::after {
  transform: translateX(16px);
  background: #fff;
}

.sm-key-preview {
  font-size: 0.76rem;
  color: var(--muted);
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  background: var(--fill);
  border-radius: 7px;
  padding: 6px 11px;
  min-height: 26px;
}

.sm-key-preview:empty {
  display: none;
}

.sm-modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* Confirm dialog */
.sm-confirm-backdrop {
  z-index: 600;
}

.sm-confirm-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 26px;
  width: 100%;
  max-width: 370px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sm-confirm-msg {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
}

.sm-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.sm-danger-btn {
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.14s;
  font-family: inherit;
}

.sm-danger-btn:hover {
  background: #b91c1c;
}

/* ── Model Config ────────────────────────────────────────────────────────── */

.mc-page {
  padding: 0;
}

.mc-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - var(--navbar-h) - 64px);
}

.mc-projects-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 0;
  position: sticky;
  top: 0;
  height: 100%;
  overflow-y: auto;
}

.mc-projects-head {
  padding: 0 16px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
}

.mc-projects-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mc-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 16px;
  color: var(--muted);
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s;
}

.mc-project-item:hover {
  background: var(--accent-pill);
  color: var(--ink);
}

.mc-project-item.mc-project-active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.mc-project-name {
  flex: 1;
  min-width: 0;
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mc-project-count {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-pill);
  color: var(--accent);
  font-size: 0.67rem;
  font-weight: 700;
}

.mc-content-section {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 26px;
  background: var(--bg);
}

.mc-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.mc-heading {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.mc-subtitle {
  margin: 6px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.mc-notice {
  margin-bottom: 0;
}

.mc-filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mc-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.mc-search {
  width: min(360px, 100%);
  padding: 8px 13px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.83rem;
  color: var(--ink);
  outline: none;
  transition: background 0.14s;
}

.mc-search:focus {
  background: var(--accent-light);
}

.mc-new-btn {
  flex-shrink: 0;
}

.mc-select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--faint) 50%),
    linear-gradient(135deg, var(--faint) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size:
    6px 6px,
    6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.mc-table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  min-width: 0;
}

.mc-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.mc-table thead th {
  padding: 14px 16px;
  background: #f8fafc;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  text-align: left;
}

.mc-table tbody td {
  padding: 14px 16px;
  border-top: 1px solid #eef2f7;
  font-size: 0.84rem;
  color: var(--ink);
  vertical-align: top;
}

.mc-table tbody tr:hover {
  background: #fafcff;
}

.mc-task {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 0.76rem;
  color: var(--accent-dim);
}

.mc-desc {
  color: var(--muted) !important;
  width: 36%;
}

.mc-desc-copy {
  color: var(--muted);
  line-height: 1.55;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.mc-desc-copy.is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mc-desc-copy.is-expanded {
  display: block;
}

.mc-desc-toggle {
  margin-top: 8px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.mc-desc-toggle:hover {
  color: var(--accent-dim);
  text-decoration: underline;
}

.mc-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mc-badge-on {
  background: #dcfce7;
  color: #166534;
}

.mc-badge-off {
  background: #e2e8f0;
  color: #475569;
}

.mc-actions {
  white-space: nowrap;
  text-align: right;
}

.mc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--faint);
  text-align: center;
}

.mc-empty svg {
  opacity: 0.32;
}

.mc-empty p {
  margin: 0;
  font-size: 0.86rem;
}

.mc-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 16px 18px;
  border-top: 1px solid #eef2f7;
  background: #fbfdff;
}

.mc-modal-backdrop,
.mc-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(10, 20, 60, 0.38);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.mc-modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 660px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.mc-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
}

.mc-modal-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.mc-modal-close {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--faint);
  transition:
    background 0.13s,
    color 0.13s;
}

.mc-modal-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

.mc-modal-form {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mc-confirm-backdrop {
  z-index: 600;
}

@media (max-width: 900px) {
  .mc-layout {
    grid-template-columns: 1fr;
  }

  .mc-projects-panel {
    position: static;
    height: auto;
    padding-bottom: 0;
  }

  .mc-projects-list {
    display: flex;
    gap: 8px;
    padding: 0 16px;
    overflow-x: auto;
  }

  .mc-project-item {
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--surface);
  }

  .mc-content-section {
    padding-top: 12px;
  }

  .mc-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .mc-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .mc-search {
    width: 100%;
  }

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

  .mc-table {
    min-width: 760px;
    table-layout: auto;
  }
}

/* ── Login page ───────────────────────────────────────────────────────────── */

.login-body {
  margin: 0;
  background: linear-gradient(155deg, #0a1628 0%, #0e2254 45%, #0f2d6e 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.login-scene {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-glow {
  position: fixed;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(80px);
}

.login-glow-1 {
  width: 580px;
  height: 580px;
  top: -180px;
  right: -80px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.3), rgba(37, 99, 235, 0.03));
}

.login-glow-2 {
  width: 480px;
  height: 480px;
  bottom: -160px;
  left: -100px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.22), rgba(67, 56, 202, 0.03));
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  background: #ffffff;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 28px 56px rgba(7, 15, 45, 0.5),
    0 8px 20px rgba(7, 15, 45, 0.3);
  padding: 40px 40px 36px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-brand-mark {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(140deg, #1d4ed8 0%, #2563eb 55%, #3b82f6 100%);
  box-shadow:
    0 6px 16px rgba(37, 99, 235, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.login-brand-name {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: 0.01em;
}

.login-brand-tagline {
  display: block;
  font-size: 0.74rem;
  color: #64748b;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}

.login-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(226, 232, 240, 0.9) 25%,
    rgba(226, 232, 240, 0.9) 75%,
    transparent
  );
  margin-bottom: 28px;
}

.login-heading {
  margin-bottom: 26px;
}

.login-title {
  margin: 0 0 6px;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #0f172a;
  line-height: 1.2;
}

.login-subtitle {
  margin: 0;
  color: #64748b;
  font-size: 0.875rem;
  line-height: 1.5;
}

.login-alert {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 0.86rem;
  margin-bottom: 20px;
  line-height: 1.4;
}

.login-form {
  display: grid;
  gap: 16px;
}
.login-field {
  display: grid;
  gap: 6px;
}

.login-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #374151;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.login-input-wrap {
  position: relative;
}

.login-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-size: 0.93rem;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.login-input-wrap .login-input {
  padding-right: 42px;
}

.login-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
  background: #ffffff;
}

.login-input::placeholder {
  color: #94a3b8;
}

.login-eye-btn {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 140ms ease;
}

.login-eye-btn:hover {
  color: #475569;
}

.login-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(140deg, #1d4ed8 0%, #2563eb 55%, #3b82f6 100%);
  color: #ffffff;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow:
    0 4px 14px rgba(37, 99, 235, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    filter 150ms ease;
}

.login-submit:hover {
  transform: translateY(-1px);
  box-shadow:
    0 8px 22px rgba(37, 99, 235, 0.52),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  filter: brightness(1.05);
}

.login-submit:active {
  transform: translateY(0);
  filter: brightness(0.97);
}

.login-footer-note {
  margin: 24px 0 0;
  text-align: center;
  color: #94a3b8;
  font-size: 0.76rem;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .admin-content {
    padding: 20px 16px 32px;
  }
  .ai-workbench-grid,
  .react-agent-grid,
  .li-grid {
    grid-template-columns: 1fr;
    height: auto;
  }
  .task-runner-actions-head,
  .task-runner-submit-group {
    width: 100%;
    justify-content: flex-start;
  }
  .task-runner-page .ai-composer-foot {
    width: 100%;
    justify-content: flex-start;
  }
  .task-runner-session-badge {
    width: 100%;
    justify-content: center;
  }
  .pm-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .pm-projects-panel {
    height: auto;
  }
  .pm-field-row {
    grid-template-columns: 1fr;
  }
  .login-card {
    padding: 28px 24px 24px;
  }
}

/* ── Knowledge Base Import ───────────────────────────────────────────────── */

.kb-import {
  max-width: 720px;
}

.kb-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.kb-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kb-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 4px;
}

.kb-header p {
  font-size: 0.86rem;
  color: var(--muted);
  margin: 0;
}

/* ── Step indicator ── */

.kb-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 28px;
}

.kb-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--faint);
  white-space: nowrap;
}

.kb-step--active {
  color: var(--accent);
}
.kb-step--done {
  color: var(--muted);
}

.kb-step-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--fill);
  color: var(--faint);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background 0.2s,
    color 0.2s;
}

.kb-step--active .kb-step-dot {
  background: var(--accent);
  color: #fff;
}

.kb-step--done .kb-step-dot {
  background: #d1fae5;
  color: #065f46;
}

.kb-step-line {
  flex: 1;
  height: 1px;
  background: var(--accent-mid);
  margin: 0 10px;
  min-width: 24px;
}

/* ── Panel ── */

.kb-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.kb-panel--done {
  text-align: center;
  padding: 48px 32px;
}

/* ── Section label ── */

.kb-section-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Project cards ── */

.kb-project-select {
  width: 100%;
  max-width: 360px;
  padding: 9px 12px;
  background: var(--fill);
  border: 1px solid var(--accent-mid);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  outline: none;
  appearance: auto;
}

.kb-project-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Drop zone ── */

.kb-drop-zone[hidden] {
  display: none;
}

.kb-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 24px;
  background: var(--fill);
  border: 2px dashed var(--accent-mid);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
  text-align: center;
}

.kb-drop-zone:hover,
.kb-drop-zone.drag-over {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.kb-drop-text {
  font-size: 0.88rem;
  font-weight: 500;
}

.kb-drop-hint {
  font-size: 0.76rem;
  color: var(--faint);
}

.kb-file-badge[hidden] {
  display: none;
}

.kb-file-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 7px 12px;
  background: var(--accent-light);
  border: 1px solid var(--accent-mid);
  border-radius: 99px;
  font-size: 0.82rem;
  color: var(--accent);
}

.kb-file-clear {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--faint);
  padding: 0;
  line-height: 1;
}

.kb-file-clear:hover {
  color: var(--accent);
}

/* ── Actions row ── */

.kb-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

/* ── Analyzing panel ── */

.kb-panel--analyzing {
  padding: 0;
  overflow: hidden;
}
.kb-panel--analyzing[hidden] {
  display: none;
}

.kb-scan-card {
  width: 100%;
  background: #06101e;
  border-radius: var(--radius);
  padding: 28px 32px 30px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

.kb-scan-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  color: rgba(255, 255, 255, 0.22);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.kb-scan-table {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 22px;
  overflow: hidden;
  padding: 1px 0;
}

.kb-scan-row {
  display: grid;
  grid-template-columns: 3fr 2fr 1.5fr 1fr;
  gap: 6px;
}

.kb-scan-row span {
  height: 7px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.05);
  animation: kbRowPulse 3s ease-in-out infinite;
}

.kb-scan-row:nth-child(2) span {
  animation-delay: 0s;
}
.kb-scan-row:nth-child(3) span {
  animation-delay: 0.3s;
}
.kb-scan-row:nth-child(4) span {
  animation-delay: 0.6s;
}
.kb-scan-row:nth-child(5) span {
  animation-delay: 0.9s;
}
.kb-scan-row:nth-child(6) span {
  animation-delay: 1.2s;
}

@keyframes kbRowPulse {
  0%,
  100% {
    background: rgba(255, 255, 255, 0.05);
  }
  50% {
    background: rgba(255, 255, 255, 0.11);
  }
}

.kb-scan-row--head span {
  height: 9px;
  background: rgba(99, 102, 241, 0.25);
  animation: kbHeadPulse 2.5s ease-in-out infinite;
}

@keyframes kbHeadPulse {
  0%,
  100% {
    background: rgba(99, 102, 241, 0.25);
  }
  50% {
    background: rgba(99, 102, 241, 0.45);
  }
}

@keyframes kbScan {
  0% {
    top: -2px;
    opacity: 0;
  }
  6% {
    opacity: 1;
  }
  94% {
    opacity: 1;
  }
  100% {
    top: calc(100% + 2px);
    opacity: 0;
  }
}

.kb-scan-beam {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(99, 102, 241, 0.6);
  animation: kbScan 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  pointer-events: none;
}

.kb-scan-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kb-scan-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  animation: kbIndicatorPulse 1.4s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes kbIndicatorPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

.kb-scan-status {
  margin: 0;
  font-size: 0.76rem;
  color: #34d399;
  letter-spacing: 0.02em;
}

.kb-scan-status::after {
  content: '_';
  animation: kbBlink 0.9s step-start infinite;
}

@keyframes kbBlink {
  50% {
    opacity: 0;
  }
}

/* ── Analysis result ── */

.kb-result-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.kb-result-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.kb-result-badge[data-type-theme='vocabulary'] {
  background: #059669;
}
.kb-result-badge[data-type-theme='grammar'] {
  background: #2563eb;
}
.kb-result-badge[data-type-theme='sentence'] {
  background: #7c3aed;
}
.kb-result-badge[data-type-theme='reading'] {
  background: #ea580c;
}
.kb-result-badge[data-type-theme='paragraph'] {
  background: #0d9488;
}

.kb-result-confidence {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.kb-confidence-track {
  flex: 1;
  height: 5px;
  background: var(--fill);
  border-radius: 99px;
  overflow: hidden;
}

.kb-confidence-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  width: 0%;
  transition: width 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}

.kb-confidence-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 34px;
}

.kb-result-meta {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
}

.kb-dot {
  color: var(--faint);
}

.kb-result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.kb-result-box {
  background: var(--fill);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border-left: 3px solid transparent;
}

.kb-result-box--embed {
  border-left-color: var(--accent);
}
.kb-result-box--meta {
  border-left-color: #f59e0b;
}

.kb-result-box-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.kb-box-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kb-box-dot--embed {
  background: var(--accent);
}
.kb-box-dot--meta {
  background: #f59e0b;
}

.kb-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.kb-tag {
  padding: 3px 9px;
  background: var(--accent-mid);
  color: var(--accent);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
}

@keyframes kbTagIn {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.kb-tag--animated {
  opacity: 0;
  animation: kbTagIn 0.22s ease forwards;
}

.kb-result-fields {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.kb-field-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--fill);
  border-radius: var(--radius-sm);
}

.kb-field-key {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kb-field-val {
  font-family: monospace;
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--faint);
}

.kb-reasoning {
  padding: 12px 16px;
  background: var(--fill);
  border-left: 3px solid var(--accent-mid);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 4px;
}

.kb-reasoning-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.kb-reasoning-text {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.65;
}

/* ── Progress ── */

.kb-progress-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
}

.kb-progress-track {
  height: 8px;
  background: var(--fill);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 10px;
}

.kb-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.kb-progress-hint {
  font-size: 0.78rem;
  color: var(--faint);
}

/* ── Done ── */

.kb-done-check {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #d1fae5;
  color: #065f46;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.kb-done-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.kb-done-stats {
  font-size: 0.84rem;
  color: var(--muted);
}

/* ── Error ── */

.kb-error[hidden] {
  display: none;
}

.kb-error {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 14px;
  background: #fee2e2;
  color: #991b1b;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
}

/* ── Knowledge Browser (kbb-*) ───────────────────────────────────────────── */

.kbb-root {
  max-width: 900px;
}

.kbb-import-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

.kbb-search-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

/* ── Project bar（select + stats cards） ── */

.kbb-project-bar {
  display: flex;
  align-items: flex-start;
  gap: 12px 16px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  flex-wrap: wrap;
  min-height: 72px;
}

.kbb-project-select {
  flex-shrink: 0;
  border: none !important;
  background: transparent !important;
  padding: 10px 12px 10px 0;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  max-width: 200px;
}

/* Vertical divider between select and stats */
.kbb-stats-divider {
  width: 1px;
  height: 30px;
  background: var(--border);
  flex-shrink: 0;
  margin: 8px 2px 0;
}

/* ── Stats Row ── */

.kbb-stats-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
  align-items: flex-start;
  padding-top: 2px;
}

.kbb-stat-card {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--fill);
  border: 1px solid var(--accent-mid);
  border-radius: 20px;
  padding: 6px 13px;
  white-space: nowrap;
}

.kbb-stat-card[data-stat-total] {
  background: var(--accent-light);
  border-color: var(--accent);
}

.kbb-stat-card[data-stat-total] .kbb-stat-value {
  color: var(--accent);
}

.kbb-stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  min-height: unset;
}

.kbb-stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0;
  white-space: nowrap;
  line-height: 1.25;
}

/* Skeleton pulse */
@keyframes kbbSkelPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.kbb-skel {
  background: var(--accent-mid);
  border-radius: 6px;
  animation: kbbSkelPulse 1.4s ease-in-out infinite;
  min-height: 1rem;
  width: 60%;
  margin: 0 auto;
}

/* ── Type bar（属于当前 project 的 type chips） ── */

.kbb-type-bar {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
  min-height: 36px;
}

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

.kbb-chip {
  padding: 5px 13px;
  border-radius: 20px;
  border: 1px solid var(--accent-mid);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
  line-height: 1.4;
}

.kbb-chip:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.kbb-chip--active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Table ── */

.kbb-table-wrap {
  background: var(--surface);
  border: 1px solid var(--accent-mid);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.kbb-table {
  width: 100%;
  border-collapse: collapse;
}

.kbb-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--accent-mid);
  background: var(--accent-light);
}

.kbb-table td {
  padding: 10px 14px;
  font-size: 0.84rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.kbb-table tbody tr:last-child td {
  border-bottom: none;
}

.kbb-table tbody tr:hover {
  background: var(--fill);
}

.kbb-th-action {
  width: 48px;
}
.kbb-th-type {
  width: 120px;
}
.kbb-th-project {
  width: 110px;
}

.kbb-item-title {
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
}

.kbb-item-id {
  font-size: 0.72rem;
  color: var(--faint);
  font-family: monospace;
  margin-top: 1px;
}

.kbb-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--accent-pill);
  color: var(--accent);
}

.kbb-delete-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    color 0.15s;
}

.kbb-delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Skeleton rows */
.kbb-skel-row td {
  padding: 12px 14px;
}

.kbb-skel-row .kbb-skel {
  height: 14px;
  width: 40%;
  margin: 0;
}

.kbb-skel-row:nth-child(2) .kbb-skel {
  width: 65%;
}
.kbb-skel-row:nth-child(3) .kbb-skel {
  width: 50%;
}
.kbb-skel-row:nth-child(4) .kbb-skel {
  width: 70%;
}
.kbb-skel-row:nth-child(5) .kbb-skel {
  width: 45%;
}

/* ── Load more / empty ── */

.kbb-load-more-row {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}

.kbb-load-more-row[hidden] {
  display: none;
}

.kbb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.kbb-empty[hidden] {
  display: none;
}

.kbb-empty svg {
  opacity: 0.35;
}

/* ── Delete dialog ── */

.kbb-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  max-width: 360px;
  width: 100%;
}

.kbb-dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
}

.kbb-dialog-body {
  padding: 24px;
}

.kbb-dialog-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.kbb-dialog-desc {
  font-size: 0.86rem;
  color: var(--muted);
  margin: 0 0 20px;
}

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

.danger-button {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: #dc2626;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.danger-button:hover {
  background: #b91c1c;
}

/* ── kbb checkbox column ── */

.kbb-th-cb {
  width: 40px;
}

.kbb-cb {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.kbb-table td:first-child {
  padding-left: 14px;
}

.kbb-table tr.kbb-row--selected {
  background: var(--accent-light);
}

/* ── Bulk action bar ── */

.kbb-bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--accent-mid);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.kbb-bulk-bar[hidden] {
  display: none;
}

.kbb-bulk-count {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--accent);
  flex: 1;
}

.kbb-bulk-cancel {
  font-size: 0.82rem;
  padding: 6px 12px;
}

.kbb-bulk-bar .danger-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  padding: 6px 14px;
}

/* ── Action cell (view + delete buttons) ── */

.kbb-actions-cell {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.kbb-view-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    color 0.15s;
}

.kbb-view-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Detail dialog ── */

.kbb-detail-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.18);
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
}

/* 未打开时必须 display:none，否则会覆盖 UA stylesheet 的 dialog:not([open]){display:none} */
.kbb-detail-dialog:not([open]) {
  display: none;
}
.kbb-detail-dialog[open] {
  display: flex;
  flex-direction: column;
}

.kbb-detail-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.kbb-detail-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.kbb-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--accent-mid);
  flex-shrink: 0;
}

.kbb-detail-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 440px;
}

.kbb-detail-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.kbb-detail-close:hover {
  background: var(--fill);
}

.kbb-detail-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  flex: 1;
  min-height: 0;
}

.kbb-detail-kv {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.kbb-detail-kv tr + tr td {
  border-top: 1px solid #f1f5f9;
}

.kbb-detail-kv td {
  padding: 7px 4px;
  vertical-align: top;
}

.kbb-detail-key {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  padding-right: 16px;
  width: 1%;
  font-family: monospace;
  font-size: 0.78rem;
}

.kbb-detail-val {
  color: var(--ink);
  word-break: break-word;
  white-space: pre-wrap;
}

.kbb-detail-val--null {
  color: var(--faint);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Knowledge Search Page  (.ks-*)
   ═══════════════════════════════════════════════════════════════════════════ */

.ks-root {
  max-width: 860px;
}

/* ── Search bar ── */

.ks-search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.ks-input-wrap {
  flex: 1;
  position: relative;
}

.ks-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.ks-input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  outline: none;
  box-sizing: border-box;
}

.ks-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.ks-search-btn {
  flex-shrink: 0;
  padding: 10px 20px;
}

/* ── Filters ── */

.ks-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.ks-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  outline: none;
  cursor: pointer;
}

.ks-limit-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-left: auto;
}

/* ── Status ── */

.ks-status {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Result cards ── */

.ks-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ks-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.ks-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ks-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.ks-rank {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--fill);
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
  margin-top: 2px;
}

.ks-card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  flex: 1;
  line-height: 1.4;
}

.ks-score-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ks-score-bar-bg {
  width: 60px;
  height: 6px;
  background: var(--fill);
  border-radius: 99px;
  overflow: hidden;
}

.ks-score-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.ks-score-text {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 36px;
  text-align: right;
}

.ks-card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.ks-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--fill);
  color: var(--muted);
  border: 1px solid var(--accent-mid);
}

.ks-card-desc {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ks-card-detail {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: none;
}

.ks-card.ks-card--open .ks-card-detail {
  display: block;
}
.ks-card.ks-card--open .ks-card-desc {
  -webkit-line-clamp: unset;
  overflow: visible;
}

.ks-detail-kv {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.ks-detail-kv td {
  padding: 3px 0;
  vertical-align: top;
}
.ks-detail-key {
  color: var(--muted);
  font-family: monospace;
  white-space: nowrap;
  padding-right: 14px;
  width: 1%;
}
.ks-detail-val {
  color: var(--ink);
  word-break: break-word;
  white-space: pre-wrap;
}
.ks-detail-val--null {
  color: var(--faint);
  font-style: italic;
}

/* ── Empty ── */

.ks-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── Skeleton ── */

.ks-skel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ks-skel-line {
  background: var(--accent-mid);
  border-radius: 4px;
  animation: kbbSkelPulse 1.4s ease-in-out infinite;
}

@media (max-width: 720px) {
  .ks-search-bar {
    flex-direction: column;
  }

  .ks-search-btn {
    width: 100%;
  }

  .ks-limit-label {
    margin-left: 0;
  }

  .ks-card-header {
    flex-wrap: wrap;
  }

  .ks-score-wrap {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   Seduw Companion  —  Premium Chat Interface
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Layout ──────────────────────────────────────────────────────────────── */

.companion-page {
  display: flex;
  flex-direction: row;
  height: calc(100vh - var(--navbar-h) - 80px);
  background: #fff;
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(37, 99, 235, 0.08),
    0 4px 24px rgba(37, 99, 235, 0.07),
    0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.companion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  background: linear-gradient(135deg, #1a3065 0%, #1e4db7 100%);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.companion-header::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 80% 50%, rgba(255, 255, 255, 0.06) 0%, transparent 60%),
    radial-gradient(circle at 20% 80%, rgba(99, 179, 237, 0.1) 0%, transparent 50%);
  pointer-events: none;
}

.companion-header-info {
  display: flex;
  align-items: center;
  gap: 13px;
  position: relative;
  z-index: 1;
}

.companion-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.18),
    0 2px 8px rgba(37, 99, 235, 0.5);
  letter-spacing: -0.02em;
  transition: box-shadow 0.4s ease;
}

/* Pulse ring while AI is generating */
.companion-page.is-thinking .companion-avatar {
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.18),
    0 0 0 6px rgba(96, 165, 250, 0.35),
    0 0 0 10px rgba(96, 165, 250, 0.12);
  animation: cp-avatar-pulse 1.8s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes cp-avatar-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, 0.18),
      0 0 0 6px rgba(96, 165, 250, 0.35),
      0 0 0 10px rgba(96, 165, 250, 0.12);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, 0.22),
      0 0 0 8px rgba(96, 165, 250, 0.5),
      0 0 0 14px rgba(96, 165, 250, 0.06);
  }
}

.companion-header-info h2 {
  margin: 0 0 1px;
  font-size: 0.94rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.companion-header-info p {
  margin: 0;
  font-size: 0.73rem;
  color: rgba(255, 255, 255, 0.58);
}

.companion-header-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.58);
}

.companion-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
  animation: cp-status-blink 2.4s ease-in-out infinite;
}

@keyframes cp-status-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.companion-header-actions {
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 1;
}

.companion-header-actions .ghost-button {
  color: rgba(255, 255, 255, 0.7);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.76rem;
  padding: 5px 12px;
}

.companion-header-actions .ghost-button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.companion-mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.companion-header-actions .ghost-button.is-active {
  background: rgba(191, 219, 254, 0.22);
  color: #fff;
  border-color: rgba(191, 219, 254, 0.45);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* ── Messages ────────────────────────────────────────────────────────────── */

.companion-messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.companion-messages::-webkit-scrollbar {
  width: 5px;
}
.companion-messages::-webkit-scrollbar-track {
  background: transparent;
}
.companion-messages::-webkit-scrollbar-thumb {
  background: rgba(37, 99, 235, 0.15);
  border-radius: 99px;
}
.companion-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(37, 99, 235, 0.28);
}

/* Message entrance animation */
@keyframes cp-msg-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.companion-page .ai-message {
  animation: cp-msg-in 0.32s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

/* Override: user bubble */
.companion-page .ai-message-user .ai-message-bubble {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 11px 17px;
  font-size: 0.9rem;
  box-shadow:
    0 2px 12px rgba(37, 99, 235, 0.28),
    0 1px 2px rgba(37, 99, 235, 0.18);
}

/* Override: assistant bubble */
.companion-page .ai-message-assistant {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 88%;
}

.cp-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
}

.cp-msg-content {
  flex: 1;
  min-width: 0;
}

.cp-msg-content .ai-message-meta {
  padding: 0 2px;
  margin-bottom: 4px;
}

.companion-page .ai-message-assistant .ai-message-bubble {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px 18px 18px 18px;
  padding: 13px 17px;
  font-size: 0.9rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s;
}

/* Welcome message special styling */
.companion-page .ai-message-featured .ai-message-bubble {
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.06);
}

/* Streaming state */
.companion-page .ai-message-streaming .ai-message-bubble {
  box-shadow:
    0 0 0 2px rgba(37, 99, 235, 0.12),
    0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ── Input area ──────────────────────────────────────────────────────────── */

.companion-input-wrap {
  padding: 12px 18px 16px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: #f8fafc;
  border-top: 1px solid #e8f0fe;
}

.companion-hint {
  margin: 0;
  padding: 7px 12px;
  font-size: 0.76rem;
  color: #64748b;
  background: #fef9c3;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 7px;
}

.companion-hint::before {
  content: '⚠';
  flex-shrink: 0;
}

.companion-hint-btn {
  background: none;
  border: none;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.companion-samples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.companion-page .ai-starter-chip {
  background: #fff;
  border: 1.5px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 0.78rem;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.companion-page .ai-starter-chip:hover {
  background: #eff6ff;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.15);
}

.companion-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 16px;
  padding: 6px 6px 6px 16px;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.companion-form:focus-within {
  border-color: #93c5fd;
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.09),
    0 1px 4px rgba(0, 0, 0, 0.04);
}

.companion-form textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink);
  max-height: 120px;
  overflow-y: auto;
  padding: 6px 0;
}

.companion-form textarea::placeholder {
  color: #94a3b8;
}

.companion-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.15s,
    box-shadow 0.18s;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.companion-send-btn:hover:not(:disabled) {
  transform: scale(1.08) translateY(-1px);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
}

.companion-send-btn:active:not(:disabled) {
  transform: scale(0.94);
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.25);
}

.companion-send-btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

/* ── Thinking block (yellow, visible only while model is streaming) ──────── */

.cp-thinking {
  display: none;
  margin: 6px 14px 8px;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 14px 12px;
  font-size: 0.8rem;
  line-height: 1.65;
  color: #78350f;
}

.cp-thinking.is-active {
  display: block;
  animation: cp-row-in 0.18s ease both;
}

.cp-thinking-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #b45309;
  margin-bottom: 7px;
}

.cp-thinking-text {
  white-space: pre-wrap;
  word-break: break-word;
  opacity: 0.9;
}

/* Animated dots inside the Thinking header */
.cp-thinking-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.cp-thinking-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #d97706;
  animation: cp-wave 1.1s ease-in-out infinite;
}

.cp-thinking-dots span:nth-child(1) {
  animation-delay: 0s;
}
.cp-thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.cp-thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

/* ── Trace panel (no bubble wrapper, timeline style) ─────────────────────── */

.cp-trace {
  margin-top: 8px;
  margin-bottom: 6px;
}

/* Pill toggle */
.cp-trace-summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 7px;
  border-radius: 20px;
  cursor: pointer;
  color: #64748b;
  font-size: 0.71rem;
  font-weight: 500;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  user-select: none;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
  letter-spacing: 0.01em;
}

.cp-trace-summary:hover {
  background: #e8edf4;
  border-color: #cbd5e1;
  color: #475569;
}

.cp-trace-summary::-webkit-details-marker {
  display: none;
}

.cp-chevron {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  transition: transform 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
  color: #94a3b8;
}

details[open] .cp-chevron {
  transform: rotate(90deg);
}

/* Timeline body */
.cp-trace-body {
  margin-top: 10px;
  margin-left: 6px;
  padding-left: 14px;
  border-left: 2px solid #e2e8f0;
  display: flex;
  flex-direction: column;
}

/* Row entrance */
@keyframes cp-row-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cp-trace-row {
  position: relative;
  padding: 5px 0 5px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: cp-row-in 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Timeline dot on the left border */
.cp-trace-row::before {
  content: '';
  position: absolute;
  left: -19px;
  top: 11px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #f8fafc;
  box-sizing: border-box;
}

.cp-trace-row-thought::before {
  background: #a78bfa;
}
.cp-trace-row-search::before {
  background: #60a5fa;
}
.cp-trace-row-result::before {
  background: #34d399;
}
.cp-trace-row-memory::before {
  background: #f59e0b;
}
.cp-trace-row-history::before {
  background: #06b6d4;
}

.cp-trace-badge-memory {
  color: #b45309;
  background: #fef3c7;
  border-color: #fcd34d;
}

.cp-trace-badge-history {
  color: #0f766e;
  background: #cffafe;
  border-color: #67e8f9;
}

/* Row header: badge + live indicator */
.cp-trace-row-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Type badge */
.cp-trace-type-badge {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 1.6;
}

.cp-trace-badge-thought {
  background: #ede9fe;
  color: #7c3aed;
}
.cp-trace-badge-search {
  background: #dbeafe;
  color: #1d4ed8;
}
.cp-trace-badge-result {
  background: #dcfce7;
  color: #15803d;
}

/* Row body */
.cp-trace-row-body {
  font-size: 0.78rem;
  line-height: 1.55;
  color: #64748b;
  word-break: break-word;
}

.cp-trace-row-thought .cp-trace-row-body {
  color: #6d28d9;
  font-style: italic;
  opacity: 0.9;
}

/* Live streaming thought row — blinking cursor at end of text */
.cp-trace-row-live .cp-trace-row-body::after {
  content: '▍';
  display: inline-block;
  color: #a78bfa;
  animation: cp-cursor-blink 0.8s step-end infinite;
  margin-left: 1px;
}
@keyframes cp-cursor-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* Thought dot pulse (is-thinking state) */
@keyframes cp-dot-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.65);
  }
}

/* ── Answer area ─────────────────────────────────────────────────────────── */

.cp-answer {
  padding: 10px 0 4px;
  min-height: 1.4em;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--ink);
}

/* References 区块：与正文隔开，字号缩小，弱化色调 */
.cp-answer h2:last-of-type,
.cp-answer h3:last-of-type {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.cp-answer h2:last-of-type + ol,
.cp-answer h2:last-of-type + ul,
.cp-answer h3:last-of-type + ol,
.cp-answer h3:last-of-type + ul {
  margin: 6px 0 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cp-answer h2:last-of-type + ol li,
.cp-answer h2:last-of-type + ul li,
.cp-answer h3:last-of-type + ol li,
.cp-answer h3:last-of-type + ul li {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 3px 8px;
  background: #f8fafc;
  border-radius: 6px;
  border-left: 2px solid #cbd5e1;
  line-height: 1.5;
}

/* Blinking cursor while streaming */
.ai-message-streaming .cp-answer:not(:empty)::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cp-cursor 0.75s step-end infinite;
}

@keyframes cp-cursor {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* ── Animated wave dots ──────────────────────────────────────────────────── */

.cp-trace-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  margin-left: 2px;
}

.cp-trace-dots span {
  width: 3.5px;
  height: 3.5px;
  border-radius: 50%;
  background: #94a3b8;
  animation: cp-wave 1.1s ease-in-out infinite;
}

.cp-trace-dots span:nth-child(1) {
  animation-delay: 0s;
}
.cp-trace-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.cp-trace-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

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

/* ── Main chat wrapper ───────────────────────────────────────────────────── */

.companion-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* ── Session sidebar ─────────────────────────────────────────────────────── */

.companion-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e2e8f0;
  background: #f8fafc;
  overflow: hidden;
}

.companion-sidebar-header {
  padding: 14px 14px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #94a3b8;
  flex-shrink: 0;
}

.companion-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 6px 6px;
}

.companion-session-list::-webkit-scrollbar {
  width: 4px;
}
.companion-session-list::-webkit-scrollbar-track {
  background: transparent;
}
.companion-session-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 99px;
}

.companion-session-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s;
  margin-bottom: 1px;
}

.companion-session-item:hover {
  background: #e2e8f0;
}

.companion-session-item.is-active {
  background: #eff6ff;
  box-shadow: inset 2px 0 0 var(--accent);
}

.companion-session-title {
  font-size: 0.78rem;
  font-weight: 500;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.companion-session-item.is-active .companion-session-title {
  color: var(--accent);
}

.companion-session-time {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-top: 2px;
  white-space: nowrap;
}

.companion-sidebar-footer {
  padding: 8px;
  flex-shrink: 0;
  border-top: 1px solid #e2e8f0;
}

.companion-sidebar-more-btn {
  width: 100%;
  padding: 6px 0;
  font-size: 0.75rem;
  color: #64748b;
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
  transition:
    background 0.14s,
    color 0.14s;
}

.companion-sidebar-more-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.companion-session-empty {
  padding: 16px 10px;
  font-size: 0.74rem;
  color: #cbd5e1;
  text-align: center;
}
