/* 订阅用量看板：共用样式（index.html 与 login.html）
   CSP: style-src 'self'，因此所有样式都在本文件；JS 只通过
   style.setProperty 设置 --pct / --elapsed 两个自定义属性。 */

:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;

  --page: #eef1f4;
  --surface: #ffffff;
  --surface-sunk: #f6f8fa;
  --ink: #17212b;
  --ink-2: #45515e;
  --muted: #5d6976;
  --hair: #dce2e8;
  --hair-strong: #b9c3cd;
  --focus: #1d63b8;

  /* 进度条：填充色 + 同色相的浅色轨道 */
  --brand: #2a78d6;
  --brand-track: #d9e6f7;
  --brand-strong: #1d63b8;
  --warn-fill: #d99400;
  --warn-track: #faeccb;
  --err-fill: #d03b3b;
  --err-track: #f6d8d8;
  --pace: #17212b;

  /* 状态 */
  --ok-dot: #0e9a2a;
  --ok-bg: #e2f3e4;
  --warn-dot: #e9a000;
  --warn-bg: #fbefd0;
  --off-dot: #85909b;
  --off-bg: #e7ebef;
  --err-dot: #d03b3b;
  --err-bg: #fbe3e3;

  --err-text: #b3261e;
  --warn-text: #8a5800;
  --ok-text: #1b6e2e;

  --alert-err-bg: #fdf1f1;
  --alert-err-line: #efc3c3;
  --alert-warn-bg: #fdf8e8;
  --alert-warn-line: #ecd79e;

  --input-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0f1317;
    --surface: #171c22;
    --surface-sunk: #1c2229;
    --ink: #e7ecf1;
    --ink-2: #b6c0ca;
    --muted: #96a2ae;
    --hair: #29313a;
    --hair-strong: #3f4954;
    --focus: #6aa6ee;

    --brand: #4a90e8;
    --brand-track: #1d3250;
    --brand-strong: #2a6cc0;
    --warn-fill: #c98500;
    --warn-track: #3a3018;
    --err-fill: #d03b3b;
    --err-track: #3a1d21;
    --pace: #e7ecf1;

    --ok-dot: #34b84a;
    --ok-bg: #183823;
    --warn-dot: #eeae2e;
    --warn-bg: #3a3016;
    --off-dot: #7d8894;
    --off-bg: #262d35;
    --err-dot: #e2605f;
    --err-bg: #432327;

    --err-text: #ff9d95;
    --warn-text: #f0c36a;
    --ok-text: #74d08a;

    --alert-err-bg: #2a191c;
    --alert-err-line: #5c2d33;
    --alert-warn-bg: #2a2416;
    --alert-warn-line: #5a4a22;

    --input-bg: #11161b;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button { font: inherit; }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--hair);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.meta .updated { color: var(--ink-2); }
.meta .updated.is-old { color: var(--warn-text); font-weight: 600; }
.meta .fetch-state { color: var(--err-text); font-weight: 600; }

.btn-quiet {
  margin-left: auto;
  min-height: 34px;
  padding: 4px 14px;
  font-size: 0.875rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--hair-strong);
  border-radius: 6px;
  cursor: pointer;
}

.btn-quiet:hover { background: var(--surface-sunk); }
.btn-quiet:disabled { opacity: 0.6; cursor: progress; }

/* ---------- 主体 ---------- */

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

.placeholder {
  margin: 0;
  padding: 40px 0;
  text-align: center;
  color: var(--muted);
}

.placeholder.is-error { color: var(--err-text); }

/* ---------- 提醒条 ---------- */

.alerts {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.alert {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 12px;
  font-size: 0.875rem;
  border: 1px solid;
  border-radius: 6px;
}

.alert-error { background: var(--alert-err-bg); border-color: var(--alert-err-line); }
.alert-warn  { background: var(--alert-warn-bg); border-color: var(--alert-warn-line); }

.alert-level {
  flex: none;
  padding: 0 8px;
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.6;
  border-radius: 999px;
}

.alert-error .alert-level { background: #b3261e; color: #ffffff; }
.alert-warn  .alert-level { background: #f2b52a; color: #17212b; }

.alert-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---------- 卡片网格 ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 16px;
}

.card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 8px;
}

/* 标题独占一行（邮箱可能很长），套餐与状态固定在第二行，便于跨卡片扫读 */
.card-head {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.card-title {
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.badge,
.status {
  font-size: 0.75rem;
  line-height: 1.6;
  white-space: nowrap;
  border-radius: 999px;
}

.badge {
  max-width: 10em;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
  color: var(--ink-2);
  border: 1px solid var(--hair-strong);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 9px 1px 8px;
  font-weight: 600;
  color: var(--ink);
  background: var(--st-bg);
}

.status::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--st-dot);
}

.st-ok       { --st-bg: var(--ok-bg);   --st-dot: var(--ok-dot); }
.st-warn,
.st-cooldown { --st-bg: var(--warn-bg); --st-dot: var(--warn-dot); }
.st-disabled { --st-bg: var(--off-bg);  --st-dot: var(--off-dot); }
.st-error    { --st-bg: var(--err-bg);  --st-dot: var(--err-dot); }
.st-unknown  { --st-bg: var(--off-bg);  --st-dot: var(--off-dot); }

/* 禁用：空心圆点，和“正常”在形状上也有区别 */
.st-disabled::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--st-dot);
}

.card-body {
  display: grid;
  gap: 14px;
}

.card.is-stale .card-body {
  opacity: 0.55;
  filter: saturate(0.35);
}

.empty-note {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* ---------- 额度条 ---------- */

.meters {
  display: grid;
  gap: 14px;
}

.meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.875rem;
}

