:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8faff;
  --border: #e3e9f3;
  --text: #1b2436;
  --muted: #6c7891;
  --primary: #3b5bdb;
  --primary-dark: #2f4bbf;
  --primary-soft: #edf1ff;
  --success: #0f9d63;
  --success-soft: #e8f8f0;
  --warn: #d9840b;
  --warn-soft: #fff5e4;
  --danger: #d83a3a;
  --danger-soft: #ffeded;
  --info-soft: #eaf2ff;
  --shadow: 0 2px 10px rgba(28, 42, 78, .06);
  --radius: 12px;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }

/* ---------------------------------------------------------------- 登录 */
#login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1100px 600px at 15% 10%, #e9efff 0%, transparent 60%),
              radial-gradient(900px 500px at 90% 90%, #e6f5ff 0%, transparent 60%), var(--bg);
}
.login-card {
  width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 36px; box-shadow: 0 18px 50px rgba(31, 48, 92, .10);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: .5px; }
.login-card p.sub { margin: 0 0 26px; color: var(--muted); font-size: 13px; }
.login-card .field { margin-bottom: 16px; }
.login-card button { width: 100%; margin-top: 8px; }

/* ---------------------------------------------------------------- 布局 */
#app-view { display: none; min-height: 100vh; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 218px; flex: 0 0 218px; background: #17223b; color: #c8d2e8;
  display: flex; flex-direction: column; padding: 20px 12px;
}
.brand { color: #fff; font-size: 17px; font-weight: 700; padding: 6px 12px 22px; letter-spacing: .5px; }
.brand small { display: block; font-size: 11px; font-weight: 400; color: #8494b6; margin-top: 5px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-radius: 9px;
  cursor: pointer; margin-bottom: 4px; color: #c8d2e8; border: none; background: transparent;
  width: 100%; text-align: left; transition: .15s;
}
.nav-item:hover { background: #22304e; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.sidebar-footer { margin-top: auto; padding: 12px; font-size: 11px; color: #7585a6; line-height: 1.7; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 26px;
}
.topbar .title { font-size: 16px; font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.content { padding: 24px 26px 40px; max-width: 1400px; width: 100%; }

/* ---------------------------------------------------------------- 通用组件 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }
.card h2 .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); outline: none; transition: .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { min-height: 70px; resize: vertical; }
.check { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; cursor: pointer; }
.check input { width: auto; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f3caca; }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 27px; font-weight: 700; margin-top: 8px; }
.stat .value.green { color: var(--success); } .stat .value.blue { color: var(--primary); }
.stat .value.orange { color: var(--warn); } .stat .value.red { color: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfcff; }
td.actions { white-space: nowrap; }
.mono { font-family: Consolas, Monaco, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.empty { padding: 36px 10px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.gray { background: #eef1f6; color: #5f6b80; }
.badge.blue { background: var(--info-soft); color: var(--primary); }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.orange { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

.progress-track { height: 7px; background: #eef1f7; border-radius: 20px; overflow: hidden; min-width: 90px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #4c6ef5, #0f9d63); transition: width .4s; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
.toolbar .spacer { flex: 1; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.alert.error { background: var(--danger-soft); color: #a52121; border: 1px solid #f5cccc; }
.alert.ok { background: var(--success-soft); color: #0a7048; border: 1px solid #c7ecd9; }
.alert.info { background: var(--info-soft); color: #2b47a8; border: 1px solid #d3e0ff; }

/* ---------------------------------------------------------------- 抽屉 / 日志 */
.drawer-mask { position: fixed; inset: 0; background: rgba(16, 24, 44, .42); z-index: 40; display: none; }
.drawer-mask.show { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 94vw); background: var(--bg);
  z-index: 41; transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(20, 32, 60, .18);
}
.drawer.show { transform: translateX(0); }
.drawer-head { padding: 18px 22px; background: #fff; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.drawer-head h3 { margin: 0; font-size: 16px; }
.drawer-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 12px 22px; background: #fff; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.logbox {
  background: #111a2c; color: #d3ddf2; border-radius: 9px; padding: 12px; height: 340px;
  overflow-y: auto; font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 1.7;
}
.logbox .line { white-space: pre-wrap; word-break: break-all; }
.logbox .ts { color: #6f83a8; margin-right: 8px; }
.logbox .WARN { color: #ffc46b; } .logbox .ERROR { color: #ff8b8b; }
.logbox .DEBUG { color: #8ea3c8; } .logbox .INFO { color: #d3ddf2; }
.logbox .evt { color: #7fd4a8; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #c9d5f5; border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 90; background: #17223b; color: #fff;
  padding: 12px 18px; border-radius: 9px; box-shadow: 0 12px 30px rgba(0,0,0,.2); font-size: 13px;
  opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; max-width: 420px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #a52121; }
.hidden { display: none !important; }

@media (max-width: 1000px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .sidebar { width: 64px; flex-basis: 64px; }
  .brand, .nav-item span:not(.ico), .sidebar-footer { display: none; }
  .nav-item { justify-content: center; }
}
