/* MGTG 守护台 —— 白天（白色主体）/ 夜间（深海军蓝）双主题
   主题由 <html data-theme="light|dark"> 切换（theme.js 早加载防闪烁，app.js 顶栏按钮切换）。
   所有颜色走 CSS 变量，深色主题只覆盖 :root[data-theme="dark"] 下的变量。 */
:root, :root[data-theme="light"] {
  --bg: #edf3fb;            /* 页面最底层：极浅蓝，宽屏两侧自然留白 */
  --bg-panel: #ffffff;      /* 卡片面板：纯白主体（呼应图标的白色镜框） */
  --bg-card: #f4f8fd;       /* 输入框/次级卡片 */
  --bg-hover: #ecf3fc;
  --surface: #ffffff;       /* 按钮/输入框等可交互面（随主题翻转） */
  --topbar-bg: rgba(255, 255, 255, 0.78);  /* 顶栏/抽屉吸顶（半透明毛玻璃） */
  --scrim: rgba(13, 28, 56, 0.36);          /* 抽屉/弹窗遮罩 */
  --border: #dfe8f4;
  --border-soft: #eaf1f9;
  --text: #18202e;          /* 取自图标屏幕的深海军蓝 */
  --muted: #69788e;
  --accent: #2e86ff;        /* 机器人机身蓝 */
  --accent-2: #36c5ff;      /* 天线/高光青（渐变亮端） */
  --accent-deep: #2470ff;   /* 渐变深端（光泽按钮的底色） */
  --accent-dim: rgba(46, 134, 255, 0.10);
  --green: #1faa6e;
  --yellow: #c98a00;
  --red: #e5484d;
  --glow-1: rgba(46, 134, 255, 0.13);
  --glow-2: rgba(54, 197, 255, 0.11);
  --radius: 18px;           /* 跟随图标的「圆方脸」轮廓，更圆润 */
  --radius-sm: 14px;
  --radius-btn: 12px;       /* 按钮/输入框统一圆角 */
  --shadow-sm: 0 1px 3px rgba(24, 50, 100, 0.06), 0 1px 2px rgba(24, 50, 100, 0.04);
  --shadow-md: 0 6px 18px rgba(28, 62, 120, 0.09);
  --shadow-lg: 0 18px 50px rgba(28, 62, 120, 0.16);
  --content-w: 1180px;      /* 内容列最大宽度，超宽屏幕两侧留白 */
  --gutter: clamp(14px, 4vw, 32px);
  --font: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

/* 夜间模式：图标屏幕同款深海军蓝 + 蓝青光晕（仅覆盖颜色变量，布局/圆角不变） */
:root[data-theme="dark"] {
  --bg: #070d1a;
  --bg-panel: #0f1a2c;
  --bg-card: #14223a;
  --bg-hover: #1a2c48;
  --surface: #14223a;
  --topbar-bg: rgba(9, 16, 30, 0.80);
  --scrim: rgba(0, 0, 0, 0.58);
  --border: #26395a;
  --border-soft: #1c2a44;
  --text: #e7eef8;
  --muted: #8da0b8;
  --accent: #4da3ff;
  --accent-2: #36c5ff;
  --accent-deep: #2e7bff;
  --accent-dim: rgba(77, 163, 255, 0.16);
  --green: #3fbf83;
  --yellow: #e0a52a;
  --red: #ff6b66;
  --glow-1: rgba(61, 160, 255, 0.17);
  --glow-2: rgba(54, 197, 255, 0.12);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(900px 380px at 12% -120px, var(--glow-1), transparent 70%),
    radial-gradient(820px 360px at 92% -80px, var(--glow-2), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  min-height: 100dvh;
}

h1 { font-size: 19px; margin: 0; letter-spacing: 0.2px; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 700; }
h3 { font-size: 14px; margin: 22px 0 10px; color: var(--accent); }

.accent { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

button, input, select { touch-action: manipulation; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- 顶栏：半透明白 + 毛玻璃，内容与主列对齐 ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-inner {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 14px var(--gutter);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---- 统一入口标签：守护台 ⇄ 手机控制台（同域路径互切，小而醒目、不易误触） ---- */
.app-tabs {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.app-tab {
  font-size: 12px;
  line-height: 1;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}
.app-tab.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }
a.app-tab:hover { color: var(--text); background: var(--bg-hover); }
a.app-tab:active { transform: scale(0.96); }
.login-tabs { display: flex; justify-content: center; margin-top: 16px; }
/* 「手机控制」入口仅手机端（窄屏 ≤720px）显示；电脑端隐藏，避免误点跳手机控制台、端口打架 */
.app-tabs { display: none; }

/* ---- 机器人 logo（icon.png 真图标）：蓝色光晕投影，悬停时歪头打招呼 ---- */
.bot-logo {
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(46, 134, 255, 0.35));
  transition: transform 0.2s ease;
}
.brand .bot-logo:hover { transform: rotate(-8deg) scale(1.08); }

/* ---- 主内容列：居中、限宽、两侧自然留白 ---- */
main {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 24px var(--gutter) 72px;
}

/* ---- 按钮 ---- */
.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 8px 15px;
  min-height: 36px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover { border-color: var(--accent); background: var(--bg-hover); box-shadow: var(--shadow-md); }
.btn:active { transform: scale(0.97); }
/* 主按钮：青→深蓝纵向渐变 + 顶部细高光，复刻图标机身的玻璃光泽 */
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent-deep));
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), 0 6px 16px rgba(36, 112, 255, 0.30);
}
.btn.primary:hover { filter: brightness(1.06); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), 0 8px 22px rgba(36, 112, 255, 0.36); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { border-color: rgba(229, 72, 77, 0.5); color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: rgba(229, 72, 77, 0.07); }
.btn.wide { width: 100%; }
.btn.small-btn { padding: 5px 11px; min-height: 30px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---- 徽章 ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  white-space: nowrap;
}
.badge.ok { color: var(--green); border-color: rgba(31, 170, 110, 0.4); background: rgba(31, 170, 110, 0.10); }
.badge.warn { color: var(--yellow); border-color: rgba(201, 138, 0, 0.4); background: rgba(201, 138, 0, 0.10); }
.badge.bad { color: var(--red); border-color: rgba(229, 72, 77, 0.4); background: rgba(229, 72, 77, 0.10); }
/* 状态徽章前加一颗呼吸小圆点：扫一眼颜色就知道现在好不好 */
.badge.ok::before, .badge.warn::before, .badge.bad::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  animation: dot-breathe 2s ease-in-out infinite;
}
.badge.bad::before { animation-duration: 1s; }   /* 出问题时跳得更急，引导视线 */
@keyframes dot-breathe {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
  50% { opacity: 0.55; box-shadow: 0 0 0 3px transparent; }
}

