/* ============================================================
   上海特区知识库 · 知识运营台 全局样式
   设计 token 集中在 :root，全站浅色企业风
   ============================================================ */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;

  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #f0fdfa;
  --primary-border: #99f6e4;

  --accent: #ea580c;
  --accent-soft: #fff7ed;
  --accent-border: #fed7aa;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --success: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;

  --neutral-soft: #f3f4f6;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-card: 0 1px 3px rgba(16, 24, 40, 0.06);

  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --sidebar-width: 240px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--neutral-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--text-secondary);
}

/* ========== 整体框架：侧边栏 + 主工作区 ========== */

.shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  border-radius: 9px;
  font-size: 16px;
  font-weight: 600;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 15px; font-weight: 600; }
.brand-text small { font-size: 12px; color: var(--text-muted); }

.side-nav {
  flex: 1;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.nav-group-label {
  margin: 0 10px 6px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: none;
}
.nav-link:hover {
  background: var(--neutral-soft);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.side-user {
  border-top: 1px solid var(--border);
  padding: 14px 10px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.side-user-info { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.side-user-info strong {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-user-info span { font-size: 12px; color: var(--text-muted); }

.logout-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.logout-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* ========== 主工作区 ========== */

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

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 32px 40px 20px;
  border-bottom: 1px solid var(--border);
}
.page-header-text h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.page-subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.page-header-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.35;
  flex-shrink: 0;
}
.page-header-user strong { font-size: 13px; font-weight: 600; }
.page-header-user span { font-size: 12px; color: var(--text-muted); }

.content {
  padding: 28px 40px 64px;
  max-width: 1440px;
  width: 100%;
}
.content h2 {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 650;
}
.content h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
}

/* ========== 卡片 ========== */

.card, .content section.card-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  margin: 0 0 20px;
}
.card > h2:first-child, .card-section > h2:first-child { margin-top: 0; }

.card-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  margin: 0 0 20px;
  max-width: 720px;
  display: grid;
  gap: 16px;
}
.card-form h2, .card-form h3 { margin: 0; }

/* ========== 表单 ========== */

.content label, .card-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.5;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary-border);
  outline-offset: 0;
  border-color: var(--primary);
}
textarea { min-height: 96px; resize: vertical; }
select[multiple] { min-height: 120px; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 0;
}
fieldset legend {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 6px;
}

.check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: 400 !important;
  color: var(--text) !important;
}
.check input { width: auto; }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  border: 0;
  padding: 0;
}

.checkbox-option {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 10px !important;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text) !important;
  cursor: pointer;
}

.checkbox-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.checkbox-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.form-actions { display: flex; gap: 10px; align-items: center; }

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .field-pair { grid-template-columns: 1fr; }
}

.inner-form {
  display: grid;
  gap: 16px;
  max-width: 560px;
  margin: 0 0 18px;
}

/* ========== 按钮 ========== */

button[type="submit"], .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button[type="submit"]:hover, .button:hover {
  background: var(--primary-hover);
  color: #fff;
  text-decoration: none;
}

.button.secondary, button.secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
.button.secondary:hover, button.secondary:hover {
  background: var(--neutral-soft);
  color: var(--text);
}

button.danger, .button.danger {
  background: var(--danger) !important;
  color: #fff !important;
}
button.danger:hover, .button.danger:hover { background: var(--danger-hover) !important; }

button.small, .button.small {
  padding: 5px 12px;
  font-size: 13px;
}

.inline { display: inline; }
.inline button[type="submit"] { padding: 5px 12px; font-size: 13px; }

/* ========== 表格 ========== */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
  margin: 0 0 20px;
}

.content table, table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.content th, .content td, table.data-table th, table.data-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.content th, table.data-table th {
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.content tbody tr:hover, table.data-table tbody tr:hover { background: var(--surface-soft); }
.content tr:last-child td, table.data-table tr:last-child td { border-bottom: 0; }
.content table a, table.data-table a { font-weight: 500; }

.table-empty {
  text-align: center !important;
  color: var(--text-muted);
  padding: 32px 16px !important;
}

/* ========== 状态徽标 badge ========== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.pending, .badge.expired {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}
.badge.published, .badge.active, .badge.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success-border);
}
.badge.failed, .badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-border);
}
.badge.disabled, .badge.revoked, .badge.neutral {
  background: var(--neutral-soft);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ========== 运营总览：KPI 卡片 ========== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0 0 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.kpi-label {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-value {
  font-size: 32px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.kpi-note { font-size: 12px; color: var(--text-muted); }
.kpi-link { font-size: 13px; font-weight: 500; margin-top: 2px; }

.kpi-card.attention { border-color: var(--accent-border); }
.kpi-card.attention .kpi-value { color: var(--accent); }
.kpi-card.danger { border-color: var(--danger-border); }
.kpi-card.danger .kpi-value { color: var(--danger); }
.kpi-card.ok .kpi-value { color: var(--success); }

/* ========== 运营总览：两栏工作区 ========== */

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin: 0 0 24px;
}

