/* ==========================================================================
   sub2api-admin · 设计系统
   - 主题：跟随系统 / 亮 / 暗（<html data-theme="light|dark"> 覆盖 data-theme-mode）
   - 布局：移动优先，<=860px 数据表退化为卡片行，>=861px 自适应多列
   - 与 Tailwind CDN 并存：本文件负责色彩/组件/响应式，Tailwind 只做布局工具类
   ========================================================================== */

/* ---------- 主题变量 ---------- */
:root,
html[data-theme='light'] {
  color-scheme: light;
  --bg: #f5f6fa;
  --bg-accent: radial-gradient(1100px 500px at 12% -8%, rgba(124, 58, 237, 0.1), transparent 62%);
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --panel-3: #f2f4f8;
  --surface: #ffffff;
  --border: #e3e6ee;
  --border-strong: #cfd5e4;
  --text: #16182b;
  --text-2: #4a5070;
  --text-3: #7d84a0;
  --brand: #6d28d9;
  --brand-2: #7c3aed;
  --brand-fg: #ffffff;
  --brand-soft: rgba(124, 58, 237, 0.1);
  --brand-ring: rgba(124, 58, 237, 0.18);
  --ok: #047857;
  --ok-soft: rgba(5, 150, 105, 0.1);
  --warn: #b45309;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --zebra: rgba(22, 24, 43, 0.024);
  --hover: rgba(109, 40, 217, 0.06);
  --shadow-1: 0 1px 2px rgba(18, 20, 45, 0.06), 0 1px 3px rgba(18, 20, 45, 0.04);
  --shadow-2: 0 8px 24px rgba(18, 20, 45, 0.08);
  --shadow-pop: 0 16px 40px rgba(18, 20, 45, 0.14);
  --skeleton: linear-gradient(90deg, rgba(22, 24, 43, 0.05), rgba(22, 24, 43, 0.1), rgba(22, 24, 43, 0.05));
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0a0a14;
  --bg-accent: radial-gradient(1100px 520px at 10% -10%, rgba(124, 58, 237, 0.22), transparent 60%);
  --panel: #121220;
  --panel-2: #171728;
  --panel-3: #1d1d33;
  --surface: #121220;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --text: #eef0f7;
  --text-2: #b6bcd4;
  --text-3: #8087a6;
  --brand: #8b5cf6;
  --brand-2: #7c3aed;
  --brand-fg: #ffffff;
  --brand-soft: rgba(124, 58, 237, 0.16);
  --brand-ring: rgba(139, 92, 246, 0.32);
  --ok: #34d399;
  --ok-soft: rgba(16, 185, 129, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --zebra: rgba(255, 255, 255, 0.022);
  --hover: rgba(139, 92, 246, 0.12);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-pop: 0 18px 44px rgba(0, 0, 0, 0.55);
  --skeleton: linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background-color: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 { color: var(--text); margin: 0; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, kbd { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace; }

:focus-visible {
  outline: 2px solid var(--brand-ring);
  outline-offset: 2px;
  border-radius: 6px;
}

.num { font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -60px;
  padding: 10px 14px; border-radius: 0 0 10px 10px;
  background: var(--brand); color: var(--brand-fg);
  font-size: 13px; z-index: 90; transition: top 0.15s;
}
.skip-link:focus { top: 0; text-decoration: none; }

::selection { background: var(--brand-soft); }

/* 滚动条（桌面） */
@media (pointer: fine) {
  * { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }
}

/* ---------- 布局容器 ---------- */
.wrap {
  width: 100%;
  max-width: 1440px;
  margin-inline: auto;
  padding-inline: 16px;
}

/* ---------- 顶部栏 ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(1px)) {
  .appbar { background: var(--panel); }
}

.appbar__inner {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding-block: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand__logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(135deg, #a78bfa 0%, var(--brand-2) 55%, #5b21b6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.brand__sub {
  font-size: 11px;
  color: var(--text-3);
  padding-left: 10px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

.appbar__right { display: flex; align-items: center; gap: 10px; }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-3);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  white-space: nowrap;
}
.conn__dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--text-3);
  box-shadow: 0 0 0 3px transparent;
  transition: background 0.15s, box-shadow 0.15s;
  flex: none;
}
.conn__dot.is-on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* 主题切换 */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  flex: none;
}
.theme-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 26px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button[aria-pressed='true'] {
  background: var(--panel);
  color: var(--brand);
  box-shadow: var(--shadow-1);
}
.theme-toggle svg { width: 15px; height: 15px; }

/* ---------- 选项卡 ---------- */
.tabs {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin-inline: -16px;
  padding-inline: 16px;
  scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: none;
  scroll-snap-align: start;
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--hover); }
.tab-btn.active {
  color: var(--brand-fg);
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  box-shadow: 0 2px 8px var(--brand-ring);
}

/* ---------- 凭据条 ---------- */
.creds {
  background: color-mix(in srgb, var(--panel) 62%, transparent);
  border-bottom: 1px solid var(--border);
}
.creds__inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding-block: 12px;
}
.creds__hint {
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
}
.creds__hint::before {
  content: '';
  width: 12px; height: 12px; flex: none;
  background: currentColor;
  opacity: 0.5;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='4' y='10' width='16' height='11' rx='2'/%3E%3Cpath d='M8 10V7a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='4' y='10' width='16' height='11' rx='2'/%3E%3Cpath d='M8 10V7a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- 主区 ---------- */
.page { padding-block: 20px 32px; }

.status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 20px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--text-2);
  transition: color 0.15s;
}
.status:not(:empty)::before {
  content: '';
  flex: none;
  width: 3px;
  align-self: stretch;
  min-height: 16px;
  border-radius: 999px;
  background: var(--border-strong);
}
.status.is-busy::before { background: var(--brand); }
.status.is-ok { color: var(--ok); }
.status.is-ok::before { background: var(--ok); }
.status.is-error { color: var(--danger); }
.status.is-error::before { background: var(--danger); }

