:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2329;
  --muted: #8a919c;
  --line: #e5e7eb;
  --line-strong: #d0d4da;
  --primary: #e5486f;
  --primary-soft: #fdebf0;
  --hover: #f7f8fa;
  --danger: #d93026;
  --s0: #9aa1ab; --s1: #d48806; --s2: #2f9e44; --s3: #b0b5bd;
  --radius: 6px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --panel: #1d2024; --text: #e6e8eb; --muted: #8b929c; --line: #2c3036;
    --line-strong: #3a3f46; --primary: #ff6b8e; --primary-soft: #3a2029; --hover: #24282d;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 6px 8px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { width: 100%; resize: vertical; }

.btn {
  border: 1px solid var(--line-strong); background: var(--panel); border-radius: var(--radius);
  padding: 6px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.block { width: 100%; padding: 9px; }
.link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; text-decoration: none; }

/* 登录 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 28px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; }

/* 布局 */
.layout {
  display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 52px 1fr;
  grid-template-areas: "top top" "side main"; height: 100vh;
}
.topbar {
  grid-area: top; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 16px; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.sidebar { grid-area: side; overflow: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 12px 0; }
.main { grid-area: main; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.side-block { padding: 0 12px 16px; }
.side-title { font-size: 12px; color: var(--muted); margin: 0 4px 6px; display: flex; justify-content: space-between; }
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: var(--radius); cursor: pointer;
}
.side-list li:hover { background: var(--hover); }
.side-list li.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-list .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-list .del { visibility: hidden; color: var(--muted); border: none; background: none; cursor: pointer; padding: 0 2px; }
.side-list li:hover .del { visibility: visible; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: var(--bg); border-radius: var(--radius); padding: 8px; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* 筛选 */
.filters { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row.between { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 12px; color: var(--muted); }
.field.grow { flex: 1 1 260px; }
.field select, .field input { width: 100%; }
.field:not(.grow):not(.range) { width: 120px; }
.field.range { width: 150px; }
.pair { display: flex; gap: 4px; }
.input-group { display: flex; }
.input-group select { width: 100px; flex: none; border-radius: var(--radius) 0 0 var(--radius); border-right: none; }
.input-group input { flex: 1; border-radius: 0 var(--radius) var(--radius) 0; }
.checks { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.check, .inline { display: flex; align-items: center; gap: 6px; }
.btns { display: flex; gap: 8px; }

/* 工具栏 */
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.batch { display: flex; gap: 8px; align-items: center; }
.batch.disabled select { opacity: .5; pointer-events: none; }

/* 表格 */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; flex: 1 1 auto; min-height: 200px; }
table.grid { border-collapse: collapse; width: 100%; white-space: nowrap; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.grid thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; font-weight: 600; font-size: 13px; box-shadow: inset 0 -1px var(--line-strong); }
.grid tbody tr:hover { background: var(--hover); }
.grid tbody tr.selected { background: var(--primary-soft); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .cb { width: 32px; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { color: var(--primary); }
.grid th.sorted::after { content: " ↓"; color: var(--primary); }
.grid th.sorted.asc::after { content: " ↑"; }
.grid td.kw { font-weight: 500; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.grid td.kw .other { font-size: 11px; color: var(--muted); margin-left: 4px; }
.grid .empty { text-align: center; color: var(--muted); padding: 40px; }
.nil { color: var(--line-strong); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; border: 1px solid currentColor; }
.st-0 { color: var(--s0); } .st-1 { color: var(--s1); } .st-2 { color: var(--s2); } .st-3 { color: var(--s3); text-decoration: line-through; }
.tag { display: inline-block; background: var(--bg); border-radius: 4px; padding: 1px 6px; font-size: 12px; margin-right: 4px; }
.comp-高 { color: var(--danger); } .comp-中 { color: var(--s1); } .comp-低 { color: var(--s2); }

.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.pager button { min-width: 34px; }
.pager button.current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager input { width: 64px; }

/* 弹窗 */
.dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(480px, calc(100vw - 32px)); background: var(--panel); color: var(--text); }
.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog h2 { margin: 0 0 14px; font-size: 18px; word-break: break-all; }
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.detail-grid div { background: var(--bg); border-radius: var(--radius); padding: 6px 8px; }
.detail-grid span { display: block; font-size: 12px; color: var(--muted); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2329; color: #fff; padding: 8px 16px; border-radius: 6px; z-index: 100; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "top" "side" "main"; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; padding: 12px 4px; }
  .side-block { min-width: 180px; padding-bottom: 0; }
  .main { padding: 12px 16px; overflow: visible; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; }
  .field:not(.grow):not(.range), .field.range { width: calc(50% - 5px); }
}
