:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d9e0e8;
  --border-strong: #c3ccd8;
  --text: #172033;
  --muted: #667085;
  --primary: #1f6feb;
  --primary-hover: #1a5dcc;
  --primary-soft: #eaf1ff;
  --danger: #d1242f;
  --danger-soft: #fdecee;
  --ok: #1a7f37;
  --ok-soft: #e9f7ee;
  --warn: #9a6700;
  --warn-soft: #fff6e0;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

button {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
button:hover { background: var(--primary-hover); }
button.secondary { color: #243044; background: #e6ebf2; }
button.secondary:hover { background: #d8dfe9; }
button.danger { background: var(--danger); }
button.danger:hover { background: #b51f28; }
button.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
button.block { width: 100%; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}
input[type="checkbox"] {
  width: 15px;
  height: 15px;
  padding: 0;
  accent-color: var(--primary);
  vertical-align: -2px;
}

.status { min-height: 20px; font-size: 13px; margin-top: 8px; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

/* ---------- 登录 ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 6px; font-size: 21px; }
.login-card p { margin: 0 0 20px; }
.stack { display: grid; gap: 6px; margin-bottom: 16px; }
.stack span { font-size: 13px; color: var(--muted); }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.dirty { color: var(--warn); font-size: 13px; white-space: nowrap; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  height: calc(100vh - 58px);
}
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 10px;
}
.sidebar-actions { display: flex; gap: 4px; }
.config-empty { padding: 10px 6px; }
.config-list { overflow-y: auto; padding: 0 8px 14px; display: grid; gap: 4px; align-content: start; }
.config-item {
  display: grid;
  gap: 3px;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  width: 100%;
}
.config-item:hover { background: #f1f4f9; }
.config-item.active { background: var(--primary-soft); border-color: #c9dcff; }
.config-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.config-item .meta { font-size: 12px; color: var(--muted); }

.main { overflow-y: auto; padding: 18px 22px 40px; }
.empty {
  margin: 12vh auto 0;
  max-width: 420px;
  text-align: center;
  color: var(--muted);
}
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }

/* ---------- 配置栏 ---------- */
.workspace { max-width: 1180px; margin: 0 auto; }
.config-bar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.config-name {
  font-size: 17px;
  font-weight: 600;
  border-color: transparent;
  padding-left: 0;
}
.config-name:focus { border-color: var(--primary); padding-left: 10px; }
.sub-row { display: flex; gap: 8px; align-items: center; }
.sub-row input { flex: 1; font-size: 12px; color: var(--muted); background: #f8fafc; }

/* ---------- 标签 ---------- */
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 16px 0 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tabs button {
  background: transparent;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  padding: 9px 14px;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { background: #eef2f7; color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.stats-line { margin-left: auto; font-size: 12px; color: var(--muted); padding-bottom: 8px; }

.tab-panel { min-height: 200px; }

/* ---------- 节点工具栏 ---------- */
.node-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.node-toolbar input[type="search"], .node-toolbar #nodeSearch { flex: 1; min-width: 180px; }
.checkline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }

.batch-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: var(--primary-soft);
  border: 1px solid #c9dcff;
  border-radius: 10px;
  font-size: 13px;
}
.batch-bar span { font-weight: 600; white-space: nowrap; }

/* ---------- 节点列表 ---------- */
.node-layout {
  display: grid;
  grid-template-columns: 344px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.node-list {
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  padding-right: 4px;
  position: sticky;
  top: 0;
  align-self: start;
}
.node-item {
  position: relative;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  width: 100%;
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
}
.node-item:hover { border-color: var(--border-strong); background: #fbfcfe; }
.node-item.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.1); }
.node-item input[type="checkbox"] { margin-top: 3px; }
.node-main { min-width: 0; display: grid; gap: 3px; }
.node-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.node-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.node-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-groups { display: flex; gap: 4px; flex-wrap: wrap; }
.node-anomalies { display: flex; gap: 4px; flex-wrap: wrap; }
.node-empty { color: var(--muted); text-align: center; padding: 28px 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  line-height: 1.6;
  padding: 0 6px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475467;
  white-space: nowrap;
}
.badge.type { background: #eaf1ff; color: #1a56c4; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.group { background: #f2f4f7; color: #475467; }

/* ---------- 节点详情 ---------- */
.node-detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 240px;
  padding: 16px;
}
.detail-placeholder { color: var(--muted); text-align: center; margin: 64px 0; }
.detail-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.detail-name {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  border-color: transparent;
  padding-left: 0;
}
.detail-name:focus { border-color: var(--primary); padding-left: 10px; }
.detail-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }
.detail-sub { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.detail-anomalies { margin-bottom: 8px; }
.node-form { display: block; }

.field-group { border-top: 1px solid #eef1f5; padding-top: 12px; margin-top: 12px; }
.field-group:first-of-type { border-top: 0; margin-top: 4px; padding-top: 0; }
.field-group-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; margin-bottom: 8px; }
.field-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.field-label { font-size: 13px; color: #344054; }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-control { display: flex; gap: 6px; align-items: center; min-width: 0; }
.field-control input[type="text"],
.field-control input[type="number"],
.field-control input[type="password"],
.field-control select { width: 100%; }
.field-hint { grid-column: 2; font-size: 12px; color: var(--muted); margin-top: -4px; }
.checkbox-row { display: inline-flex; align-items: center; gap: 6px; }

.group-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  background: #fff;
  cursor: pointer;
}
.group-chip.checked { border-color: var(--primary); background: var(--primary-soft); }
.group-chip .cat { font-size: 10px; color: var(--muted); }

.raw-editor { margin-top: 16px; border-top: 1px solid #eef1f5; padding-top: 12px; }
.raw-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.raw-tabs button { background: transparent; color: var(--muted); padding: 5px 10px; border-radius: 7px; }
.raw-tabs button.active { background: var(--primary-soft); color: var(--primary); }
.raw-tabs .copy-link { margin-left: auto; }
.raw-textarea {
  width: 100%;
  min-height: 130px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  resize: vertical;
}
.raw-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.raw-actions span { font-size: 12px; color: var(--danger); }

/* ---------- YAML / 检查 ---------- */
.panel-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
#yamlText {
  width: 100%;
  min-height: calc(100vh - 300px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  resize: vertical;
}
.check-report { display: grid; gap: 10px; }
.report-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
}
.report-block strong { display: block; margin-bottom: 6px; font-size: 13px; }
.report-block.ok { border-color: #b7e0c3; background: var(--ok-soft); }
.report-block.issue { border-color: #f0d59a; background: var(--warn-soft); }
.report-block.error { border-color: #f3b6bd; background: var(--danger-soft); }
.report-list { margin: 0; padding-left: 18px; display: grid; gap: 3px; font-size: 12.5px; }
.report-list li { word-break: break-all; }
.report-tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- 弹窗 ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45); }
.modal {
  position: relative;
  width: min(640px, 100%);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}
.modal.wide { width: min(820px, 100%); }
.modal-head { padding: 16px 18px 10px; display: flex; align-items: center; gap: 8px; }
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-close { background: transparent; color: var(--muted); font-size: 18px; padding: 4px 8px; }
.modal-close:hover { background: #eef2f7; color: var(--text); }
.modal-body { padding: 4px 18px 12px; overflow-y: auto; display: grid; gap: 10px; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}
.modal-foot .grow { flex: 1; }
.modal textarea { width: 100%; min-height: 150px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.form-row { display: grid; gap: 5px; }
.form-row > span { font-size: 12.5px; color: var(--muted); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview-list { display: grid; gap: 6px; max-height: 220px; overflow-y: auto; }
.preview-item {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12.5px;
}
.preview-item .meta { color: var(--muted); font-size: 12px; }
.preview-error { color: var(--danger); font-size: 12px; }
.diff-line { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.diff-line .from { color: var(--muted); text-decoration: line-through; }
.diff-line .to { color: var(--ok); font-weight: 600; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: grid;
  gap: 8px;
}
.toast {
  min-width: 220px;
  max-width: 360px;
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.3);
  animation: toast-in 0.18s ease;
}
.toast.ok { background: #166534; }
.toast.error { background: #991b1b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr); }
  .node-layout { grid-template-columns: 1fr; }
  .node-list { max-height: 320px; position: static; }
}

@media (max-width: 720px) {
  .topbar { height: auto; padding: 10px 12px; flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .config-list { display: flex; overflow-x: auto; padding-bottom: 10px; }
  .config-item { min-width: 160px; }
  .main { padding: 14px 12px 32px; }
  .sub-row { flex-wrap: wrap; }
  .sub-row input { flex-basis: 100%; }
  .field-row { grid-template-columns: 1fr; gap: 4px; }
  .field-hint { grid-column: 1; }
  .detail-actions { flex-wrap: wrap; }
  #yamlText { min-height: 50vh; }
}