#tabBody { min-width: 0; }
#tabBody.tab-enter { animation: tabIn 0.22s ease-out; }
@keyframes tabIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.footnote {
  padding-bottom: 40px;
  font-size: 11px;
  line-height: 1.7;
  color: var(--text-3);
}
.footnote code { color: var(--text-2); }

/* ---------- 工具条（每个 tab 顶部的筛选区） ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.toolbar > .field,
.toolbar > .btn { flex: 1 1 160px; }
.toolbar > .toolbar__grow { flex: 1 1 100%; }
.toolbar__grow { min-width: 0; }
.toolbar > .btn { flex: 0 0 auto; }

/* ---------- 表单控件 ---------- */
.field,
input[type='text'].field,
input[type='password'].field,
input[type='number'].field,
input[type='date'].field,
input[type='search'].field,
select.field,
textarea.field {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-1);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field::placeholder { color: var(--text-3); }
.field:hover { border-color: var(--border-strong); }
.field:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.field:disabled { opacity: 0.55; cursor: not-allowed; }

select.field {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%23888fa8' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
}

.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-3);
  margin-bottom: 5px;
}

.field-mini {
  padding: 6px 9px;
  font-size: 12.5px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
  min-width: 0;
}
.field-mini:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

.cell-field {
  width: 100%;
  padding: 6px 9px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.cell-field:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

input[type='checkbox'] { accent-color: var(--brand); width: 15px; height: 15px; cursor: pointer; }
input[type='date'] { min-height: 38px; }

.spin {
  display: inline-block;
  width: 11px; height: 11px;
  border-radius: 999px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.06s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--border-strong); background: var(--panel-2); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn--primary {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  border-color: transparent;
  color: var(--brand-fg);
  box-shadow: 0 2px 10px var(--brand-ring);
}
.btn--primary:hover { background: linear-gradient(180deg, var(--brand), var(--brand-2)); border-color: transparent; }
.btn--primary:disabled { background: var(--panel-3); color: var(--text-3); box-shadow: none; }

.btn--danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 38%, transparent);
  background: var(--danger-soft);
}
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); border-color: var(--danger); }

