:root {
  --primary: #1668dc;
  --primary-dark: #0f4fa8;
  --primary-light: #e8f1ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #1f2937;
  --text-2: #56637a;
  --text-3: #8b96a8;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .1);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --head-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 13px; color: var(--text); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c9d1dd; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #aeb9c9; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ 登录页 ============ */
#login-view {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1668dc 0%, #0b3f8f 55%, #072a63 100%);
  z-index: 100;
}
#login-view::before {
  content: ''; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 20% 30%, rgba(255,255,255,.14), transparent 42%),
                    radial-gradient(circle at 80% 70%, rgba(255,255,255,.1), transparent 40%);
}
.login-card {
  position: relative; width: 380px; padding: 36px 34px 30px;
  background: #fff; border-radius: 14px; box-shadow: 0 24px 70px rgba(0, 0, 0, .3);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-logo svg { width: 34px; height: 34px; }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.login-card .sub { color: var(--text-3); font-size: 12px; margin: 6px 0 26px; }
.login-card label { display: block; font-size: 12px; color: var(--text-2); margin: 0 0 6px; }
.login-card .field { margin-bottom: 16px; }
.login-card input {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); outline: none; transition: .15s;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,104,220,.13); }
.login-card button {
  width: 100%; height: 40px; margin-top: 6px; border: 0; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; transition: .15s;
}
.login-card button:hover { background: var(--primary-dark); }
.login-card button:disabled { opacity: .6; cursor: not-allowed; }
.login-err { min-height: 18px; color: var(--danger); font-size: 12px; margin-top: 10px; text-align: center; }
.login-tip { margin-top: 18px; text-align: center; font-size: 11px; color: var(--text-3); }

/* ============ 布局 ============ */
#app { display: none; height: 100%; flex-direction: column; }
#app.on { display: flex; }
.topbar {
  height: var(--head-h); flex: 0 0 var(--head-h); display: flex; align-items: center;
  padding: 0 18px; background: #fff; border-bottom: 1px solid var(--border); gap: 14px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: .3px; }
.brand svg { width: 26px; height: 26px; }
.topnav { display: flex; gap: 2px; margin-left: 20px; }
.topnav button {
  height: 34px; padding: 0 15px; border: 0; background: transparent; color: var(--text-2);
  border-radius: 7px; cursor: pointer; font-size: 13px; transition: .15s;
}
.topnav button:hover { background: #f1f5f9; color: var(--text); }
.topnav button.on { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.topbar .spacer { flex: 1; }
.sse-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.sse-dot i { width: 7px; height: 7px; border-radius: 50%; background: #cbd5e1; display: block; }
.sse-dot.live i { background: var(--success); box-shadow: 0 0 0 3px rgba(22,163,74,.16); }
.userbox { display: flex; align-items: center; gap: 8px; position: relative; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.userbox .name { font-size: 13px; }
.userbox .role { font-size: 11px; color: var(--text-3); }
.menu {
  position: absolute; right: 0; top: 40px; min-width: 160px; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 5px; display: none; z-index: 60;
}
.menu.on { display: block; }
.menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent;
  border-radius: 6px; cursor: pointer; color: var(--text);
}
.menu button:hover { background: #f1f5f9; }

.main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 18px 18px; gap: 12px; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; gap: 12px; }
.view.on { display: flex; }

/* ============ 工具栏 ============ */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow-sm);
}
.toolbar .grow { flex: 1; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); }
.search-box input { width: 260px; height: 32px; padding: 0 10px 0 30px; }

input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  height: 32px; padding: 0 9px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: #fff; outline: none; transition: .12s;
}
textarea { height: auto; padding: 7px 9px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,104,220,.12); }
input:disabled, select:disabled { background: #f6f8fa; color: var(--text-3); }
select { cursor: pointer; padding-right: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; }

.btn {
  height: 32px; padding: 0 13px; border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: .13s; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border-strong); color: var(--text); }
.btn svg { width: 15px; height: 15px; }
.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.danger { color: var(--danger); border-color: #f3c5c5; }
.btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f5f9; color: var(--text); }

