:root {
  --brand: #07c160;
  --brand-dark: #06ad56;
  --brand-light: #e8f8ef;
  --accent: #1890ff;
  --accent-light: #e6f4ff;
  --warn: #fa8c16;
  --warn-light: #fff7e6;
  --danger: #f5222d;
  --bg: #eef2f7;
  --bg-gradient: linear-gradient(135deg, #e8f5e9 0%, #eef2f7 45%, #e3f2fd 100%);
  --surface: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 2px 12px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
  --sidebar-w: 240px;
  --transition: 0.2s ease;
}

/* ── 暗色模式 ── */
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  --surface: #1e293b;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.2);
  --brand-light: #064e3b;
  --accent-light: #1e3a5f;
  --warn-light: #3b2a10;
  --danger: #ef4444;
}
/* 暗色模式下的覆盖修正 */
[data-theme="dark"] .app-sidebar { background: #0f172a; }
[data-theme="dark"] .app-sidebar nav a { color: #94a3b8; }
[data-theme="dark"] .app-sidebar nav a.active { background: rgba(7,193,96,.15); }
[data-theme="dark"] .auth-bar { background: linear-gradient(90deg, #1e293b, #0f172a); border-color: #334155; }
[data-theme="dark"] .auth-bar.ok { background: linear-gradient(90deg, #064e3b, #1e293b); }
[data-theme="dark"] .page-header { background: var(--surface); }
[data-theme="dark"] .data-table th { background: #334155; color: #94a3b8; }
[data-theme="dark"] .data-table tr:hover td { background: #1e293b; }
[data-theme="dark"] .bar-track { background: #334155; }
[data-theme="dark"] .hint-box { background: #064e3b; border-color: #065f46; }
[data-theme="dark"] .trend-date { color: #64748b; }
[data-theme="dark"] .form-group input, [data-theme="dark"] .form-group select, [data-theme="dark"] .form-group textarea { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .workflow-step { background: #0f172a; }
[data-theme="dark"] .toolbar { background: #1e293b; }
[data-theme="dark"] .chips-wrap { background: #1e293b; }
[data-theme="dark"] .messages { background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%); }
[data-theme="dark"] .msg-row.assistant .msg-bubble { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .input-area { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .input-wrap input { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .input-wrap input:focus { border-color: var(--brand); background: #1e293b; }
[data-theme="dark"] .feedback-bar button { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .feedback-bar select { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .chip { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .chip:hover { border-color: var(--brand); background: #064e3b; }
[data-theme="dark"] .ticket-sidebar { background: #1e293b; }
[data-theme="dark"] .ticket-sidebar-header { background: #0f172a; }
[data-theme="dark"] .ticket-item:hover { background: #0f172a; }
[data-theme="dark"] .ticket-item.active { background: #1e3a5f; }
[data-theme="dark"] .msg-bubble-row.ai .bubble-content { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .msg-bubble-row.user .bubble-content { background: #064e3b; }
[data-theme="dark"] .msg-bubble-row.agent .bubble-content { background: #065f46; }
[data-theme="dark"] .quick-btns button { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .reply-row textarea { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .kb-hint { background: #064e3b; border-color: #065f46; }
[data-theme="dark"] .ticket-desc { background: #3b2a10; border-color: #525252; }
[data-theme="dark"] .kb-sidebar { background: #1e293b; }
[data-theme="dark"] .kb-domain-header { background: #0f172a; }
[data-theme="dark"] .kb-domain { border-color: #334155; }
[data-theme="dark"] .kb-doc-item { border-color: #334155; }
[data-theme="dark"] .btn-secondary { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
[data-theme="dark"] .badge-pill.badge-green { background: #064e3b; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #475569; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #64748b; }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 14px;
  font-weight: 500; cursor: pointer; border: 1px solid transparent;
  transition: all var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); box-shadow: 0 4px 12px rgba(7,193,96,.35); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.05); }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(226,232,240,.6);
}
.card h3 {
  font-size: 15px; font-weight: 600; color: var(--text);
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.card-accent { border-top: 3px solid var(--brand); }

/* ── Stat cards ── */
.stat-card { position: relative; overflow: hidden; }
.stat-card .value {
  font-size: 32px; font-weight: 700; color: var(--brand);
  line-height: 1.2; letter-spacing: -.02em;
}
.stat-card .detail { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.stat-card .icon-bg {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  font-size: 36px; opacity: .12;
}
.stat-card.warn .value { color: var(--warn); }
.stat-card.accent .value { color: var(--accent); }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left; padding: 12px 14px;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.data-table th {
  background: #f8fafc; color: var(--text-secondary);
  font-weight: 600; font-size: 12px; text-transform: none;
}
.data-table tr:hover td { background: #fafbfc; }
.data-table tr:last-child td { border-bottom: none; }
.q-cell { max-width: 320px; word-break: break-word; line-height: 1.5; }

/* ── App shell (admin / agent) ── */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: var(--sidebar-w); background: #1e293b; color: #e2e8f0;
  display: flex; flex-direction: column; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
}
.app-sidebar .brand {
  padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-sidebar .brand-title { font-size: 15px; font-weight: 700; color: #fff; }
.app-sidebar .brand-sub { font-size: 11px; color: #94a3b8; margin-top: 4px; }
.app-sidebar nav { padding: 12px 10px; flex: 1; }
.app-sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: #cbd5e1; text-decoration: none; font-size: 13px;
  margin-bottom: 2px; transition: all var(--transition);
}
.app-sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.app-sidebar nav a.active { background: rgba(7,193,96,.2); color: #4ade80; }
.app-sidebar .sidebar-footer {
  padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 11px; color: #64748b;
}
.app-main { flex: 1; min-width: 0; background: var(--bg); }
.page-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 20px 28px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.page-header .subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.page-body { padding: 24px 28px 40px; }
.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 28px 0 14px;
}
.section-title:first-child { margin-top: 0; }

/* ── Grid ── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.grid-wide { grid-template-columns: 1fr; }
.span-full { grid-column: 1 / -1; }

/* ── Bars & badges ── */
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.bar-track { flex: 1; max-width: 200px; height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--brand); transition: width .4s ease; }
.bar-fill.blue { background: var(--accent); }
.badge-pill {
  display: inline-block; font-size: 11px; padding: 3px 10px;
  border-radius: 20px; font-weight: 500;
}
.badge-green { background: var(--brand-light); color: var(--brand-dark); }
.badge-blue { background: var(--accent-light); color: var(--accent); }
.badge-warn { background: var(--warn-light); color: var(--warn); }
.status-ok { color: #16a34a; font-weight: 500; }
.status-warn { color: var(--warn); font-weight: 500; }

/* ── Workflow steps ── */
.workflow-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.workflow-step {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.workflow-step .step-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.workflow-step h4 { font-size: 13px; margin-bottom: 6px; }
.workflow-step p { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.workflow-step code { font-size: 11px; background: #e2e8f0; padding: 1px 5px; border-radius: 4px; }

/* ── Form ── */
.form-grid { display: grid; gap: 16px; max-width: 720px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(7,193,96,.12);
}
.form-group textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-msg { font-size: 13px; margin-top: 8px; }
.form-msg.ok { color: #16a34a; }
.form-msg.err { color: var(--danger); }
.hint-box {
  background: var(--brand-light); border: 1px solid #b7eb8f;
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px;
  margin-top: 12px; display: none; line-height: 1.6;
}

/* ── Trend chart ── */
.trend-chart { display: flex; align-items: flex-end; gap: 10px; min-height: 150px; padding: 16px 4px 0; border-bottom: 1px solid var(--border); }
.trend-col { flex: 1; min-width: 40px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.trend-bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; justify-content: center; }
.trend-bar { width: 12px; border-radius: 4px 4px 0 0; min-height: 3px; transition: height .4s ease; }
.trend-bar.faq { background: linear-gradient(180deg, #4ade80, var(--brand)); }
.trend-bar.doc { background: linear-gradient(180deg, #60a5fa, var(--accent)); }
.trend-date { font-size: 10px; color: var(--text-muted); }
.trend-legend { display: flex; gap: 20px; font-size: 12px; color: var(--text-secondary); margin-top: 10px; }
.trend-legend span::before {
  content: ''; display: inline-block; width: 10px; height: 10px;
  border-radius: 3px; margin-right: 6px; vertical-align: -1px;
}
.trend-legend .faq::before { background: var(--brand); }
.trend-legend .doc::before { background: var(--accent); }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Skeleton screen ── */
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
  color: transparent !important;
  user-select: none;
  pointer-events: none;
}
.skeleton-line { height: 14px; margin-bottom: 10px; width: 100%; }
.skeleton-line:last-child { width: 65%; }
.skeleton-title { height: 20px; width: 50%; margin-bottom: 14px; }
.skeleton-card {
  height: 80px; border-radius: var(--radius); margin-bottom: 12px;
}
.skeleton-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }
[data-theme="dark"] .skeleton { background: linear-gradient(90deg, #334155 25%, #1e293b 50%, #334155 75%); background-size: 200px 100%; }
