:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #55565a;
  --ink-3: #8a8f99;
  --line: #e9ebf0;
  --blue: #0a7cff;
  --purple: #a550e8;
  --green: #2fbf62;
  --teal: #1fa8b8;
  --asxs: #6e6e73;
  --orange: #ff9500;
  --red: #ff3b30;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .05);
  --shadow-lift: 0 2px 6px rgba(16, 24, 40, .06), 0 10px 24px rgba(16, 24, 40, .09);
  --pad: clamp(16px, 1.6vw, 32px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Inter", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

::selection { background: rgba(10, 124, 255, .18); }

/* ---------- 顶栏（控制横栏） ---------- */

.topbar {
  padding: calc(14px + env(safe-area-inset-top)) calc(var(--pad) + env(safe-area-inset-right)) 10px calc(var(--pad) + env(safe-area-inset-left));
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.strip-slot { display: none; }

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

.badge {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #0a7cff, #1fa8b8);
  box-shadow: 0 4px 10px rgba(10, 124, 255, .28);
  flex: none;
}

.brand-text h1 { margin: 0; font-size: 17px; font-weight: 720; letter-spacing: .2px; }
.updated { font-size: 12px; color: var(--ink-3); margin-top: 1px; }

.controls { display: flex; gap: 8px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, #2f8dff, #0a7cff);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 8px rgba(10, 124, 255, .3);
}
.btn-off { color: var(--ink-3); font-weight: 500; }
.btn-refreshing { opacity: .6; pointer-events: none; }
.btn-danger {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, #ff5a4e, #ff3b30);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 8px rgba(255, 59, 48, .3);
}
.btn-danger:disabled { opacity: .45; box-shadow: none; pointer-events: none; }

/* ---------- 区块 ---------- */

main {
  padding: 0 calc(var(--pad) + env(safe-area-inset-right)) calc(var(--pad) + env(safe-area-inset-bottom)) calc(var(--pad) + env(safe-area-inset-left));
}

.sec { margin-top: 14px; }

.sec-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 6px 2px 10px;
}
.sec-title { font-size: 15px; font-weight: 720; }
.sec-sub { font-weight: 500; color: var(--ink-3); font-size: 13px; margin-left: 8px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(16, 24, 40, .04);
  padding: 16px 18px;
  transition: transform .16s ease, box-shadow .16s ease;
}
.card:hover { box-shadow: var(--shadow-lift); }

/* ---------- 菜单栏同款摘要条 ---------- */

.strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 22px;
  padding: 12px 18px;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 640;
  font-variant-numeric: tabular-nums;
}
.strip .seg { white-space: nowrap; }
.strip .seg b { font-weight: 720; margin-right: 1px; }
.strip .cap { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--ink-3); }
.strip .seg.err { color: var(--red) !important; }

/* ---------- 用量总览：四家分区 ---------- */

.providers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  align-items: start;
}

.provider { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* 分区内的一组指标：桌面端每项是独立卡片，手机端合并成一张卡内的紧凑行 */
.provider-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quota-item {
  background: var(--card);
  border: 1px solid rgba(16, 24, 40, .04);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  transition: transform .16s ease, box-shadow .16s ease;
}
.quota-item:hover { box-shadow: var(--shadow-lift); }

.prov-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 720;
  padding: 2px 2px 0;
}
.prov-head .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prov-head .tail { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--ink-3); }

.quota-card { display: flex; flex-direction: column; gap: 8px; }
.quota-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.q-title { font-size: 13px; font-weight: 620; color: var(--ink-2); }
.q-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-value.small { font-size: 17px; }
.q-value.money { font-size: 27px; }

.bar {
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: 4px;
  transition: width .5s ease;
}

.q-detail { font-size: 12px; color: var(--ink-3); }
.q-detail + .q-detail { margin-top: -3px; }

