/* ==========================================================================
   中企引擎集团 CRM · 前端样式（原生 CSS，零依赖）
   设计基调：企业级信息密集型后台，品牌色延续深蓝（#1f4e79 → #2e7ebf）
   ========================================================================== */
:root {
  --brand: #1f4e79;
  --brand-2: #2e7ebf;
  --brand-3: #e8f1fb;
  --ink: #1f2937;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --ink-4: #9ca3af;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e3e8ef;
  --line-2: #eef1f6;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --warn: #b45309;
  --warn-bg: #fff7ed;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --info: #0e7490;
  --info-bg: #ecfeff;
  --purple: #6d28d9;
  --purple-bg: #f5f3ff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .16);
  --sidebar-w: 226px;
  --topbar-h: 56px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12px; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ------------------------------ 登录页 ------------------------------ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1100px 520px at 15% -10%, rgba(46, 126, 191, .28), transparent 60%),
    radial-gradient(900px 520px at 100% 110%, rgba(31, 78, 121, .30), transparent 55%),
    linear-gradient(135deg, #123a5c 0%, #1f4e79 45%, #2e7ebf 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 940px;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: var(--panel);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.login-brand { padding: 40px 40px 34px; color: #fff; background: linear-gradient(150deg, #1f4e79, #2e7ebf 90%); }
.login-brand h1 { font-size: 25px; letter-spacing: .5px; }
.login-brand .sub { margin-top: 8px; opacity: .92; font-size: 13px; }
.login-brand .firms { margin-top: 26px; display: grid; gap: 9px; }
.login-brand .firm { display: flex; align-items: center; gap: 9px; font-size: 12.5px; opacity: .96; }
.login-brand .firm i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #a7f3d0; box-shadow: 0 0 0 3px rgba(167, 243, 208, .22);
}
.login-brand .lines { margin-top: 28px; display: flex; flex-wrap: wrap; gap: 7px; }
.login-brand .lines span {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .24);
}
.login-brand .tip { margin-top: 26px; font-size: 11.5px; opacity: .8; line-height: 1.7; border-top: 1px solid rgba(255,255,255,.2); padding-top: 14px; }
.login-form { padding: 36px 38px; }
.login-form h2 { font-size: 18px; color: var(--brand); }
.login-form .hint { color: var(--ink-3); font-size: 12.5px; margin: 6px 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(46, 126, 191, .14);
}
.field .help { font-size: 11.5px; color: var(--ink-4); margin-top: 4px; }

/* ------------------------------ 布局骨架 ------------------------------ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: #10243a; color: #cbd7e6; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .logo { padding: 16px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .logo b { color: #fff; font-size: 15px; letter-spacing: .3px; display: block; }
.sidebar .logo small { color: #7f93aa; font-size: 11px; }
.nav { padding: 10px 8px 26px; }
.nav-group { margin-top: 12px; }
.nav-group > .gt {
  font-size: 10.5px; letter-spacing: 1px; color: #6d8199; padding: 5px 12px; text-transform: uppercase;
}
.nav a.item {
  display: flex; align-items: center; gap: 9px; padding: 7px 12px; border-radius: 7px;
  color: #cbd7e6; font-size: 13px; margin: 1px 0; cursor: pointer;
}
.nav a.item:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.item.active { background: var(--brand-2); color: #fff; font-weight: 600; }
.nav a.item .ic { width: 16px; text-align: center; opacity: .85; font-size: 13px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { font-size: 14px; font-weight: 600; color: var(--brand); }
.topbar .crumb small { font-weight: 400; color: var(--ink-4); margin-left: 8px; font-size: 12px; }
.topbar .spacer { flex: 1; }
.role-badge {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--brand-3);
  color: var(--brand); border: 1px solid #cfe0f2; white-space: nowrap;
}
.userbox { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.userbox .nm { font-size: 13px; }
.userbox .dp { font-size: 11px; color: var(--ink-4); }
.content { padding: 18px 20px 60px; }

/* ------------------------------ 通用组件 ------------------------------ */
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 18px; color: var(--ink); }
.page-head .desc { color: var(--ink-3); font-size: 12.5px; }
.page-head .spacer { flex: 1; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card > h3 {
  font-size: 14px; color: var(--brand); margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.card > h3 .spacer { flex: 1; }
.card > h3 .count { font-size: 12px; color: var(--ink-4); font-weight: 400; }

.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px) { .grid.c3, .grid.c2 { grid-template-columns: 1fr; } }

/* KPI 磁贴 */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 22px; font-weight: 700; color: var(--brand); margin-top: 6px; letter-spacing: -.4px; }
.kpi .v small { font-size: 12px; font-weight: 400; color: var(--ink-4); margin-left: 4px; }
.kpi .s { font-size: 11.5px; color: var(--ink-4); margin-top: 4px; }
.kpi.accent .v { color: var(--brand-2); }
.kpi.warn .v { color: var(--warn); }
.kpi.danger .v { color: var(--danger); }
.kpi.ok .v { color: var(--ok); }