.meter-label {
  min-width: 0;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.meter-pct {
  flex: none;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar {
  --pct: 0;
  --elapsed: 0;
  position: relative;
  height: 8px;
  margin: 6px 0 5px;
  background: var(--track);
  border-radius: 4px;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--pct) * 1%);
  background: var(--fill);
  border-radius: 4px;
}

.bar.has-fill .bar-fill { min-width: 3px; }

/* 本周期已过去的时间：细竖线，带一圈卡片底色做间隔 */
.bar-pace {
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: calc(var(--elapsed) * 1% - 1px);
  width: 2px;
  background: var(--pace);
  border-radius: 1px;
  box-shadow: 0 0 0 1.5px var(--surface);
}

.lvl-low  { --fill: var(--brand);     --track: var(--brand-track); }
.lvl-mid  { --fill: var(--warn-fill); --track: var(--warn-track); }
.lvl-high { --fill: var(--err-fill);  --track: var(--err-track); }
.lvl-none { --fill: transparent;      --track: var(--hair); }

.meter-foot {
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.meter-foot .cd { color: var(--ink-2); }

/* ---------- 数值 ---------- */

.values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
}

.value-label {
  font-size: 0.8125rem;
  color: var(--ink-2);
}

.value-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 5px;
}

.value-num {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.value-unit {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ---------- 其他信息 ---------- */

.facts {
  margin: 0;
  display: grid;
  gap: 5px;
  font-size: 0.875rem;
}

.fact {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 12px;
}

.fact dt {
  flex: none;
  max-width: 55%;
  color: var(--ink-2);
}

.fact dd {
  min-width: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0 8px;
  text-align: right;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.fact dd .cd { color: var(--muted); }

/* ---------- 卡片底部 ---------- */

.card-foot {
  margin-top: auto;
  padding-top: 9px;
  display: grid;
  gap: 3px;
  font-size: 0.8125rem;
  color: var(--muted);
  border-top: 1px solid var(--hair);
}

.foot-line {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  font-variant-numeric: tabular-nums;
}

.stale-note {
  color: var(--warn-text);
  font-weight: 600;
}

.card-error {
  margin: 0;
  color: var(--err-text);
  overflow-wrap: anywhere;
}

/* ---------- 卡片操作（重新授权） ---------- */

.card-actions {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.reauth {
  display: grid;
  justify-items: start;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface-sunk);
  border: 1px solid var(--hair);
  border-radius: 6px;
}

.reauth-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--brand-strong);
  border-radius: 6px;
  text-decoration: none;
}

.reauth-link:hover {
  filter: brightness(1.06);
  text-decoration: underline;
}

.reauth-hint,
.reauth-bad,
.reauth-ok {
  margin: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.reauth-hint { color: var(--ink-2); }
.reauth-hint .cd { color: var(--ink); font-weight: 600; white-space: nowrap; }
.reauth-bad { color: var(--err-text); font-weight: 600; }
.reauth-ok { color: var(--ok-text); font-weight: 600; }

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

.btn-action {
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
}

.btn-action.is-secondary {
  min-height: 30px;
  padding: 2px 12px;
  font-size: 0.8125rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--hair-strong);
}

.btn-action.is-secondary:hover { background: var(--surface-sunk); }

.btn-action.is-primary {
  min-height: 38px;
  padding: 6px 18px;
  font-size: 0.875rem;
  color: #ffffff;
  background: var(--brand-strong);
  border: 1px solid transparent;
}

.btn-action.is-primary:hover { filter: brightness(1.06); }

/* 等待第二次点击：换成琥珀色，和普通状态明显不同 */
.btn-action.is-confirming,
.btn-action.is-confirming:hover {
  color: var(--ink);
  background: var(--warn-bg);
  border: 1px solid var(--warn-dot);
  filter: none;
}

.btn-action:disabled {
  opacity: 0.55;
  cursor: progress;
  filter: none;
}

.action-msg {
  font-size: 0.8125rem;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.action-msg.is-error { color: var(--err-text); }

/* ---------- 竖线说明 ---------- */

.pace-note {
  margin: 20px 0 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.pace-key {
  position: relative;
  flex: none;
  width: 40px;
  height: 6px;
  background: var(--brand-track);
  border-radius: 3px;
}

.pace-key::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 55%;
  background: var(--brand);
  border-radius: 3px;
}

.pace-key::after {
  content: "";
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: 38%;
  width: 2px;
  background: var(--pace);
  border-radius: 1px;
  box-shadow: 0 0 0 1.5px var(--page);
}

/* ---------- 登录页 ---------- */

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-box {
  width: 100%;
  max-width: 340px;
  padding: 26px 24px 20px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 10px;
}

.login-title {
  margin: 0 0 20px;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-2);
}

.field input {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  font: inherit;
  font-size: 16px; /* 避免 iOS 聚焦时自动放大 */
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--hair-strong);
  border-radius: 6px;
}

.field input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}

.btn-primary {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  font-weight: 600;
  color: #ffffff;
  background: var(--brand-strong);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; filter: none; }

.form-error {
  min-height: 1.5em;
  margin: 12px 0 0;
  font-size: 0.875rem;
  color: var(--err-text);
}

/* ---------- 小屏 ---------- */

@media (max-width: 560px) {
  .topbar-inner { padding: 10px 14px; }
  .page { padding: 12px 12px 32px; }
  .cards { grid-template-columns: 1fr; gap: 12px; }
}

@media (forced-colors: active) {
  .bar { border: 1px solid CanvasText; }
  .bar-fill { background: Highlight; }
  .bar-pace { background: CanvasText; }
  .status::before { background: CanvasText; }
}