/* ---- 提示横幅 ---- */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: rgba(229, 72, 77, 0.08);
  border: 1px solid rgba(229, 72, 77, 0.4);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

/* ---- 面板与卡片 ---- */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

/* ---- 站点标签页（多分站时主页只显示选中站） ---- */
.station-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 14px;
  padding-bottom: 2px;
}
.station-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  min-height: 40px;
  background: var(--bg-panel);
  color: var(--muted);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.station-tab:hover { border-color: var(--accent); color: var(--text); box-shadow: var(--shadow-md); }
.station-tab.active {
  background: linear-gradient(135deg, rgba(54, 197, 255, 0.14), rgba(46, 134, 255, 0.10));
  border-color: rgba(46, 134, 255, 0.45);
  color: var(--accent);
  font-weight: 600;
}

.station-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.station-head h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.station-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
/* 已暂停站点：整卡轻微压暗，配合「已暂停检测」徽章一眼可辨（按钮仍清晰可点） */
.station-paused { opacity: 0.82; }

/* ---- 探针接入引导：新站点 key 没粘贴时的醒目提示（监测没生效是最大的事） ---- */
.setup-guide {
  border: 1px solid rgba(201, 138, 0, 0.4);
  background: rgba(201, 138, 0, 0.07);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.setup-guide .sg-title { color: var(--yellow); font-weight: 600; margin-bottom: 6px; }
.setup-guide .sg-body { font-size: 13px; color: var(--text); }
.setup-guide ol { margin: 6px 0 10px; padding-left: 20px; }
.setup-guide li { margin: 3px 0; overflow-wrap: anywhere; }
.setup-guide.slim {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--yellow);
}