.btn--ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 38%, transparent);
  background: var(--ok-soft);
}
.btn--ok:hover { background: color-mix(in srgb, var(--ok) 18%, transparent); border-color: var(--ok); }

.btn--solid-danger {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, #ef4444, #dc2626);
  box-shadow: 0 2px 10px rgba(220, 38, 38, 0.3);
}
.btn--solid-danger:hover { background: linear-gradient(180deg, #dc2626, #b91c1c); }
.btn--solid-danger:disabled { background: var(--panel-3); color: var(--text-3); box-shadow: none; }

.btn--sm { padding: 5px 9px; font-size: 12px; border-radius: 8px; gap: 4px; box-shadow: none; }
.btn--block { width: 100%; }

/* ---------- 数据表 / 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.card + .card { margin-top: 18px; }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.card__title { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }
.card__meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.card__body { padding: 16px; }

.tables { display: flex; flex-direction: column; gap: 18px; }

.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-3);
  background: var(--panel-2);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 11px 14px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:nth-child(even) { background: var(--zebra); }
table.data tbody tr:hover { background: var(--hover); }
table.data td:first-child { color: var(--text); }
table.data code { font-size: 11.5px; color: var(--text-2); background: var(--panel-3); padding: 2px 6px; border-radius: 6px; }
table.data .rowcell { display: block; }

/* 表头排序（th-sort 由 renderTable 标记；升/降/还原三态） */
th.th-sort { cursor: pointer; user-select: none; -webkit-user-select: none; }
th.th-sort::after { content: '↕'; opacity: 0.35; margin-left: 5px; font-size: 10px; }
th.th-sort:hover::after { opacity: 0.8; }
th.th-sort.is-sorted::after { content: '↑'; opacity: 1; color: var(--brand); }
th.th-sort.is-sorted-desc::after { content: '↓'; opacity: 1; color: var(--brand); }

/* 行内操作：主操作 + 更多菜单 */
.row-acts { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.menu-wrap { position: relative; display: inline-block; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 25;
  min-width: 128px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  animation: tabIn 0.15s ease-out;
}
.menu > button {
  appearance: none;
  border: 0;
  background: none;
  text-align: left;
  padding: 8px 10px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.menu > button:hover { background: var(--hover); }
.menu > button.is-danger { color: var(--danger); }

/* 语义色（片段里沿用 Tailwind 文本色类名，这里按主题重新映射） */
.text-emerald-400 { color: var(--ok) !important; }
.text-red-400, .text-red-500 { color: var(--danger) !important; }
.text-yellow-400 { color: var(--warn) !important; }
.text-gray-200, .text-gray-300 { color: var(--text) !important; }
.text-gray-400 { color: var(--text-2) !important; }
.text-gray-500, .text-gray-600 { color: var(--text-3) !important; }
.text-brand-500 { color: var(--brand) !important; }
.bg-brand-500\/5 { background: var(--brand-soft) !important; }

/* 表格内行操作按钮组 */
td .btn--sm + .btn--sm { margin-left: 5px; }

/* ---------- 行内展开面板（编辑表单/检测结果） ---------- */
/* 必须保持 table-cell（colspan 跨全列铺满）；写成 block 会被收缩成窄条 */
td.inline-form-cell {
  display: table-cell;
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 var(--brand-2);
}
td.inline-form-cell > .inline-form,
td.inline-form-cell > .probe-inline,
td.inline-form-cell > .text-gray-400 { padding: 4px 6px; }
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
.inline-form > div { min-width: 0; }
.inline-form .field-label { margin-bottom: 4px; }

/* ---------- 批量操作条 ---------- */
.batchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 14px;
  margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--brand) 45%, transparent);
  background: var(--brand-soft);
  border-radius: 12px;
  animation: tabIn 0.18s ease-out;
}
.batchbar__count { font-size: 12.5px; font-weight: 600; color: var(--brand); }
.batchbar__spacer { flex: 1 1 auto; }

/* ---------- 分段卡（工具页） ---------- */
.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-1);
  padding: 18px;
}
.section__head { margin-bottom: 14px; }
.section__title { font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.section__desc { font-size: 11.5px; color: var(--text-3); margin: 4px 0 0; line-height: 1.6; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

/* ---------- 开关 ---------- */
.switch { position: relative; display: inline-block; width: 38px; height: 21px; vertical-align: middle; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background 0.18s; pointer-events: none; }
.switch .track::before {
  content: '';
  position: absolute;
  width: 15px; height: 15px; left: 3px; top: 3px;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::before { transform: translateX(17px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--brand-ring); }
.switch input:disabled + .track { opacity: 0.5; }

/* ---------- 全局反馈：顶部请求进度条 / toast / 骨架屏 / 忙态 ---------- */
#netbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 100;
  pointer-events: none;
  overflow: hidden;
  display: none;
}
#netbar.on { display: block; }
#netbarFill {
  display: none;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  box-shadow: 0 0 8px var(--brand-ring);
  transition: width 0.25s ease;
}
/* 确定进度模式：隐藏流动动画，显示宽度百分比 */
#netbar.det::after { display: none; }
#netbar.det #netbarFill { display: block; }
#netbar::after {
  content: '';
  position: absolute;
  top: 0; left: -40%;
  width: 40%; height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--brand-2), var(--brand), transparent);
  animation: netbar 1.1s ease-in-out infinite;
}
@keyframes netbar { to { left: 105%; } }

