:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e2e8f2;
  --text: #1b2436;
  --muted: #6b7891;
  --primary: #1f5fd6;
  --primary-dark: #17499f;
  --red: #d92b2b;
  --red-bg: #fdeaea;
  --yellow: #d98207;
  --yellow-bg: #fdf3e0;
  --green: #16a34a;
  --green-bg: #e9f7ee;
  --blue: #2f6fed;
  --shadow: 0 2px 10px rgba(23, 43, 84, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* 顶栏 */
.topbar {
  background: linear-gradient(100deg, #12376f 0%, #1f5fd6 55%, #2f87e8 100%);
  color: #fff;
  padding: 14px 24px 0;
  box-shadow: 0 2px 14px rgba(18, 55, 111, .22);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 20px;
}
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: .5px; }
.topbar .sub { margin: 0; font-size: 12px; opacity: .82; }

.tabs { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.tab {
  background: transparent; border: none; color: rgba(255,255,255,.82);
  padding: 10px 18px; border-radius: 8px 8px 0 0; cursor: pointer;
  font-size: 14px; font-family: inherit;
  transition: .18s;
}
.tab:hover { background: rgba(255,255,255,.12); color: #fff; }
.tab.active { background: var(--bg); color: var(--primary); font-weight: 600; }

/* 主体 */
.wrap { padding: 20px 24px 60px; max-width: 1680px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* 工具栏 */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--card); padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px;
  background: #fff; outline: none; transition: .16s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,95,214,.12); }
#searchBox { width: 240px; }
.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
textarea { width: 100%; resize: vertical; line-height: 1.9; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 15px; border-radius: 8px; cursor: pointer; font-size: 14px;
  font-family: inherit; transition: .16s; white-space: nowrap;
}
.btn:hover { border-color: #c3cfdf; background: #f8fafd; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--red); border-color: #f2c9c9; }
.btn.danger:hover { background: var(--red-bg); }
.btn.big { padding: 11px 28px; margin-top: 6px; }

/* 分段控件 */
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn {
  border: none; background: #fff; padding: 8px 20px; cursor: pointer;
  font-family: inherit; font-size: 14px; color: var(--muted);
}
.seg-btn.active { background: var(--primary); color: #fff; }

/* 统计卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat {
  background: var(--card); border-radius: 12px; padding: 15px 18px;
  box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 2px; letter-spacing: .5px; }
.stat.red { border-left-color: var(--red); }
.stat.red .v { color: var(--red); }
.stat.yellow { border-left-color: var(--yellow); }
.stat.yellow .v { color: var(--yellow); }
.stat.green { border-left-color: var(--green); }
.stat.green .v { color: var(--green); }

.card-block {
  background: var(--card); border-radius: 12px; padding: 16px 18px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-block h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.tip { color: var(--muted); font-size: 12.5px; margin: 0 0 10px; }
.inline-tip { margin-left: 10px; }

/* 表格 */
.table-scroll { overflow: auto; max-height: 68vh; border-radius: 10px; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; background: #fff; }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; white-space: nowrap;
}
table.grid thead th {
  position: sticky; top: 0; background: #eef3fb; z-index: 2;
  font-weight: 600; color: #2b3c5c; font-size: 12.5px;
}
table.grid tbody tr:hover { background: #f7faff; }
table.grid td.st, table.grid th.st { text-align: center; }
td.op { white-space: nowrap; }
td .mini {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 2px 8px; cursor: pointer; font-size: 12px; font-family: inherit; margin-right: 4px;
}
td .mini:hover { border-color: var(--primary); color: var(--primary); }
td .mini.del:hover { border-color: var(--red); color: var(--red); }
.row-red { background: #fff7f7; }
.row-yellow { background: #fffdf5; }
.ck { width: 36px; text-align: center !important; }

/* 状态灯 */
.lamp {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  vertical-align: middle; box-shadow: 0 0 0 3px rgba(0,0,0,.05);
}
.lamp.red { background: var(--red); box-shadow: 0 0 0 3px var(--red-bg); animation: pulse 1.9s infinite; }
.lamp.yellow { background: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-bg); }
.lamp.green { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.lamp.mini { width: 9px; height: 9px; margin-right: 3px; box-shadow: none; animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.gray { background: #eef1f6; color: var(--muted); }

.hint { color: var(--muted); font-size: 12.5px; padding: 0 4px 10px; }
.hint b { color: var(--text); }

/* 图表 */
canvas { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 22px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* 表单 */
.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.form-row label { width: 160px; color: var(--muted); flex-shrink: 0; }
.form-row input, .form-row select { flex: 1; min-width: 0; }
.form-row.checks { flex-wrap: wrap; gap: 16px; }
.form-row.checks label { width: auto; color: var(--text); display: inline-flex; align-items: center; gap: 5px; }
.form-row.checks input { width: auto; }

/* 弹窗 */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(15, 27, 51, .5);
  z-index: 100; align-items: center; justify-content: center; padding: 20px;
}
.modal.show { display: flex; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 22px 24px;
  width: min(720px, 100%); max-height: 90vh; overflow: auto;
}
.modal-box h3 { margin: 0 0 16px; font-size: 16px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.modal-grid .form-row.full { grid-column: 1 / -1; }
.modal-grid .form-row label { width: 130px; font-size: 13px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translate(-50%, 20px);
  background: #1b2436; color: #fff; padding: 11px 22px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 200;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); }
.toast.ok { background: #12833f; }

@media (max-width: 900px) {
  .modal-grid { grid-template-columns: 1fr; }
  #searchBox { width: 100%; }
  .topbar { padding: 12px 14px 0; }
  .wrap { padding: 14px 12px 50px; }
}
