:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6eaf1;
  --border-strong: #d7dee9;
  --text: #131a26;
  --text-2: #596576;
  --text-3: #8b95a6;
  --accent: #2f6bff;
  --accent-hover: #1f57e0;
  --accent-soft: #edf2ff;
  --green: #109c68;
  --green-soft: #e8f7f0;
  --red: #de3b43;
  --red-soft: #fdecec;
  --amber: #c8871a;
  --amber-soft: #fdf4e3;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05);
  --shadow-md: 0 6px 20px -6px rgba(17, 24, 39, .12), 0 1px 3px rgba(17, 24, 39, .05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

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

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--border); }

/* ------------------------------------------------------------------ 布局 */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2f6bff, #4f9dff);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px -3px rgba(47, 107, 255, .5);
}
.brand-mark svg { width: 19px; height: 19px; }

.brand-name { font-size: 14.5px; font-weight: 650; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--text-3); line-height: 1.3; }

.nav { padding: 6px 12px; flex: 1; overflow-y: auto; }

.nav-group {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 14px 8px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background .14s, color .14s;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav-ico { width: 16px; text-align: center; font-size: 13px; opacity: .85; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 12px 18px 16px;
}
.foot-row { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); }
.foot-note { font-size: 11px; color: var(--text-3); margin-top: 3px; font-family: var(--mono); }
.foot-logout { display: inline-block; margin-top: 7px; font-size: 12px; color: var(--text-3); cursor: pointer; }
.foot-logout[hidden] { display: none; }
.foot-logout:hover { color: var(--red); }

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3);
  display: inline-block;
  flex: 0 0 7px;
}
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(16, 156, 104, .14); }
.dot.warn { background: var(--amber); box-shadow: 0 0 0 3px rgba(200, 135, 26, .14); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(222, 59, 67, .14); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 246, 250, .86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 15px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-desc { margin: 1px 0 0; font-size: 12.5px; color: var(--text-3); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content { padding: 22px 30px 48px; max-width: 1280px; width: 100%; }

/* ------------------------------------------------------------------ 组件 */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); border-color: #c3ccdb; color: var(--text); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.section { margin-bottom: 22px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}
.section-title { font-size: 14px; font-weight: 650; letter-spacing: -.005em; }
.section-sub { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 8px; }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px 14px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.kpi-label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 27px; font-weight: 660; letter-spacing: -.02em; line-height: 1.25; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.kpi.green .kpi-value { color: var(--green); }
.kpi.red .kpi-value { color: var(--red); }
.kpi-blue .kpi-value { color: var(--accent); }
.kpi-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--border); }
.kpi.green .kpi-bar { background: var(--green); }
.kpi.red .kpi-bar { background: var(--red); }
.kpi-blue .kpi-bar { background: var(--accent); }

/* 平台卡片 */
.plat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.plat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 18px 15px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 11px;
  transition: box-shadow .18s, border-color .18s;
}
.plat:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }

.plat-top { display: flex; align-items: flex-start; gap: 12px; }
.plat-ico {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  letter-spacing: -.02em;
}
.plat-ico.usr { background: linear-gradient(135deg, #2f6bff, #5e9bff); }
.plat-ico.ruixun { background: linear-gradient(135deg, #0e9f8a, #35c4a8); }
.plat-ico.onenet { background: linear-gradient(135deg, #0064c8, #2e9fe6); }
.plat-name { font-size: 14px; font-weight: 640; }
.plat-desc { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }
.plat-host { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }
.plat-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-3);
  border: 1px solid var(--border);
  line-height: 1.6;
}
.tag.api { background: var(--green-soft); color: var(--green); border-color: rgba(16, 156, 104, .18); }
.tag.nolink { background: var(--amber-soft); color: var(--amber); border-color: rgba(200, 135, 26, .2); }

/* 表格 */
.table-wrap { overflow: auto; border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.tbl td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: #fafbfd; }
.tbl .strong { color: var(--text); font-weight: 550; }
.tbl .mono { font-family: var(--mono); font-size: 12px; color: var(--text-3); }
.tbl .num { font-variant-numeric: tabular-nums; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.empty-title { color: var(--text); font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* 搜索栏 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.input {
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 0 11px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  min-width: 0;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 107, 255, .12); }
.input::placeholder { color: #a8b1c0; }
.input-search { width: 260px; }
select.input { padding-right: 8px; cursor: pointer; }
.grow { flex: 1; }

/* 平台切换 */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); font-weight: 620; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.7;
}
.badge.on { background: var(--green-soft); color: var(--green); }
.badge.off { background: #f1f3f7; color: #78838f; }
.badge.alarm { background: var(--red-soft); color: var(--red); }
.badge.muted { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }

.pager { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); }

/* 表单 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.field .input { width: 100%; height: 36px; }

.card-pad { padding: 18px; }
.card-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head-title { font-size: 13.5px; font-weight: 640; }
.card-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 9px; align-items: center; }

.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 11px;
  font-size: 12.8px;
  line-height: 1.6;
  margin-bottom: 16px;
  border: 1px solid;
}
.alert .alert-ico { flex: 0 0 auto; font-weight: 700; }
.alert.info { background: var(--accent-soft); border-color: rgba(47, 107, 255, .18); color: #1e4bb8; }
.alert.warn { background: var(--amber-soft); border-color: rgba(200, 135, 26, .22); color: #96620c; }
.alert.err { background: var(--red-soft); border-color: rgba(222, 59, 67, .2); color: #b0262d; }

pre.raw {
  margin: 0;
  padding: 13px 15px;
  background: #0f1724;
  color: #cfd8e6;
  border-radius: 11px;
  overflow: auto;
  max-height: 300px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
}

/* Toast */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 9px; z-index: 90; }
.toast {
  background: #131a26;
  color: #fff;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 30px -8px rgba(0, 0, 0, .45);
  animation: toastIn .22s ease-out;
  max-width: 380px;
}
.toast.ok { background: #0c7a53; }
.toast.err { background: #b0262d; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 36, .45);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(1100px, 100%);
  height: min(80vh, 820px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 30px 70px -20px rgba(15, 22, 36, .4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 13.5px; font-weight: 620; }
.modal-actions { display: flex; gap: 8px; }
.modal-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.modal-body iframe { flex: 1; width: 100%; border: 0; background: var(--surface-2); }
.modal-hint { padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); background: var(--surface-2); }

.spin-ico { display: inline-block; }
.loading .spin-ico { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  height: 13px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef1f6 25%, #f6f8fb 37%, #eef1f6 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plat-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { display: none; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* ---------------- 未登录：全屏纯登录页，隐藏侧栏/顶栏 ---------------- */
body.pre-login .sidebar,
body.pre-login .topbar { display: none !important; }
body.pre-login .content {
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 0 16px;
}
body.pre-login .content > .card { margin: 0 !important; }

/* ---------------- 两级子菜单 ---------------- */
.nav-group[data-toggle] { cursor: pointer; user-select: none; }
.nav-group[data-toggle]::after { content: '▾'; float: right; opacity: .55; font-size: 10px; }
.nav.closed .nav-item,
.nav.closed #navExt { display: none; }
.nav-item.nav-sub { padding-left: 38px; font-size: 13px; opacity: .92; }
#navExt .nav-ext {
  display: flex; align-items: center; gap: 8px;
  margin: 1px 10px; padding: 7px 10px 7px 34px;
  border-radius: 8px; font-size: 13px; color: var(--text-2);
  text-decoration: none; transition: background .15s, color .15s;
}
#navExt .nav-ext:hover { background: rgba(47,107,255,.08); color: var(--accent); }
#navExt .nav-ext .ext-tag { margin-left: auto; font-size: 10px; opacity: .6; }
