:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --bg-2: #ffffff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 25px -5px rgba(15,23,42,.08), 0 4px 10px -4px rgba(15,23,42,.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

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

.sidebar {
  width: 220px;
  background: #101827;
  color: #cbd5e1;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 100;
}
.sidebar .brand {
  padding: 20px 20px 16px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 9px;
}
.sidebar .brand .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #4ade80; flex-shrink: 0;
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: #64748b; margin-top: 2px; }
.sidebar nav { padding: 8px 0 20px; flex: 1; }

/* ---------- 分组（父级） ---------- */
.sidebar .nav-group { margin-bottom: 2px; }
.sidebar .nav-parent {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px 10px 20px; border: none; background: none; cursor: pointer;
  color: #94a3b8; font-size: 12.5px; font-weight: 600; font-family: inherit;
  letter-spacing: .4px; text-align: left; transition: color .15s;
}
.sidebar .nav-parent:hover { color: #e2e8f0; }
.sidebar .nav-parent .np-text { flex: 1; }
.sidebar .nav-parent .chev {
  width: 14px; height: 14px; flex-shrink: 0; opacity: .6;
  transition: transform .22s;
}
.sidebar .nav-group.open .nav-parent .chev { transform: rotate(180deg); }
.sidebar .nav-parent .badge {
  background: var(--danger); color: #fff; font-size: 10.5px;
  padding: 1px 6px; border-radius: 10px; font-weight: 500;
}

/* ---------- 子项 ---------- */
.sidebar .nav-children {
  overflow: hidden; max-height: 0; opacity: 0;
  transition: max-height .26s ease, opacity .2s ease;
}
.sidebar .nav-group.open .nav-children { max-height: 1200px; opacity: 1; }

.sidebar a.nav-child {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px 9px 22px; color: #cbd5e1; font-size: 13.5px;
  border-left: 3px solid transparent; transition: all .15s;
  position: relative;
}
.sidebar a.nav-child::before {
  content: ''; width: 4px; height: 4px; border-radius: 50%;
  background: #475569; flex-shrink: 0; margin-right: -3px;
  transition: background .15s;
}
.sidebar a.nav-child.top-level { padding-left: 20px; font-size: 14px; }
.sidebar a.nav-child.top-level::before { display: none; }
.sidebar a.nav-child:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-child:hover::before { background: #94a3b8; }
.sidebar a.nav-child.active {
  background: linear-gradient(90deg, rgba(37,99,235,.25), rgba(37,99,235,.08));
  color: #fff; border-left-color: var(--primary); font-weight: 500;
}
.sidebar a.nav-child.active::before { background: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.25); }
.sidebar .icon { width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; opacity: .85; font-size: 13px; }
.sidebar .badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 10px; font-weight: 500;
}
.side-close {
  display: none; border: none; background: rgba(255,255,255,.1); color: #cbd5e1;
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  font-size: 17px; line-height: 1; flex-shrink: 0; margin-left: auto;
}

/* 移动端遮罩 */
.sidebar-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 99; opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s;
}
.sidebar-mask.show { opacity: 1; visibility: visible; }
body.no-scroll { overflow: hidden; }

