/* =========================================================================
   TokenTracker 用量 · 样式
   黑白双主题：html[data-theme="dark" | "light"]
   主题变量集中在下面两组，改配色只改这里即可。
   ========================================================================= */

/* ---------------- 深色主题（默认） ---------------- */
:root,
html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-glow-1: rgba(79, 140, 255, .18);
  --bg-glow-2: rgba(124, 92, 255, .14);
  --card: #141f38;
  --card-2: #1a2745;
  --card-border: #24334f;
  --card-grad-top: rgba(255, 255, 255, .05);
  --card-grad-bottom: rgba(255, 255, 255, .015);
  --text: #e8eefc;
  --text-dim: #8fa1c4;
  --text-soft: #bcd0ff;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --green: #34d399;
  --amber: #fbbf24;
  --pink: #f472b6;
  --track: rgba(255, 255, 255, .06);
  --heat-0: #16233f;
  --heat-1: #1f4785;
  --heat-2: #2f6fc4;
  --heat-3: #6ea0ff;
  --heat-4: #a9c7ff;
  --divider: rgba(36, 51, 79, .6);
  --shadow: 0 30px 80px rgba(0, 0, 0, .45);
  --input-bg: rgba(8, 13, 26, .7);
  --chart-hi: #6ea0ff;
  --chart-lo: #3b5bb0;
}

/* ---------------- 浅色主题 ---------------- */
html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-glow-1: rgba(79, 140, 255, .16);
  --bg-glow-2: rgba(124, 92, 255, .12);
  --card: #ffffff;
  --card-2: #eef2fa;
  --card-border: #dfe5f0;
  --card-grad-top: rgba(255, 255, 255, .9);
  --card-grad-bottom: rgba(244, 246, 251, .9);
  --text: #16203a;
  --text-dim: #6b7a99;
  --text-soft: #3d5da8;
  --accent: #2f6fe4;
  --accent-2: #6a45e8;
  --green: #10a97a;
  --amber: #d98a00;
  --pink: #db3d8b;
  --track: rgba(22, 32, 58, .08);
  --heat-0: #e6ebf5;
  --heat-1: #bcd4f7;
  --heat-2: #7aa9ee;
  --heat-3: #3d7fe0;
  --heat-4: #1f56b8;
  --divider: rgba(223, 229, 240, .9);
  --shadow: 0 18px 50px rgba(31, 45, 80, .12);
  --input-bg: #ffffff;
  --chart-hi: #5b93ff;
  --chart-lo: #2f6fe4;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background-color .25s ease, color .25s ease;
}

.hidden { display: none !important; }

/* ---------------- 登录 ---------------- */
.auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, var(--card-grad-top), var(--card-grad-bottom));
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 34px 26px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.auth-logo { font-size: 50px; line-height: 1; margin-bottom: 12px; filter: drop-shadow(0 6px 18px rgba(79,140,255,.45)); }
.auth-card h1 { font-size: 23px; letter-spacing: .5px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin: 8px 0 20px; }
.auth-card input {
  width: 100%; padding: 14px 16px; margin-bottom: 11px;
  border-radius: 12px; border: 1px solid var(--card-border);
  background: var(--input-bg); color: var(--text); font-size: 16px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.22); }
.btn-primary {
  width: 100%; padding: 14px; margin-top: 4px; border: none; border-radius: 12px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 16px; font-weight: 600; letter-spacing: 6px; cursor: pointer;
}
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; }
.oauth-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-oauth {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 8px; border-radius: 12px; border: 1px solid var(--card-border);
  background: var(--card-2); color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
}
.auth-err { color: #e5484d; font-size: 13px; margin-top: 12px; min-height: 18px; }
.auth-hint { color: var(--text-dim); font-size: 11.5px; margin-top: 4px; line-height: 1.4; }

/* ---------------- 顶栏 ---------------- */
main { max-width: 720px; margin: 0 auto; padding: 12px 14px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 12px; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { font-size: 26px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--text-dim); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 11px; border: 1px solid var(--card-border);
  background: var(--card); color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--card-2); }
