/* ---------------------------------------------------------------------------
   设计令牌
   简约高级的中性色体系：低饱和冷灰 + 祖母绿主色；明暗两套完全对齐。
--------------------------------------------------------------------------- */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #eef0f3;
  --row-hover: #f6f8fa;
  --text: #16181d;
  --text-muted: #6a7180;
  --border: #e4e6eb;
  --border-faint: #eef0f3;
  --brand: #0e9d66;
  --brand-soft: #e7f6ef;
  --ok: #12915c;
  --ok-soft: #e5f6ec;
  --warn: #b97d0d;
  --warn-soft: #fbf1dd;
  --danger: #d4423a;
  --danger-soft: #fdeceb;
  --topbar: rgba(255, 255, 255, 0.86);
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(18, 22, 33, 0.05), 0 1px 3px rgba(18, 22, 33, 0.04);
  --shadow-md: 0 6px 20px -4px rgba(18, 22, 33, 0.14);
  --ring: 0 0 0 3px rgba(14, 157, 102, 0.22);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121317;
    --surface: #1a1c21;
    --surface-muted: #22242b;
    --row-hover: #20232a;
    --text: #e8e8ec;
    --text-muted: #9aa0ad;
    --border: #2b2e36;
    --border-faint: #24262d;
    --brand: #3ecf92;
    --brand-soft: #14301f;
    --ok: #45c98c;
    --ok-soft: #12291c;
    --warn: #e2a33c;
    --warn-soft: #2e2413;
    --danger: #ef6b62;
    --danger-soft: #331b19;
    --topbar: rgba(26, 28, 33, 0.86);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 6px 20px -4px rgba(0, 0, 0, 0.5);
    --ring: 0 0 0 3px rgba(62, 207, 146, 0.28);
  }
}

:root[data-theme="dark"] {
  --bg: #121317;
  --surface: #1a1c21;
  --surface-muted: #22242b;
  --row-hover: #20232a;
  --text: #e8e8ec;
  --text-muted: #9aa0ad;
  --border: #2b2e36;
  --border-faint: #24262d;
  --brand: #3ecf92;
  --brand-soft: #14301f;
  --ok: #45c98c;
  --ok-soft: #12291c;
  --warn: #e2a33c;
  --warn-soft: #2e2413;
  --danger: #ef6b62;
  --danger-soft: #331b19;
  --topbar: rgba(26, 28, 33, 0.86);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 20px -4px rgba(0, 0, 0, 0.5);
  --ring: 0 0 0 3px rgba(62, 207, 146, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------------------
   顶栏：sticky + 毛玻璃，滚离内容时保持上下文
--------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--topbar);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px) saturate(1.5);
  -webkit-backdrop-filter: blur(12px) saturate(1.5);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: 0.01em; }
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.brand .tag {
  font-size: 12px; color: var(--brand); background: var(--brand-soft);
  padding: 2px 9px; border-radius: 999px; font-weight: 500;
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px; color: var(--text-muted); background: var(--surface-muted);
  border: 1px solid transparent; padding: 3px 10px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.conn {
  font-size: 12px; padding: 3px 11px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-muted); color: var(--text-muted);
}
.conn::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; margin-right: 6px; vertical-align: 1px;
}
.conn.ok { color: var(--ok); border-color: transparent; background: var(--ok-soft); }
.conn.danger { color: var(--danger); border-color: transparent; background: var(--danger-soft); }

