/* =====================================================================
 * 运营后台样式 · 专业中后台质感（对标 Ant Design 类中后台）
 * 设计令牌 → 通用组件 → 框架布局 → 业务区块
 * 保留既有 class 名，向后兼容 core.js helper 生成的 DOM
 * ===================================================================== */

/* ---------- 2. 设计令牌 ---------- */
:root {
  /* 背景 / 面板 / 边框 */
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e8ecf1;
  --border-light: #eef1f5;

  /* 文字 */
  --text: #1d2129;
  --text-sub: #4e5969;
  --text-muted: #86909c;
  --text-placeholder: #c9cdd4;

  /* 主色 */
  --primary: #2563eb;
  --primary-hover: #1d5fd6;
  --primary-light: #e8f1fe;
  --primary-dark: #1d5fd6;

  /* 语义色 */
  --success: #00b42a;
  --success-light: #e8ffea;
  --warning: #ff7d00;
  --warning-light: #fff7e8;
  --danger: #f53f3f;
  --danger-light: #ffece8;
  --info: #165dff;
  --info-light: #e8f0fe;

  /* 侧边栏 */
  --sidebar: #171c26;
  --sidebar-text: #a9b2bf;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(37, 99, 235, 0.18);

  /* 圆角 */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-pill: 10px;

  /* 阴影 */
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, 0.18);
  --shadow: var(--shadow-card);

  /* 间距节奏：4 / 8 / 12 / 16 / 20 / 24 / 32 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* 字号层级 */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-body: 14px;
  --fs-block: 15px;
  --fs-card: 16px;
  --fs-metric: 24px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

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

html, body { height: 100%; }

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

.hidden { display: none !important; }

/* 细滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3d9e0; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #b8c1cc; }
::-webkit-scrollbar-track { background: transparent; }

/* focus 可见 */
:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 1px; }

/* =====================================================================
 * 3. 通用组件
 * ===================================================================== */

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: var(--radius-sm); font-size: var(--fs-sm); font-family: var(--font);
  cursor: pointer; white-space: nowrap; line-height: 1;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-danger { color: var(--danger); border-color: #f6c6c6; background: var(--panel); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border: none; background: transparent; color: var(--text-sub); }
.btn-ghost:hover { color: var(--primary); background: var(--primary-light); }

.btn-sm { height: 28px; padding: 0 10px; font-size: var(--fs-xs); border-radius: 5px; }
.btn-block { width: 100%; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn .loading { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 表单控件 ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: var(--fs-xs); color: var(--text-sub); }

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], select, textarea {
  height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0 10px; font-size: var(--fs-sm); font-family: var(--font);
  background: #fff; color: var(--text); min-width: 120px; width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { height: auto; resize: vertical; min-height: 64px; padding: 8px 10px; line-height: 1.5; }
select { min-width: 120px; }

input::placeholder, textarea::placeholder { color: var(--text-placeholder); }
input:hover, select:hover, textarea:hover { border-color: #c9d2dc; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }

/* 带前缀图标的输入框 */
.input-wrap { position: relative; }
.input-wrap .prefix {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); display: flex; pointer-events: none;
}
.input-wrap input { padding-left: 32px; }

/* ---------- 面板 / 工具栏 ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: var(--sp-4);
  margin-bottom: var(--sp-4); box-shadow: var(--shadow-card);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-3); gap: 10px; flex-wrap: wrap;
}
.panel-title { font-weight: 600; font-size: var(--fs-block); color: var(--text); }

.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: var(--sp-3);
}
.toolbar .field { min-width: 140px; }

/* ---------- 指标卡 ---------- */
.grid-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--sp-4); margin-bottom: var(--sp-4);
}
.metric-card {
  position: relative; background: var(--panel); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: var(--sp-4);
  box-shadow: var(--shadow-card); overflow: hidden;
}
.metric-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--primary); opacity: 0; transition: opacity .15s ease;
}
.metric-card:hover::before { opacity: 1; }
.metric-label { font-size: var(--fs-xs); color: var(--text-sub); margin-bottom: 8px; }
.metric-value { font-size: var(--fs-metric); font-weight: 700; color: var(--text); line-height: 1.2; }
.metric-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; }

