:root {
  --primary: #2563EB;
  --primary-soft: #EFF4FF;
  --text: #14181f;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f6f8;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(20, 24, 40, .05);
  --sidebar: 224px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
button, input, select, textarea { font-family: inherit; font-size: 14px; color: inherit; }
[hidden] { display: none !important; }

/* ---------------- 登录 ---------------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f6f8 45%, #e6f0ff 100%);
}
.login-card {
  width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 18px 46px rgba(23, 37, 84, .12); padding: 32px 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .logo { width: 40px; height: 40px; border-radius: 11px; background: var(--primary); display: grid; place-items: center; }
.login-brand strong { display: block; font-size: 16px; }
.login-brand span { color: var(--muted); font-size: 13px; }
.login-hint {
  margin-top: 18px; padding: 12px 14px; background: #f8fafc; border: 1px dashed var(--line);
  border-radius: 10px; font-size: 13px; color: var(--muted);
}
.login-hint b { color: var(--text); }

/* ---------------- 表单元素 ---------------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; transition: border-color .18s, box-shadow .18s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
.textarea { resize: vertical; min-height: 76px; }
.input[type="time"], .input[type="date"] { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; transition: background .18s, border-color .18s, color .18s, transform .1s;
  white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #fafbfc; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-danger { color: var(--danger); border-color: #f3d0d0; }
.btn-danger:hover { background: #fef2f2; border-color: #eab6b6; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- 布局 ---------------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: #fff; border-right: 1px solid var(--line); padding: 18px 14px;
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.sidebar .brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; flex: none; }
.sidebar .brand strong { font-size: 15px; display: block; line-height: 1.25; }
.sidebar .brand span { font-size: 12px; color: var(--muted); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px;
  border: 0; background: transparent; cursor: pointer; text-align: left; color: #374151;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item svg { flex: none; }
.sidebar .spacer { flex: 1; }
.user-box { border-top: 1px solid var(--line); padding-top: 12px; font-size: 13px; }
.user-box .name { font-weight: 600; }
.user-box .role { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--line); padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { font-size: 13px; color: var(--muted); }
.topbar .crumb b { color: var(--text); font-size: 16px; display: block; }
.content { padding: 20px 24px 48px; flex: 1; }

/* ---------------- 卡片与网格 ---------------- */
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.card-head p { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.toolbar .field { margin-bottom: 0; }
.toolbar .input, .toolbar .select { width: auto; min-width: 130px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 25px; font-weight: 800; margin: 4px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.kpi .note { color: var(--muted); font-size: 12px; }

/* ---------------- 表格 ---------------- */
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th {
  position: sticky; top: 0; background: #fafbfc; color: var(--muted); font-weight: 600;
  font-size: 13px; z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 26px 0; font-size: 14px; }

/* ---------------- 标签 ---------------- */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  border: 1px solid transparent; line-height: 1.7;
}
.tag-ok { background: #eaf7ee; color: var(--ok); border-color: #cdebd6; }
.tag-warn { background: #fff7e6; color: var(--warn); border-color: #fbe3b8; }
.tag-danger { background: #fdeeee; color: var(--danger); border-color: #f6d4d4; }
.tag-info { background: var(--primary-soft); color: var(--primary); border-color: #d6e2ff; }
.tag-muted { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.up { color: var(--danger); }
.down { color: var(--ok); }

/* ---------------- 图表 ---------------- */
.chart svg { display: block; width: 100%; height: auto; }
.axis-label { fill: var(--muted); font-size: 11px; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 11px; }
.bars li { font-size: 13px; }
.bars .row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.bars .row b { font-variant-numeric: tabular-nums; }
.bars .track { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bars .fill { display: block; height: 100%; border-radius: 999px; }

/* ---------------- 弹层 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .42); display: grid; place-items: center;
  padding: 20px; z-index: 60;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 22px 60px rgba(15, 23, 42, .28); max-height: 88vh; display: flex; flex-direction: column; }
.modal > header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal > .body { padding: 18px 20px; overflow: auto; }
.modal > footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal .close { border: 0; background: transparent; cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.modal .close:hover { background: #f3f4f6; }

/* ---------------- 提示条 ---------------- */
.alert { padding: 10px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: #fdeeee; color: var(--danger); border: 1px solid #f6d4d4; }
.alert-ok { background: #eaf7ee; color: var(--ok); border: 1px solid #cdebd6; }
.alert-info { background: var(--primary-soft); color: #1e40af; border: 1px solid #d6e2ff; }

.note { color: var(--muted); font-size: 13px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.hint-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.hint-list li { margin-bottom: 4px; }

/* ---------------- 账号权限管理 ---------------- */
.kv-box {
  display: flex; flex-direction: column; gap: 4px;
  background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.kv-box .kv-label { color: var(--muted); font-size: 12px; }
.kv-box .kv-value { font-weight: 700; font-size: 15px; word-break: break-all; }
.row-ops { display: flex; gap: 6px; justify-content: flex-end; }
.row-self td { background: var(--primary-soft); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  border: 1px solid transparent; line-height: 1.7; font-weight: 600;
}
.badge-admin { background: var(--primary-soft); color: var(--primary); border-color: #d6e2ff; }
.badge-hr { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
td .tag { margin-left: 6px; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; overflow-x: auto;
    gap: 4px; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar .brand { padding: 0 10px 0 0; }
  .sidebar .brand span { display: none; }
  .sidebar .brand div { white-space: nowrap; }
  .sidebar .spacer, .user-box { display: none; }
  .nav-item { white-space: nowrap; padding: 7px 10px; font-size: 13px; }
  .nav-item span { display: inline; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .content { padding: 16px 14px 40px; }
  .topbar { padding: 12px 14px; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .toolbar { width: 100%; }
  .toolbar .field, .toolbar .input, .toolbar .select { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