#toastStack {
  position: fixed;
  top: 14px; right: 14px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: min(400px, calc(100vw - 28px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 11px;
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: toastIn 0.2s ease-out;
}
@supports not (backdrop-filter: blur(1px)) {
  .toast { background: var(--panel); }
}
.toast--ok { border-left-color: var(--ok); }
.toast--error { border-left-color: var(--danger); }
.toast--info { border-left-color: var(--brand); }
.toast__icon { flex: none; font-weight: 700; font-size: 12px; line-height: 1.7; }
.toast--ok .toast__icon { color: var(--ok); }
.toast--error .toast__icon { color: var(--danger); }
.toast--info .toast__icon { color: var(--brand); }
.toast__msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast__x {
  flex: none;
  appearance: none;
  background: none;
  border: 0;
  padding: 0 0 0 6px;
  font-size: 16px;
  line-height: 1.2;
  color: var(--text-3);
  cursor: pointer;
}
.toast__x:hover { color: var(--text); }
.toast.is-out { opacity: 0; transform: translateY(-6px); transition: opacity 0.24s, transform 0.24s; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* 表格加载骨架屏 */
.skel {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: var(--skeleton);
  background-size: 200% 100%;
  animation: skel 1.1s ease-in-out infinite;
}
td .skel { width: 100%; max-width: 170px; }
@keyframes skel {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* 空态行 */
table.data td.empty-cell { padding: 34px 14px; text-align: center; color: var(--text-3); font-size: 12.5px; }

/* 按钮忙态（btnTask 注入 .spin + is-busy） */
.btn .spin {
  width: 12px; height: 12px;
  border-color: color-mix(in srgb, currentColor 32%, transparent);
  border-top-color: currentColor;
}
.btn.is-busy { pointer-events: none; opacity: 0.72; }

/* 行内控件忙态 */
.switch.is-busy { opacity: 0.5; pointer-events: none; }
table.data tbody tr.is-pending { opacity: 0.55; pointer-events: none; }

/* ---------- 多选 chips（探测分组选择等） ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--border-strong); }
.chip input { width: 13px; height: 13px; margin: 0; flex: none; }
.chip.on {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
  font-weight: 500;
}
.chip .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--text-3); flex: none; }
.chip .dot.on { background: var(--ok); }

/* 分组选择表：选中行高亮 + 已选名单回显 */
#probeGroups tbody tr { cursor: pointer; }
#probeGroups tbody tr.is-sel { background: var(--brand-soft); }
#probeGroups tbody tr.is-sel td b { color: var(--brand); }
.grp-sel-hint { margin-top: 8px; font-size: 12.5px; color: var(--text-3); }
.grp-sel-hint b { color: var(--brand); }

/* 分组下渠道名单（展开行） */
.grp-accts-wrap { padding: 10px 14px; }
.grp-accts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}
.grp-acct {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.grp-acct .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--text-3); flex: none; }
.grp-acct .dot.on { background: var(--ok); }
.grp-acct.off { opacity: 0.6; }
.grp-acct.off .grp-acct-name { text-decoration: line-through; }

/* 探测结果：渠道分组小标题行 */
table.data tr.ch-head td {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--panel-2);
  font-weight: 500;
  color: var(--text);
}
table.data tr.ch-head td .ch-head-btns { margin-left: auto; display: inline-flex; gap: 6px; }