/* 待办卡片数量角标 */
.todo-card { cursor: pointer; }
.todo-badge {
  position: absolute; top: 12px; right: 12px;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill);
  background: var(--danger-light); color: var(--danger);
  font-size: var(--fs-xs); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- 网格 ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border-light);
  text-align: left; white-space: nowrap;
}
.table th {
  color: var(--text-sub); font-weight: 600; background: #f7f8fa; font-size: var(--fs-xs);
}
.table tbody tr { transition: background .12s ease; }
.table tbody tr:hover td { background: #f7f9fc; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .link { color: var(--primary); cursor: pointer; }
.table .link:hover { text-decoration: underline; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--radius-pill); font-size: var(--fs-xs);
  background: #eef2f6; color: var(--text-sub); line-height: 1.5;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.success { background: var(--success-light); color: var(--success); }
.badge.warning { background: var(--warning-light); color: var(--warning); }
.badge.danger { background: var(--danger-light); color: var(--danger); }
.badge.info { background: var(--info-light); color: var(--info); }
.badge.dot::before { opacity: 1; }

/* ---------- 空状态 ---------- */
.empty {
  text-align: center; color: var(--text-muted); padding: 40px 0; font-size: var(--fs-sm);
}
.empty::before {
  content: ""; display: block; width: 40px; height: 40px; margin: 0 auto 10px;
  border-radius: var(--radius); background: var(--border-light);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386909c' stroke-width='1.6'%3E%3Cpath d='M4 7h16v10H4z'/%3E%3Cpath d='M9 11h6'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386909c' stroke-width='1.6'%3E%3Cpath d='M4 7h16v10H4z'/%3E%3Cpath d='M9 11h6'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ---------- 分页 ---------- */
.pager {
  display: flex; align-items: center; gap: 10px; margin-top: var(--sp-3);
  justify-content: flex-end; flex-wrap: wrap;
}
.pager .total { color: var(--text-muted); font-size: var(--fs-xs); }
.pager select { height: 28px; min-width: 110px; font-size: var(--fs-xs); }
.pager .btn-sm { min-width: 64px; }

/* ---------- 抽屉 ---------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(15, 22, 32, 0.35); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 90vw;
  background: var(--panel); z-index: 41; box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
}
.drawer-head {
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-title { font-weight: 600; font-size: var(--fs-card); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-5); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 22, 32, 0.35); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--panel); border-radius: var(--radius); width: 520px; max-width: 92vw;
  max-height: 86vh; display: flex; flex-direction: column; box-shadow: var(--shadow-pop);
}
.modal-head {
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border-light);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-weight: 600; font-size: var(--fs-card); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot {
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border-light);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---------- 表单网格 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.form-grid .full { grid-column: 1 / -1; }
.form-row { margin-bottom: var(--sp-4); }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- 描述列表 ---------- */
.desc {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 24px; font-size: var(--fs-sm);
}
.desc dt { color: var(--text-sub); font-size: var(--fs-xs); }
.desc dd { color: var(--text); margin-top: 2px; }
@media (max-width: 640px) { .desc { grid-template-columns: 1fr; } }

/* ---------- 标签页 ---------- */
.sub-tabs { display: flex; gap: 4px; margin-bottom: var(--sp-3); flex-wrap: wrap; }
.sub-tabs .tab {
  padding: 6px 14px; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-sub); font-size: var(--fs-sm);
  transition: background .15s ease, color .15s ease;
}
.sub-tabs .tab:hover { color: var(--primary); }
.sub-tabs .tab.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }

/* ---------- 地图占位 ---------- */
.map-box {
  background: var(--border-light); border: 1px dashed var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted);
  min-height: 280px; text-align: center; padding: var(--sp-5); font-size: var(--fs-sm);
}
.map-canvas { width: 100%; height: 320px; border-radius: var(--radius); overflow: hidden; }

