* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1d2638;
  --border: #2a3550;
  --text: #e6eaf2;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent-2: #7aa2ff;
  --green: #2ecc71;
  --red: #ff5c5c;
  --amber: #f5a623;
  --radius: 12px;
}

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

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

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }

.nav { flex: 1; padding: 12px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 4px 0;
  border-radius: 8px; color: var(--muted);
  text-decoration: none; cursor: pointer;
  transition: all .15s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 18px; text-align: center; }

.sidebar-footer { padding: 14px 18px; border-top: 1px solid var(--border); }
.health-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 20px;
  background: var(--panel-2); font-size: 12px; color: var(--muted);
}
.health-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.health-pill.ok .dot { background: var(--green); }
.health-pill.err .dot { background: var(--red); }

/* ---------- 主区域 ---------- */
.main { flex: 1; padding: 24px 32px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.api-base { color: var(--muted); font-size: 12px; }

/* ---------- 卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.stat-card { margin: 0; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin: 6px 0 2px; }
.stat-detail { color: var(--muted); font-size: 12px; }
.stat-detail.ok { color: var(--green); }
.stat-detail.err { color: var(--red); }

.card-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head .card-title { margin-bottom: 0; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.cfg-item {
  background: var(--panel-2); border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.cfg-key { color: var(--muted); font-size: 12px; }
.cfg-value { font-size: 13px; word-break: break-all; }

/* ---------- 表单 ---------- */
.desc { color: var(--muted); margin-bottom: 16px; }
.form-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.form-row label { color: var(--muted); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.form-item { display: flex; flex-direction: column; gap: 6px; }
.form-item-wide { grid-column: 1 / -1; }
.form-item label { color: var(--muted); font-size: 13px; }
.form-item .hint { color: var(--muted); font-size: 12px; opacity: .8; margin: 0; line-height: 1.5; }
.group-picker { display: flex; gap: 12px; align-items: flex-start; }
.group-picker select {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px; font-size: 13px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.group-picker select:focus { border-color: var(--accent); outline: none; }
.group-picker-actions { display: flex; flex-direction: column; gap: 8px; }
.sender-picker { display: flex; gap: 8px; align-items: center; }
.sender-picker input#cfgGroupSender { flex: 1; min-width: 0; }
.sender-picker input#cfgSenderMobile { width: 150px; flex: none; }
.group-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.group-tag {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; line-height: 1.6;
}
.group-tag b { color: var(--accent); font-weight: 600; }
.group-tag .tag-id { color: var(--muted); font-size: 11px; opacity: .8; }

input[type="text"], input[type="number"], input[type="url"], input[type="time"], textarea, select {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 9px 12px; font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 9px 16px;
  font-size: 14px; cursor: pointer; transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; }

/* ---------- token ---------- */
.token-box { display: flex; flex-direction: column; gap: 14px; }
.token-field label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.token-display {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; overflow-x: auto;
}
.token-display code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; word-break: break-all; }
.token-meta { display: flex; gap: 24px; color: var(--muted); font-size: 13px; }
.token-meta b { color: var(--text); }
.token-actions { display: flex; gap: 12px; }

/* ---------- 结果 / 提示 ---------- */
.result {
  margin-top: 8px; padding: 12px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px; white-space: pre-wrap; word-break: break-all;
  max-height: 320px; overflow: auto; display: none;
}
.result.show { display: block; }
.result.ok { border-color: var(--green); }
.result.err { border-color: var(--red); }

.notice {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px;
  background: rgba(245, 166, 35, .08); border: 1px solid rgba(245, 166, 35, .3);
  color: var(--amber); font-size: 13px;
}
.notice:empty { display: none; }  /* 无提示内容时隐藏,避免空框占位 */
.notice code { background: rgba(0,0,0,.3); padding: 2px 6px; border-radius: 4px; }
.notice.ok { background: rgba(61, 176, 131, .08); border-color: rgba(61, 176, 131, .3); color: var(--green); }
.notice.err { background: rgba(224, 93, 93, .08); border-color: rgba(224, 93, 93, .3); color: var(--red); }

/* 广告识别表格 */
.table-wrap { overflow-x: auto; }
.data-table { display: table; width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table tbody { display: table-row-group; }
.data-table tr { display: table-row; height: auto; }
.data-table th {
  text-align: left; color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 10px; border-bottom: 1px solid var(--panel-2); vertical-align: top; }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table .nowrap { white-space: nowrap; }
.data-table .tag-id { display: block; color: var(--muted); font-size: 11px; word-break: break-all; line-height: 1.4; }
.data-table .ads-reason { color: var(--text-2); min-width: 180px; }
.table-empty { text-align: center; color: var(--muted); padding: 24px; }
.ads-raw-wrap td { background: rgba(0, 0, 0, .2); }
.ads-raw-wrap pre {
  margin: 0; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-all;
  color: var(--text-2); max-height: 320px; overflow: auto;
}
.btn-xs { padding: 3px 10px; font-size: 12px; }

/* 推送历史 */
.history-list { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.history-empty {
  padding: 16px; text-align: center; border-radius: 8px;
  background: var(--panel-2); border: 1px dashed var(--border); color: var(--muted); font-size: 13px;
}
.history-item {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: pointer; transition: border-color .15s;
}
.history-item:hover { border-color: var(--accent); }
.history-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; flex-wrap: wrap;
}
.history-time { color: var(--muted); font-size: 12px; font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
.history-msg { font-size: 13px; color: var(--text-2); flex: 1; min-width: 120px; }
.tag { padding: 2px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.tag-channel { background: rgba(47, 128, 237, .12); color: var(--accent-2); }
.tag-status.success { background: rgba(61, 176, 131, .15); color: var(--green); }
.tag-status.error { background: rgba(224, 93, 93, .15); color: var(--red); }
.tag-status.skipped { background: rgba(245, 166, 35, .15); color: var(--amber); }
.history-body {
  display: none; margin: 0; padding: 12px 14px; border-top: 1px solid var(--border);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-all; max-height: 320px; overflow: auto;
  color: var(--text-2); background: rgba(0,0,0,.15);
}
.history-item.open .history-body { display: block; }

/* ---------- 链接 ---------- */
.link-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.link-item {
  display: block; padding: 12px 14px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--accent-2); text-decoration: none; transition: all .15s;
}
.link-item:hover { border-color: var(--accent); }

/* ---------- Tab 切换 ---------- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 12px 20px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 999;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* ---------- 登录遮罩 ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-mask.show { display: flex; }
.login-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px 48px; text-align: center; max-width: 380px;
}
.login-card h2 { margin: 16px 0 8px; font-size: 20px; }
.login-desc { color: var(--muted); margin-bottom: 24px; }
.login-actions { display: flex; gap: 12px; justify-content: center; }
.login-hint { color: var(--muted); font-size: 12px; margin-top: 16px; opacity: .8; }

@media (max-width: 720px) {
  .sidebar { width: 64px; }
  .brand-name, .brand-sub, .nav-item span:not(.nav-icon), .api-base { display: none; }
  .nav-item { justify-content: center; }
  .main { padding: 16px; }
}