:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e2e6ee;
  --border-strong: #ccd3e0;
  --text: #1f2733;
  --muted: #7b8798;
  --accent: #2f6fed;
  --accent-dark: #2258c9;
  --accent-soft: #eaf0fe;
  --danger: #d94a4a;
  --danger-soft: #fdeeee;
  --ok: #1f9d63;
  --ok-soft: #e8f7ef;
  --warn: #b7791f;
  --warn-soft: #fdf5e6;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 8px 24px rgba(20, 30, 50, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

.hidden { display: none !important; }
.flex-1 { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
code {
  background: #eef1f6; border-radius: 4px; padding: 1px 5px;
  font-family: Consolas, "Courier New", monospace; font-size: 12.5px;
}

/* ------------------------------------------------------------ 按钮 */
.btn {
  appearance: none; border: 1px solid var(--border-strong); background: #fff;
  color: var(--text); padding: 7px 14px; border-radius: 6px; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
  font-family: inherit;
}
.btn:hover { background: #f7f9fc; border-color: #b7c0d0; }
.btn:active { background: #eef1f6; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-primary:active { background: #1c4bab; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef1f6; border-color: transparent; color: var(--text); }
.btn-danger-ghost { border-color: #f0c8c8; background: var(--danger-soft); color: var(--danger); }
.btn-danger-ghost:hover { background: #fbdcdc; border-color: #e5a8a8; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #c03c3c; border-color: #c03c3c; }
.btn-block { width: 100%; padding: 10px; font-size: 15px; margin-top: 4px; }
.btn-sm { padding: 3px 9px; font-size: 12.5px; }

.icon-btn {
  border: 0; background: transparent; font-size: 16px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 5px;
}
.icon-btn:hover { background: #eef1f6; color: var(--text); }

/* ------------------------------------------------------------ 登录 */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, #eef3fc 0%, #f4f6f9 55%, #eef0f6 100%);
}
.login-card {
  width: 100%; max-width: 340px; background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 30px 26px 24px; box-shadow: var(--shadow); text-align: center;
}
.login-logo {
  width: 46px; height: 46px; border-radius: 11px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 23px; font-weight: 700; margin: 0 auto 12px;
}
.login-card h1 { margin: 0 0 2px; font-size: 20px; letter-spacing: 2px; }
.login-card .muted { margin: 0 0 20px; }
.login-card label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.login-card input { margin-top: 5px; }

/* ------------------------------------------------------------ 表单控件 */
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 6px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 237, .13);
}
input::placeholder { color: #aab4c2; }
select { cursor: pointer; padding-right: 4px; }
textarea { resize: vertical; min-height: 56px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); cursor: pointer; }

/* ------------------------------------------------------------ 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 18px; height: 54px;
  background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; letter-spacing: 1px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.stats b { color: var(--text); font-size: 13.5px; }
.stats .stat-warn b { color: var(--warn); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------ 面板 */
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  margin: 14px 18px 0;
}
.filter-panel { padding: 12px 14px 10px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px 10px; }
.filter-grid.extra { margin-top: 8px; padding-top: 10px; border-top: 1px dashed var(--border); }
.filter-item { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.filter-item > span { font-size: 12px; color: var(--muted); }
.filter-item.wide { grid-column: span 2; }
.range-row { display: flex; align-items: center; gap: 5px; }
.range-row input { min-width: 0; }
.range-row .tilde { color: var(--muted); font-size: 12px; }
.filter-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

/* ------------------------------------------------------------ 工具条 */
.toolbar { display: flex; align-items: center; gap: 8px; margin: 12px 18px 0; flex-wrap: wrap; }

.colpick { position: relative; }
.colpick-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px; width: 210px; max-height: 60vh; overflow: auto;
}
.colpick-menu label {
  display: flex; align-items: center; gap: 7px; padding: 4px 6px;
  border-radius: 5px; font-size: 13px; cursor: pointer;
}
.colpick-menu label:hover { background: #f4f6fa; }
.colpick-menu .colpick-actions {
  display: flex; gap: 6px; padding: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border);
}

/* ------------------------------------------------------------ 表格 */
.table-panel { overflow: hidden; margin-bottom: 18px; }
.table-scroll { overflow: auto; max-height: calc(100vh - 320px); min-height: 160px; }
table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 10; background: #f7f9fc;
  border-bottom: 1px solid var(--border-strong); text-align: left; font-weight: 600;
  padding: 9px 10px; white-space: nowrap; color: #4a5666; font-size: 12.5px;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { background: #eef2f8; }
thead th .arrow { color: var(--accent); margin-left: 3px; font-size: 10px; }
tbody td {
  padding: 8px 10px; border-bottom: 1px solid #eef1f6; white-space: nowrap;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
tbody tr:hover td { background: #f8fafd; }
tbody tr.selected td { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.center, th.center { text-align: center; }

th.sticky-l1, td.sticky-l1 { position: sticky; left: 0; z-index: 11; background: #fff; }
th.sticky-l2, td.sticky-l2 {
  position: sticky; left: 38px; z-index: 11; background: #fff;
  box-shadow: 1px 0 0 var(--border);
}
thead th.sticky-l1, thead th.sticky-l2 { background: #f7f9fc; z-index: 12; }
tbody tr:hover td.sticky-l1, tbody tr:hover td.sticky-l2 { background: #f8fafd; }
tbody tr.selected td.sticky-l1, tbody tr.selected td.sticky-l2 { background: var(--accent-soft); }

th.sticky-r, td.sticky-r {
  position: sticky; right: 0; z-index: 11; background: #fff;
  box-shadow: -1px 0 0 var(--border);
}
thead th.sticky-r { background: #f7f9fc; z-index: 12; }
tbody tr:hover td.sticky-r { background: #f8fafd; }
tbody tr.selected td.sticky-r { background: var(--accent-soft); }

.cell-name { font-weight: 600; cursor: pointer; color: var(--accent); }
.cell-name:hover { text-decoration: underline; }
.cell-actions { display: flex; gap: 2px; }
.tag {
  display: inline-block; min-width: 26px; text-align: center; padding: 1px 7px;
  border-radius: 10px; font-size: 12px; line-height: 17px;
}
.tag-yes { background: var(--ok-soft); color: var(--ok); }
.tag-no { background: #f1f3f7; color: #8b95a5; }
.tag-other { background: var(--warn-soft); color: var(--warn); }
.dash { color: #c3cad6; }

.table-empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.table-empty p { margin: 0 0 14px; }

.pager {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px;
  border-top: 1px solid var(--border); background: #fcfdfe; flex-wrap: wrap;
}
.pager .pageinfo { font-size: 13px; color: var(--muted); }
.pager .flex-1 { flex: 1; }
.pager select { width: auto; padding: 4px 8px; }
.pager .btn { padding: 4px 10px; font-size: 12.5px; }

/* ------------------------------------------------------------ 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(24, 32, 46, .42); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow: auto;
}
.modal {
  background: #fff; border-radius: 10px; box-shadow: var(--shadow); width: 100%;
  max-width: 620px; display: flex; flex-direction: column; max-height: calc(100vh - 80px);
}
.modal-lg { max-width: 880px; }
.modal-sm { max-width: 400px; }
.modal-head {
  display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; overflow: auto; flex: 1; }
.modal-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 18px;
  border-top: 1px solid var(--border); background: #fcfdfe; border-radius: 0 0 10px 10px;
}
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
.form-grid .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-grid .field > label { font-size: 12.5px; color: var(--muted); }
.form-grid .field.span2 { grid-column: span 2; }
.form-grid .field.span3 { grid-column: span 3; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label { font-size: 13px; color: var(--muted); }
.req::after { content: " *"; color: var(--danger); }

.form-error {
  background: var(--danger-soft); color: var(--danger); border: 1px solid #f0c8c8;
  padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-top: 10px;
}
.steps { margin: 0 0 16px; padding-left: 20px; color: #4a5666; font-size: 13.5px; }
.steps li { margin-bottom: 5px; }
.radio-row { display: flex; flex-direction: column; gap: 5px; }
.radio { display: flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; }

.import-result {
  border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px;
  background: #fafbfd; font-size: 13.5px; max-height: 320px; overflow: auto;
}
.import-result h4 { margin: 0 0 8px; font-size: 14px; }
.import-result .nums { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.import-result .nums span { color: var(--muted); }
.import-result .nums b { font-size: 16px; }
.import-result .n-ok b { color: var(--ok); }
.import-result .n-warn b { color: var(--warn); }
.import-result .n-skip b { color: var(--muted); }
.problem-list { margin: 8px 0 0; padding-left: 18px; color: #6b7686; max-height: 190px; overflow: auto; }
.problem-list li { margin-bottom: 3px; }

/* ------------------------------------------------------------ Toast */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #232b38; color: #fff; padding: 9px 18px; border-radius: 20px;
  font-size: 13.5px; z-index: 200; box-shadow: var(--shadow); max-width: 80vw;
}
.toast.ok { background: #1c7a51; }
.toast.err { background: #b83a3a; }

/* ------------------------------------------------------------ 响应式 */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid .field.span3 { grid-column: span 2; }
  .stats { display: none; }
  .panel, .toolbar { margin-left: 10px; margin-right: 10px; }
  .modal-mask { padding: 16px 8px; }
}
@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .field.span2, .form-grid .field.span3 { grid-column: span 1; }
  .topbar { gap: 8px; padding: 0 10px; }
}
