:root {
  --bg: #F3F5F7;
  --panel: #FFFFFF;
  --line: #DFE4EA;
  --line-strong: #A9B4C0;
  --text: #2E3440;
  --muted: #6B7684;
  --blue: #5E81AC;
  --blue-tint: #E5EFF5;
  --green: #5C8F8E;
  --green-tint: #EAF2EC;
  --orange: #C4703F;
  --orange-tint: #F6EBE5;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
        "PingFang SC", "Hiragino Sans GB", sans-serif;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 14px; margin-bottom: 10px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: #B2503C; font-size: 13px; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 12.5px; }
code { font-family: var(--mono); background: var(--bg); padding: 1px 4px; border-radius: 4px; }

/* 按钮 */
button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  padding: 6px 12px;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--bg); }
button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
button.primary:hover { background: #4C6E94; border-color: #4C6E94; }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--blue-tint); border-color: var(--blue); }
button.small { padding: 3px 8px; font-size: 12px; }
button.wide { width: 100%; margin-top: 6px; }
button:disabled { opacity: .55; cursor: default; }
a.link {
  color: var(--text); text-decoration: none; padding: 6px 12px;
  border: 1px solid var(--line-strong); border-radius: 6px; font-size: 14px;
}
a.link:hover { background: var(--blue-tint); border-color: var(--blue); }

/* 登录 */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 24px; box-shadow: 0 8px 24px rgba(46,52,64,.06);
}
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card p { margin: 0 0 16px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text], .field input[type=password] {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 6px;
}

.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--blue); }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand strong { font-size: 15px; }
.brand .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line-strong); flex: none;
}
.dot.dirty { background: var(--orange); }
.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.status { font-size: 12.5px; color: var(--muted); margin-right: 4px; }
.status.ok { color: var(--green); }
.status.bad { color: #B2503C; }

/* 标签页 */
.tabs {
  display: flex; gap: 4px; padding: 8px 18px 0; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.tab {
  border: none; background: transparent; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 8px 12px; color: var(--muted);
}
.tab:hover { background: transparent; color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

/* 布局 */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 460px;
  gap: 14px; padding: 14px 18px 40px; align-items: start;
}
.layout.no-preview { grid-template-columns: minmax(0, 1fr); }
.layout.no-preview .preview { display: none; }
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static !important; }
}

.editor { min-width: 0; }
.pane { display: flex; flex-direction: column; gap: 12px; }
.pane-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.pane-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pane-tools input[type=search] {
  padding: 6px 10px; font: inherit; border: 1px solid var(--line-strong);
  border-radius: 6px; min-width: 200px; background: var(--panel); color: var(--text);
}

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
textarea {
  width: 100%; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  padding: 10px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--panel); color: var(--text); resize: vertical;
}

/* 规则表 */
.table-wrap {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 210px);
}
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  position: sticky; top: 0; z-index: 2; background: #F8FAFB;
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.grid td {
  padding: 3px 6px; border-bottom: 1px solid #EFF2F5; vertical-align: middle;
}
table.grid tr:hover td { background: #FBFCFD; }
table.grid tr.match-row td { background: var(--blue-tint); }
table.grid tr.hidden-row { display: none; }
.col-idx { width: 42px; }
.col-note { width: 150px; }
.col-type { width: 150px; }
.col-policy { width: 130px; }
.col-opts { width: 110px; }
.col-act { width: 92px; }

table.grid input, table.grid select {
  width: 100%; font: inherit; font-size: 12.5px; color: var(--text);
  padding: 4px 6px; border: 1px solid transparent; border-radius: 4px;
  background: transparent;
}
table.grid input:hover, table.grid select:hover { border-color: var(--line); }
table.grid input:focus, table.grid select:focus {
  outline: none; border-color: var(--blue); background: var(--panel);
  box-shadow: 0 0 0 2px var(--blue-tint);
}
table.grid input.note { color: var(--muted); }
table.grid input:disabled { color: var(--muted); background: var(--bg); }
.idx { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 2px; }
.icon-btn {
  border: 1px solid transparent; background: transparent; border-radius: 4px;
  padding: 2px 5px; font-size: 12px; color: var(--muted); line-height: 1.2;
}
.icon-btn:hover { background: var(--blue-tint); color: var(--blue); border-color: var(--blue); }
.icon-btn.danger:hover { background: var(--orange-tint); color: var(--orange); border-color: var(--orange); }

/* 策略组 */
.group-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.group-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.group-card .grow { display: flex; gap: 8px; align-items: center; }
.group-card .grow input, .group-card .grow select {
  font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line-strong);
  border-radius: 5px; background: var(--panel); color: var(--text);
}
.group-card .grow input { flex: 1; min-width: 0; }
.group-card label { font-size: 12px; color: var(--muted); }
.tag-nodes { font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block; font-size: 11.5px; padding: 1px 6px; border-radius: 10px;
  background: var(--blue-tint); color: var(--blue); font-family: var(--mono);
}

/* 预览 */
.preview {
  position: sticky; top: 108px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: calc(100vh - 130px);
}
.preview-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.preview-head #preview-meta { margin-right: auto; }
.code {
  margin: 0; padding: 12px; overflow: auto; flex: 1;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre; tab-size: 2;
}
.preview-error { padding: 0 12px 12px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); font-size: 12px; }

/* 模态 */
.modal {
  position: fixed; inset: 0; background: rgba(46,52,64,.35);
  display: grid; place-items: center; padding: 24px; z-index: 40;
}
.modal-card {
  width: min(620px, 100%); background: var(--panel); border-radius: 12px;
  padding: 18px; box-shadow: 0 16px 40px rgba(46,52,64,.18);
}
.modal-card h2 { font-size: 15px; margin-bottom: 6px; }
.modal-card textarea { margin: 10px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #2E3440; color: #fff; padding: 9px 16px; border-radius: 20px;
  font-size: 13px; z-index: 60; box-shadow: 0 6px 20px rgba(46,52,64,.25);
  max-width: 80vw;
}
.toast.bad { background: #A4442F; }