.icon-btn.on { border-color: var(--accent); color: var(--accent); }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px rgba(52,211,153,.8); flex: none; }
.sync-dot.warn { background: var(--amber); box-shadow: 0 0 8px rgba(251,191,36,.8); }
.sync-dot.bad { background: #ff6b6b; box-shadow: 0 0 8px rgba(255,107,107,.8); }

/* ---------------- 区间标签 ---------------- */
.tabs {
  display: flex; gap: 6px; padding: 5px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: 14px; margin-bottom: 12px;
  position: sticky; top: 8px; z-index: 10;
}
.tab { flex: 1; padding: 9px 0; border: none; border-radius: 10px; background: transparent; color: var(--text-dim); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.tab.active { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; }

/* ---------------- 卡片 ---------------- */
.cards { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; margin-bottom: 12px; }
.card {
  background: linear-gradient(180deg, var(--card-grad-top), var(--card-grad-bottom));
  border: 1px solid var(--card-border); border-radius: 16px; padding: 16px;
}
.card-label { font-size: 12px; color: var(--text-dim); letter-spacing: .5px; margin-bottom: 6px; }
.range-label { color: var(--accent); }
.big-num {
  font-size: clamp(28px, 8.5vw, 42px); font-weight: 800; line-height: 1.15;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  font-variant-numeric: tabular-nums;
}
.mid-num { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tiny { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.side-stack { display: grid; grid-template-rows: 1fr 1fr; gap: 12px; }
.half { padding: 12px 14px; display: flex; flex-direction: column; justify-content: center; }
.sub-rows { margin-top: 10px; border-top: 1px dashed var(--card-border); padding-top: 8px; }
.sub-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 2.5px 0; gap: 8px; }
.sub-row .k { color: var(--text-dim); }
.sub-row .v { font-variant-numeric: tabular-nums; }

/* ---------------- 分布条 ---------------- */
.token-split { margin: 0 0 12px; }
.split-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--card); border: 1px solid var(--card-border); }
.seg { height: 100%; transition: width .5s ease; }
.seg-in { background: var(--accent); }
.seg-out { background: var(--pink); }
.seg-cache { background: var(--accent-2); opacity: .8; }
.legend { display: flex; gap: 14px; margin-top: 7px; font-size: 11.5px; color: var(--text-dim); flex-wrap: wrap; }
.legend b { color: var(--text); font-weight: 600; margin-left: 2px; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-in { background: var(--accent); }
.dot-out { background: var(--pink); }
.dot-cache { background: var(--accent-2); }

/* ---------------- 面板 ---------------- */
.panel { margin-bottom: 12px; padding: 14px 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 8px; }
.panel-head h2 { font-size: 14.5px; font-weight: 700; }
.hint { font-size: 11px; color: var(--text-dim); font-weight: 400; }
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-detail {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 12.5px; color: var(--text-soft); line-height: 1.7;
}
.chart-detail b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------------- 排行 ---------------- */
.rank-list .row { padding: 9px 0; border-bottom: 1px solid var(--divider); }
.rank-list .row:last-child { border-bottom: none; }
.rank-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.rank-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-idx { color: var(--text-dim); font-size: 11px; margin-right: 5px; font-variant-numeric: tabular-nums; }
.rank-val { font-size: 12px; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-val b { color: var(--text); font-weight: 600; }
.rank-bar { height: 6px; border-radius: 999px; background: var(--track); margin-top: 6px; overflow: hidden; }
.rank-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.rank-sub { display: flex; gap: 12px; font-size: 11px; color: var(--text-dim); margin-top: 4px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }

/* ---------------- 统计网格（详细数据） ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--divider); border-radius: 12px; overflow: hidden; border: 1px solid var(--divider); }
.stat-cell { background: var(--card); padding: 10px 12px; }
.stat-cell.wide { grid-column: 1 / -1; }
.stat-k { font-size: 11px; color: var(--text-dim); margin-bottom: 3px; }
.stat-v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; word-break: break-all; }
.stat-v.sm { font-size: 13px; font-weight: 600; }

/* ---------------- 热力图 ---------------- */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap-body { display: flex; align-items: flex-start; }
.heat-days { display: grid; grid-template-rows: repeat(7, 16px); font-size: 9px; color: var(--text-dim); margin-right: 4px; width: 20px; line-height: 16px; }
.heat-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; }
.heat-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--heat-0); }
.heat-cell.l1 { background: var(--heat-1); }
.heat-cell.l2 { background: var(--heat-2); }
.heat-cell.l3 { background: var(--heat-3); }
.heat-cell.l4 { background: var(--heat-4); }
.heat-cell.today { outline: 1.5px solid var(--green); }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: 10px; color: var(--text-dim); margin-top: 8px; }
.heat-legend i.heat-cell { display: inline-block; }

/* ---------------- 设置面板 ---------------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(8, 12, 22, .6);
  backdrop-filter: blur(3px); z-index: 40; display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; max-height: 86dvh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--card-border);
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { font-size: 16px; }
.sheet-close { border: none; background: transparent; color: var(--text-dim); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.set-group { margin-bottom: 18px; }
.set-group > h3 { font-size: 12px; color: var(--text-dim); font-weight: 600; margin-bottom: 8px; letter-spacing: .5px; }

/* 设置面板顶部的当前状态摘要 */
.set-summary {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 16px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  font-size: 12.5px; color: var(--text-soft);
}
.set-sum-sep { color: var(--text-dim); opacity: .6; }
.seg-ctl { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--card-border); border-radius: 12px; padding: 4px; }
.seg-ctl button {
  flex: 1; padding: 9px 4px; border: none; border-radius: 9px; background: transparent;
  color: var(--text-dim); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.seg-ctl button.active { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--divider); }
.set-row:last-child { border-bottom: none; }
.set-row .lab { font-size: 13.5px; }
.set-row .desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.set-input {
  width: 112px; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--card-border);
  background: var(--input-bg); color: var(--text); font-size: 14px; text-align: right; outline: none;
  font-variant-numeric: tabular-nums;
}
.set-input:focus { border-color: var(--accent); }
.switch { width: 46px; height: 27px; border-radius: 999px; border: none; background: var(--track); position: relative; cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: transform .18s ease; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(19px); }
.sheet-btn {
  width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--card-border);
  background: var(--card); color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 6px;
}
.sheet-btn.danger { color: #e5484d; }

/* ---------------- 其它 ---------------- */
.foot { display: flex; justify-content: space-between; color: var(--text-dim); font-size: 11px; padding: 14px 4px 0; gap: 10px; }
.empty { color: var(--text-dim); font-size: 12.5px; text-align: center; padding: 14px 0; }
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: var(--card-2); color: var(--text); border: 1px solid var(--card-border);
  padding: 10px 18px; border-radius: 12px; font-size: 13px; z-index: 60;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.toast.show { opacity: 1; }