/* 探测结果降维：渠道折叠行 + 比例条 + 批量操作条 */
.ch-fold {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.ch-fold:hover td { background: var(--hover) !important; }
.ch-fold .bar {
  width: 90px;
  height: 7px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
  flex: none;
}
.ch-fold .bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ef4444, #f59e0b 60%, #10b981);
}
.probe-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 0 14px 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  background: var(--brand-soft);
  border-radius: 12px;
}
.probe-bulk__title { font-size: 12px; font-weight: 600; color: var(--brand); }
.probe-view-toggle { display: inline-flex; gap: 2px; padding: 3px; background: var(--panel-3); border: 1px solid var(--border); border-radius: 999px; }
.probe-view-toggle button {
  appearance: none; border: 0; background: transparent; border-radius: 999px;
  padding: 4px 12px; font: inherit; font-size: 12px; color: var(--text-3); cursor: pointer;
}
.probe-view-toggle button.on { background: var(--panel); color: var(--brand); box-shadow: var(--shadow-1); }
.probe-hist { padding: 8px 14px 0; }
.probe-hist__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  margin: 0 6px 6px 0;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.probe-hist__item:hover { border-color: var(--brand); color: var(--brand); }
.probe-hist__item.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* 探测就地进度条（工具页检测区内部，滚动到哪都能看到） */
.probe-live {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  animation: tabIn 0.18s ease-out;
}
.probe-live__bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
}
#probeLiveFill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  box-shadow: 0 0 8px var(--brand-ring);
  transition: width 0.3s ease;
}
#probeLiveText { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 顶栏小图标按钮 */
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 30px;
  border: 1px solid var(--border);
  background: var(--panel-3);
  border-radius: 999px;
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.iconbtn:hover { color: var(--text); border-color: var(--border-strong); }
.iconbtn svg { width: 15px; height: 15px; }

/* 会话操作日志抽屉 */
.oplog {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 92vw);
  z-index: 95;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  animation: tabIn 0.2s ease-out;
}
.oplog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.oplog__head h3 { font-size: 14px; }
.oplog__list { flex: 1; overflow: auto; padding: 8px 12px; }
.oplog__empty { color: var(--text-3); font-size: 12.5px; padding: 10px 4px; }
.oplog__item {
  display: flex;
  gap: 8px;
  font-size: 12px;
  line-height: 1.55;
  padding: 7px 6px;
  border-bottom: 1px dashed var(--border);
  color: var(--text-2);
}
.oplog__item span:first-child { flex: none; color: var(--text-3); }
.oplog__item span:last-child { overflow-wrap: anywhere; }
.oplog__item--ok span:last-child { color: var(--ok); }
.oplog__item--error span:last-child { color: var(--danger); }
.oplog__sec-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.04em;
  margin: 16px 0 6px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}
