:root {
  --primary: #2f6fed;
  --primary-dark: #1f57c9;
  --bg: #f4f6fb;
  --sidebar: #1f2a44;
  --sidebar-hover: #2c3a5c;
  --text: #253046;
  --muted: #7b8698;
  --border: #e3e8f0;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
body.modal-open { overflow: hidden; }

button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2f6fed 0%, #6b3df5 100%);
  padding: 20px;
}
.login-card {
  width: 380px;
  max-width: 100%;
  background: #fff;
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.login-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.login-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.login-tabs button {
  flex: 1; padding: 8px; border: none; background: #eef1f7; border-radius: var(--radius);
  color: var(--muted); font-weight: 600;
}
.login-tabs button.active { background: var(--primary); color: #fff; }

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; outline: none; background: #fff;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 111, 237, .12);
}
.field input:disabled, .field select:disabled { background: #f4f6fb; color: var(--muted); }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint-block { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: none; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 500;
  transition: background .15s ease;
}
.btn:hover:not(:disabled) { background: var(--primary-dark); }
.btn.block { width: 100%; padding: 11px; }
.btn.ghost { background: #eef1f7; color: var(--text); }
.btn.ghost:hover:not(:disabled) { background: #e1e6f0; }
.btn.danger { background: var(--danger); }
.btn.danger:hover:not(:disabled) { background: #b91c1c; }
.btn.success { background: var(--success); }
.btn.success:hover:not(:disabled) { background: #15803d; }
.btn.sm { padding: 5px 11px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px; background: var(--sidebar); color: #cbd5e1; flex-shrink: 0;
  display: flex; flex-direction: column;
}
.sidebar .brand {
  padding: 20px 18px; font-size: 16px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar nav { padding: 10px 0; flex: 1; }
.sidebar nav a {
  display: block; padding: 11px 20px; color: #cbd5e1; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar nav a.active {
  background: var(--sidebar-hover); color: #fff; border-left-color: var(--primary);
}
.sidebar .foot {
  padding: 14px 18px; font-size: 12px; color: #93a1b8;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.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; gap: 12px; padding: 0 22px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-size: 17px; font-weight: 700; flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.topbar .who b { color: var(--text); }

.hamburger {
  display: none; background: none; border: none; font-size: 20px;
  color: var(--text); padding: 4px 6px; line-height: 1;
}
.backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 30;
}
.backdrop.show { display: block; }

.content { padding: 22px; flex: 1; min-width: 0; }
.page-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.hidden { display: none !important; }

/* 致命错误页 */
.fatal {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px;
}
.fatal h2 { font-size: 20px; }
.fatal p { color: var(--muted); }

/* ---------------- 卡片 ---------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.card {
  background: #fff; border-radius: var(--radius); padding: 18px;
  box-shadow: 0 1px 3px rgba(20, 30, 60, .06);
}
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 6px; }
.card.clickable { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20, 30, 60, .12); }

/* ---------------- 面板 / 表格 ---------------- */
.panel {
  background: #fff; border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(20, 30, 60, .06); overflow: hidden;
}
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); align-items: center;
}
.toolbar input, .toolbar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; outline: none; font-family: inherit;
}
.toolbar .spacer { flex: 1; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: #fafbfe; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #f8faff; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 6px; }
td.up { color: var(--success); font-weight: 600; }
td.down { color: var(--danger); font-weight: 600; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty > div { margin-bottom: 12px; }

.mini-table { max-height: 200px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.mini-table table { min-width: 0; }
.mini-table th, .mini-table td { padding: 7px 10px; font-size: 12px; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; white-space: nowrap; }
.tag.green { background: #e7f7ee; color: #15803d; }
.tag.gray { background: #eef1f7; color: #5b6675; }
.tag.blue { background: #e8f0fe; color: #1f57c9; }
.tag.orange { background: #fdf1e3; color: #b45309; }
.tag.red { background: #fdeaea; color: #b91c1c; }

/* ---------------- 分页 ---------------- */
.pager {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; color: var(--muted); font-size: 13px;
}
.pager .pager-total { margin-right: auto; }
.pager select {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; font-family: inherit;
}

/* ---------------- 模态框 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; width: 460px; max-width: 100%;
  max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modal.wide { width: 620px; }
.modal h3 { padding: 18px 22px; border-bottom: 1px solid var(--border); font-size: 16px; }
.modal .body { padding: 20px 22px; }
.modal .foot {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal .row { display: flex; gap: 12px; }
.modal .row .field { flex: 1; min-width: 0; }
.confirm-text { font-size: 14px; line-height: 1.7; }

.kv { display: flex; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.kv .k { width: 90px; color: var(--muted); flex-shrink: 0; }

/* ---------------- 提示 ---------------- */
#toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 90vw;
}
.toast {
  padding: 10px 20px; border-radius: 8px; color: #fff; font-size: 13px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .2); animation: fade .2s ease;
}
.toast.ok { background: var(--success); }
.toast.err { background: var(--danger); }
@keyframes fade { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; } }

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, .2);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .topbar { padding: 0 14px; }
  .topbar .who-name { display: none; }
  .content { padding: 14px; }
}

@media (max-width: 560px) {
  .modal .row { flex-direction: column; gap: 0; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
  .card .v { font-size: 22px; }
  .toolbar > input, .toolbar > select { flex: 1 1 45%; width: auto !important; }
  .pager { justify-content: center; }
  .pager .pager-total { width: 100%; text-align: center; margin-right: 0; }
}