/* 未接入（缺 key）的槽位：整行压暗，和「正在监测」明显区分 */
.row-nokey td { color: var(--muted); background: rgba(201, 138, 0, 0.03); }
.row-nokey td:first-child { border-left: 2px solid var(--yellow); }
.probe-card.card-nokey { border-style: dashed; opacity: 0.9; }

/* 已隔离的槽位：整行/卡片压暗下沉，明确「反复扑街，已暂不参与候选」，与可用储备区分 */
.row-quarantined td { color: var(--muted); background: rgba(201, 138, 0, 0.03); }
.row-quarantined td:first-child { border-left: 2px solid var(--yellow); }
.probe-card.card-quarantined { opacity: 0.8; border-style: dashed; }

/* ---- 一眼区：当前分组 + 关键指标，打开页面 1 秒内回答「现在好不好」 ---- */
.station-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px 24px;
  padding: 18px 20px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(54, 197, 255, 0.11), rgba(46, 134, 255, 0.07));
  border: 1px solid rgba(46, 134, 255, 0.18);
  border-radius: var(--radius);
}
.hero-main { min-width: 0; }
.hero-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 2px 0 6px; }
.hero-group .group-name { font-size: 24px; font-weight: 700; color: var(--text); letter-spacing: 0.2px; overflow-wrap: anywhere; }
.hero-meta { overflow-wrap: anywhere; }
.hero-stats { display: flex; gap: 28px; flex-shrink: 0; }
.stat b {
  display: block;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat b i { font-style: normal; font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 2px; -webkit-text-fill-color: var(--muted); }
.stat span { font-size: 12px; color: var(--muted); }

/* ---- 消耗账单看板（合并卡）：今日探测/Codex 小条 + 各账号账单表 ----
   原「今日探测消耗」「账号消耗」两张卡合并为一张：少一个标题/提示行/卡片边框，
   采集口径等长说明全部进 title 悬停提示，正文只留数字。 */
.cost-strip {
  margin-top: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(46, 134, 255, 0.08), rgba(54, 197, 255, 0.06));
  border: 1px solid rgba(46, 134, 255, 0.22);
}
.cost-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.cost-head .btn { margin-left: auto; flex-shrink: 0; }
.cost-title { font-size: 14px; font-weight: 700; color: var(--text); }
/* 今日探测（蓝）/ 今日 Codex（绿）两枚紧凑小条 */
.today-strips { display: flex; gap: 8px 10px; flex-wrap: wrap; }
.today-strips:not(:last-child) { margin-bottom: 10px; }
.today-strip {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.22);
  font-variant-numeric: tabular-nums;
}
.today-strip .ts-label { font-size: 13px; font-weight: 700; color: #4ade80; }
.today-strip b { font-size: 15px; }
.today-strip.probe { background: rgba(46, 134, 255, 0.08); border-color: rgba(46, 134, 255, 0.25); }
.today-strip.probe .ts-label { color: var(--accent); }
.usage-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.usage-table { min-width: 560px; }
.usage-table td b { font-variant-numeric: tabular-nums; }
/* 网关跨站调度设置（设置抽屉）：两枚下拉一行排，窄屏自动换行 */
.gw-routing-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.gw-routing-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1 1 220px; }
.gw-routing-row select { width: 100%; }

/* 各账号主 token 当前所在分组（同伴跟随切换后一眼可见切到哪了） */
.usage-group {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent);
  background: rgba(46, 134, 255, 0.12);
  border: 1px solid rgba(46, 134, 255, 0.28);
  white-space: nowrap;
}