.oplog__list > .oplog__sec-title:first-child { margin-top: 4px; }
.oplog__list a { color: var(--brand); }

/* 账号页总览摘要条 */
.statbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-1);
  padding: 10px 14px;
}
.stat__num {
  display: block;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat__label { font-size: 11px; color: var(--text-3); }
.stat.is-warn .stat__num { color: var(--danger); }
.stat.is-ok .stat__num { color: var(--ok); }

/* 账号页行内检测结果 */
.probe-inline { font-size: 12.5px; }
.probe-inline__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--text-2);
}
.probe-inline__row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.probe-inline__row:last-child { border-bottom: 0; }
.probe-inline__row .mdl { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.probe-inline__row.is-fail .mdl { color: var(--danger); }
/* 已移除的模型：划线淡化；不可移除：黄色提示行 */
.probe-inline__row.is-removed .mdl { text-decoration: line-through; opacity: 0.55; }
.probe-inline__row.is-warn { background: var(--warn-soft); border-radius: 8px; padding: 6px 8px; margin: 2px -8px; }
.probe-inline__note { flex-basis: 100%; font-size: 11.5px; line-height: 1.6; color: var(--warn); }
table.data tr.is-removed td { color: var(--text-3); }
table.data tr.is-removed td:first-child { text-decoration: line-through; }

/* 模型不一致审计：账号行内展开的偷换明细 */
.audit-detail {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.audit-detail-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  padding: 4px 10px;
  background: var(--panel-3);
  border-radius: 8px;
}
.audit-detail-row .mdl { color: var(--text-2); overflow-wrap: anywhere; }

/* ---------- 提示 / 结果块 ---------- */
.alert {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 11px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-2);
}
.alert--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-soft); }
.alert--error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); }

pre.code-block {
  margin: 12px 0 0;
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-2);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 340px;
}

/* HTML 原生 dialog 表单容器 */
dialog.sheet {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 16px;
  padding: 0;
  width: min(680px, calc(100vw - 32px));
  box-shadow: var(--shadow-pop);
}
dialog.sheet::backdrop { background: rgba(6, 8, 20, 0.55); backdrop-filter: blur(2px); }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* 单元格内的复合展示 */
.meta-inline { color: var(--text-2); }
.meta-inline b { font-weight: 600; color: var(--text); }
.cell-raw { display: none; }
.mono-wrap {
  margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.health-main { font-weight: 500; }

/* 仅在移动端出现 / 仅在桌面出现 */
.only-sm { display: none; }
@media (max-width: 860px) {
  .only-sm { display: inline-flex; }
  .only-lg { display: none !important; }
}

/* ==========================================================================
   响应式：平板 / 桌面
   ========================================================================== */
@media (min-width: 600px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tables-grid { grid-template-columns: 1fr; }
}

@media (min-width: 861px) {
  .wrap { padding-inline: 28px; }
  .page { padding-block: 28px 40px; }

  .appbar__inner {
    grid-template-columns: auto 1fr auto;
    gap: 20px;
    padding-block: 10px;
  }
  .tabs {
    grid-column: auto;
    justify-content: flex-start;
    margin-inline: 0;
    padding-inline: 0;
    overflow: visible;
  }

  .creds__inner {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.5fr) minmax(0, 0.9fr);
    align-items: center;
    gap: 14px;
  }

  .toolbar { gap: 10px; }
  .toolbar > .field { flex: 0 0 auto; width: auto; }
  .toolbar > .btn { flex: 0 0 auto; }
  .toolbar > .toolbar__grow { flex: 1 1 300px; max-width: 460px; }
  #groupSearch, #keySearch, #acctSearch { width: 260px; }
  #groupStatusFilter, #keyStatusFilter, #acctStatusFilter, #keyGroupFilter, #acctGroupFilter { width: 150px; }
  #planGroup, #probeGroup { width: 260px; }

  .inline-form .cell-field { width: auto; }
}

