:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --sidebar: #ffffff;
  --line: #e6ebf2;
  --text: #1f2d3d;
  --muted: #8492a6;
  --primary: #409eff;
  --primary-strong: #337ecc;
  --primary-soft: #ecf5ff;
  --ok: #67c23a;
  --ok-soft: #f0f9eb;
  --warn: #e6a23c;
  --warn-soft: #fdf6ec;
  --bad: #f56c6c;
  --bad-soft: #fef0f0;
  --shadow: 0 1px 4px rgba(0, 21, 41, 0.06);
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #171e26;
  --sidebar: #121821;
  --line: #263242;
  --text: #d8e0ea;
  --muted: #7d8b9c;
  --primary: #4da3ff;
  --primary-strong: #6cb6ff;
  --primary-soft: #16283d;
  --ok: #35c46a;
  --ok-soft: #12281c;
  --warn: #f2b544;
  --warn-soft: #2b2313;
  --bad: #ff5f5f;
  --bad-soft: #2b1616;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: var(--primary); text-decoration: none; }
code, pre { font-family: "SFMono-Regular", Menlo, Consolas, monospace; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; fill: currentColor; flex: none; }

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

/* 侧边栏 */
.sidebar {
  width: 220px;
  flex: none;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #6fb7ff);
  color: #fff; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text small { color: var(--muted); font-size: 11px; }
.menu { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 6px;
  color: var(--text); font-size: 14px;
}
.menu-item .icon { color: var(--muted); }
.menu-item:hover { background: var(--primary-soft); }
.menu-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.menu-item.active .icon { color: var(--primary); }
.sidebar-foot { padding: 12px 18px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* 顶栏与内容 */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 22px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.crumb-root, .sep { color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 6px;
  border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
.content { padding: 20px 22px 40px; max-width: 1500px; width: 100%; }

/* 卡片 */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card.stat { display: flex; align-items: center; gap: 14px; margin: 0; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}
.stat-icon .icon { width: 20px; height: 20px; }
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat-icon.bad { background: var(--bad-soft); color: var(--bad); }
.stat-icon.primary { background: var(--primary-soft); color: var(--primary); }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 12px; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; background: var(--bg); white-space: nowrap; }
.table tbody tr:hover { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table code { font-size: 12px; color: var(--muted); }
.row-link { cursor: pointer; }

.muted { color: var(--muted); }
.error { color: var(--bad); }
.spacer { flex: 1; }
.hidden { display: none !important; }
.link { font-size: 13px; }
.search {
  width: 220px; padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

/* 状态药丸 */
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; line-height: 18px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--primary-soft); color: var(--primary); }
.pill.off { background: var(--bg); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 0 6px; border-radius: 4px; background: var(--bg); color: var(--muted); }
.chip.ok { color: var(--ok); }
.chip.bad { color: var(--bad); background: var(--bad-soft); }

/* 表单 */
label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
input, select, textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; align-items: end; }
.row-form button { height: 38px; margin-bottom: 10px; }

button { font: inherit; cursor: pointer; }
.btn-primary {
  background: var(--primary); color: #fff; border: 0;
  border-radius: 6px; padding: 8px 18px; font-weight: 600;
}
.btn-primary:hover { background: var(--primary-strong); }
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px;
}
.btn-danger {
  background: transparent; color: var(--bad);
  border: 1px solid var(--bad); border-radius: 6px; padding: 5px 10px;
}
.btn-sm { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

/* 两列布局 */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* 上传 */
.dropzone {
  display: flex; align-items: center; justify-content: center;
  height: 96px; margin-bottom: 12px;
  border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; text-align: center; padding: 0 12px;
}
.dropzone.dragover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.progress { position: relative; height: 26px; margin-top: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin: 6px 0 14px; }
.checks label {
  margin: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  display: flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer;
}
.checks input { width: auto; margin: 0; }

/* 令牌 */
.token pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}

/* 抽屉 */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .35);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
.drawer-mask.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 520px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .25s ease; z-index: 50;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0 0 2px; font-size: 16px; }
.drawer-body { padding: 16px 18px; overflow-y: auto; }
.drawer-body h3 { font-size: 13px; color: var(--muted); margin: 18px 0 8px; font-weight: 500; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
canvas.spark { width: 100%; height: 90px; background: var(--bg); border-radius: 6px; }

/* 登录页 */
.login-body { background: radial-gradient(1200px 500px at 50% -10%, var(--primary-soft), var(--bg)); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 28px 26px;
}
.login-brand { display: flex; align-items: center; gap: 10px; font-size: 16px; margin-bottom: 6px; }
.login-card form { margin-top: 18px; }
.login-card button { width: 100%; margin-top: 4px; }
.login-foot { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 820px) {
  .sidebar { width: 64px; }
  .brand-text, .menu-item span, .sidebar-foot { display: none; }
  .brand { justify-content: center; padding: 16px 0; }
  .menu-item { justify-content: center; padding: 10px 0; }
  .content { padding: 14px; }
  .search { width: 140px; }
}


/* 设备详情 */
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.detail-section { margin-top: 20px; }
.detail-section h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 500; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.metric { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.metric-label { font-size: 12px; color: var(--muted); }
.metric-value { font-size: 18px; font-weight: 700; margin-top: 2px; }
.metric-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.service-list { display: flex; flex-direction: column; gap: 6px; }
.service-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.service-name { flex: 1; font-family: "SFMono-Regular", Menlo, Consolas, monospace; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; margin-top: 5px; }
.dot.success { background: var(--ok); }
.dot.warning { background: var(--warn); }
.dot.critical { background: var(--bad); }
.dot.info { background: var(--primary); }
.problem-list { display: flex; flex-direction: column; gap: 6px; }
.problem-row { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.ok-text { color: var(--ok); margin: 4px 0; }
.spark-wrap { position: relative; }
.spark-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.timeline { display: flex; flex-direction: column; gap: 10px; max-height: 340px; overflow: auto; padding-right: 4px; }
.timeline-item { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.timeline-main { flex: 1; min-width: 0; }
.timeline-title { line-height: 1.4; }
.timeline-detail { font-size: 12px; color: var(--muted); word-break: break-all; margin-top: 2px; }
.timeline-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
@media (max-width: 520px) { .metric-grid { grid-template-columns: repeat(2, 1fr); } }