.todo-list { display: flex; flex-direction: column; }
.todo-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--border);
}
.todo-item:last-child { border-bottom: 0; }
.todo-main { flex: 1; min-width: 0; }
.todo-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.todo-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}
.todo-tags { display: inline-flex; gap: 6px; }
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 10px; }
.empty-state p { margin: 4px 0; font-size: 14px; color: var(--text-secondary); }
.empty-state .empty-hint { font-size: 12px; color: var(--text-muted); }

/* ========== 知识库健康度 ========== */

.health-list { display: flex; flex-direction: column; }
.health-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.health-row:last-child { border-bottom: 0; }
.health-label { color: var(--text-secondary); }
.health-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.health-value .sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ========== 快捷操作 ========== */

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0 0 24px;
}
.quick-action {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.quick-action:hover {
  border-color: var(--primary-border);
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.1);
  text-decoration: none;
}
.quick-action .qa-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 4px;
}
.quick-action strong { font-size: 14px; font-weight: 600; }
.quick-action span { font-size: 12px; color: var(--text-muted); }

/* ========== 描述列表 / 状态页 ========== */

.status-list { display: flex; flex-direction: column; }
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.status-row:last-child { border-bottom: 0; }
.status-label { color: var(--text-secondary); flex-shrink: 0; }
.status-value { text-align: right; min-width: 0; }

.ok { color: var(--success); font-weight: 600; }
.warn { color: var(--accent); font-weight: 600; }

/* ========== 提示与辅助文字 ========== */

.hint { font-size: 13px; color: var(--text-muted); line-height: 1.7; margin: 6px 0; }
.muted { color: var(--text-muted); }
.subtle { font-size: 12px; color: var(--text-muted); }

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 16px;
  border: 1px solid transparent;
}
.alert.warning {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #9a3412;
}
.alert.danger-zone {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: #991b1b;
}
.alert.info {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary-hover);
}

.document-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 14px 0 16px;
}

.document-count {
  margin: 0 0 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.document-filter {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.document-filter label {
  min-width: 220px;
}

.document-filter select,
.document-filter button {
  min-height: 40px;
}

.org-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 140px;
}

.org-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border: 1px solid var(--primary-border);
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  white-space: nowrap;
}

.org-badge.all {
  border-color: var(--border);
  background: var(--neutral-soft);
  color: var(--text-secondary);
}

.page-documents .table-wrap table {
  min-width: 1060px;
}

.page-documents .table-wrap th:first-child,
.page-documents .table-wrap td:first-child {
  min-width: 280px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 20px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px 20px;
  margin: 0 0 20px;
}
.filter-bar label { min-width: 180px; }
.filter-bar button[type="submit"] { height: 40px; }

/* ========== 审核详情页 ========== */

.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.meta-list { display: flex; flex-direction: column; gap: 0; }
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.meta-row:last-child { border-bottom: 0; }
.meta-row .meta-label { color: var(--text-muted); flex-shrink: 0; }
.meta-row .meta-value { text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ========== 密钥签发页 ========== */

.raw-key {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-soft);
  word-break: break-all;
}

dl.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 18px;
  margin: 0 0 16px;
  font-size: 14px;
}
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ========== 登录页 ========== */

.admin-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(16, 24, 40, 0.08);
  padding: 36px 36px 32px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 650;
}
.login-card .login-sub {
  margin: 0 0 24px;
  font-size: 13px;
  color: var(--text-muted);
}
.login-card form { display: grid; gap: 16px; }
.login-card label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.login-card button[type="submit"] { width: 100%; padding: 11px; }
.login-card .error {
  margin: 0 0 16px;
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
}
.login-foot {
  margin: 22px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== 响应式 ========== */

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .review-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .brand { padding-bottom: 10px; }
  .side-nav {
    flex-direction: row;
    gap: 16px;
    overflow-x: auto;
    padding: 8px 0 4px;
  }
  .nav-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
  .nav-group-label { display: none; }
  .nav-link { white-space: nowrap; }
  .side-user { border-top: 0; padding: 8px 0 0; }
  .page-header { padding: 24px 20px 16px; }
  .page-header-user { display: none; }
  .content { padding: 20px 20px 48px; }
}

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .page-header-text h1 { font-size: 24px; }
  .table-wrap { border-radius: var(--radius-sm); }
  .card, .card-form, .content section.card-section { padding: 16px; }
  .filter-bar label { min-width: 100%; }

  .document-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }
  .document-count { margin-bottom: 0; }
  .document-filter { align-items: stretch; }
  .document-filter label { flex: 1; min-width: 0; }
  .document-filter button { align-self: flex-end; }
  .pager { justify-content: center; }
}