.key-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.key-field input {
  width: 200px; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.key-field input:focus-visible { outline: none; border-color: var(--brand); box-shadow: var(--ring); }

/* ---------------------------------------------------------------------------
   按钮
--------------------------------------------------------------------------- */
button {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
button:hover { border-color: var(--brand); color: var(--brand); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button:active { transform: translateY(0.5px); }
button.ghost { background: transparent; }
button.danger { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
/* 所有"默认隐藏"面板的唯一开关：setup/二维码/配置警告/告警条都靠这个类隐藏。 */
.hidden { display: none !important; }
button:disabled:hover { border-color: var(--border); color: var(--text); }

/* ---------------------------------------------------------------------------
   页签：分段式胶囊，取代旧的“卡片顶边”错觉
--------------------------------------------------------------------------- */
.tabs {
  display: inline-flex; flex-wrap: wrap; gap: 2px;
  margin: 14px 20px 0; padding: 4px;
  background: var(--surface-muted); border: 1px solid var(--border); border-radius: 12px;
  width: fit-content; max-width: calc(100% - 40px);
}
.tab {
  border: 0; background: transparent; color: var(--text-muted);
  padding: 7px 15px; border-radius: 9px; font-weight: 500;
}
.tab:hover { color: var(--text); background: transparent; }
.tab.active {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.alert {
  margin: 12px 20px 0; padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger); border: 1px solid transparent;
  font-size: 13px;
}
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.hidden { display: none; }

main { padding: 16px 20px 48px; }
.panel { display: none; }
.panel.active { display: block; }

/* ---------------------------------------------------------------------------
   卡片与指标
--------------------------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.metric-label { font-size: 12px; color: var(--text-muted); }
.metric-value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.metric.ok .metric-value { color: var(--ok); }
.metric.warn .metric-value { color: var(--warn); }
.metric.danger .metric-value { color: var(--danger); }

.site-block + .site-block { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.site-head { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 10px; }
.site-block .cards { margin-bottom: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 15px; font-weight: 600; margin-bottom: 12px; letter-spacing: 0.01em;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.filter { font-size: 12px; font-weight: 400; color: var(--text-muted); display: flex; align-items: center; gap: 10px; }
.filter label { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; cursor: pointer; }
.filter input[type="checkbox"] { margin: 0; accent-color: var(--brand); }
@media (max-width: 600px), (pointer: coarse) { .filter label { min-height: 44px; } }
.filter select {
  padding: 5px 9px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-muted); color: var(--text); font: inherit; font-size: 12px;
}

.kv { display: grid; gap: 2px; }
.kv-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border-faint); }
.kv-row:last-child { border-bottom: none; }
.kv-k { color: var(--text-muted); }
.kv-v { font-weight: 550; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   表格
--------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.rate-cell { white-space: normal; min-width: 130px; }
.rate-line { display: flex; align-items: center; gap: 6px; }
.rate-value { white-space: nowrap; }
.rate-info {
  flex: none; width: 18px; height: 18px; padding: 0; line-height: 1; font-size: 11px; font-weight: 700;
  border-radius: 50%; color: var(--text-muted); background: var(--surface-muted); border: 1px solid var(--border);
}
.rate-info:hover, .rate-info:focus-visible { color: var(--brand); border-color: var(--brand); outline: none; }
.rate-info[aria-expanded="true"] { color: var(--surface); background: var(--brand); border-color: var(--brand); }
.rate-detail {
  margin-top: 8px; padding: 10px 12px; border-left: 2px solid var(--brand); background: var(--surface-muted);
  border-radius: 6px; white-space: normal; overflow-wrap: anywhere; font-size: 12px; line-height: 1.6;
  min-width: 240px;
}
.rate-meta { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; color: var(--text); }
.rate-explain { margin: 0 0 6px; }
.rate-refresh { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: var(--brand-soft); }
.rate-refresh strong { color: var(--brand); }
.rate-none { margin: 0 0 6px; font-weight: 600; color: var(--warn); }
.rate-logs-title { margin-top: 6px; font-weight: 600; color: var(--text-muted); }
.rate-others ul, .rate-raw ul { margin: 4px 0 0; padding-left: 16px; }
.rate-others li + li { margin-top: 4px; }
.rate-raw { margin-top: 8px; }
.rate-raw summary { cursor: pointer; color: var(--text-muted); }
.rate-raw li + li { margin-top: 6px; }
.rate-raw code {
  display: block; margin-top: 2px; padding: 6px 8px; border-radius: 6px; background: var(--surface);
  border: 1px solid var(--border); font-family: var(--mono); font-size: 11px; white-space: pre-wrap;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; white-space: nowrap; }
th {
  color: var(--text-muted); font-weight: 550; font-size: 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
td { border-bottom: 1px solid var(--border-faint); }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--row-hover); }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
td.empty, .empty { color: var(--text-muted); text-align: center; padding: 20px; }

.badge { padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--surface-muted); border: 1px solid transparent; color: var(--text-muted); }
.badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.danger { color: var(--danger); background: var(--danger-soft); }

.logbox {
  margin: 0; padding: 12px 14px; max-height: 60vh; overflow: auto;
  background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12px; line-height: 1.65; white-space: pre-wrap; word-break: break-all;
}

.hint { color: var(--text-muted); font-size: 12px; margin: 0 0 12px; }

.setup-panel { margin: 24px; max-width: 720px; }
.setup-panel h2 { margin-top: 0; font-size: 20px; letter-spacing: -0.01em; }
.settings-card { max-width: 760px; }
.settings-row { display: grid; gap: 8px; margin: 18px 0; }
.settings-row input[type="password"] {
  width: 100%; box-sizing: border-box; padding: 10px 12px;
  background: var(--surface-muted); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit;
}
.settings-row input[type="password"]:focus-visible { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.settings-ports { border-top: 1px solid var(--border); margin-top: 24px; padding-top: 16px; display: grid; gap: 10px; }

/* API Key 列表管理 */
.keys-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 6px 0 10px; }
.key-cell { white-space: normal; min-width: 240px; }
.key-cell .key-input { width: 220px; max-width: 100%; font-family: var(--mono); font-size: 12px; }
.key-input { width: 100%; min-width: 90px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-muted); color: var(--text); font: inherit; font-size: 13px; }
.key-input:focus-visible { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.key-act { margin-left: 6px; padding: 3px 9px; font-size: 11px; }
#keysTable input[type="checkbox"] { accent-color: var(--brand); cursor: pointer; }
#keysTable td { vertical-align: middle; }

.policy-switch {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 0;
  min-height: 32px; border: 0; background: transparent; font-size: 12px; color: var(--text-muted);
}
.policy-switch[aria-checked="true"] { color: var(--ok); }
.policy-switch:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.switch-track { width: 30px; height: 18px; border-radius: 999px; background: var(--text-muted); padding: 2px; }
.switch-track::after {
  content: ""; display: block; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); transition: transform 0.15s ease;
}
.policy-switch[aria-checked="true"] .switch-track { background: var(--ok); }
.policy-switch[aria-checked="true"] .switch-track::after { transform: translateX(12px); }
@media (prefers-reduced-motion: reduce) { .switch-track::after { transition: none; } }
@media (max-width: 600px), (pointer: coarse) { .policy-switch { min-height: 44px; } }

.settings-row input[type="number"] {
  width: 100%; max-width: 240px; box-sizing: border-box; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit;
  background: var(--surface-muted); color: var(--text);
}
.port-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.action-result { margin-top: 12px; margin-bottom: 0; }
.config-warning { padding: 16px; margin-bottom: 16px; border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: var(--radius-sm); }
.config-warning h2 { font-size: 15px; margin: 0 0 8px; }
.config-warning ul { padding-left: 20px; margin: 0; }
.config-warning li + li { margin-top: 8px; }
.config-warning .actions { margin-top: 16px; }
.config-sensitive { color: var(--warn); font-size: 12px; margin: 0 0 12px; }
.config-editor {
  display: block; width: 100%; min-height: 320px; height: 52vh; margin-top: 8px; padding: 12px;
  resize: vertical; overflow: auto; tab-size: 2; font-family: var(--mono); font-size: 13px; line-height: 1.6;
  color: var(--text); background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.config-editor:focus-visible, #panel-config button:focus-visible { outline: none; box-shadow: var(--ring); }
#configEditorStatus { min-height: 20px; overflow-wrap: anywhere; }
.config-warning code { overflow-wrap: anywhere; }
.task-description { white-space: normal; min-width: 180px; max-width: 280px; line-height: 1.6; }
@media (max-width: 600px) {
  .port-inputs { grid-template-columns: 1fr; gap: 0; }
  .actions button { min-height: 44px; }
  #editConfig { min-height: 44px; }
  .config-warning { padding: 12px; }
  .config-warning .actions, #configEditorPanel .actions { display: grid; grid-template-columns: 1fr; }
  #tasksTable, #tasksTable tbody { display: block; }
  #tasksTable thead { display: none; }
  #tasksTable tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 16px 0; border-bottom: 1px solid var(--border); }
  #tasksTable tr:last-child { border-bottom: 0; }
  #tasksTable td { display: block; border: 0; padding: 0; white-space: normal; overflow-wrap: anywhere; min-width: 0; max-width: none; }
  #tasksTable td::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--text-muted); font-size: 11px; font-weight: 400; }
  #tasksTable td:first-child { grid-column: 1 / -1; font-size: 14px; font-weight: 600; }
  #tasksTable td:first-child::before { display: none; }
  #tasksTable td:nth-child(3), #tasksTable td:nth-child(8) { grid-column: 1 / -1; }
}

/* ---------------------------------------------------------------------------
   总览 · 用量与性能（Token / 积分 / 耗时趋势）
--------------------------------------------------------------------------- */
:root {
  --series-token: #6d6bf5;
  --series-credit: #e0a33c;
  --series-first: #d9628f;
  --series-token-soft: rgba(109, 107, 245, 0.14);
  --series-m0: #6d6bf5;
  --series-m1: #d9628f;
  --series-m2: #e0a33c;
  --series-m3: #2f9e78;
  --series-m4: #3d8bfd;
  --series-m5: #c45c26;
  --series-m6: #6b5bd2;
  --series-m7: #3f8f9d;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-token: #8f8dff;
    --series-credit: #f0b455;
    --series-first: #ef7ba6;
    --series-token-soft: rgba(143, 141, 255, 0.16);
    --series-m0: #8f8dff;
    --series-m1: #ef7ba6;
    --series-m2: #f0b455;
    --series-m3: #49c4a0;
    --series-m4: #79b0ff;
    --series-m5: #e88858;
    --series-m6: #b3a6ff;
    --series-m7: #7ec8d4;
  }
}

:root[data-theme="dark"] {
  --series-token: #8f8dff;
  --series-credit: #f0b455;
  --series-first: #ef7ba6;
  --series-token-soft: rgba(143, 141, 255, 0.16);
  --series-m0: #8f8dff;
  --series-m1: #ef7ba6;
  --series-m2: #f0b455;
  --series-m3: #49c4a0;
  --series-m4: #79b0ff;
  --series-m5: #e88858;
  --series-m6: #b3a6ff;
  --series-m7: #7ec8d4;
}

.usage-section { margin-bottom: 22px; }

/* 运行状态移到总览最上面后，标题自身不再叠加顶部间距。 */
.panel > .overview-subheading:first-child { margin-top: 0; }

.overview-subheading {
  margin: 22px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.usage-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.usage-heading h2 {
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.usage-heading .hint { margin: 0; }

.stats-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stats-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.stats-controls select,
.stats-controls input {
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stats-controls .stats-account select { min-width: 220px; }

.stats-controls .stats-follow {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-height: 31px;
  white-space: nowrap;
  cursor: pointer;
}

.stats-controls .stats-follow input[type="checkbox"] {
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  accent-color: var(--brand);
  cursor: pointer;
}

.stats-controls input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.stats-controls button {
  padding: 7px 18px;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: #ffffff;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.stats-controls button:hover { color: #ffffff; filter: brightness(1.08); }

.usage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.usage-metric {
  padding: 14px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.usage-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.usage-label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--series-token);
}

.usage-metric.credit .usage-label::before { background: var(--series-credit); }
.usage-metric.first .usage-label::before { background: var(--series-first); }
.usage-metric.neutral .usage-label::before { background: var(--text-muted); }

.usage-value {
  font-size: 26px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.usage-detail {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.usage-charts {
  display: grid;
  /* 单列堆叠：合并后的用量图和耗时图都需要完整宽度。 */
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.chart-card { margin-bottom: 0; }
.latency-chart, .token-chart { grid-column: 1 / -1; }

.chart-legend {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-left: 10px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.chart-legend span { white-space: nowrap; }

.series-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-left: 0;
  background: var(--series-token);
}

.chart-legend .series-dot:first-child { margin-left: 0; }
.series-dot.token { background: var(--series-token); }
.series-dot.credit { background: var(--series-credit); }
.series-dot.first { background: var(--series-first); }
.series-dot.m0 { background: var(--series-m0); }
.series-dot.m1 { background: var(--series-m1); }
.series-dot.m2 { background: var(--series-m2); }
.series-dot.m3 { background: var(--series-m3); }
.series-dot.m4 { background: var(--series-m4); }
.series-dot.m5 { background: var(--series-m5); }
.series-dot.m6 { background: var(--series-m6); }
.series-dot.m7 { background: var(--series-m7); }

.stats-chart { width: 100%; }

.stats-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  cursor: crosshair;
}

.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

.chart-label {
  fill: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line, .chart-bar, .stats-chart circle { transition: opacity 0.12s ease; }

/* 悬停时只强调最近的一条线/一组柱，其余系列退到背景，避免几十条线糊在一起。 */
.stats-chart svg.chart-hovering .chart-line:not(.is-hovered),
.stats-chart svg.chart-hovering .chart-bar:not(.is-hovered),
.stats-chart svg.chart-hovering circle:not(.is-hovered) { opacity: 0.14; }

.stats-chart svg.chart-hovering .chart-line.is-hovered { stroke-width: 3; }

.chart-tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  min-width: 120px;
  max-width: 280px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-size: 12px;
  line-height: 1.5;
}

.chart-tooltip[hidden] { display: none; }

.chart-tooltip-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.chart-tooltip-head .series-dot { flex: none; }

.chart-tooltip-body {
  margin-top: 2px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-body strong { color: var(--text); font-weight: 600; }

.chart-line.series-token { stroke: var(--series-token); }
.chart-line.series-credit { stroke: var(--series-credit); }
.chart-line.series-first { stroke: var(--series-first); stroke-dasharray: 5 4; }
.chart-line.series-m0 { stroke: var(--series-m0); }
.chart-line.series-m1 { stroke: var(--series-m1); }
.chart-line.series-m2 { stroke: var(--series-m2); }
.chart-line.series-m3 { stroke: var(--series-m3); }
.chart-line.series-m4 { stroke: var(--series-m4); }
.chart-line.series-m5 { stroke: var(--series-m5); }
.chart-line.series-m6 { stroke: var(--series-m6); }
.chart-line.series-m7 { stroke: var(--series-m7); }

circle.series-token { fill: var(--series-token); }
circle.series-credit { fill: var(--series-credit); }
circle.series-first { fill: var(--series-first); }
circle.series-m0 { fill: var(--series-m0); }
circle.series-m1 { fill: var(--series-m1); }
circle.series-m2 { fill: var(--series-m2); }
circle.series-m3 { fill: var(--series-m3); }
circle.series-m4 { fill: var(--series-m4); }
circle.series-m5 { fill: var(--series-m5); }
circle.series-m6 { fill: var(--series-m6); }
circle.series-m7 { fill: var(--series-m7); }

/* 柱形与折线同图时，柱形用半透明的同一系列色，折线保持实线覆盖在上层。 */
.chart-bar { stroke: none; opacity: 0.55; }
rect.series-token { fill: var(--series-token); }
rect.series-credit { fill: var(--series-credit); }
rect.series-first { fill: var(--series-first); }
rect.series-m0 { fill: var(--series-m0); }
rect.series-m1 { fill: var(--series-m1); }
rect.series-m2 { fill: var(--series-m2); }
rect.series-m3 { fill: var(--series-m3); }
rect.series-m4 { fill: var(--series-m4); }
rect.series-m5 { fill: var(--series-m5); }
rect.series-m6 { fill: var(--series-m6); }
rect.series-m7 { fill: var(--series-m7); }

.stats-empty {
  margin: 0;
  padding: 26px 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------------------
   总览运行状态：百分比是主视觉，下方状态分布给出构成明细；
   告警用色条+文字双重区分，不依赖颜色辨识。
--------------------------------------------------------------------------- */
.health-layout { display: grid; grid-template-columns: minmax(240px, 0.8fr) minmax(0, 2fr); gap: 16px; margin-bottom: 16px; }
.health-layout .card { margin: 0; min-width: 0; }
.health-card h3, .account-alert-card h3 { margin: 0; font-size: 14px; }
.health-value { font-size: 48px; line-height: 1.15; font-weight: 650; letter-spacing: -1.5px; margin: 20px 0 14px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.health-value.healthy { color: var(--ok); }
.health-value.degraded { color: var(--warn); }
.health-value.unavailable { color: var(--danger); }
.health-track { height: 6px; border-radius: 4px; background: var(--surface-muted); overflow: hidden; }
.health-track > div { height: 100%; width: 0; background: var(--warn); transition: width 180ms ease; }
.health-track > .healthy { background: var(--ok); }
.health-track > .unavailable { background: var(--danger); }
.health-status { font-weight: 600; font-size: 13px; margin: 14px 0 10px; }
.state-dist { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 12px; }
.state-chip {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-muted); border: 1px solid transparent; color: var(--text-muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.state-chip.ok { color: var(--ok); background: var(--ok-soft); }
.state-chip.warn { color: var(--warn); background: var(--warn-soft); }
.state-chip.danger { color: var(--danger); background: var(--danger-soft); }
.health-footnote { border-top: 1px solid var(--border-faint); padding-top: 12px; }
.account-alert-list { max-height: 350px; overflow: auto; padding-right: 3px; scrollbar-gutter: stable; }
.account-alert { --alert-color: #5677b6; border-left: 3px solid var(--alert-color); background: var(--surface-muted); border-radius: 0 8px 8px 0; padding: 12px 14px; margin-bottom: 9px; }
.account-alert:last-child { margin-bottom: 0; }
.alert-urgent { --alert-color: var(--danger); }
.alert-important { --alert-color: #ce7620; }
.alert-warning { --alert-color: var(--warn); }
.account-alert-head { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.alert-priority { color: var(--alert-color); border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; font-size: 11px; font-weight: 600; }
.account-alert-head strong { font-size: 13px; }
.account-alert-head time { font-size: 11px; color: var(--text-muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.account-alert-file { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.account-alert p { margin: 4px 0; font-size: 12px; color: var(--text-muted); }
.chip-link { text-decoration: none; color: inherit; }
.chip-link:hover { text-decoration: underline; }
.account-alert-list:focus-visible { outline: none; box-shadow: var(--ring); }
@media (prefers-reduced-motion: reduce) { .health-track > div { transition: none; } }
@media (max-width: 720px) {
  .health-layout { grid-template-columns: minmax(0, 1fr); }
  .health-value { margin: 12px 0; font-size: 42px; }
  .account-alert-head time { margin-left: 0; width: 100%; }
}

@media (max-width: 640px) {
  .usage-charts { grid-template-columns: 1fr; }
  .stats-controls { align-items: stretch; }
  .stats-controls label,
  .stats-controls .stats-account select,
  .stats-controls select,
  .stats-controls input { width: 100%; min-width: 0; }
  .stats-controls button { width: 100%; }
  .usage-value { font-size: 22px; }
}

@media (min-width: 641px) and (max-width: 980px) {
  .usage-charts { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   账号 网页新增 / 删除
--------------------------------------------------------------------------- */
.account-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 12px; }

.add-account-panel {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px; background: var(--surface-muted);
}

.add-account-panel h3 { margin: 0 0 12px; font-size: 14px; }

.add-account-form {
  display: grid; gap: 12px 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.add-account-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-muted); }

.add-account-form select,
.add-account-form input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}

.add-account-form .path-prefix { font-size: 12px; color: var(--text-muted); }

.add-account-result { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-top: 14px; }

.add-account-result img { border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

#addAccountLink { word-break: break-all; }

.add-account-link-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-account-link-row #addAccountLink { flex: 1 1 260px; min-width: 0; }
.add-account-link-row #addAccountCopy { flex: none; }

@media (max-width: 640px) {
  .add-account-form { grid-template-columns: 1fr; }
  .add-account-result img { width: 100%; max-width: 240px; height: auto; }
}

/* ---- 模型列表：复制角标、已屏蔽标识与解除屏蔽 ---- */
.model-id-cell { white-space: nowrap; }
.copy-model {
  margin-left: 6px; padding: 1px 6px; font-size: 11px; line-height: 1.7;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-muted); color: var(--text-muted); cursor: pointer;
}
.copy-model:hover, .copy-model:focus-visible { color: var(--brand); border-color: var(--brand); outline: none; }
.copy-model.copied { color: var(--ok); border-color: var(--ok); }
.copy-model.copy-failed { color: var(--danger); border-color: var(--danger); }
.blocked-badge { margin-left: 6px; }
.site-badge { margin-left: 6px; white-space: nowrap; }
.site-badge.cn { color: var(--brand); border-color: transparent; background: var(--brand-soft); }
.site-badge.intl { color: var(--warn); border-color: transparent; background: var(--warn-soft); }
.site-badge.both { color: var(--ok); border-color: transparent; background: var(--ok-soft); }
.unblock-model {
  margin-left: 6px; padding: 2px 8px; font-size: 11px; line-height: 1.5;
  border-radius: 6px; color: var(--danger); border-color: var(--danger); background: transparent;
}
tr.model-blocked td { opacity: .62; }
tr.model-blocked:hover td { opacity: 1; }