/* ---- 健康脉搏条：绿=成功 红=失败，柱高=耗时 ---- */
.pulse {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 22px;
  vertical-align: middle;
}
.pulse i {
  width: 4px;
  min-height: 4px;
  border-radius: 2px;
  background: var(--green);
  opacity: 0.85;
}
.pulse i.fail { background: var(--red); opacity: 1; }
.pulse i:hover { opacity: 1; transform: scaleX(1.4); }

/* ---- 候选表格：窄屏横向滚动而不是挤压 ---- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -6px;
  padding: 0 6px;
}
table { width: 100%; min-width: 880px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: 0.4px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
td.reason-cell { white-space: normal; max-width: 300px; min-width: 160px; color: var(--muted); font-size: 12px; }
td.cell-dim { color: var(--muted); font-size: 12px; }
td { font-variant-numeric: tabular-nums; }

/* ---- 手机端槽位卡片（默认隐藏，窄屏替代表格） ---- */
.probe-cards { display: none; }
.probe-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.probe-card.card-current { border-color: rgba(31, 170, 110, 0.4); background: rgba(31, 170, 110, 0.06); }
.pc-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pc-slot { color: var(--accent); font-weight: 700; }
.pc-group { font-weight: 600; overflow-wrap: anywhere; min-width: 0; flex: 1; }
.pc-health { flex-shrink: 0; font-size: 12px; }
.pc-meta { overflow-wrap: anywhere; }
.pc-note { font-size: 12px; overflow-wrap: anywhere; }
.probe-card .btn { align-self: flex-start; }

.health-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.health-healthy { background: var(--green); box-shadow: 0 0 0 3px rgba(31, 170, 110, 0.18); }
.health-review { background: var(--yellow); }
.health-unhealthy { background: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.16); }
.health-unknown { background: var(--muted); }

.row-current { background: rgba(31, 170, 110, 0.06); }
.row-current td:first-child { border-left: 2px solid var(--green); }

.score-good { color: var(--green); font-weight: 600; }
.score-mid { color: var(--yellow); font-weight: 600; }
.score-bad { color: var(--red); font-weight: 600; }

/* ---- 安全体检 ---- */
.sec-head { display: flex; align-items: center; gap: 16px; margin: 8px 0 12px; }
.sec-score { font-size: 38px; font-weight: 700; line-height: 1; min-width: 62px; text-align: center; }
.sec-summary { display: flex; flex-direction: column; gap: 8px; }
.sec-items { display: flex; flex-direction: column; gap: 6px; }
.sec-row { display: flex; gap: 9px; padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--bg-card); }
.sec-row .sec-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.sec-row.ok .sec-dot { background: var(--green); }
.sec-row.warn .sec-dot { background: var(--yellow); }
.sec-row.bad .sec-dot { background: var(--red); }
.sec-row .sec-body { min-width: 0; }
.sec-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; }
.sec-row.warn .sec-tag { color: var(--yellow); }
.sec-row.bad .sec-tag { color: var(--red); }
.sec-fix { color: var(--accent); margin-top: 3px; }

/* ---- 事件 ---- */
.events-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.events-head h2 { margin: 0; }
.event-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.event-filters .btn.active { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.events { max-height: 340px; overflow-y: auto; font-size: 13px; }
.event-row { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.event-row:last-child { border-bottom: none; }
.event-row > span:last-child { overflow-wrap: anywhere; min-width: 0; }
.event-time { color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.event-level { flex-shrink: 0; width: 44px; font-size: 12px; }
.event-level.info { color: var(--accent); }
.event-level.warn { color: var(--yellow); }
.event-level.error { color: var(--red); }

/* ---- 设置抽屉 ---- */
.drawer {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}
.drawer-inner {
  width: min(580px, 100%);
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 0 var(--gutter) calc(60px + env(safe-area-inset-bottom));
  animation: drawer-in 0.22s ease-out;
}
@keyframes drawer-in {
  from { transform: translateX(28px); opacity: 0.4; }
  to { transform: translateX(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer-inner { animation: none; }
  .modal-card { animation: none; }
  .btn { transition: none; }
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  margin: 0 calc(-1 * var(--gutter)) 14px;
  padding: 14px var(--gutter);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
  z-index: 2;
}
.drawer-head h2 { margin: 0; }

/* 设置抽屉里的站点折叠节（多站点时不至于一拉到底） */
.station-fold { border: 1px solid var(--border-soft); border-radius: var(--radius-sm); margin: 14px 0; background: var(--bg-card); }
.station-fold > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  list-style: none;
}
.station-fold > summary::-webkit-details-marker { display: none; }
.station-fold > summary::before { content: '▸'; color: var(--muted); margin-right: 2px; transition: transform 0.15s ease; }
.station-fold[open] > summary::before { transform: rotate(90deg); }
.station-fold > form { padding: 0 14px 14px; }

/* ---- 页内弹窗（替代原生 confirm/prompt） ---- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  width: min(420px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.16s ease-out;
}
@keyframes modal-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-card h2 { margin-bottom: 8px; }
.modal-card p { margin: 0 0 8px; font-size: 13px; }
.modal-card input { width: 100%; margin: 8px 0 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn.primary.danger { background: linear-gradient(135deg, #ff6b64, var(--red)); border-color: transparent; color: #fff; box-shadow: 0 6px 16px rgba(229, 72, 77, 0.26); }
.btn.primary.danger:hover { filter: brightness(1.05); }

/* 新建站点表单高亮提示 */
.flash-new { animation: flash-border 2.4s ease-out; border-radius: var(--radius-sm); }
@keyframes flash-border {
  0%, 60% { box-shadow: 0 0 0 2px var(--accent); }
  100% { box-shadow: 0 0 0 2px transparent; }
}

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-bottom: 12px; }
.grid-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
/* .full 必须同时覆盖 label / div / button：探针槽位、同伴账号、保存按钮都是 div/button.full，
   只写 label.full 会让它们被塞进双列网格的半列里，宽屏下内容被挤出可视区（云端「添加同伴」被挡住的根因） */
.grid-form .full { grid-column: 1 / -1; }
input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  color: var(--text);
  padding: 9px 11px;
  min-height: 38px;
  font-size: 13px;
  font-family: var(--font);
}
input::placeholder { color: #aab2c0; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46, 134, 255, 0.18); }

.probe-slot {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.probe-slot .slot-id { color: var(--accent); font-weight: 600; }

.follower-row {
  display: grid;
  grid-template-columns: 90px 70px 1fr 1fr 56px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
h3 .btn { margin-left: 10px; vertical-align: middle; }

.error-text { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* ---- 登录页 ---- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 30px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { margin-bottom: 4px; }
/* 登录页头部：机器人 + 标题 + 副标题整体居中对齐 */
.login-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.login-head .muted { margin: 0; }
.login-logo {
  width: 76px;
  height: 76px;
  margin-bottom: 8px;
  animation: bot-float 3.6s ease-in-out infinite;
}
@keyframes bot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-hint { margin: 2px 0 0; line-height: 1.6; }

/* ---- 新手指引弹窗 ---- */
.guide-card { width: min(480px, 100%); }
.guide-steps { margin: 10px 0 12px; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.guide-steps li { font-size: 13px; line-height: 1.7; }
.guide-steps b { color: var(--accent, #2e86ff); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(26px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 13px;
  z-index: 99;
  box-shadow: var(--shadow-lg);
}
.toast.error { border-color: var(--red); color: var(--red); }

/* ---- 全局健康头条：开页第一眼的「现在好不好」一句话 ---- */
.health-headline {
  margin: 0 0 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  animation: fade-up 0.25s ease-out;
}
.health-headline.ok { border-color: rgba(31, 170, 110, 0.45); }
.health-headline.warn { border-color: rgba(201, 138, 0, 0.5); }
.health-headline.bad { border-color: rgba(229, 72, 77, 0.55); }
.hh-dot { flex-shrink: 0; font-size: 11px; line-height: 1.7; }
.health-headline.ok .hh-dot { color: var(--green); }
.health-headline.warn .hh-dot { color: var(--yellow); animation: dot-breathe 1.6s infinite; }
.health-headline.bad .hh-dot { color: var(--red); animation: dot-breathe 1s infinite; }
.health-headline.ok .hh-text { color: var(--green); font-weight: 600; }
.health-headline.warn .hh-text { color: var(--yellow); font-weight: 600; }
.health-headline.bad .hh-text { color: var(--red); font-weight: 600; }

/* ---- 顶栏铃铛 + 通知中心 ---- */
.btn-bell { position: relative; padding: 8px 12px; }
.btn-bell svg { display: block; }
.bell-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg-panel);
}
.notif-panel {
  position: fixed;
  top: 62px;
  right: max(12px, calc((100vw - var(--content-w)) / 2));
  width: min(400px, calc(100vw - 24px));
  max-height: min(480px, calc(100dvh - 90px));
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: fade-up 0.18s ease-out;
}
.notif-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.notif-list { overflow-y: auto; padding: 4px 0; }
.notif-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
}
.notif-row:last-child { border-bottom: none; }
.notif-row.unread { background: var(--accent-dim); }
.notif-row .event-type { margin-top: 2px; }
.notif-body { min-width: 0; }
.notif-msg { overflow-wrap: anywhere; line-height: 1.55; }
.notif-empty { padding: 16px 14px; margin: 0; }
/* 分级降噪：「需要处理」红字分节 + 红边行；「动态」灰字分节（系统已自动处理，扫一眼即可） */
.notif-sec {
  padding: 9px 14px 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--muted);
}
.notif-sec.urgent { color: var(--red); }
.notif-row.urgent-row { border-left: 3px solid var(--red); padding-left: 11px; }
/* 角标分轻重：默认红（有需要处理的未读）；soft = 只有动态未读，琥珀色不吓人 */
.bell-count.soft { background: var(--yellow); color: #1c2233; }

/* ---- 事件类型小章（与级别色区分：类型用中性底色 + 各自色字） ---- */
.event-type {
  flex-shrink: 0;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 19px;
  margin-top: 1px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  color: var(--muted);
  white-space: nowrap;
}
.et-switch { color: var(--accent); border-color: rgba(46, 134, 255, 0.35); background: rgba(46, 134, 255, 0.08); }
.et-emergency { color: var(--red); border-color: rgba(229, 72, 77, 0.35); background: rgba(229, 72, 77, 0.08); }
.et-alert { color: var(--yellow); border-color: rgba(201, 138, 0, 0.35); background: rgba(201, 138, 0, 0.08); }
.et-health { color: var(--green); border-color: rgba(31, 170, 110, 0.35); background: rgba(31, 170, 110, 0.08); }
.et-candidate { color: var(--accent-2); border-color: rgba(54, 197, 255, 0.35); background: rgba(54, 197, 255, 0.08); }
.et-follower { color: #9d7bff; border-color: rgba(157, 123, 255, 0.35); background: rgba(157, 123, 255, 0.08); }
.et-gateway { color: #d177c9; border-color: rgba(209, 119, 201, 0.32); background: rgba(209, 119, 201, 0.08); }

/* ---- 切换时间线弹窗 ---- */
.timeline-card { width: min(620px, 100%); }
.timeline-body { max-height: min(58vh, 560px); overflow-y: auto; margin: 6px 0 4px; }
.timeline { padding: 4px 2px 0 6px; }
.tl-row {
  position: relative;
  padding: 0 0 16px 20px;
  border-left: 2px solid var(--border);
  margin-left: 5px;
}
.tl-row:last-child { border-left-color: transparent; padding-bottom: 4px; }
.tl-dot {
  position: absolute;
  left: -6px;
  top: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--bg-panel);
}
.tl-dot.ok { background: var(--green); }
.tl-dot.warn { background: var(--yellow); }
.tl-dot.bad { background: var(--red); }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.tl-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tl-swap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.tl-group {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-group.to { border-color: rgba(31, 170, 110, 0.45); color: var(--green); font-weight: 600; }
.tl-arrow { color: var(--accent); font-weight: 700; }
.tl-msg { font-size: 12.5px; overflow-wrap: anywhere; }

/* ---- 余额预警红标 ---- */
.low-balance { color: var(--red); font-weight: 700; white-space: nowrap; }
.low-balance i {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 600;
  margin-left: 5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.4);
  vertical-align: 1px;
}

/* ---- 备份与恢复按钮排 ---- */
.backup-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- 微动效（统一在此声明，prefers-reduced-motion 时全部关闭） ---- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
/* 注意：.panel 等定时刷新会整体重建的节点绝不能挂入场动画——
   仪表盘每 15s 重绘一次站点区，入场动画会跟着重播，看起来就是「页面一闪一闪」。
   入场动画只允许用在真正一次性挂载的 UI 上（弹窗/抽屉/通知面板）。 */
.probe-card, .panel, .cost-strip { transition: border-color 0.18s ease, box-shadow 0.18s ease; }
.btn { transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease; }
.btn:active { transform: scale(0.97); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- 平板及以下 ---- */
@media (max-width: 900px) {
  .station-head { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ---- 手机端 ---- */
@media (max-width: 720px) {
  body { font-size: 13px; }
  /* 顶栏压缩：手机上信息密度优先——标题/徽章缩小、按钮变紧凑单行，整条顶栏控制在两行内 */
  .topbar-inner { padding-top: 8px; padding-bottom: 8px; gap: 6px; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 15px; }
  .brand .bot-logo { width: 26px; height: 26px; }
  .badge { font-size: 11px; padding: 2px 8px; }
  #round-info { display: none; }            /* 顶栏只留关键信息 */
  .app-tabs { display: inline-flex; padding: 2px; }   /* 手机端恢复显示入口标签 */
  .login-tabs { display: flex; }
  .app-tab { font-size: 11px; padding: 5px 9px; }
  .actions { width: 100%; gap: 6px; }
  .actions .btn { flex: 1 1 auto; min-height: 36px; padding: 6px 8px; font-size: 12px; }
  /* 夜间/设置/退出是低频操作：不参与等分，收成紧凑小按钮，把宽度让给「立即检测/暂停切换」 */
  #btn-theme, #btn-logout, #btn-settings { flex: 0 0 auto; padding: 6px 9px; }
  main { padding-top: 12px; }
  .health-headline { margin-bottom: 10px; padding: 9px 12px; }
  .panel { padding: 14px; border-radius: var(--radius-sm); }
  .station-hero { padding: 14px; }
  .hero-group .group-name { font-size: 19px; }
  .hero-stats { gap: 20px; }
  .cost-strip { padding: 12px 14px; }
  .today-strip { padding: 5px 10px; }
  .stat b { font-size: 21px; }
  /* 窄屏：表格换成槽位卡片，不再横向滚动 */
  .table-wrap { display: none; }
  .probe-cards { display: block; }
  .pulse { height: 26px; width: 100%; justify-content: space-between; }
  .pulse i { width: 5px; }
  .grid-form { grid-template-columns: 1fr; }
  .probe-slot { grid-template-columns: 36px 1fr; }
  .probe-slot input[data-pfield="group_name"] { grid-column: 2; }
  .follower-row { grid-template-columns: 1fr 1fr; }
  .follower-row [data-ffield="main_token_name"],
  .follower-row [data-ffield="admin_token"] { grid-column: 1 / -1; }
  .follower-row .btn { grid-column: 1 / -1; }
  .drawer-inner { width: 100%; border-left: none; }
  input, select { font-size: 16px; }        /* 避免 iOS 聚焦自动放大 */
  .events { max-height: 280px; }
  .notif-panel { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); right: 12px; left: 12px; width: auto; }
  .btn-bell { flex: 0 0 auto !important; }   /* 铃铛保持小尺寸，不参与按钮等分 */
  .event-row { flex-wrap: wrap; }
  .event-type { order: -1; }
}
