:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --sidebar-w: 240px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; width: 100%; background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: none; border-radius: 8px; background: var(--primary); color: #fff; font-size: 14px; font-weight: 600; transition: .15s; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f3f4f6; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.orange { background: #fef3c7; color: #92400e; }
.badge.gray { background: #f3f4f6; color: #374151; }
.badge.red { background: #fee2e2; color: #991b1b; }

/* 筛选标签 */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 12px; }
.filter-label { font-size: 13px; color: var(--muted); }
.tag { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 4px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; transition: all .15s; }
.tag:hover { border-color: var(--primary); }
.tag.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.muted { color: var(--muted); }
.link { color: var(--primary); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
.msg.warn { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 10px 12px; border-radius: 8px; font-size: 13px; }

/* 权限分配 */
.perm-group { display: flex; flex-wrap: wrap; gap: 10px 18px; padding: 8px 0; }
.perm-chk { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.perm-chk input { width: 16px; height: 16px; }

/* 照片上传 */
.photo-field { display: flex; align-items: center; gap: 10px; }
.photo-field img { border: 1px solid var(--border); background: #f8fafc; }
.photo-field input[type=file] { max-width: 220px; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg,#2563eb 0%, #4f46e5 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.login-card .hint { font-size: 12px; color: var(--muted); margin-top: 14px; }
.login-logo { font-size: 30px; margin-bottom: 8px; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: #0f172a; color: #cbd5e1; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; transition: transform .2s; }
.sidebar .brand { padding: 18px 18px; font-size: 16px; font-weight: 700; color: #fff; border-bottom: 1px solid #1e293b; display: flex; align-items: center; gap: 8px; }
.sidebar nav { padding: 10px 10px; overflow-y: auto; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: #cbd5e1; font-size: 14px; margin-bottom: 2px; }
.sidebar nav a:hover { background: #1e293b; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .foot { padding: 12px 16px; border-top: 1px solid #1e293b; font-size: 12px; color: #64748b; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 16px; gap: 12px; position: sticky; top: 0; z-index: 20; }
.topbar .menu-btn { display: none; background: none; border: none; font-size: 22px; color: var(--text); }
.topbar .title { font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.topbar .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }

.content { padding: 18px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 19px; }
.page-head .spacer { flex: 1; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .value.small { font-size: 18px; }

/* 面板/卡片 */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

/* 工具栏 */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 320px; }

/* 表格 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { background: #f9fafb; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.data tbody tr:hover { background: #f9fafb; }
table.data .actions { display: flex; gap: 6px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 13px; }

/* 模态框 */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 24px 12px; overflow-y: auto; }
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 600px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal .modal-head h3 { font-size: 16px; flex: 1; }
.modal .modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal .modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* 知识库 */
.kb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.kb-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: .15s; border: 1px solid var(--border); }
.kb-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,.12); transform: translateY(-2px); }
.kb-card .thumb { height: 120px; background: #eef2ff; display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--primary); }
.kb-card .kb-body { padding: 12px; }
.kb-card .kb-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-card .kb-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* 预览 */
.preview-box { background: #0f172a; border-radius: 8px; overflow: hidden; }
.preview-box video, .preview-box iframe, .preview-box img { width: 100%; max-height: 60vh; border: none; display: block; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 200; opacity: 0; transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.funnel-stage { display: flex; flex-direction: column; gap: 8px; }
.funnel-bar { display: flex; align-items: center; gap: 10px; }
.funnel-bar .name { width: 70px; font-size: 13px; color: var(--muted); }
.funnel-bar .track { flex: 1; background: #f1f5f9; border-radius: 6px; height: 26px; overflow: hidden; }
.funnel-bar .fill { height: 100%; background: linear-gradient(90deg,#2563eb,#4f46e5); display: flex; align-items: center; padding-left: 8px; color: #fff; font-size: 12px; }

/* 移动端 */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar .menu-btn { display: block; }
  .content { padding: 12px; }
  .kpi .value { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head h2 { font-size: 17px; }
  .modal { max-width: 100%; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 50; }
  .backdrop.show { display: block; }
}
.backdrop { display: none; }
