:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --dim: #5b6b83;
  --dim-2: #6b7a90;
  --accent: #2563eb;
  --accent-2: #0891b2;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04),
    0 10px 28px -16px rgba(15, 23, 42, 0.22);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

/* 原生感：禁掉浏览器层面的缩放与下拉刷新/橡皮筋，把滚动行为交给页面自己 */
html {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--bg);
  background-image: radial-gradient(
      58% 46% at 10% -8%,
      rgba(37, 99, 235, 0.13),
      transparent 68%
    ),
    radial-gradient(46% 38% at 92% -4%, rgba(8, 145, 178, 0.12), transparent 66%),
    radial-gradient(40% 34% at 55% 4%, rgba(139, 92, 246, 0.07), transparent 70%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  padding: 0 max(16px, env(safe-area-inset-left)) 0
    max(16px, env(safe-area-inset-right));
  overflow-x: hidden;
}

main,
.topbar,
footer {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 26px 4px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-right: auto;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 14px;
  background: linear-gradient(150deg, #ffffff, #eaf1ff);
  border: 1px solid rgba(37, 99, 235, 0.18);
  box-shadow: 0 8px 22px -12px rgba(37, 99, 235, 0.55);
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 640;
  letter-spacing: 0.2px;
  color: #0b1220;
}

.brand p {
  margin: 3px 0 0;
  color: var(--dim);
  font-size: 12.5px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: #eaeff7;
  border: 1px solid var(--border);
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  padding: 6px 13px;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--accent);
}

.segmented button.active {
  background: #fff;
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.segmented.small button {
  padding: 4px 10px;
  font-size: 12px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--dim);
  font-size: 17px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-sm);
  transition: color 0.16s, border-color 0.16s, transform 0.3s;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: rgba(37, 99, 235, 0.3);
}

.icon-btn.spinning {
  animation: spin 0.8s linear infinite;
}

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

/* ---------- kpi ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  position: relative;
  padding: 15px 16px 14px;
  border-radius: var(--radius);
  background: linear-gradient(168deg, #ffffff 0%, #fbfdff 100%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(37, 99, 235, 0.45),
    transparent
  );
}

.kpi .label {
  color: var(--dim);
  font-size: 11.5px;
  letter-spacing: 0.4px;
  margin-bottom: 7px;
}

.kpi .value {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.5px;
  line-height: 1.15;
  color: #0b1220;
  word-break: break-all;
}

.kpi .sub {
  margin-top: 5px;
  color: var(--dim-2);
  font-size: 11.5px;
  font-family: var(--mono);
}

.kpi.accent .value {
  background: linear-gradient(118deg, #1d4ed8, #0891b2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- cards ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 10px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: 0.2px;
  color: #0b1220;
}

.hint {
  margin: 3px 0 0;
  color: var(--dim-2);
  font-size: 12px;
}

.chart {
  width: 100%;
  height: 320px;
}

.chart-tall {
  height: 420px;
}

/* ---------- channel list ---------- */

.channel-list {
  display: flex;
  flex-direction: column;
}

/* ---------- 渠道额度小卡片（数据来自 OpenCode Go，页面不露出上游名字） ---------- */

.og-card {
  padding: 13px 16px 14px;
  margin-bottom: 16px;
}

.og-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.og-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: #0b1220;
}

.og-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 6px;
  background: linear-gradient(140deg, #eff4ff, #e3edff);
  border: 1px solid rgba(37, 99, 235, 0.18);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.og-updated {
  color: var(--dim-2);
  font-family: var(--mono);
  font-size: 11px;
}

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

.og-row {
  display: grid;
  grid-template-columns: 42px repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
}

.og-account {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.og-window {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 11px;
  background: #f7f9fc;
  border: 1px solid var(--border);
}

.og-label {
  color: var(--dim);
  font-size: 11.5px;
}

.og-pct {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.3px;
}

.og-pct.ok {
  color: #047857;
}

.og-pct.mid {
  color: #0369a1;
}

.og-pct.warn {
  color: #b45309;
}

.og-pct.bad {
  color: #b91c1c;
}

.og-pct.none {
  color: var(--dim-2);
}

.og-error {
  color: var(--dim-2);
  font-size: 12px;
}

/* ---------- 最近请求列表 ---------- */
.recent-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(60px, 0.5fr) minmax(0, 1.05fr) minmax(
      74px,
      0.6fr
    ) minmax(80px, 0.7fr);
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-top: 1px solid rgba(15, 23, 42, 0.05);
}

.recent-row:first-child {
  border-top: 0;
}

.recent-row.head {
  padding: 4px;
  color: var(--dim-2);
  font-size: 11.5px;
  letter-spacing: 0.4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
}

.badge.ok {
  background: rgba(16, 185, 129, 0.13);
  color: #047857;
}

.badge.err {
  background: rgba(239, 68, 68, 0.13);
  color: #b91c1c;
}

.recent-model {
  text-align: left;
  font-size: 12px;
  color: #475569;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-speed {
  color: #334155;
}

.stat-group {
  display: contents;
}

.user-row,
.channel-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(76px, 0.9fr)) minmax(
      96px,
      1fr
    );
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  border-top: 1px solid rgba(15, 23, 42, 0.05);
}