/* 标签 */
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; line-height: 18px; white-space: nowrap; border: 1px solid transparent;
  background: var(--brand-3); color: var(--brand);
}
.tag.gray { background: #f1f5f9; color: var(--ink-2); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.info { background: var(--info-bg); color: var(--info); }
.tag.purple { background: var(--purple-bg); color: var(--purple); }
.tag.line { background: transparent; border-color: var(--line); color: var(--ink-2); }

/* 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 12.8px; background: #fff; }
table.data th, table.data td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data th { background: #f5f8fc; color: var(--brand); font-weight: 600; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
table.data tbody tr:hover { background: #f8fbff; }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.mono { font-family: var(--mono); font-size: 12px; }
table.data .empty-row td { text-align: center; color: var(--ink-4); padding: 26px; }
.muted { color: var(--ink-4); }

/* 键值对 */
.kvs { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 9px 14px; }
.kv { font-size: 12.8px; border-bottom: 1px dashed var(--line-2); padding-bottom: 6px; min-width: 0; }
.kv .k { color: var(--ink-4); font-size: 11.5px; display: flex; align-items: center; gap: 5px; }
.kv .v { margin-top: 2px; word-break: break-all; }
.kv.wide { grid-column: 1 / -1; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; gap: 6px; font-family: inherit; font-size: 12.8px;
  padding: 6px 13px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff;
  color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f6f9fd; border-color: #cdd9e8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1a4267; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-2); padding: 5px 8px; }
.btn.ghost:hover { background: var(--brand-3); }
.btn.danger { background: #fff; border-color: #f0c4c4; color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 表单行内 */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } }

/* 脱敏徽标 */
.perm-flag { font-size: 10px; padding: 0 5px; border-radius: 4px; margin-left: 4px; vertical-align: middle; }
.perm-MASKED { background: #eef2ff; color: #4338ca; }
.perm-STATS_ONLY { background: #fff7ed; color: #b45309; }
.perm-HIDDEN { background: #f1f5f9; color: #94a3b8; }
.masked-val { color: #4338ca; font-family: var(--mono); font-size: 12px; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 12.5px; color: var(--ink-3); flex-wrap: wrap; }
.pager .spacer { flex: 1; }
.pager .pbtns { display: flex; gap: 4px; }
.pager .pbtns button {
  min-width: 28px; height: 28px; border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 12.5px; color: var(--ink-2);
}
.pager .pbtns button.cur { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .pbtns button:disabled { opacity: .45; cursor: not-allowed; }

/* 工具条 */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select {
  padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 12.8px;
  font-family: inherit; background: #fff; color: var(--ink);
}
.toolbar input[type=text] { min-width: 190px; }
.toolbar .spacer { flex: 1; }

/* 标签页 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  border: none; background: transparent; padding: 8px 13px; font-size: 13px; color: var(--ink-3);
  cursor: pointer; border-bottom: 2px solid transparent; font-family: inherit;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs button:hover { color: var(--brand-2); }

/* 时间轴 */
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.timeline .ti { position: relative; margin-bottom: 13px; }
.timeline .ti::before {
  content: ""; position: absolute; left: -19px; top: 4px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--brand-2); box-shadow: 0 0 0 3px #e8f1fb;
}
.timeline .ti .th { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.timeline .ti .tt { font-size: 13px; font-weight: 600; }
.timeline .ti .tm { font-size: 11.5px; color: var(--ink-4); }
.timeline .ti .tb { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }

/* 阶段条 */
.steps { display: flex; gap: 0; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 6px 10px; }
.step .dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; }
.step.done .dot { background: var(--ok); }
.step.doing .dot { background: var(--brand-2); box-shadow: 0 0 0 3px rgba(46,126,191,.18); }
.step .arrow { color: var(--line); margin: 0 2px; }

/* 简易条形图 */
.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 128px 1fr 120px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-row .lbl { color: var(--ink-2); text-align: right; }
.bar-track { background: #f1f5f9; border-radius: 999px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 999px; min-width: 2px; }
.bar-fill.warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.bar-fill.danger { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.bar-fill.ok { background: linear-gradient(90deg, #15803d, #22c55e); }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* 模态框 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: flex-start;
  justify-content: center; padding: 48px 18px; z-index: 100; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px;
  animation: pop .14s ease-out;
}
.modal.wide { max-width: 860px; }
@keyframes pop { from { transform: translateY(-8px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal .mhead { padding: 15px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .mhead h3 { font-size: 15px; color: var(--brand); }
.modal .mhead .x { margin-left: auto; cursor: pointer; border: none; background: none; font-size: 20px; color: var(--ink-4); line-height: 1; }
.modal .mbody { padding: 18px 20px; }
.modal .mfoot { padding: 13px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 9px; }

/* 提示 */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand-2); border-radius: 8px;
  padding: 11px 15px; box-shadow: var(--shadow-lg); font-size: 13px; max-width: 380px; animation: pop .14s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast .tt { font-weight: 600; margin-bottom: 2px; font-size: 12.8px; }
.toast.warn { border-left-color: var(--warn); }

/* 内联提示块 */
.notice { border-radius: var(--radius-sm); padding: 10px 13px; font-size: 12.5px; margin-bottom: 12px; border: 1px solid; }
.notice.info { background: var(--info-bg); border-color: #bae6fd; color: #155e75; }
.notice.warn { background: var(--warn-bg); border-color: #fed7aa; color: #92400e; }
.notice.danger { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.notice.ok { background: var(--ok-bg); border-color: #bbf7d0; color: #166534; }

.empty { text-align: center; color: var(--ink-4); padding: 34px 16px; font-size: 13px; }
.loading { text-align: center; color: var(--ink-4); padding: 30px; font-size: 13px; }
.spinner {
  display: inline-block; width: 15px; height: 15px; border: 2px solid #dbe4f0; border-top-color: var(--brand-2);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hash { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); word-break: break-all; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.list-plain { margin: 0; padding-left: 18px; font-size: 12.8px; color: var(--ink-2); }
.list-plain li { margin-bottom: 3px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -100%; z-index: 60; transition: left .2s; width: var(--sidebar-w); }
  .sidebar.open { left: 0; }
  .login-card { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .bar-row { grid-template-columns: 84px 1fr 90px; }
}
.menu-toggle { display: none; }
@media (max-width: 860px) { .menu-toggle { display: inline-flex; } }
