:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1c1f23;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --ok: #12805c;
  --warn: #b45309;
  --bad: #c0392b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --border: #2c323b;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --accent: #6f9bff;
    --accent-soft: #23304d;
    --ok: #3ddc97;
    --warn: #f0b429;
    --bad: #ff6b6b;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 20px 80px; }

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

header.top h1 { font-size: 20px; margin: 0; letter-spacing: .3px; }
header.top .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 13px; font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

nav.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
nav.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 14px; font-size: 14px; color: var(--muted); cursor: pointer;
  font-family: inherit;
}
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

section.tab { display: none; }
section.tab.active { display: block; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.card > h2 { margin: 0 0 4px; font-size: 15px; }
.card > .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1 1 200px; }
.field.wide { flex-basis: 100%; }
.field.narrow { flex: 0 1 130px; }
.field > label { font-size: 12.5px; color: var(--muted); }
.field > .note { font-size: 12px; color: var(--muted); }

input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font: inherit; font-size: 14px; width: 100%;
}
textarea { resize: vertical; min-height: 62px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.check { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.check input { width: auto; }

button.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 15px; font: inherit; font-size: 14px; cursor: pointer;
}
button.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.btn.danger { background: var(--bad); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.sm { padding: 5px 10px; font-size: 13px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 15px; background: var(--panel);
  display: flex; justify-content: space-between; gap: 14px; align-items: flex-start;
}
.item .meta { min-width: 0; }
.item .name { font-weight: 600; }
.item .desc { color: var(--muted); font-size: 13px; margin-top: 3px; word-break: break-word; }
.item .actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.item.off { opacity: .55; }

.tag {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 5px; padding: 1px 7px; font-size: 12px; margin-right: 5px;
}
.tag.grey { background: var(--border); color: var(--muted); }

.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.preset {
  text-align: left; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
  font: inherit; color: var(--text);
}
.preset:hover { border-color: var(--accent); }
.preset b { display: block; font-size: 14px; margin-bottom: 4px; }
.preset span { color: var(--muted); font-size: 12.5px; }

/* 规则编辑器 */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 30px 16px; overflow-y: auto; z-index: 40;
}
.backdrop.show { display: flex; }
.editor {
  background: var(--panel); border-radius: 14px; border: 1px solid var(--border);
  width: min(880px, 100%); padding: 22px;
}
.editor h2 { margin: 0 0 16px; font-size: 17px; }
fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 16px; margin: 0 0 14px;
}
fieldset > legend { padding: 0 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
fieldset .legend-hint { color: var(--muted); font-size: 12.5px; margin: -4px 0 12px; }

.editor-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  position: sticky; bottom: -22px; background: var(--panel);
  padding: 14px 0 2px; border-top: 1px solid var(--border);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; padding: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; cursor: pointer; background: var(--bg);
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip input { display: none; }

table.events { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.events th, table.events td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.events th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
table.events td.outcome { white-space: nowrap; }
.o-fired { color: var(--ok); font-weight: 600; }
.o-failed { color: var(--bad); font-weight: 600; }
.o-cancelled, .o-withdrawn { color: var(--warn); }
.o-scheduled { color: var(--accent); }
.o-below_threshold, .o-skipped_cooldown, .o-skipped_schedule { color: var(--muted); }

.empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px;
  border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 90; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); color: #fff; }

.vars { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.vars code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 6px; font-size: 12px; cursor: pointer;
}
.vars code:hover { border-color: var(--accent); color: var(--accent); }

.steps { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }
