:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --updated: #ea580c;
  --updated-bg: #fff4ec;
  --ok: #16a34a;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --paused: #9ca3af;
  --hover: #f3f4f6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2b2f37;
    --primary: #3b82f6;
    --updated: #fb923c;
    --updated-bg: #2a1d12;
    --ok: #22c55e;
    --error: #f87171;
    --error-bg: #2a1616;
    --paused: #6b7280;
    --hover: #22262d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
p.error { color: var(--error); min-height: 1em; margin: 8px 0 0; white-space: pre-line; }
p.ok { color: var(--ok); margin: 4px 0 0; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 14px; margin: 18px 0 4px; }
h3:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; resize: vertical; }
label, .field { display: block; margin-bottom: 14px; font-weight: 500; font-style: normal; }
label > input, label > select, label > .inline { margin-top: 6px; font-weight: 400; }
.field textarea { margin-top: 6px; }
.inline { display: flex; align-items: center; gap: 8px; }
.inline input { width: 120px; }

.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--error); }
.btn.warn { background: var(--updated); border-color: var(--updated); color: #fff; }
.icon-btn { border: 0; background: none; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.label-row { display: flex; justify-content: space-between; align-items: center; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 17px; font-weight: 600; }
.brand .muted { font-weight: 400; font-size: 14px; margin-left: 4px; }
.top-actions { display: flex; gap: 8px; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: left;
  font: inherit; color: inherit;
}
.stat:hover { border-color: var(--muted); }
.stat.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.stat .num { font-size: 28px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat.updated .num { color: var(--updated); }
.stat.error .num { color: var(--error); }
.stat.updated.has { background: var(--updated-bg); border-color: var(--updated); }

.toolbar { display: flex; align-items: center; gap: 12px; margin: 20px 0 12px; }
.toolbar input { max-width: 320px; }

/* 状态点 */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--paused); }
.dot.ok { background: var(--ok); }
.dot.updated { background: var(--updated); box-shadow: 0 0 0 3px color-mix(in srgb, var(--updated) 25%, transparent); }
.dot.error { background: var(--error); }
.dot.pending { background: var(--primary); }

/* 列表 */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 2fr) minmax(0, 1.1fr) auto;
  gap: 16px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.item.updated { border-color: var(--updated); background: linear-gradient(90deg, var(--updated-bg), var(--panel) 60%); }
.item.paused { opacity: .6; }
.item .title { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.item .title:hover span { text-decoration: underline; }
.item .url { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; margin-left: 16px; text-decoration: none; }
.item .url:hover { color: var(--primary); }
.item .note { color: var(--muted); font-size: 12px; margin-left: 16px; }
.value { font-family: ui-monospace, Menlo, monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.value.old { color: var(--muted); text-decoration: line-through; font-size: 12px; -webkit-line-clamp: 1; }
.err-text { color: var(--error); font-size: 12px; }
.meta { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--updated); color: #fff; font-weight: 500; font-style: normal; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; }
.empty .btn { margin-top: 12px; }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.editor, .dialog {
  background: var(--panel);
  border-radius: 14px;
  display: flex; flex-direction: column;
  max-height: 100%;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.editor { width: min(1400px, 100%); height: 100%; }
.dialog { width: min(560px, 100%); }
.editor-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.editor-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }
.picker-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.urlbar { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.frame-wrap { position: relative; flex: 1; background: #fff; min-height: 300px; }
.frame-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }
.frame-tip, .frame-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #6b7280; background: var(--bg); padding: 20px; text-align: center;
}
.frame-tip .big { font-size: 18px; color: var(--text); font-weight: 600; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.form-pane { padding: 16px 18px; overflow-y: auto; }
.preview-box { margin-bottom: 14px; font-weight: 500; font-style: normal; }
.preview-value {
  margin-top: 6px; padding: 8px 10px; border-radius: 8px;
  background: var(--bg); font-family: ui-monospace, Menlo, monospace; font-size: 12px; font-weight: 400;
  max-height: 120px; overflow: auto; word-break: break-all; white-space: pre-wrap;
}
.preview-value.has { color: var(--text); }
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 400; margin-bottom: 8px; cursor: pointer; }
.check input { width: auto; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.form-actions.pad { padding: 12px 18px; border-top: 1px solid var(--line); margin: 0; }
.dialog-body { padding: 16px 18px; overflow-y: auto; }

/* 小按钮、提示 */
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--hover); }
.grow { flex: 1; margin: 0 !important; align-self: center; }
.preview-meta { font-size: 12px; margin-top: 4px; min-height: 18px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.preview-meta.ok { color: var(--ok); }
.preview-meta.err { color: var(--error); }
.spinner.sm { width: 12px; height: 12px; border-width: 2px; }
#loadingText { color: var(--text); font-weight: 500; }

/* 设置：标签页 */
.dialog.wide { width: min(1080px, 100%); height: min(860px, 100%); }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); flex: none; }
.tabs button { font: inherit; background: none; border: 0; padding: 10px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.tab-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tab-panel .dialog-body { flex: 1; }
.dialog-body > :not(.tpl-layout) { max-width: 560px; }

/* 通知模板 */
.tpl-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.tpl-preview { position: sticky; top: 0; align-self: start; }
.vars { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 99px; padding: 2px 10px; cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.preset-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.feishu-card { margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.feishu-head { background: #ff8800; color: #fff; padding: 10px 14px; font-weight: 600; }
.feishu-body { padding: 12px 14px; white-space: pre-wrap; word-break: break-all; line-height: 1.7; font-size: 13px; }
.feishu-body .c-red { color: #f54a45; }
.feishu-body .c-grey { color: #8f959e; }
.feishu-btns { border-top: 1px solid var(--line); margin: 0 14px; padding: 10px 0 12px; }
.feishu-btns span { display: inline-block; background: #3370ff; color: #fff; border-radius: 6px; padding: 4px 12px; font-size: 13px; }
.json-preview { margin: 6px 0 0; background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 12px; max-height: 280px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* 启动加载 */
.splash { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); }
.btn .spinner.sm { display: inline-block; vertical-align: -2px; margin-right: 6px; border-color: rgba(255, 255, 255, .4); border-top-color: #fff; }
.spinner.sm.dark, .btn .spinner.sm.dark { display: inline-block; vertical-align: -2px; border-color: var(--line); border-top-color: var(--primary); }
.notify-test { margin: 6px 0 4px; }
.notify-test .preview-meta { white-space: pre-line; }

/* 版本更新 */
.ver-badge { font: inherit; font-size: 12px; font-weight: 400; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; margin-left: 6px; cursor: pointer; vertical-align: 2px; }
.ver-badge:hover { color: var(--text); }
.ver-badge.has-update { color: #fff; background: var(--updated); border-color: var(--updated); }
.ver-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.ver-big { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.release { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.release.latest { border-color: var(--updated); background: var(--updated-bg); }
.release-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.release-head b { font-size: 15px; }
.release ul { margin: 4px 0 0; padding-left: 20px; }
.release li { margin: 2px 0; }
.update-actions { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; flex-wrap: wrap; }
.steps { list-style: none; padding: 0; margin: 8px 0; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--muted); }
.steps li.done { color: var(--ok); }
.steps li.active { color: var(--text); font-weight: 500; }
.steps li.fail { color: var(--error); }
.steps .mark { width: 16px; text-align: center; flex: none; }
.rollback { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* 提取、下载按钮 */
.extracted { margin-top: 6px; font-size: 13px; font-weight: 400; color: var(--muted); }
.extracted b { color: var(--text); font-family: ui-monospace, Menlo, monospace; background: color-mix(in srgb, var(--primary) 12%, transparent); padding: 1px 6px; border-radius: 4px; }
.extracted.err b { color: var(--error); background: none; padding: 0; font-family: inherit; }
.hint { font-size: 12px; background: color-mix(in srgb, var(--primary) 8%, var(--panel)); border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent); border-radius: 8px; padding: 8px 10px; margin: -6px 0 14px; }
.field > input { margin-top: 6px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
#downloadPreview { word-break: break-all; }
.pick-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 2; background: #1f2937; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.pick-banner .link { color: #93c5fd; margin-left: 8px; }
.dl-link { font-size: 12px; text-decoration: none; color: var(--primary); white-space: nowrap; }
.dl-link:hover { text-decoration: underline; }

/* 备份 */
.backup-list { list-style: none; padding: 0; margin: 8px 0 0; border-top: 1px solid var(--line); }
.backup-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.backup-list .grow { flex: 1; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

/* 详情 */
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 13px; margin-bottom: 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.kv code { font-size: 12px; }
.history { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 130px 1fr; gap: 10px; font-size: 13px; }
.history .t { color: var(--muted); font-size: 12px; }

/* 登录 */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: min(340px, 100%); background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box input { margin: 0 0 10px; }
.login-box .muted { margin: 0 0 16px; }
.login-box .btn { width: 100%; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px);
}
.toast.err { background: #b91c1c; }

@media (max-width: 960px) {
  .tpl-layout { grid-template-columns: 1fr; }
  .tpl-preview { position: static; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .item { grid-template-columns: 1fr; gap: 8px; }
  .actions { justify-content: flex-start; }
  .editor-body { grid-template-columns: 1fr; grid-template-rows: minmax(320px, 55%) auto; overflow-y: auto; }
  .picker-pane { border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .brand .muted { display: none; }
  .container { padding: 16px 16px 60px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 0; }
  .editor, .dialog { border-radius: 0; height: 100%; }
  .urlbar { flex-direction: column; }
}

/* 链接样式的按钮、label 做的按钮，和普通按钮对齐 */
a.btn, label.btn { display: inline-block; text-decoration: none; margin: 0; font-weight: 400; line-height: 1.5; }
#downloadPreview { display: block; }

/* 预览网页上方：选择元素 / 浏览网页 切换 */
.modebar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; color: inherit; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--primary); color: #fff; }
/* 更新日志 */
.changelog { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.changelog h3 { margin: 0 0 10px; }
.release.current { border-color: var(--primary); }
.release .tag { font-size: 12px; color: var(--primary); margin-left: 6px; font-weight: 500; }
/* 更新进度条 */
.pbar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.pbar-fill { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .6s ease; }
.pbar-fill.ok { background: var(--ok); }
.pbar-fill.fail { background: var(--error); }
.pbar-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
/* 浏览时加载新页面：旧页面还在，上面盖一层半透明 */
.frame-loading.overlay { background: rgba(255, 255, 255, .6); backdrop-filter: blur(1px); z-index: 1; }
/* 页面顶上的提示条 */
.banner { margin-bottom: 14px; padding: 10px 14px; border-radius: 10px; background: #fef3c7; color: #92400e; font-size: 14px; }
.banner.err { background: #fee2e2; color: #991b1b; }

/* 监测方式：网页 / 接口数据 */
.sourcebar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 0; }
.editor:not(.api) .api-only, .editor.api .page-only { display: none !important; }
.api-tip { margin: 0 12px 10px; }
.api-pane { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--panel); color: var(--text); }
.api-pane input { margin: 10px 12px; width: auto; }
.api-fields { flex: 1; overflow: auto; padding: 0 12px 12px; }
.api-field { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; background: var(--panel); color: inherit; font: inherit; font-size: 13px; cursor: pointer; }
.api-field:hover { background: var(--hover); }
.api-field.on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--panel)); }
.api-field .path { font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.api-field .path b { display: block; font-family: system-ui, sans-serif; font-size: 13px; }
.api-field .val { overflow-wrap: anywhere; color: var(--muted); }
.api-group { font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