@media (min-width: 1200px) {
  .creds__inner { grid-template-columns: 220px minmax(0, 640px) minmax(0, 320px); }
}

/* ==========================================================================
   响应式：移动端（<=860px）—— 数据表退化为卡片
   ========================================================================== */
@media (max-width: 860px) {
  .brand__sub { display: none; }
  .conn { padding: 5px 9px; font-size: 11px; }

  #toastStack { top: 10px; right: 10px; width: calc(100vw - 20px); }

  .card { border-radius: 12px; }
  .card__head { padding: 12px 14px; }
  .card__body { padding: 14px; }

  .table-wrap { overflow: visible; }

  table.data { display: block; }
  table.data thead { display: none; }
  table.data tbody { display: block; }

  table.data tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow-1);
    padding: 4px 0;
    overflow: hidden;
  }
  table.data tbody tr:nth-child(even) { background: var(--panel); }
  table.data tbody tr:hover { background: var(--panel); }
  table.data tbody tr + tr { margin-top: 10px; }

  table.data td {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 0;
    font-size: 13px;
  }
  table.data td::before {
    content: attr(data-label);
    flex: none;
    width: 74px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-3);
    padding-top: 1px;
    overflow-wrap: anywhere;
  }
  table.data td::before:empty { display: none; }
  table.data td > * { min-width: 0; }

  /* 主标识列 -> 卡片标题 */
  table.data td.cell-primary {
    display: block;
    padding: 12px 14px 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
  }
  table.data td.cell-primary::before { display: none; }

  /* 移动端隐藏的列（勾选 / 健康）——特异性需压过 table.data td 的 display 规则 */
  table.data th.cell-hide-sm, table.data td.cell-hide-sm { display: none; }

  /* 操作列：移动端按钮铺成网格，方便点按 */
  table.data td.cell-actions {
    display: block;
    padding: 10px 14px 12px;
    margin-top: 2px;
    border-top: 1px solid var(--border);
    background: var(--panel-2);
  }
  table.data td.cell-actions::before { display: none; }
  table.data td.cell-actions > .btn {
    width: auto;
    margin: 4px 4px 0 0 !important;
  }

  /* 行内展开的编辑表单：整行铺开 */
  table.data td[colspan] {
    display: block;
    padding: 12px 14px 14px;
    background: var(--brand-soft);
  }
  table.data td[colspan]::before { display: none; }
  .inline-form { gap: 10px; }
  .inline-form > div { flex: 1 1 140px; }
  .inline-form > div:first-child { flex: 1 1 100%; }

  .toolbar > .field { flex: 1 1 100%; }
  .toolbar > .btn { flex: 1 1 auto; min-height: 40px; }
  .toolbar > .toolbar__grow { flex: 1 1 100%; }

  .section { padding: 15px; border-radius: 12px; }
  .grid-2 { gap: 14px; }

  dialog.sheet { width: calc(100vw - 20px); }
  .badge { font-size: 10.5px; }
}

/* 触屏设备去掉 hover 残留 */
@media (hover: none) {
  table.data tbody tr:hover { background: transparent; }
  tbody tr:nth-child(even) { background: var(--zebra); }
}

/* 降低动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* 打印 */
@media print {
  .appbar, .creds, .theme-toggle, .toolbar, .batchbar, #netbar, #toastStack { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
  table.data { display: table; width: 100%; }
  table.data thead { display: table-header-group; }
  table.data tbody tr { display: table-row; }
  table.data td { display: table-cell; }
}