/* ---------- 条形图（纯 CSS） ---------- */
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 72px; gap: 10px; align-items: center; font-size: var(--fs-xs); }
.bar-row > b { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-track { background: var(--border-light); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 6px; transition: width .3s ease; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.toast {
  background: var(--sidebar); color: #fff; padding: 10px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop); font-size: var(--fs-sm); max-width: 70vw;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- 内联键值 ---------- */
.kv-inline { display: flex; gap: 18px; flex-wrap: wrap; font-size: var(--fs-sm); }
.kv-inline b { color: var(--text); font-weight: 600; }
.kv-inline span { color: var(--text-sub); }

/* ---------- 工具类 ---------- */
.section-title { font-weight: 600; margin: var(--sp-4) 0 10px; font-size: var(--fs-sm); color: var(--text); }
.muted { color: var(--text-muted); }
.mt12 { margin-top: var(--sp-3); }
.mb12 { margin-bottom: var(--sp-3); }
.btn-group, .actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar.flat { margin-bottom: 0; }

/* =====================================================================
 * 4. 框架布局
 * ===================================================================== */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; background: var(--sidebar); color: var(--sidebar-text);
  flex-shrink: 0; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; height: 56px;
  padding: 0 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-logo, .login-logo {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
.brand-text { font-weight: 600; color: #fff; font-size: var(--fs-body); }

.menu { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.menu-group-title {
  font-size: 11px; color: var(--text-muted); padding: 14px 10px 6px;
  letter-spacing: 1px; text-transform: uppercase;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; cursor: pointer;
  color: var(--sidebar-text); text-decoration: none; border-left: 3px solid transparent;
  border-radius: 6px; font-size: var(--fs-sm);
  transition: background .15s ease, color .15s ease;
}
.menu-item .menu-icon { display: flex; align-items: center; color: inherit; flex-shrink: 0; }
.menu-item .menu-icon svg { width: 16px; height: 16px; }
.menu-item:hover { background: var(--sidebar-hover); color: #fff; }
.menu-item.active {
  background: var(--sidebar-active); color: #fff;
  border-left-color: var(--primary);
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-5); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: var(--fs-block); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; font-size: var(--fs-sm); }
.user-role { font-size: 11px; color: var(--text-muted); }

.content { flex: 1; padding: var(--sp-5); overflow-x: auto; }

/* ---------- 响应式 ≤992px ---------- */
@media (max-width: 992px) {
  .sidebar { width: 64px; }
  .sidebar-brand { justify-content: center; padding: 0 8px; }
  .brand-text, .menu-item span.menu-text, .menu-group-title { display: none; }
  .menu-item { justify-content: center; padding: 10px 0; }
  .menu-group-title { padding: 10px 0 4px; }
  .content { padding: var(--sp-3); }
  .topbar-right { gap: 8px; }
}

/* =====================================================================
 * 5. 登录页
 * ===================================================================== */

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #171c26 0%, #2c3e50 100%);
  padding: 20px;
}
.login-card {
  width: 400px; max-width: 100%; background: var(--panel);
  border-radius: 12px; box-shadow: var(--shadow-pop); padding: 32px 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand .login-logo { width: 42px; height: 42px; font-size: 20px; border-radius: 10px; }
.login-title { font-size: var(--fs-card); font-weight: 600; }
.login-sub { font-size: var(--fs-xs); color: var(--text-sub); margin-top: 2px; }
.login-card .field { margin-bottom: var(--sp-4); }
.login-error {
  color: var(--danger); font-size: var(--fs-sm); margin: 4px 0 12px;
  background: var(--danger-light); border-radius: var(--radius-sm); padding: 8px 12px;
}

/* ---------- 字典维护页 ---------- */
.dict-layout { display: grid; grid-template-columns: 280px 1fr; gap: var(--sp-4); align-items: start; }
@media (max-width: 1100px) { .dict-layout { grid-template-columns: 1fr; } }
.dict-type-list { display: flex; flex-direction: column; gap: 8px; }
.dict-type-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; background: var(--panel); transition: border-color .15s ease, background .15s ease; }
.dict-type-item:hover { border-color: var(--primary); }
.dict-type-item.active { border-color: var(--primary); background: var(--primary-light); }
.dict-type-item .t-name { font-weight: 600; font-size: var(--fs-sm); }
.dict-type-item .t-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: var(--fs-xs); color: var(--text-sub); }
.dict-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