/* ============ 表格 ============ */
.table-wrap {
  flex: 1; min-height: 0; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; overflow: hidden;
}
.table-scroll { flex: 1; min-height: 0; overflow: auto; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
table.grid th {
  position: sticky; top: 0; z-index: 5; background: #f8fafc; text-align: left; font-weight: 600;
  color: var(--text-2); font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap; user-select: none;
}
table.grid th.sortable { cursor: pointer; }
table.grid th.sortable:hover { color: var(--primary); }
table.grid td {
  padding: 8px 10px; border-bottom: 1px solid #f0f3f7; white-space: nowrap;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover > td { background: #f7fafd; }
table.grid tbody tr.sel > td { background: var(--primary-light); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid .ck { width: 34px; text-align: center; }
table.grid .exp { width: 28px; text-align: center; color: var(--text-3); }
table.grid .exp span { display: inline-block; transition: transform .15s; }
table.grid tr.expanded .exp span { transform: rotate(90deg); color: var(--primary); }
.wb-no { font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; }
.sub-row > td { background: #fbfcfe !important; padding: 0 !important; }
.sub-box { padding: 10px 12px 12px 44px; }
.sub-box table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.sub-box th { background: #f1f5f9; font-size: 11.5px; padding: 6px 9px; text-align: left; color: var(--text-2); white-space: nowrap; }
.sub-box td { padding: 6px 9px; border-top: 1px solid #eef2f6; white-space: nowrap; }
.sub-empty { color: var(--text-3); padding: 8px 2px; font-size: 12px; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11.5px; line-height: 18px; background: #eef2f7; color: var(--text-2); }
.tag.blue { background: #e7f0ff; color: #1668dc; }
.tag.green { background: #e6f6ec; color: #16a34a; }
.tag.orange { background: #fdf0e0; color: #d97706; }
.tag.gray { background: #f0f2f5; color: #64748b; }
.count-pill { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 20px; background: #eef2f7; color: var(--text-2); font-size: 11.5px; text-align: center; }
.count-pill.has { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.pager { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-top: 1px solid var(--border); background: #fcfdfe; }
.pager .info { color: var(--text-3); font-size: 12px; }
.pager .spacer { flex: 1; }
.pager button { min-width: 30px; height: 28px; }

.empty { padding: 60px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 54px; height: 54px; opacity: .45; margin-bottom: 12px; }
.empty p { margin: 4px 0; }

/* ============ 抽屉 / 弹窗 ============ */
.mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 200; display: none; }
.mask.on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(1180px, 94vw); background: var(--bg);
  z-index: 210; box-shadow: var(--shadow-lg); display: none; flex-direction: column; transform: translateX(20px);
}
.drawer.on { display: flex; animation: slidein .22s cubic-bezier(.22,.61,.36,1) forwards; }
@keyframes slidein { to { transform: translateX(0) } }
.drawer-head {
  height: 56px; flex: 0 0 56px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.drawer-head .spacer { flex: 1; }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px 20px; }
.drawer-foot {
  flex: 0 0 auto; padding: 11px 16px; background: #fff; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}

.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 14px; }
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 14px; }
.hint { color: var(--text-3); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px 16px; }
.form-item { display: flex; flex-direction: column; gap: 5px; }
.form-item.wide { grid-column: span 2; }
.form-item label { font-size: 12px; color: var(--text-2); }
.form-item label .req { color: var(--danger); margin-left: 2px; }
.form-item input, .form-item select, .form-item textarea { width: 100%; }

/* 明细可编辑表格 */
.items-table-wrap { overflow: auto; max-height: 52vh; border: 1px solid var(--border); border-radius: 6px; }
table.edit-grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.edit-grid th {
  position: sticky; top: 0; z-index: 3; background: #f8fafc; padding: 7px 8px; font-size: 12px; font-weight: 600;
  color: var(--text-2); border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left;
}
table.edit-grid td { padding: 0; border-bottom: 1px solid #f0f3f7; }
table.edit-grid td input, table.edit-grid td select {
  width: 100%; min-width: 110px; height: 30px; border: 0; border-radius: 0; background: transparent; padding: 0 8px;
}
table.edit-grid td input:focus, table.edit-grid td select:focus {
  box-shadow: inset 0 0 0 2px var(--primary); background: #fff; position: relative; z-index: 2;
}
table.edit-grid td.rowno { width: 42px; text-align: center; color: var(--text-3); font-size: 12px; background: #fafbfc; }
table.edit-grid td.act { width: 46px; text-align: center; }
table.edit-grid tr:hover td.rowno { background: #f1f5f9; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--text-3); padding: 4px; border-radius: 4px; line-height: 0; }
.icon-btn:hover { color: var(--danger); background: #fee2e2; }
.icon-btn svg { width: 15px; height: 15px; }

/* ============ 模态框 ============ */
.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -48%);
  width: min(760px, 94vw); max-height: 88vh; background: #fff; border-radius: 12px;
  box-shadow: var(--shadow-lg); z-index: 220; display: none; flex-direction: column; overflow: hidden;
}
.modal.on { display: flex; animation: pop .18s ease forwards; }
.modal.wide { width: min(1080px, 96vw); }
@keyframes pop { from { opacity: .4; transform: translate(-50%, -46%) scale(.98) } to { opacity: 1; transform: translate(-50%, -50%) scale(1) } }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 16px 18px; overflow: auto; flex: 1; min-height: 0; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; background: #fcfdfe; }

.close-x { border: 0; background: transparent; cursor: pointer; color: var(--text-3); padding: 5px; border-radius: 6px; line-height: 0; }
.close-x:hover { background: #f1f5f9; color: var(--text); }
.close-x svg { width: 17px; height: 17px; }

/* ============ Toast ============ */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 9px 16px; border-radius: 7px; background: #fff; box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; font-size: 13px; animation: drop .2s ease;
}
@keyframes drop { from { opacity: 0; transform: translateY(-10px) } to { opacity: 1; transform: none } }
.toast.ok { border-color: #b7e2c5; background: #f2fbf5; color: #15803d; }
.toast.err { border-color: #f5c2c2; background: #fef4f4; color: #b91c1c; }
.toast.warn { border-color: #f6ddb3; background: #fffbf2; color: #b45309; }

/* ============ 步骤条 ============ */
.steps { display: flex; align-items: center; gap: 0; margin-bottom: 16px; }
.step { display: flex; align-items: center; gap: 8px; color: var(--text-3); }
.step i {
  width: 22px; height: 22px; border-radius: 50%; background: #eef2f7; color: var(--text-3);
  display: grid; place-items: center; font-size: 11.5px; font-style: normal; font-weight: 600;
}
.step.on { color: var(--primary); font-weight: 600; }
.step.on i { background: var(--primary); color: #fff; }
.step.done i { background: #d6ebd9; color: var(--success); }
.step-line { flex: 1; height: 1px; background: var(--border); margin: 0 12px; }

.map-table { width: 100%; border-collapse: collapse; }
.map-table th { text-align: left; font-size: 12px; color: var(--text-2); padding: 6px 8px; background: #f8fafc; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.map-table td { padding: 5px 8px; border-bottom: 1px solid #f2f5f8; }
.map-table select, .map-table input { width: 100%; }
.map-table .fname { font-size: 12.5px; }
.map-table .fkey { font-size: 11px; color: var(--text-3); }
.map-scroll { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.matched { color: var(--success); font-size: 11px; }

.preview-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 12px; }
.preview-table th { background: #f1f5f9; padding: 5px 8px; border: 1px solid var(--border); white-space: nowrap; font-weight: 600; }
.preview-table td { padding: 4px 8px; border: 1px solid #eef2f6; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.preview-scroll { max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.rowidx { background: #fafbfc; color: var(--text-3); text-align: center; }

.dropzone {
  border: 2px dashed var(--border-strong); border-radius: 10px; padding: 34px; text-align: center;
  background: #fbfcfe; cursor: pointer; transition: .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-light); }
.dropzone svg { width: 40px; height: 40px; color: var(--primary); opacity: .75; }
.dropzone p { margin: 10px 0 3px; font-size: 13.5px; }
.dropzone .hint { font-size: 12px; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.stat .k { font-size: 12px; color: var(--text-3); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }

.settings-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.settings-tabs button {
  height: 34px; padding: 0 14px; border: 0; background: transparent; cursor: pointer; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.settings-tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.pane { display: none; }
.pane.on { display: block; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; background: #eef2f7; border-radius: 20px; font-size: 12px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--text-3); line-height: 1; padding: 0; }
.chip button:hover { color: var(--danger); }

.col-picker { display: grid; grid-template-columns: 1fr 40px 1fr; gap: 10px; align-items: center; }
.col-list { border: 1px solid var(--border); border-radius: 6px; height: 320px; overflow: auto; }
.col-list .it {
  padding: 6px 10px; border-bottom: 1px solid #f2f5f8; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 12.5px;
}
.col-list .it:hover { background: #f7fafd; }
.col-list .it.on { background: var(--primary-light); }
.col-list .it .k { color: var(--text-3); font-size: 11px; margin-left: auto; }
.col-list .it .mv { display: flex; gap: 2px; margin-left: auto; }
.col-list-head { padding: 7px 10px; background: #f8fafc; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-2); font-weight: 600; }
.mid-btns { display: flex; flex-direction: column; gap: 8px; }

.log-table td { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; }
.text-c { text-align: center; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-3); }
.mb8 { margin-bottom: 8px; }
.mb12 { margin-bottom: 12px; }
.mt12 { margin-top: 12px; }
.row-flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

@media (max-width: 900px) {
  .topnav button { padding: 0 10px; }
  .search-box input { width: 160px; }
  .form-item.wide { grid-column: span 1; }
}
