:root {
  --bg: #f1f5f7;
  --surface: #ffffff;
  --surface-2: #f7fafb;
  --border: #e0e8ec;
  --border-strong: #cbd8de;
  --text: #1c2b33;
  --text-2: #4a5e69;
  --muted: #7b8d97;
  --primary: #0f6f78;
  --primary-dark: #0b565e;
  --primary-soft: #e4f2f2;
  --amber: #a8610a;
  --amber-soft: #fbf1e0;
  --green: #1c7a4f;
  --green-soft: #e5f4ec;
  --red: #b5362c;
  --red-soft: #faeae8;
  --shadow: 0 1px 2px rgba(24, 48, 58, 0.04), 0 8px 24px rgba(24, 48, 58, 0.06);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

button, input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
button { cursor: pointer; }
a { color: var(--primary); }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: var(--surface);
}
.login-brand {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 64px 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700; letter-spacing: 1px;
  margin-bottom: 28px;
}
.login-brand h1 { font-size: 30px; margin: 0 0 12px; letter-spacing: -0.5px; }
.login-brand p { color: var(--text-2); margin: 0 0 36px; max-width: 420px; }
.brand-points { display: grid; gap: 14px; max-width: 420px; }
.brand-point { display: flex; gap: 12px; align-items: flex-start; }
.brand-point .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  margin-top: 8px; flex: none;
}
.brand-point span { color: var(--text-2); }
.brand-foot { margin-top: 48px; color: var(--muted); font-size: 12px; }

.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-card { width: 100%; max-width: 390px; }
.login-card h2 { font-size: 22px; margin: 0 0 6px; }
.login-card .sub { color: var(--muted); margin: 0 0 28px; }
.login-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 9px; margin-bottom: 22px; }
.login-tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px 0; border-radius: 7px;
  color: var(--text-2); font-weight: 500;
}
.login-tabs button.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { resize: vertical; min-height: 76px; }
.code-row { display: flex; gap: 8px; }
.code-row .input { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-plain { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }
.btn-plain:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: #f0cfcb; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.login-error {
  background: var(--red-soft); color: var(--red); border: 1px solid #f0cfcb;
  padding: 9px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px;
}
.login-hint { color: var(--muted); font-size: 12px; margin-top: 18px; text-align: center; }

/* ---------- 应用骨架 ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 234px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-head { padding: 20px 20px 16px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid var(--border); }
.side-logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex: none;
}
.side-logo-text { font-weight: 650; font-size: 15px; letter-spacing: -.3px; }
.side-logo-text small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; letter-spacing: 0; }
.side-nav { padding: 12px 10px 24px; flex: 1; }
.nav-group { margin-bottom: 14px; }
.nav-group-title {
  font-size: 11px; color: var(--muted); letter-spacing: 1px; padding: 8px 12px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  border: 0; background: transparent; color: var(--text-2); padding: 8px 12px;
  border-radius: 7px; margin-bottom: 2px; position: relative; font-size: 13.5px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav-symbol {
  width: 20px; height: 20px; border-radius: 5px; background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--muted); flex: none;
}
.nav-item.active .nav-symbol { background: #fff; color: var(--primary); }
.side-foot { padding: 14px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11.5px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; flex: none; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 26px; gap: 18px;
}
.topbar-title { font-size: 16px; font-weight: 650; }
.topbar-title small { color: var(--muted); font-weight: 400; margin-left: 10px; font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 9px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 20px; padding: 5px 12px 5px 6px;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.user-chip .uname { font-size: 13px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 24px 26px 40px; }

/* ---------- 通用组件 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 18px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.4px; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.stat .value { font-size: 24px; font-weight: 680; letter-spacing: -.6px; margin-top: 6px; }
.stat .foot { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.stat .value.warn { color: var(--amber); }
.stat .value.good { color: var(--green); }
.stat .value.neg { color: var(--red); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
.dash-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; font-size: 13px; }
.bar-row .bar-label { width: 92px; flex: none; color: var(--text-2); }
.bar-track { flex: 1; height: 9px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 6px; }
.bar-row .bar-val { width: 56px; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }

.progress-line { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.progress-line .pl-name { width: 130px; flex: none; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-line .pl-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.progress-line .pl-fill { height: 100%; background: var(--primary); border-radius: 5px; }
.progress-line .pl-val { width: 42px; text-align: right; font-size: 12.5px; color: var(--text-2); }

/* ---------- 表格 ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.search-box { position: relative; flex: 1; min-width: 200px; max-width: 330px; }
.search-box .input { padding-left: 34px; }
.search-box::before {
  content: "⌕"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 17px; line-height: 1;
}
.filter-select { padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); min-width: 132px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 11px 12px; background: var(--surface-2); color: var(--text-2);
  font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid #edf2f4; white-space: nowrap; max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
.data-table tbody tr:hover { background: #f9fcfc; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.cell-empty { color: #b6c3ca; }
.money { font-variant-numeric: tabular-nums; font-weight: 550; }
.cell-warn { color: var(--red); font-weight: 650; }
.row-actions { display: flex; gap: 6px; }
.link-btn { border: 0; background: transparent; color: var(--primary); padding: 3px 4px; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--red); }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.chip.green { background: var(--green-soft); color: var(--green); border-color: #cbe8d7; }
.chip.amber { background: var(--amber-soft); color: var(--amber); border-color: #f0dfc0; }
.chip.red { background: var(--red-soft); color: var(--red); border-color: #f0cfcb; }
.chip.blue { background: var(--primary-soft); color: var(--primary-dark); border-color: #c9e4e4; }

.empty { text-align: center; padding: 54px 20px; color: var(--muted); }
.empty .empty-title { font-size: 15px; color: var(--text-2); margin-bottom: 6px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--border); margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.pager-btns { display: flex; gap: 6px; }
.pager-btns button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px; padding: 5px 10px; color: var(--text-2); }
.pager-btns button:disabled { opacity: .45; cursor: not-allowed; }
.pager-btns button.current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 弹窗 ---------- */
#modal-layer { position: fixed; inset: 0; z-index: 60; display: none; }
#modal-layer.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 38, 46, .42); }
.modal {
  position: relative; width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 60px);
  margin: 30px auto; background: var(--surface); border-radius: 12px; box-shadow: 0 24px 64px rgba(16, 34, 42, .22);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.narrow { width: min(430px, calc(100vw - 32px)); }
.modal-head { padding: 17px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { border: 0; background: transparent; font-size: 20px; color: var(--muted); line-height: 1; padding: 2px 6px; }
.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: 8px; background: var(--surface-2); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.form-field .req { color: var(--red); margin-left: 3px; }
.form-field .hint { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.readonly-input { background: var(--surface-2); color: var(--text-2); }
.modal-note { background: var(--primary-soft); color: var(--primary-dark); padding: 10px 13px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.modal-danger { color: var(--text-2); font-size: 14px; }

/* ---------- 提示 ---------- */
#toast-layer { position: fixed; top: 18px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 11px 16px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px;
  animation: toastIn .2s ease-out;
}
.toast.error { border-left-color: var(--red); color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.center-state { display: flex; align-items: center; justify-content: center; min-height: 60vh; flex-direction: column; gap: 12px; color: var(--muted); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fatal { max-width: 560px; margin: 12vh auto; padding: 26px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.fatal h3 { margin: 0 0 10px; color: var(--red); }
.fatal p { color: var(--text-2); }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid, .dash-grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-nav { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px; }
  .nav-group { margin: 0; display: flex; gap: 4px; flex: none; }
  .nav-group-title { display: none; }
  .nav-item { white-space: nowrap; margin: 0; }
  .side-foot { display: none; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