.main { flex: 1; margin-left: 220px; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 顶部图标按钮 */
.menu-btn {
  display: none; width: 36px; height: 36px; flex-shrink: 0;
  border: none; background: none; color: var(--text-2); cursor: pointer;
  align-items: center; justify-content: center; border-radius: 8px;
}
.menu-btn:hover { background: #f1f5f9; }
.menu-btn svg { width: 21px; height: 21px; }
.topbar-btn {
  position: relative; display: inline-flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 10px; border: 1px solid var(--border); background: #fff;
  border-radius: 8px; color: var(--text-2); cursor: pointer; font-family: inherit;
  font-size: 13px; text-decoration: none; transition: all .15s; flex-shrink: 0;
}
.topbar-btn:hover { border-color: var(--primary); color: var(--primary); }
.topbar-btn svg { width: 18px; height: 18px; }
.topbar-btn .dot-badge {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px;
  background: var(--danger); color: #fff; border-radius: 9px; font-size: 10.5px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
  font-weight: 600;
}
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}

.content { padding: 20px 24px 40px; flex: 1; }

/* ---------- 卡片 ---------- */
.card {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-head h3 { font-size: 14.5px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.nopad { padding: 0; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.stat .value { font-size: 25px; font-weight: 600; letter-spacing: -.5px; line-height: 1.2; }
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.stat.primary .value { color: var(--primary); }
.stat.success .value { color: var(--success); }
.stat.warning .value { color: var(--warning); }
.stat.danger .value { color: var(--danger); }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table th {
  text-align: left; padding: 11px 14px; background: #f8fafc;
  color: var(--text-2); font-weight: 500; font-size: 12.5px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table tbody tr:hover { background: #f8fafc; }
table tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
.td-actions { white-space: nowrap; }
.td-actions a, .td-actions button { margin-right: 6px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 13.5px; cursor: pointer;
  transition: all .15s; font-family: inherit; line-height: 1.4; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; border-color: #15803d; color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-lg { padding: 11px 24px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-link { border: none; background: none; color: var(--primary); padding: 4px 2px; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

/* ---------- 表单 ---------- */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; color: var(--text); margin-bottom: 6px; font-weight: 500; }
.form-row label .req { color: var(--danger); margin-left: 3px; }
.form-row .hint { font-size: 12px; color: var(--text-3); margin-top: 5px; line-height: 1.5; }
.form-row.error input, .form-row.error textarea, .form-row.error select { border-color: var(--danger); }

input[type=text], input[type=password], input[type=number], input[type=email],
input[type=tel], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13.5px; font-family: inherit;
  color: var(--text); background: #fff; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.65; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
select { cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 10px; padding-top: 8px; }

.checkbox, .radio { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13.5px; }
.checkbox input, .radio input { width: auto; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 12px; line-height: 1.6; font-weight: 500; white-space: nowrap;
}
.tag-gray { background: #f1f5f9; color: #475569; }
.tag-blue { background: #dbeafe; color: #1d4ed8; }
.tag-green { background: #dcfce7; color: #15803d; }
.tag-amber { background: #fef3c7; color: #b45309; }
.tag-red { background: #fee2e2; color: #b91c1c; }
.tag-purple { background: #ede9fe; color: #6d28d9; }

/* ---------- 工具类 ---------- */
.flex { display: flex; } .flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.text-2 { color: var(--text-2); } .text-3 { color: var(--text-3); }
.text-sm { font-size: 12.5px; } .text-lg { font-size: 16px; }
.text-danger { color: var(--danger); } .text-success { color: var(--success); }
.text-warning { color: var(--warning); } .text-primary { color: var(--primary); }
.bold { font-weight: 600; }
.text-center { text-align: center; } .text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- 分页 ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 16px 0 4px; }
.pagination button {
  min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--border);
  background: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination button:disabled { opacity: .45; cursor: not-allowed; }
.pagination .info { font-size: 12.5px; color: var(--text-3); margin-left: 8px; }

/* ---------- 提示 ---------- */
.alert { padding: 11px 15px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 14px; line-height: 1.6; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.alert-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal {
  background: #fff; border-radius: var(--radius-lg); width: 100%; max-width: 520px;
  max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { font-size: 15px; font-weight: 600; flex: 1; }
.modal-head .close { border: none; background: none; font-size: 20px; color: var(--text-3); cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Toast ---------- */
#toast-box { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 20px; border-radius: var(--radius); font-size: 13.5px;
  background: #1e293b; color: #fff; box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease; max-width: 460px;
}
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.warning { background: #b45309; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--text-3); }
.empty .icon { font-size: 40px; margin-bottom: 10px; opacity: .35; }
.empty p { font-size: 13.5px; }

/* ---------- 加载 ---------- */
.loading { text-align: center; padding: 40px; color: var(--text-3); font-size: 13px; }
.spinner {
  width: 22px; height: 22px; border: 2.5px solid #e2e8f0; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 登录页 ---------- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #3b82f6 100%); padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 36px 34px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(15,23,42,.22);
}
.auth-card h2 { font-size: 21px; font-weight: 600; margin-bottom: 6px; }
.auth-card .sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 26px; }
.auth-card .btn-lg { width: 100%; margin-top: 6px; justify-content: center; }
.auth-links { display: flex; justify-content: space-between; margin-top: 18px; font-size: 13px; }
.captcha-row { display: flex; gap: 10px; }
.captcha-row input { flex: 1; }
.captcha-row img {
  height: 38px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border); flex-shrink: 0; width: 108px; object-fit: cover;
}

/* ---------- Tab ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button {
  padding: 9px 16px; border: none; background: none; cursor: pointer;
  font-size: 13.5px; color: var(--text-2); border-bottom: 2px solid transparent;
  font-family: inherit; white-space: nowrap; transition: all .15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* ---------- 进度/评分条 ---------- */
.score-bar { height: 6px; background: #f1f5f9; border-radius: 3px; overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 3px; transition: width .3s; }
.score-low i { background: var(--success); }
.score-mid i { background: var(--warning); }
.score-high i { background: var(--danger); }

/* ============================================================
   响应式 —— 移动端 / 平板适配
   ============================================================ */

/* ---------- 平板（<= 1024px）---------- */
@media (max-width: 1024px) {
  .content { padding: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 移动端（<= 900px）：侧栏变抽屉 ---------- */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.4, 0, .2, 1);
    box-shadow: 4px 0 24px rgba(15,23,42,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .side-close { display: flex; align-items: center; justify-content: center; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }

  .content { padding: 14px 12px 32px; }
  .topbar { padding: 0 12px; gap: 10px; height: 54px; }
  .topbar h1 { font-size: 15px; }
  .topbar .user .uname { display: none; }
  .topbar-btn .switch-label { display: none; }
  .logout-btn { padding: 5px 10px; font-size: 12.5px; }

  /* 表单栅格统一单列 */
  .form-grid,
  .form-row [style*="grid-template-columns"],
  .card-body > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat .value { font-size: 21px; }

  /* 卡片收紧 */
  .card { border-radius: 10px; margin-bottom: 12px; }
  .card-head { padding: 12px 14px; gap: 8px; flex-wrap: wrap; }
  .card-head h3 { font-size: 14px; }
  .card-body { padding: 14px; }

  /* 表格横向滚动 + 首列固定观感 */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  table { font-size: 13px; min-width: 560px; }
  table th, table td { padding: 9px 10px; }

  /* 弹窗全屏化 */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100% !important; width: 100%;
    max-height: 92vh; border-radius: 16px 16px 0 0;
  }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal.wide { max-width: 100% !important; }

  /* 操作按钮加大触控区 */
  .btn { padding: 9px 15px; }
  .btn-sm { padding: 6px 12px; font-size: 12.5px; }
  .btn-link { padding: 7px 4px; }

  /* 分页 */
  .pagination button { min-width: 36px; height: 36px; }

  /* Toast 顶部留白 */
  #toast-box { top: 12px; width: calc(100% - 24px); }
  .toast { max-width: 100%; }

  /* 登录页 */
  .auth-card { padding: 28px 22px; border-radius: 14px; }
  .auth-links { flex-direction: column; gap: 8px; align-items: flex-start; }
}

/* ---------- 小屏手机（<= 560px）---------- */
@media (max-width: 560px) {
  body { font-size: 13.5px; }
  .content { padding: 12px 10px 28px; }

  .stats { grid-template-columns: 1fr; }
  .stat { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; }
  .stat .label { margin-bottom: 0; }
  .stat .value { font-size: 20px; }
  .stat .sub { display: none; }

  .card-head { flex-direction: column; align-items: stretch; }
  .card-head .spacer { display: none; }
  .card-head input, .card-head select { width: 100% !important; }
  .card-head .btn { width: 100%; }

  /* 表格改用卡片式（每行一块） */
  table { min-width: 100%; }
  .td-actions { white-space: normal; }
  .td-actions .btn-link { display: inline-block; }

  .tabs { gap: 2px; }
  .tabs button { padding: 9px 11px; font-size: 13px; }

  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }

  .modal-body { padding: 14px; }
  .opt-cards { gap: 8px; }

  /* 车牌框等自定义小栅格 */
  .field-pair, .two-col, .form-grid-3 { grid-template-columns: 1fr !important; }
}

/* ---------- 触屏优化 ---------- */
@media (hover: none) {
  .btn:hover { background: #fff; border-color: var(--border); }
  .btn-primary:hover { background: var(--primary); border-color: var(--primary); }
  a.nav-child:hover { background: transparent; }
}

/* 安全区（iPhone 刘海屏） */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 900px) {
    .content { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
    .topbar { padding-top: env(safe-area-inset-top); height: calc(54px + env(safe-area-inset-top)); }
  }
}
