/* 首帧兜底配色（石墨·夜间）：脚本运行后由 app.js 以内联变量接管，
   这里只保证 JS 加载前不白屏 */
:root {
  --radius: 6px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
  --on-accent: #0d1117;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --bg: #111418;
  --bg-soft: #191d23;
  --panel: #171b21;
  --panel-2: #1b2027;
  --surface-1: #171b21;
  --surface-2: #14181d;
  --topbar-1: #181c22;
  --topbar-2: #151a1f;
  --input-bg: #0e1116;
  --border: #262c34;
  --border-strong: #363d47;
  --text: #dde3ea;
  --muted: #8a93a0;
  --accent: #7aa2f7;
  --accent-2: #89ddff;
  --accent-deep: #5c8af0;
  --accent-soft: rgba(122, 162, 247, 0.14);
  --accent-line: rgba(122, 162, 247, 0.4);
  --accent-text: #aac4fd;
}

/* ============================ 亮 / 暗模式 ============================ */
/* 亮色模式：只覆盖亮度相关的「中性变量」；彩色强调色仍沿用 [data-theme] 的配色，
   并通过 color-mix 在同 hue 上加深，保证浅底可读且各配色主题仍有区分 */
[data-mode='light'] {
  color-scheme: light;

  /* 纯白主题：页面/卡片/顶栏/弹窗统一白色；次级面用极淡 #fafafa，几乎看不出灰 */
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --surface-1: #ffffff;
  --surface-2: #fafafa;
  --topbar-1: #ffffff;
  --topbar-2: #fafafa;
  --input-bg: #ffffff;
  --border: #e8ebef;
  --border-strong: #cfd5db;
  --text: #1f2328;
  --muted: #57606a;
  /* 白色主题阴影极淡，仅作层次提示 */
  --shadow: 0 1px 0 rgba(31, 35, 40, 0.04), 0 8px 24px rgba(140, 149, 159, 0.2);

  /* 用量等级语义色加深，白底上更清晰 */
  --green: #1a7f37;
  --orange: #9a6700;
  --red: #cf222e;

  /* 强调色配套变量由 app.js 调色板以内联变量提供，此处仅作中性兜底 */
}

/* 浅色背景下原本固定的浅色文字需改深，否则看不清 */
[data-mode='light'] .note { color: #9a6700; }
[data-mode='light'] .error-box {
  color: #b3261e;
  background: rgba(207, 34, 46, 0.10);
  border-color: rgba(207, 34, 46, 0.35);
}
[data-mode='light'] .test-result.fail { color: #b3261e; }
[data-mode='light'] .btn-danger-ghost { color: #c0341d; }
[data-mode='light'] .act-btn.danger:hover { color: #c0341d; }
[data-mode='light'] .badge.tier {
  color: #1a7f37;
  background: rgba(26, 127, 55, 0.12);
  border-color: rgba(26, 127, 55, 0.3);
}
[data-mode='light'] .spinner {
  border-color: rgba(0, 0, 0, 0.25);
  border-top-color: #1f2630;
}
[data-mode='light'] ::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); }
[data-mode='light'] ::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.30); }

/* 白底顶栏：去掉边框线，改用阴影悬浮，整体更通透 */
[data-mode='light'] .topbar {
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(31, 35, 40, 0.04), 0 4px 12px rgba(31, 35, 40, 0.04);
}

* {
  box-sizing: border-box;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  background-clip: content-box;
  border: 2px solid transparent;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
  background-clip: content-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  /* 始终预留滚动条槽位，锁定背景滚动时页面不会左右跳动 */
  scrollbar-gutter: stable;
}

/* 弹窗打开时锁定背景页面滚动，避免滚轮穿透到后面的卡片列表 */
html.modal-open {
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------ 背景图 ------------------------------ */
/* 背景图由「设置 → 背景图」配置：app.js 写入 --bg-image / --bg-opacity 并切换 .has-bg-image */
html {
  /* 保留主题基色：作为背景图的「底衬」，透明度混合时可见 */
  background-color: var(--bg);
}

/* 背景图单独用固定图层绘制，便于只对图片调节透明度（不透明度越高越清晰） */
html::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-opacity, 1);
  z-index: -1; /* 位于主题底色之上、页面内容之下 */
  pointer-events: none;
}

/* 启用背景图时，页面级背景透明，让图片完整透出；
   --panel-2（弹窗 / 按钮 / 下拉 / 提示）保持不动，确保这些浮层依旧清晰 */
html.has-bg-image {
  --bg-soft: transparent !important;
  --panel: transparent !important;
  --surface-1: transparent !important;
  --surface-2: transparent !important;
  --topbar-1: transparent !important;
  --topbar-2: transparent !important;
  --input-bg: transparent !important;
}

/* body 默认用 --bg 铺底，会挡住背景图层，这里改为透明 */
html.has-bg-image body {
  background-color: transparent !important;
}

/* 设置面板里的背景图预览 */
.bg-preview {
  margin-top: 4px;
}
.bg-preview img {
  display: block;
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* hidden 属性必须始终生效：本项目中 .auth-view / .filter-bar / .field / .modal 等
   都声明了 display，会覆盖浏览器对 [hidden] 的默认 display:none，导致 JS 设置
   el.hidden = true 后元素依然显示（例如登录后登录页不消失）。统一兜底即可。 */
[hidden] {
  display: none !important;
}

.app {
  /* 放宽主容器：PC 大屏下每行可容纳更多卡片（配合「卡片宽度」滑块调节列数） */
  max-width: 1680px;
  margin: 0 auto;
  padding: 26px 22px 60px;
}

/* ------------------------------ 顶栏 ------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--topbar-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* 吸顶：卡片多时滚动仍能触达刷新/设置等按钮 */
  position: sticky;
  top: 0;
  z-index: 30;
  /* 背景图模式下顶栏底色透明，加毛玻璃保证按钮可读、又不挡图 */
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  /* 吸顶时与下方内容做轻微分隔，避免与卡片粘连 */
  box-shadow: 0 1px 0 var(--border);
}