.err-card { color: #b42318; }
.err-card .q-title { color: #b42318; }
.err-text { font-size: 12.5px; color: #b42318; word-break: break-all; }

/* ---------- ASXS ---------- */

.stale-chip {
  font-size: 12px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 999px;
  padding: 3px 10px;
}

.error-card {
  color: #b42318;
  font-size: 13px;
  margin-bottom: 12px;
  padding: 12px 18px;
}

.asxs-top {
  display: grid;
  grid-template-columns: 5fr 7fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}
#asxsPools { margin-bottom: 16px; }

.block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}
.block-head .count { font-weight: 500; color: var(--ink-3); font-size: 12.5px; }

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: #f6f7f9;
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 11px;
  cursor: pointer;
  margin-left: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background .16s ease;
  text-decoration: none;
  display: inline-block;
}
.chip.on { background: rgba(10, 124, 255, .1); border-color: rgba(10, 124, 255, .35); color: #0a6ae0; }
.chip-link { color: #0a6ae0; }

.sec-actions { display: inline-flex; gap: 8px; margin-left: auto; }
.sec-actions .chip { margin-left: 0; }

th.sortable { cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
th.sortable .arr { color: #0a7cff; font-weight: 700; }

.subs-list { display: flex; flex-direction: column; gap: 8px; }
.sub-row { display: flex; gap: 8px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sub-row .dot { color: var(--ink-3); flex: none; }
.sub-row.current .dot { color: var(--ink); }
.sub-row.current { color: var(--ink); font-weight: 600; }

.pool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px 24px;
}
.pool-row {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.pool-row > summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.pool-row > summary::-webkit-details-marker { display: none; }
.pool-row .sym { flex: none; font-weight: 700; }
.pool-row .pname { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pool-row .pstat { color: var(--ink-3); flex: none; }
.pool-row .pstat::before, .pool-row .ptime::before { content: "· "; }
.pool-row .ptime { color: var(--ink-3); margin-left: auto; flex: none; }
.pool-row .pdetail {
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 3px 0 4px 22px;
  line-height: 1.5;
}
.pool-row .pool-metric { display: inline-block; }
.pool-row .pool-metric:not(:last-child)::after { content: " · "; }
.pool-row .pool-tip { display: none; }
.pool-row.ok .sym { color: #2fbf62; }
.pool-row.warn .sym { color: #ff9500; }
.pool-row.warn .pstat { color: #b45309; }
.pool-row.bad .sym { color: #ff3b30; }
.pool-row.bad .pstat { color: #b42318; }
.pool-row.unknown .sym { color: #9ca3af; }

table.api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.api-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  padding: 6px 10px 8px;
  white-space: nowrap;
}
.api-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f2f6;
  color: var(--ink-2);
  white-space: nowrap;
}
.api-table tr:last-child td { border-bottom: none; }
.api-table tr:hover td { background: #fafbfd; }
.api-table td.name { color: var(--ink); font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.api-table th.num, .api-table td.num { text-align: right; }
.api-table td .mult { color: var(--ink-2); }
.api-table td.dim { color: var(--ink-3); }

/* API 表格的手机端形态：每个 API 一张竖排小卡 */
.api-cards { display: none; }
.api-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.api-card + .api-card { margin-top: 8px; }
.api-card .ac-top { display: flex; align-items: baseline; gap: 8px; }
.api-card .ac-name { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.api-card .ac-mult { margin-left: auto; flex: none; font-size: 12px; color: var(--ink-2); background: #f6f7f9; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.api-card .ac-line { display: flex; gap: 8px; font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.api-card .ac-line b { color: var(--ink-2); font-weight: 600; }
.api-card .ac-line .amt { margin-left: auto; color: var(--ink-2); }
.api-card .ac-line + .ac-line { margin-top: -2px; }

/* ---------- 原生对话框（重置日额 / 添加到主屏幕） ---------- */

html { scroll-padding-top: calc(var(--header-height, 64px) + 10px); scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body.dialog-open { position: fixed; width: 100%; overflow: hidden; }

dialog.modal {
  border: none;
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
  width: min(94vw, 420px);
  max-width: 420px;
  max-height: min(78vh, 640px);
  overflow-y: auto;
  padding: 18px;
  -webkit-overflow-scrolling: touch;
}
dialog.modal::backdrop { background: rgba(15, 20, 30, .45); }
dialog.modal:not([open]) { display: none; }
.modal-title { font-size: 16px; font-weight: 720; }
.modal-sub { font-size: 12.5px; color: var(--ink-3); margin: 6px 0 12px; line-height: 1.5; }
.modal-body { display: flex; flex-direction: column; gap: 8px; }
.reset-target {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.reset-target.disabled { opacity: .55; background: #fafbfc; }
.reset-target input[type="checkbox"] { width: 17px; height: 17px; margin: 2px 0 0; accent-color: #0a7cff; flex: none; }
.reset-target .rt-main { font-size: 13.5px; font-weight: 650; }
.reset-target .rt-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.reset-target .rt-msg { font-size: 11.5px; color: #b45309; margin-top: 3px; }
.reset-target .rt-msg.ok { color: #2f8a4c; }
.modal-msg { margin-top: 10px; font-size: 12.5px; color: #b42318; word-break: break-all; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; padding: 10px 14px; font-size: 14px; }

.reset-summary { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-2); }
.reset-ack {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.45;
  cursor: pointer;
  touch-action: manipulation;
}
.reset-ack input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: #0a7cff; flex: none; }
.reset-ack:has(input:disabled) { opacity: .55; }

.install-steps { margin: 8px 0 0; padding-left: 20px; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.install-steps li + li { margin-top: 6px; }
.install-steps strong { color: var(--ink); }

/* ---------- 应用工具行 / 状态 / 更新横幅 / 底部导航 ---------- */

.app-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 2px 0;
  font-size: 12px;
  color: var(--ink-3);
}
.app-tools .chip { margin-left: auto; }

.data-status { margin: 2px 2px 10px; font-size: 12px; color: var(--ink-3); }
.data-status.is-stale { color: #b45309; }

.update-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 2px 0;
  padding: 9px 13px;
  font-size: 12.5px;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 10px;
}
.update-banner .btn { margin-left: auto; padding: 5px 12px; font-size: 12.5px; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px calc(var(--pad) + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(var(--pad) + env(safe-area-inset-left));
  background: rgba(245, 246, 248, .88);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid rgba(16, 24, 40, .07);
}
.bottom-nav a {
  flex: 1;
  max-width: 150px;
  text-align: center;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: 9px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav a:active { background: rgba(10, 124, 255, .08); color: #0a6ae0; }

/* API 排序下拉（手机可直接用） */
.api-sort {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--ink-3);
}
.api-sort select {
  appearance: none;
  border: 1px solid var(--line);
  background: #f6f7f9 url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8f99' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  padding: 5px 26px 5px 10px;
  touch-action: manipulation;
}

.empty { font-size: 13px; color: var(--ink-3); padding: 4px 0; }

.hidden { display: none !important; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 响应式（手机端为主要适配目标） ---------- */

@media (max-width: 1080px) {
  .providers { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .asxs-top { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  /* 吸顶毛玻璃应用栏：标题 + 更新时间/刷新按钮 + Z/K/D/S 摘要条（JS 按断点把 strip 移入） */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: 0;
    background: rgba(245, 246, 248, .86);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
    border-bottom: 1px solid rgba(16, 24, 40, .07);
  }
  .topbar-row { gap: 10px; }
  .strip-slot { display: block; }

  .badge { width: 32px; height: 32px; border-radius: 9px; }
  .brand-text h1 { font-size: 16px; }
  .btn { padding: 9px 14px; }

  .topbar .strip {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 6px 0 9px;
    margin: 0;
    font-size: 14px;
    gap: 4px 14px;
  }
  .topbar .strip .cap { display: none; }

  main { padding-bottom: calc(var(--pad) + 62px + env(safe-area-inset-bottom)); }
  .card { padding: 13px 14px; border-radius: 12px; }
  .providers { grid-template-columns: 1fr; gap: 10px; }
  .provider { gap: 6px; }
  .prov-head { font-size: 13.5px; }

  /* 用量分区合并为一张紧凑卡 */
  .provider-card {
    gap: 0;
    padding: 2px 12px;
    background: var(--card);
    border: 1px solid rgba(16, 24, 40, .04);
    border-radius: 12px;
    box-shadow: var(--shadow);
  }
  .quota-item {
    padding: 9px 2px;
    gap: 5px;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  .quota-item + .quota-item { border-top: 1px solid var(--line); }
  .quota-row { gap: 8px; }
  .q-title { font-size: 12px; }
  .q-value { font-size: 15.5px; }
  .q-value.small { font-size: 14px; }
  .q-value.money { font-size: 20px; }
  .bar { height: 5px; border-radius: 2.5px; }
  .q-detail { font-size: 11px; }
  .err-text { font-size: 11.5px; }

  .sec-head { flex-wrap: wrap; row-gap: 6px; }
  .sec-actions { margin-left: 0; width: 100%; }
  .sec-actions .chip { padding: 6px 13px; }

  .block-head { font-size: 13px; margin-bottom: 10px; }
  .subs-list { gap: 6px; }
  .sub-row { font-size: 12.5px; }

  .pool-grid { grid-template-columns: 1fr; gap: 8px; }
  .pool-row { font-size: 12.5px; }
  .pool-row > summary { padding: 4px 0; }
  .pool-row .pname { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
  .pool-row .pdetail { padding-left: 20px; font-size: 11px; }

  /* 表格 → 竖排卡片 */
  .table-scroll { display: none; }
  .api-cards { display: block; }
  .api-card { padding: 8px 11px; gap: 4px; }
  .api-card .ac-name { font-size: 13px; }
  .api-card .ac-line { font-size: 11.5px; }

  .app-tools { margin-top: 2px; }
  .bottom-nav a { font-size: 12.5px; padding: 10px 0; }
}