.user-row:first-child,
.channel-row:first-child {
  border-top: 0;
}

.user-row.head,
.channel-row.head {
  padding: 4px;
  color: var(--dim-2);
  font-size: 11.5px;
  letter-spacing: 0.4px;
}

/* 渠道速度对比表：渠道名 + 4 个数据列 */
.speed-row {
  grid-template-columns: minmax(0, 1.6fr) repeat(4, minmax(72px, 0.9fr));
}

.channel-name {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
}

.channel-name .text {
  min-width: 0;
}

.channel-name .title {
  font-size: 13.5px;
  font-weight: 520;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-name .meta {
  color: var(--dim-2);
  font-size: 11.5px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell {
  font-family: var(--mono);
  font-size: 12.5px;
  color: #334155;
  text-align: right;
  white-space: nowrap;
}

.cell .dim {
  color: var(--dim-2);
}

.share-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  justify-content: flex-end;
}

.share-bar {
  position: relative;
  flex: 1;
  min-width: 40px;
  height: 6px;
  border-radius: 99px;
  background: rgba(15, 23, 42, 0.07);
  overflow: hidden;
}

.share-bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #3b82f6, #06b6d4);
}

.share-bar.alt > i {
  background: linear-gradient(90deg, #a78bfa, #ec4899);
}

.cell.share {
  min-width: 48px;
  color: #0b1220;
  font-weight: 600;
}

/* 用户表：金额是主角，占比主动退到一边 */
.amount-cell {
  color: #0b1220;
  font-weight: 600;
  font-size: 13px;
}

.cell.share.share-quiet {
  min-width: 46px;
  color: var(--dim);
  font-weight: 500;
}

/* ---------- state ---------- */

.empty {
  padding: 46px 16px;
  text-align: center;
  color: var(--dim);
}

.empty .big {
  font-size: 30px;
  margin-bottom: 10px;
  opacity: 0.7;
}

footer {
  padding: 6px 4px 34px;
  color: var(--dim);
  font-size: 11.5px;
  font-family: var(--mono);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

footer .dot {
  opacity: 0.55;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  body {
    font-size: 13.5px;
  }

  .topbar {
    padding: 18px 2px 14px;
    gap: 12px;
  }

  .brand h1 {
    font-size: 17px;
  }

  .logo {
    width: 38px;
    height: 38px;
    font-size: 19px;
    border-radius: 12px;
  }

  .controls {
    width: 100%;
  }

  .segmented {
    flex: 1 1 100%;
  }

  .segmented button {
    flex: 1;
    padding: 7px 6px;
    font-size: 12px;
  }

  .card {
    padding: 14px 13px 8px;
    border-radius: 16px;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .kpi {
    padding: 12px 13px;
  }

  .kpi .value {
    font-size: 21px;
  }

  .chart {
    height: 260px;
  }

  .chart-tall {
    height: 360px;
  }

  .user-row,
  .channel-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name share"
      "stats stats";
    row-gap: 7px;
    padding: 12px 2px;
  }

  .user-row.head,
  .channel-row.head {
    display: none;
  }

  .channel-name {
    grid-area: name;
  }

  .share-wrap {
    grid-area: share;
  }

  .stat-group {
    grid-area: stats;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
  }

  .user-row > .cell,
  .channel-row > .cell {
    text-align: left;
  }

  .og-card {
    padding: 11px 13px 12px;
  }

  .og-row {
    grid-template-columns: 34px repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .og-account {
    font-size: 11px;
  }

  .og-window {
    padding: 6px 7px;
    gap: 3px;
    flex-direction: column;
    align-items: flex-start;
  }

  .og-label {
    font-size: 10.5px;
  }

  .og-pct {
    font-size: 14px;
  }

  .recent-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name cost"
      "status speed"
      "model model";
    row-gap: 8px;
    padding: 12px 2px;
  }

  .recent-row.head {
    display: none;
  }

  .recent-row .channel-name {
    grid-area: name;
  }

  .recent-row .recent-status {
    grid-area: status;
  }

  .recent-row .recent-speed {
    grid-area: speed;
    text-align: right;
  }

  .recent-row .recent-model {
    grid-area: model;
    text-align: left;
    font-size: 11.5px;
    color: var(--dim-2);
  }

  .recent-row > .cell:last-child {
    grid-area: cost;
    text-align: right;
  }

  /* 用户表在手机上：第一行「用户名 + 金额」，第二行「请求/Tokens + 小小的占比」，
     不显示占比进度条（太扎眼） */
  .user-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name amount"
      "stats share";
  }

  .user-row .amount-cell {
    grid-area: amount;
    text-align: right;
    font-size: 15px;
  }

  .user-row .user-share {
    grid-area: share;
    justify-content: flex-end;
  }

  .user-row .user-share .share-bar {
    display: none;
  }

  .user-row .user-share .cell.share {
    min-width: 0;
    font-size: 11px;
    font-weight: 400;
    color: var(--dim-2);
  }
}