/* 滚动后给顶栏一点阴影层次（仅日间/亮色背景不明显，暗色下更清晰） */
.topbar::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-strong), transparent);
  opacity: 0.6;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  background: var(--accent);
  color: var(--on-accent);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.countdown {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  min-width: 118px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 顶栏按钮：文字保持单行，避免窄屏下被挤成两行 */
.topbar-actions .btn {
  white-space: nowrap;
}

/* --------------------------- 主题切换 --------------------------- */

.theme-switch {
  position: relative;
}

.theme-btn {
  gap: 7px;
}

/* 默认跟随当前主题 */
.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 1px solid var(--border-strong);
}

.theme-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 150px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  box-shadow: var(--shadow);
}

.theme-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.theme-item:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.theme-item[aria-selected='true'] {
  background: var(--accent-soft);
  color: var(--accent-text);
  box-shadow: inset 3px 0 var(--accent);
}

/* 菜单内的色点固定展示各自主题色，不随当前主题变化 */
.theme-dot.t-graphite {
  background: linear-gradient(135deg, #7aa2f7, #89ddff);
}

.theme-dot.t-lavender {
  background: linear-gradient(135deg, #b4a7ff, #f0a6ca);
}

.theme-dot.t-pine {
  background: linear-gradient(135deg, #6ac48f, #a9d18e);
}

.theme-dot.t-amber {
  background: linear-gradient(135deg, #e2a44f, #db8a4b);
}

/* ------------------------------ 按钮 ------------------------------ */

.btn {
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover {
  background: var(--bg-soft);
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: #fff;
}

.btn-danger-ghost {
  color: #ff8b84;
  border-color: rgba(248, 81, 73, 0.35);
  background: rgba(248, 81, 73, 0.08);
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 9px;
  border-radius: var(--radius);
  transition: background 0.12s ease, color 0.12s ease;
}

.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}

/* 卡片操作：朴素文字按钮，移动端更好点击 */
.act-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 10px;
  border-radius: var(--radius);
  min-height: 28px;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.act-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-soft);
}

.act-btn.danger:hover {
  color: #ff9b95;
  border-color: rgba(248, 81, 73, 0.45);
  background: rgba(248, 81, 73, 0.08);
}

/* 图标按钮：去掉文字只剩图标，显著收窄卡片操作区与表格操作列 */
.act-btn.icon-only {
  padding: 5px 7px;
  min-height: 28px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.act-btn .act-icon {
  display: block;
  flex: none;
}

/* 图标 + 短文案（如「复制 Cookie」） */
.act-btn.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* 置顶等「已生效」状态 */
.act-btn.is-active {
  color: var(--accent-text, var(--text));
  border-color: var(--accent-line, var(--border-strong));
  background: var(--accent-soft);
}

/* 两步确认态：变红并轻微高亮，提示「再点一次才执行」 */
.act-btn.is-armed,
.btn.is-armed {
  color: #ff9b95;
  border-color: rgba(248, 81, 73, 0.6);
  background: rgba(248, 81, 73, 0.14);
  animation: armed-pulse 1s ease-in-out infinite;
}

@keyframes armed-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.35);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.12);
  }
}

/* 窄卡片里进一步收紧图标按钮 */
@container card (max-width: 265px) {
  .act-btn.icon-only {
    padding: 4px 5px;
    min-height: 26px;
  }
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------ 概览 ------------------------------ */

/* 概览条默认按内容宽度自适应（只读分享页的 4 张卡片用它）：
   flex 基准宽度 = max-content，不会被压缩到 min-content 以下，放不下时整块换行。 */
.summary {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  margin: 16px 0 14px;
}

/* 主看板概览条：20 栏等宽栅格，宽度只由容器宽度决定，数值/文字变长变短都不会改变卡片宽度。
   窄卡片（stat-narrow，2/20）＝ 监控中的查询 / 查询失败 / 用量 ≥ N% / 自动刷新；
   宽卡片（stat-wide，3/20）＝ 余额合计 / 本月支出 / 订阅用量 / 最后刷新，要放下长文本。
   4 窄 + 4 宽 = 2×4 + 3×4 = 20 栏，正好铺满一行；两组内部等宽，宽卡是窄卡的 1.5 倍。 */
.summary.is-grid {
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
}

.stat-narrow {
  grid-column: span 2;
}

.stat-wide {
  grid-column: span 3;
}

/* 中等宽度（小笔记本 / 平板横屏）12 栏太窄，改为每行四项等宽 */
@media (max-width: 1199px) {
  .summary.is-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stat-narrow,
  .stat-wide {
    grid-column: span 1;
  }
}

.stat {
  /* 弹性布局下先按内容取宽，再均分剩余空间 */
  flex: 1 1 auto;
  min-width: 108px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 11px 13px;
}

/* 栅格内改为等分，不再按内容取宽 */
.summary.is-grid .stat {
  flex: none;
  min-width: 0;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  /* 文字必须完整显示：不截断、不出省略号，放不下时换行 */
  overflow-wrap: anywhere;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  /* 同上：完整显示，必要时折行，不用省略号 */
  overflow-wrap: anywhere;
}

/* ------------------------------ 筛选 ------------------------------ */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 12px;
}

.filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-text);
}

.chip-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.filter-select-wrap {
  position: relative;
  flex: none;
  min-width: 132px;
  max-width: 240px;
}

/* 主题化下拉箭头：用 CSS 绘制，颜色跟随 --muted，切换主题/日夜间都协调 */
.filter-select-wrap::after {
  content: '';
  position: absolute;
  right: 11px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.filter-select {
  width: 100%;
  padding: 6px 26px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.filter-select:hover {
  border-color: var(--border-strong);
}

.filter-select:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

/* 弹窗与设置面板内的下拉：与筛选栏下拉统一外观
   1) appearance:none + CSS 自绘箭头 ⇒ 箭头颜色取自 --muted，日间/夜间与各主题一致；
   2) 底色固定为 --panel-2 ⇒ 启用背景图时（--input-bg 会被置为 transparent）仍是不透明浮层，
      文字与箭头不会被背景图片干扰。 */
.select-wrap {
  position: relative;
  display: block;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.select-wrap > select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 8px 30px 8px 10px;
  background-color: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.select-wrap > select:hover {
  border-color: var(--accent);
}

.select-wrap > select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 行内（color-row）里的下拉：给一个合适的基准宽度，避免被挤压 */
.color-row > .select-wrap {
  flex: 1 1 160px;
  min-width: 140px;
}

/* 卡片内的「下次刷新」元素与样式已移除（顶栏保留全局刷新倒计时） */

.filter-search {
  width: 210px;
  flex: none;
  padding: 6px 10px;
  font-size: 13px;
}

/* 可搜索的平台下拉（参考 Element UI filterable select）：
   触发器即输入框，显示已选项；聚焦后可直接输入筛选，下拉只放选项列表，
   选中项以主题色高亮并在右侧显示 ✓。 */
.select {
  position: relative;
}

.select-input {
  position: relative;
  display: flex;
  align-items: center;
}

.select-inner {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 4px;
  padding: 8px 30px 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.select-inner:hover {
  border-color: var(--accent);
}

.select-input.is-open .select-inner {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  cursor: text;
}

.select-input.is-locked .select-inner {
  opacity: 0.65;
  cursor: not-allowed;
}

.select-inner::placeholder {
  color: var(--muted);
}

.select-suffix {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--muted);
}

.select-caret {
  display: inline-block;
  font-size: 11px;
  line-height: 1;
  transition: transform 0.2s ease, color 0.12s ease;
}

.select-input.is-open .select-caret {
  transform: rotate(180deg);
  color: var(--accent);
}

/* 下拉面板：只放选项列表，不再有独立搜索框 */
.select-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* 面板只负责圆角裁剪；滚动交给内部列表，否则内容会被裁掉且无法滚动 */
  overflow: hidden;
}

.select-list {
  max-height: min(360px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 0;
  list-style: none;
  margin: 0;
}

/* 分组标题吸顶：长列表滚动时始终能看到当前所在分组 */
.select-group {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: var(--panel-2);
}

.select-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: background-color 0.1s ease;
}

.select-item:hover {
  background: var(--accent-soft);
}

.select-item.active {
  color: var(--accent-text);
  font-weight: 600;
}

.select-item-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.select-item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-item-sub {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-item-check {
  flex: none;
  opacity: 0;
  color: var(--accent);
  font-size: 13px;
}

.select-item.active .select-item-check {
  opacity: 1;
}

.select-empty {
  padding: 16px 0;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

/* ------------------------------ 卡片 ------------------------------ */

.grid {
  display: grid;
  /* 卡片最小宽度可由「外观自定义」调节：越小每行展示越多 */
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min, 240px), 1fr));
  gap: 12px;
}

.card {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 0.15s ease;
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 4px 14px rgba(31, 35, 40, 0.06);
}

.card.error {
  border-left: 3px solid var(--red);
}

.card.stale {
  opacity: 0.85;
}

/* ------------------------------ 走势图 ------------------------------ */

.trend-multi {
  position: relative;
  margin-top: 10px;
}

.trend-multi svg {
  display: block;
  width: 100%;
  height: auto;
  /* 整块走势图可点击放大 */
  cursor: zoom-in;
}

.trend-multi:hover svg {
  opacity: 0.82;
}

.trend-multi:focus-visible {
  outline: 1px solid var(--accent-line);
  outline-offset: 2px;
  border-radius: 4px;
}

.trend-line {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

.trend-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

.trend-legend-item i {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.trend-tip {
  position: absolute;
  top: 0;
  transform: translate(-50%, -115%);
  padding: 2px 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 5;
}

/* -------------------- 趋势图放大弹窗 -------------------- */

/* 趋势图放大弹窗：收窄外边距、面板铺满，尽可能给横轴更多空间。
   注意：.modal / .modal-panel 定义在本文件更靠后的位置，同为单类选择器会覆盖这里的
   padding / width，因此必须叠加类名提升特异性，不能只写 .trend-modal / .trend-panel。 */
.modal.trend-modal {
  padding: 8px;
}

.modal-panel.trend-panel {
  /* 大屏占屏宽约 80%，小屏仍铺满可用宽度 */
  width: min(80vw, 100%);
  max-height: 96vh;
}

@media (max-width: 900px) {
  .modal-panel.trend-panel {
    width: 100%;
  }
}

.trend-zoom-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trend-zoom-ranges,
.trend-zoom-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.trend-range-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.trend-range-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.trend-range-btn.is-active {
  color: var(--accent-text);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.trend-legend-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: opacity 0.12s ease, border-color 0.12s ease;
}

.trend-legend-toggle:hover {
  border-color: var(--border-strong);
}

.trend-legend-toggle.off {
  opacity: 0.45;
  text-decoration: line-through;
}

.trend-legend-toggle i {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.trend-zoom-wrap {
  position: relative;
}

.trend-zoom-chart svg {
  display: block;
  width: 100%;
}

.trend-zoom-chart .tz-grid {
  stroke: var(--border);
  stroke-width: 1;
}

.trend-zoom-chart .tz-sep {
  stroke: var(--border);
  stroke-width: 1;
}

.trend-zoom-chart .tz-axis-line {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.trend-zoom-chart .tz-axis {
  fill: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.trend-zoom-chart .tz-title {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.trend-zoom-chart .tz-value {
  fill: var(--accent-text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

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

.trend-zoom-chart .tz-dot {
  fill: var(--panel-2);
  stroke-width: 1.6;
}

.trend-zoom-chart .tz-cross {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.trend-zoom-tip {
  position: absolute;
  z-index: 5;
  min-width: 148px;
  padding: 6px 9px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.trend-zoom-tip .tz-time {
  color: var(--muted);
  margin-bottom: 4px;
}

.trend-zoom-tip .tz-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.7;
}

.trend-zoom-tip .tz-row i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
  flex: none;
}

.trend-zoom-tip .tz-row span {
  color: var(--muted);
}

.trend-zoom-tip .tz-row b {
  margin-left: auto;
  font-weight: 600;
}

.trend-zoom-empty {
  padding: 28px 8px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.card-heading {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* 平台名：卡片第一优先级 */
.platform-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}

/* 备注名称：第三优先级，未填写时整体不渲染；用主题色底纹区分，不加文字标签 */
.card-note {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.card-meta {
  margin-top: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 状态色直接体现在平台名上（原先的圆点已移除）：正常绿色、异常红色 */
.platform-name.is-ok {
  color: var(--green);
}
.platform-name.is-err {
  color: var(--red);
}

/* 代理徽章靠右（原先由 next-refresh 的 margin-left:auto 撑开） */
.card-meta > .badge.proxy {
  margin-left: auto;
}

/* 套餐类型 + 档位徽章绑定为一组，始终同行，不被换行拆开 */
.badge-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid var(--accent-line);
  font-weight: 500;
}

.badge.tier {
  background: rgba(63, 185, 80, 0.14);
  color: #87e39a;
  border-color: rgba(63, 185, 80, 0.3);
}

/* 代理标记：中性灰，不与用量语义色抢视觉 */
.badge.proxy {
  background: var(--bg-soft);
  color: var(--muted);
  border-color: var(--border-strong);
}

/* 套餐类型：第二优先级，实心主题色填充 */
.badge.type {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 11.5px;
  padding: 2px 9px;
  border-radius: 4px;
}

.card-sub {
  margin-top: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* 备注 + 标签同组：标签始终紧跟备注之后，不受换行影响 */
.card-sub-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

/* 更新时间紧随备注/标签之后（不再靠右撑开），只保留与标签一致的间距 */
.card-time {
  white-space: nowrap;
}

.card-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: none;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.ok {
  background: var(--green);
}

.dot.err {
  background: var(--red);
}

/* 用量窗口 */

.windows {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.win-item {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.win-item:first-child {
  border-top: none;
  padding-top: 0;
}

.win-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.win-label {
  font-size: 13px;
  color: var(--text);
}

.win-value {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.win-value .pct {
  font-weight: 600;
}

.bar {
  margin-top: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}

.bar-inner {
  height: 100%;
  transition: width 0.3s ease;
}

.green {
  background: var(--green);
}

.orange {
  background: var(--orange);
}

.red {
  background: var(--red);
}

.win-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.balances {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.balance-item {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 9px;
  background: var(--bg-soft);
}

.balance-item span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.balance-item strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.extras {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------
   小卡片自适应：把卡片声明为容器，内容按「卡片自身宽度」而非视口调整，
   这样把「卡片宽度」调窄时，卡片内部依然排布整齐、不溢出。
   ------------------------------------------------------------------ */
.card {
  container-type: inline-size;
  container-name: card;
  overflow-wrap: anywhere; /* 长地址 / 长平台名不撑破卡片 */
}

/* 窄卡片：头部改为纵向堆叠（操作按钮移到下方整行），字号与间距收紧 */
@container card (max-width: 330px) {
  .card-head {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .card-actions {
    justify-content: flex-start;
  }
  .platform-name {
    font-size: 15px;
  }
  .card-title {
    font-size: 14px;
    gap: 6px;
  }
  .win-head {
    flex-wrap: wrap;
    row-gap: 2px;
  }
  .win-label,
  .win-value {
    font-size: 12.5px;
  }
  .win-value {
    min-width: 0; /* 允许在窄卡片内收缩换行，避免溢出 */
  }
  .win-item {
    min-width: 0;
  }
  .win-meta {
    font-size: 11.5px;
    gap: 6px;
  }
  .balances {
    grid-template-columns: 1fr;
  }
  .extras {
    gap: 8px;
  }
}

/* 更窄：进一步压缩按钮与徽章，次要文案缩小 */
@container card (max-width: 265px) {
  .act-btn {
    font-size: 11px;
    padding: 3px 7px;
    min-height: 24px;
  }
  .badge {
    font-size: 10px;
    padding: 1px 5px;
  }
  .card-sub {
    font-size: 11px;
    gap: 6px;
  }
  .balance-item {
    padding: 6px 8px;
  }
}

.error-box {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid rgba(248, 81, 73, 0.28);
  border-left: 3px solid var(--red);
  background: rgba(248, 81, 73, 0.08);
  color: #ffb4ae;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.auth-action {
  margin-top: 10px;
}

.note {
  margin-top: 10px;
  font-size: 12px;
  color: #e3b341;
}

/* ------------------------------ 空态 ------------------------------ */

.empty {
  text-align: center;
  padding: 48px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
}

.empty h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}

.empty p {
  margin: 0 0 18px;
  color: var(--muted);
}

/* ------------------------------ 弹窗 ------------------------------ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  /* 改用 flex + safe center：弹窗过高时不会上下裁切，可滚动到 footer */
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 作者样式的 display 会覆盖浏览器对 hidden 属性的默认 display:none，需显式声明 */
.modal[hidden] {
  display: none;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  /* 弹窗内滚到尽头时不要把滚动继续传给背景页面 */
  overscroll-behavior: contain;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.modal-panel h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.modal-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 12.5px;
  color: var(--muted);
}

input,
select,
textarea {
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

textarea {
  min-height: 76px;
  resize: vertical;
  font-size: 12px;
}

/* 密钥输入框：右侧眼睛按钮切换明文/掩码 */
.cred-secret {
  position: relative;
  display: flex;
  align-items: center;
}

.cred-secret input {
  padding-right: 38px;
}

.cred-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  color: var(--muted);
  border-radius: 4px;
  transition: background 0.12s ease, color 0.12s ease;
}

.cred-eye:hover {
  background: var(--bg-soft);
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.hint {
  margin: -6px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.edit-notice {
  margin: 0;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid var(--accent-line);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.edit-notice b {
  color: var(--text);
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.setting-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.setting-item code,
.setting-item span:last-child {
  word-break: break-all;
  text-align: right;
  color: var(--text);
}

/* --------------------------- 外观自定义 --------------------------- */

.setting-title {
  margin-top: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* --------------------- 设置弹框：左侧 tab --------------------- */

/* 设置弹框：固定高度，切换 tab 时高度不再跳动 */
#settingsModal .modal-panel {
  width: min(760px, 100%);
  height: min(560px, 88vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 内容区占满剩余高度，内部滚动；页头与页脚固定 */
#settingsModal .modal-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#settingsModal .modal-footer {
  flex: none;
  padding: 12px 14px;
  background: var(--bg-soft);
}

/* 覆盖 .modal-body 默认的纵向 flex，改为「左侧导航 + 右侧内容」 */
.settings-layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
  padding: 0;
}

.settings-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 0 0 116px;
  padding: 14px 0 14px 14px;
  margin-right: -2px;
  border-right: 1px solid var(--border);
  align-self: stretch;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-tab {
  appearance: none;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius, 6px);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.settings-tab:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.settings-tab.is-active {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: var(--accent-line);
  font-weight: 600;
}

.settings-panels {
  flex: 1;
  min-width: 0;
  min-height: 0;
  /* 撑满弹框高度，内容超出时在区内滚动 */
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 14px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-panel {
  display: none;
  flex-direction: column;
  /* 保持内容自然高度，超出时由 .settings-panels 滚动，而不是被压缩 */
  flex: none;
  gap: 12px;
  min-width: 0;
}

.settings-panel.is-active {
  display: flex;
}

/* 窄屏：tab 改为顶部横向排列，避免挤压内容区 */
@media (max-width: 640px) {
  .settings-layout {
    flex-direction: column;
    gap: 0;
  }

  .settings-tabs {
    position: static;
    flex: none;
    flex-direction: row;
    gap: 6px;
    padding: 12px 14px 0;
    overflow-x: auto;
    overscroll-behavior: contain;
  }

  .settings-tab {
    width: auto;
    white-space: nowrap;
  }

  .settings-panels {
    padding: 12px 14px 14px;
  }

  #settingsModal .modal-panel {
    height: min(560px, 92vh);
  }

  .settings-tabs {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
/* 行内由 label.field（标签 + 输入框）组成时按钮改与输入框底边对齐，
   否则按钮会浮在两行文字的中间，看起来和输入框不在一条线上 */
.color-row.align-fields {
  align-items: flex-end;
}

.proxy-test-result {
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.proxy-test-result.ok {
  color: var(--green);
}

.proxy-test-result.fail {
  color: var(--red);
}

.color-row input[type='range'] {
  flex: 1;
  min-width: 120px;
  height: auto;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}

.color-row output {
  min-width: 38px;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#customCss {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* 示例样式按钮组 */
.sample-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sample-btn {
  font-size: 12px;
  padding: 5px 11px;
}

/* --------------------------- 登录页 / 认证 --------------------------- */

.auth-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
  z-index: 60;
}

.auth-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 24px;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
}

.auth-sub {
  margin: -8px 0 0;
  font-size: 12.5px;
  text-align: center;
  color: var(--muted);
}

.auth-hint {
  margin: -2px 0 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
}

.auth-hint code {
  color: var(--text);
  font-size: 12px;
}

.auth-card .btn-primary {
  justify-content: center;
  min-height: 38px;
}

/* 两步验证：密钥 / 恢复码展示 */
/* 两步验证各步骤容器：与设置面板一致地纵向排列并留出间距，
   否则里面的输入框会紧贴下面的按钮 */
#tfaIdleBox,
#tfaSetupBox,
#tfaCodesBox,
#tfaEnabledBox,
#accTfaBox {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* 列布局下按钮默认会被拉伸成整行宽，这里让按钮保持内容宽度 */
#tfaIdleBox > .btn,
#tfaCodesBox > .btn {
  align-self: flex-start;
}
.tfa-qr {
  display: flex;
  justify-content: center;
  align-self: center;
  width: fit-content;
  margin-bottom: 12px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.tfa-qr svg {
  display: block;
  width: 160px;
  height: 160px;
}

.tfa-secret {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tfa-secret code {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  font-size: 12px;
  word-break: break-all;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.tfa-codes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.auth-error {
  margin: -6px 0 0;
  padding: 7px 10px;
  font-size: 12.5px;
  border-radius: 4px;
  border: 1px solid var(--red);
  background: transparent;
  color: var(--red);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 14px;
}

/* 新增 / 编辑弹框：表头与底部按钮固定，仅中间表单内容滚动 */
#addModal .modal-panel {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}
#addModal .modal-panel > header {
  flex: none;
}
#addModal .modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#addModal .modal-footer {
  /* 底部按钮已是 panel 的直接子元素，无需 sticky 也不会随内容滚动 */
  flex: none;
  background: var(--panel-2);
}

/* 复制 Cookie 引导弹窗：步骤与代码片段展示 */
.steps {
  margin: 6px 0 14px;
  padding-left: 20px;
}
.steps li {
  margin: 6px 0;
  line-height: 1.6;
}
.steps kbd,
kbd {
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  background: var(--kbd-bg, #2a2a3a);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
}
.code-block {
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  background: #1e1e2e;
  color: #e6e6e6;
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: all;
  overflow-x: auto;
}

/* 账号健康面板：汇总查询失败的账号并给出修复入口 */
.health-panel {
  border: 1px solid var(--orange);
  border-radius: var(--radius, 6px);
  padding: 12px 14px;
  margin-bottom: 14px;
  background: rgba(245, 158, 11, 0.08);
}
.health-panel[hidden] {
  display: none;
}
.health-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.health-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.health-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}
.health-platform {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(127, 127, 127, 0.12);
  white-space: nowrap;
}
.health-name {
  font-weight: 600;
  min-width: 100px;
  flex: 0 0 auto;
}
.health-reason {
  flex: 1 1 240px;
  min-width: 180px;
  opacity: 0.85;
  word-break: break-all;
}

/* 可点击的统计项（余额合计） */
.stat-clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.stat-clickable:hover {
  border-color: var(--accent, #3b82f6);
  background: rgba(59, 130, 246, 0.08);
}

/* 明细列表（余额合计 / 用量 ≥ 阈值 / 查询失败）：
   整张列表作为一个网格，li 用 display:contents 展开，
   使「平台 / 备注 / 名称或原因 / 数值」四列在每一行上下严格对齐 */
.stat-list {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, max-content) minmax(140px, 1fr) max-content;
  gap: 10px 14px;
  align-items: center;
}

/* 明细弹窗：宽度随内容自适应；内容过宽时列内收缩换行，而非出现横向滚动条 */
.modal-panel.detail-panel {
  width: fit-content;
  min-width: min(420px, 100%);
  max-width: min(1040px, 94vw);
  overflow-x: hidden;
}

/* 消费明细 / 订阅用量：宽高固定，切换页签时不再随内容伸缩。
   宽度 1000px 可容纳最小宽 920px 的表格且不出现横向滚动条；
   高度固定后由内容区纵向滚动，表头、页签与底部按钮保持可见。 */
#costModal .modal-panel,
#subscriptionModal .modal-panel {
  /* min(1000px, 100%)：大屏 1000px，窄屏自动收窄到容器宽度，
     不再因 id 选择器压过 640px 的 .modal-panel{width:100%} 而溢出视口 */
  width: min(1000px, 100%);
  height: min(720px, 88vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 表头、页签与底部按钮不参与伸缩，固定在上下两端 */
#costModal .modal-panel > header,
#costModal .modal-panel > footer,
#costModal .cost-tabs,
#subscriptionModal .modal-panel > header,
#subscriptionModal .modal-panel > footer,
#subscriptionModal .sub-tabs {
  flex: none;
}

/* 只有内容区滚动；min-height:0 是关键，否则内容会把固定高度撑破 */
#costModal .modal-body,
#subscriptionModal .modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.stat-list .health-name,
.stat-list .balance-item-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-list li {
  display: contents;
}
.stat-list li > :last-child {
  justify-self: end;
  white-space: nowrap;
}
/* 平台徽标背景只包住名称本身，不随列宽拉伸；过长时省略号收尾 */
.stat-list .health-platform {
  justify-self: start;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 余额明细弹窗 */
.balance-list li strong {
  white-space: nowrap;
}
.balance-item-name {
  flex: 0 0 auto;
  font-size: 12px;
  opacity: 0.75;
}
.balance-totals {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 6px;
}
.balance-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

/* 通知渠道配置 */
.notify-channels {
  display: grid;
  gap: 12px;
  margin-bottom: 10px;
}
.notify-channel {
  border: 1px solid var(--border);
  border-radius: var(--radius, 6px);
  padding: 10px 12px;
}
.notify-channel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

/* 批量操作条 */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--accent-line, var(--border));
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.bulk-count {
  font-size: 12.5px;
  color: var(--accent-text, var(--text));
  font-weight: 600;
}

/* 分组展示 */
.group-block {
  grid-column: 1 / -1;
}
.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.group-count {
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 11px;
}
.grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min, 240px), 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
tr.group-row td {
  padding: 8px 12px;
  background: var(--panel-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.col-check {
  width: 34px;
  text-align: center;
}
.col-check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 卡片备注/标签的内联编辑 */
.card-note.is-empty {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong);
  color: var(--muted);
}
.card-sub-main {
  cursor: text;
}
.inline-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.inline-input {
  width: 130px;
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 4px;
}

/* 余额预计可用时长 */
.balance-runway {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
}

/* 消费明细 */
/* 消费明细弹窗：顶部页签（统计 / 按账号明细 / 按天明细） */
.cost-tabs,
.sub-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 12px 16px 0;
}

.cost-tabs .trend-range-btn,
.sub-tabs .trend-range-btn {
  font-size: 12px;
}

/* 订阅用量：页签面板内「标题(.field) + 说明(.hint) + 表格」为普通块级流（非 flex），
   全局 .hint 的 -6px 负上边距与表格零间距在此会显得拥挤，这里统一补纵向呼吸感：
   标题与说明之间留出间距、说明与表格之间留出更大间距 */
#subPaneWindows > .field,
#subPaneDaily > .field {
  margin-bottom: 6px;
}

#subPaneWindows > .hint,
#subPaneDaily > .hint {
  /* 去掉全局 -6px 负上边距，并给表格上方留出间距 */
  margin: 0 0 14px;
}

/* 订阅用量：让表格在弹窗内独立滚动，表头吸顶（不再随内容滚走）。
   原 .table-view 只设 overflow-x:auto，会使其成为滚动容器却纵向不滚动，
   导致 thead 的 sticky 找不到纵向滚动上下文而失效。这里把面板设为纵向 flex、
   表格区占满剩余高度并 overflow:auto，thead 即可 sticky 到表格滚动区顶部。 */
#subscriptionBody > section {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

#subscriptionBody .table-view {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  margin: 0;
}

.cost-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.cost-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.cost-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  font-size: 12.5px;
}
.cost-row > span {
  color: var(--muted);
}
.cost-bar {
  margin-top: 6px;
}

/* 登录设备与日志 */
.session-list,
.login-log {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  margin: 6px 0;
}
.session-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.session-row:last-child {
  border-bottom: none;
}
.session-current {
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 10.5px;
  font-style: normal;
}
.session-ip,
.session-time {
  color: var(--muted);
  font-size: 11.5px;
}

/* 趋势图：工具条与叠加对比 */
.trend-zoom-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.trend-zoom-compare {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 6px 0 2px;
}
.compare-label {
  font-size: 11.5px;
  color: var(--muted);
}
.compare-chip {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.compare-chip:hover {
  color: var(--text);
  border-color: var(--accent);
}
.compare-chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-text);
}

/* 定时报告：卡片化容器 + 固定宽度的时间/星期控件，窄弹窗里也不会挤压换行 */
.digest-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.digest-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.digest-label {
  min-width: 30px;
  color: var(--muted);
  font-size: 12.5px;
}
.digest-note {
  color: var(--muted);
  font-size: 11.5px;
}
.digest-box .switch {
  margin: 0;
}
.time-input {
  width: 118px;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.digest-day {
  width: 100px;
  flex: none;
}
.digest-actions {
  gap: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

/* 账号标签（自建分组，用于筛选） */
.tag-chip {
  display: inline-block;
  font-size: 11px;
  line-height: 1.5;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--accent-line, var(--border));
  background: var(--accent-soft);
  color: var(--accent-text, var(--text));
  white-space: nowrap;
}
/* 间距由 .card-sub-main 的 gap 统一控制，标签不需要额外外边距 */

/* 窗口预测：预计耗尽时间 / 日均消耗 */
.win-forecast {
  color: var(--muted);
}

/* 表格视图：信息密度更高，超出宽度时横向滚动 */
.table-view {
  overflow-x: auto;
}
.table-view[hidden] {
  display: none;
}
.usage-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 13px;
}
.usage-table th,
.usage-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.usage-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.usage-table tbody tr:hover {
  background: var(--panel-2);
}
.usage-table tbody tr.is-stale {
  opacity: 0.55;
}
[data-table-sort] {
  cursor: pointer;
}
[data-table-sort]:hover {
  color: var(--text);
}
.tw-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
}
.tw-label {
  min-width: 56px;
  color: var(--muted);
  font-size: 11.5px;
}
.tw-bar {
  flex: none;
  width: 66px;
}
.tw-pct {
  font-variant-numeric: tabular-nums;
}
.tw-abs,
.tw-none {
  color: var(--muted);
  font-size: 11.5px;
}
.tw-error {
  color: var(--red);
}
.tp-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.tp-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.pin-mark {
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 10px;
}
.col-ops {
  white-space: nowrap;
}
.col-ops .act-btn {
  margin: 0 2px 2px 0;
}

/* 告警发送记录 */
.notify-log {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.log-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.log-row:last-child {
  border-bottom: none;
}
.log-time,
.log-channels {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.log-channels {
  font-size: 11.5px;
}
.log-result {
  grid-column: 2 / -1;
  color: var(--green);
  font-size: 11.5px;
  word-break: break-all;
}
.log-row.is-fail .log-result {
  color: var(--red);
}

/* 运行日志弹窗 */
#logModal .modal-panel {
  width: min(660px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#logModal .modal-panel > header,
#logModal .modal-footer {
  flex: none;
}
#logModal .modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.log-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.log-filters {
  display: inline-flex;
  gap: 8px;
}
.log-toolbar .filter-search {
  flex: 1;
  min-width: 160px;
}
.log-count {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
}
.log-empty {
  text-align: center;
  padding: 28px 0;
}
.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log-list .log-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 14px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 13px;
}
.log-list .log-row.is-fail {
  border-color: rgba(248, 81, 73, 0.35);
  background: rgba(248, 81, 73, 0.07);
}
.log-list .log-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 120px;
  color: var(--muted);
}
.log-list .log-time {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.log-list .log-source {
  font-size: 11px;
  color: var(--muted);
}
.log-list .log-main {
  min-width: 0;
}
.log-list .log-title {
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}
.log-list .log-platform {
  margin-left: 4px;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
}
.log-list .log-error {
  margin-top: 4px;
  color: var(--red);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-list .log-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.log-list .log-badge {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.log-list .log-badge.ok {
  color: var(--green);
  border-color: var(--green);
}
.log-list .log-badge.fail {
  color: var(--red);
  border-color: var(--red);
}
.log-list .log-fix {
  padding: 2px 10px;
  font-size: 12px;
}

@media (max-width: 640px) {
  .log-list .log-row {
    grid-template-columns: 1fr;
  }
  .log-list .log-meta {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  .log-list .log-actions {
    flex-direction: row;
    justify-content: flex-start;
  }
}

/* 备份列表 */
.backup-list {
  max-height: 260px;
  overflow-y: auto;
  /* 与上方说明文字、下方「刷新列表」按钮之间留出间距，避免贴在一起 */
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* 空 / 加载中的占位：给足内边距，避免容器塌成一条细缝（.hint 自带负外边距需覆盖） */
.backup-empty {
  margin: 0;
  padding: 30px 12px;
  text-align: center;
}
.backup-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.backup-row:last-child {
  border-bottom: none;
}
.backup-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backup-time,
.backup-size {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.backup-ops {
  white-space: nowrap;
}

/* 说明文案内的行内代码 */
.modal-body code,
.hint code,
.steps code {
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  background: rgba(127, 127, 127, 0.18);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.test-result {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  font-size: 12.5px;
  background: var(--bg-soft);
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}

.test-result.ok {
  border-color: rgba(63, 185, 80, 0.4);
  background: rgba(63, 185, 80, 0.08);
}

.test-result.fail {
  border-color: rgba(248, 81, 73, 0.4);
  background: rgba(248, 81, 73, 0.08);
  color: #ffb4ae;
}

.test-result ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

/* ------------------------------ Toast ------------------------------ */
/* 顶部居中提示：位于顶栏下方（top 由脚本按顶栏实际高度设置），
   左侧色条 + 圆形图标区分成功/失败，向下滑入并带明显阴影，确保一眼能看到。 */

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  z-index: 120; /* 高于弹窗(60)与顶栏(20)，弹窗内操作也能看到提示 */
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
  transform: translateX(-50%) translateY(-14px);
  opacity: 0;
  animation: toast-in 0.2s ease-out forwards;
  pointer-events: none; /* 提示不拦截点击 */
}

.toast[hidden] {
  display: none;
}

.toast::before {
  content: 'i';
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 700;
}

.toast.ok {
  border-left-color: #3fb950;
}

.toast.ok::before {
  content: '✓';
  background: rgba(63, 185, 80, 0.18);
  color: #3fb950;
}

.toast.err {
  border-left-color: #f85149;
}

.toast.err::before {
  content: '!';
  background: rgba(248, 81, 73, 0.18);
  color: #f85149;
}

@keyframes toast-in {
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ------------------------------ 响应式 ------------------------------ */

@media (max-width: 900px) {
  .app {
    padding: 16px 14px 40px;
  }

  /* 概览条：窄屏改为每行两项（等宽，仍不随文字变形） */
  .summary.is-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .brand {
    gap: 10px;
  }

  .brand-sub {
    display: none;
  }

  /* 操作区独占一行，按钮自动换行，避免横向溢出 */
  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .countdown {
    flex: 1 1 auto;
    min-width: 0;
  }

  .summary {
    gap: 8px;
  }

  .stat {
    padding: 9px 11px;
  }

  .stat-value {
    font-size: 18px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-search {
    width: 100%;
  }

  .card {
    padding: 12px 14px;
  }

  /* 操作按钮独占一行并等分，触摸目标更大 */
  .card-head {
    flex-direction: column;
    gap: 10px;
  }

  .card-actions {
    width: 100%;
    gap: 8px;
  }

  .act-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
  }

  /* 弹窗改为底部抽屉，便于单手操作 */
  .modal {
    padding: 0;
    place-items: end stretch;
  }

  .modal-panel {
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
  }

  .modal-footer {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
    min-height: 40px;
  }

  /* 窄屏提示占满一行宽度（仍位于顶栏下方） */
  .toast {
    left: 12px;
    right: 12px;
    min-width: 0;
    max-width: none;
    transform: translateY(-14px);
    animation-name: toast-in-narrow;
  }

  @keyframes toast-in-narrow {
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* iOS 聚焦输入框时字号小于 16px 会触发页面自动缩放 */
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* 时间窗口编辑器 */
.weekday-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}
.weekday-toggle {
  padding: 4px 10px;
  border: 1px solid var(--border, #2a333d);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 12px;
  cursor: pointer;
}
.weekday-toggle.is-on {
  border-color: var(--accent, #4c8dff);
  background: color-mix(in srgb, var(--accent, #4c8dff) 22%, transparent);
  color: var(--accent, #4c8dff);
}
.schedule-ranges {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0;
}
.schedule-range {
  display: flex;
  align-items: center;
  gap: 8px;
}
.schedule-range .range-sep {
  opacity: 0.6;
}
