/* ═══ MtF.lat — single-screen dashboard ═══ */

/* Dark is the default and does not follow the OS preference: the page is a
   fixed brand surface, and a visitor on a light desktop should still get the
   black-on-white look. The toggle writes [data-theme="light"] for those who
   explicitly ask for it. */
:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #fff;
  --dim: #8a8f98;
  --line: #1c1f24;
  --panel: #0a0b0d;
  --accent: #fff;
  --ok: #3ddc84;
  --err: #ff5c5c;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --r: 10px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #fff;
  --fg: #000;
  --dim: #6b7280;
  --line: #e5e7eb;
  --panel: #fafafa;
  --accent: #000;
  --ok: #059669;
  --err: #dc2626;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* [hidden] must win over any display value set below (e.g. .panel.center sets
   display:flex, which would otherwise keep a "hidden" panel on screen). */
[hidden] { display: none !important; }

html, body {
  /* min-height, not height: with a fixed 100% and flex centering, content
     taller than the viewport overflows at BOTH ends and gets clipped by
     overflow:hidden — the header ends up cut in half and unreachable. Letting
     the page grow makes a short viewport scroll instead of losing content. */
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI",
        "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
  /* Only the horizontal axis is locked: nothing on this page is wider than the
     viewport, and a stray horizontal scrollbar is a visible artifact. */
  overflow-x: hidden;
}

/* ─── 主容器：垂直居中，限制最大宽度 ─── */
.app {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  justify-content: center;
}

/* ─── 顶栏 ─── */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 4px;
  min-width: 0;
}

/* Links carry no underline: the UA default would draw a rule under the brand
   and read as a stray separator line in the header. */
a { color: inherit; text-decoration: none; }

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

.brand-mark {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 800; font-size: 13px;
}

.brand-text { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.dim { color: var(--dim); }

.bar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }

.pill {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--dim);
  font-family: var(--mono);
  white-space: nowrap;
}

.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--dim);
  font-size: 14px;
  cursor: pointer;
  transition: color .16s, border-color .16s;
}
.icon-btn:hover { color: var(--fg); border-color: var(--dim); }

/* ─── 面板 ─── */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  padding: 18px;
}

.panel.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 30px 22px;
  text-align: center;
}

.h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.accent { color: var(--fg); }

.sub { font-size: 13.5px; color: var(--dim); }
.sub b { color: var(--fg); }

/* ─── 申请表单 ─── */
.apply {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 380px;
  margin-top: 6px;
}

.input {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  transition: border-color .16s;
}
.input:focus { outline: none; border-color: var(--dim); }
.input::placeholder { color: var(--dim); }

.btn {
  padding: 10px 16px;
  border: 1px solid var(--fg);
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font: inherit;
  font-size: 14px;
  font-weight: 580;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .16s, transform .12s;
}
.btn:hover:not(:disabled) { opacity: .86; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: 7px; }

.err {
  padding: 8px 12px;
  border: 1px solid var(--err);
  border-radius: 7px;
  color: var(--err);
  font-size: 12.5px;
  margin-top: 6px;
}

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

/* ─── 有效期 ─── */
/* Lives directly under .app (a column flex), outside both panels, so the
   notice appears on the apply screen AND the key screen from one element.
   align-self:center replaces what the centered panel used to provide. */
.expiry {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
  align-self: center;
  max-width: 100%;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--dim);
}
.expiry b { color: var(--fg); font-weight: 600; }
.dot-live {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex: 0 0 auto;
}
.expiry-left {
  padding-left: 8px;
  border-left: 1px solid var(--line);
  font-family: var(--mono);
  color: var(--dim);
  white-space: nowrap;
}
/* 临近截止时提示色转为警示 */
.expiry.is-soon { border-color: var(--err); }
.expiry.is-soon .dot-live { background: var(--err); }
.expiry.is-ended { border-color: var(--err); color: var(--err); }
.expiry.is-ended .dot-live { background: var(--err); }

/* ─── 全站贡献 ─── */
.site-total {
  align-self: center;
  max-width: 100%;
  padding: 5px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12.5px;
  color: var(--dim);
  text-align: center;
  line-height: 1.7;
}
.site-total b {
  color: var(--fg);
  font-family: var(--mono);
  font-weight: 650;
}
.site-total-sep {
  display: inline-block;
  width: 1px;
  height: 10px;
  margin: 0 9px;
  vertical-align: middle;
  background: var(--line);
}

/* ─── 统计格子：Tokens 合计占满一行 ─── */
.cell-wide .sub-val {
  display: block;
  margin-top: 4px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--dim);
  font-family: var(--mono);
  white-space: normal;
}

/* ─── 到期页 ─── */
.ended { gap: 12px; }
.ended-badge {
  padding: 4px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: .04em;
}
.ended-lead {
  margin: 0;
  font-size: 15px;
  color: var(--dim);
  line-height: 1.8;
}
.ended-lead b {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 720;
  letter-spacing: -0.02em;
  margin: 0 2px;
}
.ended-sub { font-size: 12.5px; line-height: 1.8; max-width: 40ch; }
.ended-sub b { color: var(--fg); font-weight: 600; }
.ended-thanks {
  margin-top: 4px;
  font-size: 14px;
  color: var(--fg);
}

/* ─── Key 行 ─── */
.keyrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.keyrow-main { flex: 1; min-width: 0; }

.label {
  display: block;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: .02em;
  margin-bottom: 3px;
}

.keycode {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg);
  word-break: break-all;
}

/* ─── 余额 ─── */
.balance {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 0 14px;
}

.balance-main { flex: 0 0 auto; }

.balance-num {
  display: flex;
  align-items: baseline;
  gap: 1px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.balance-num .cur { font-size: 19px; font-weight: 500; color: var(--dim); }
.balance-num .of { font-size: 12.5px; font-weight: 400; color: var(--dim); margin-left: 5px; }

.balance-side { flex: 1; min-width: 0; }

/* Quota gauge. Deliberately NOT `.bar`: that name is the header row, and
   sharing it made the header collapse into a 5px grey strip. */
.quota-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin-bottom: 6px;
}
.quota-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--fg);
  transition: width .45s cubic-bezier(.4,0,.2,1);
}

.pct { font-size: 11.5px; color: var(--dim); font-family: var(--mono); }

/* ─── 充值 ─── */
.topup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 13px;
  border: 1px solid var(--ok);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.topup b { color: var(--ok); }
.topup .btn {
  background: var(--ok);
  border-color: var(--ok);
  color: #000;
}

/* ─── 四宫格 ─── */
/* Three stats: amount, requests, and the token total with its breakdown.
   The token cell holds two lines, so it gets the extra width via auto-fit
   rather than the previous fixed four-column split, which left a hole. */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.5fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}

.cell {
  padding: 14px 16px;
  background: var(--panel);
  min-width: 0;
}

.val {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── 图表 ─── */
.chart-wrap { margin-top: 12px; }
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.chart-head .dim { font-family: var(--mono); font-size: 12px; }

.chart {
  display: block;
  width: 100%;
  height: 70px;
}

/* The placeholder sits where the plot would be, so an empty chart does not
   reserve 70px of dead space above it. */
.chart-empty {
  margin: 8px 0 2px;
  padding: 14px 0;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

/* ─── 底栏 ─── */
.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}
.foot b { color: var(--fg); font-family: var(--mono); }

.link-btn {
  border: none;
  background: none;
  color: var(--dim);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.link-btn:hover { color: var(--fg); }

/* ─── 接入信息 ─── */
.meta {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  padding-top: 2px;
}
.meta-item { min-width: 0; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--dim); }

/* ─── 窄屏适配（仍单屏，压缩而非滚动） ─── */
@media (max-width: 560px) {
  .app { gap: 10px; padding: 16px 14px; }
  .pill { display: none; }
  .h1 { font-size: 22px; }
  .panel { padding: 14px; }
  .panel.center { padding: 24px 16px; }
  .balance { flex-direction: column; align-items: stretch; gap: 10px; }
  .balance-num { font-size: 26px; }
  /* 三格在手机上堆成两行：宽格占满，两个窄格并排 */
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .cell-wide { grid-column: 1 / -1; }
  .val { font-size: 15px; }
  .apply { flex-direction: column; }
  .meta { gap: 12px; }
}

/* ─── 极矮屏（笔记本分屏） ─── */
@media (max-height: 620px) {
  .chart-wrap { display: none; }
  .h1 { font-size: 21px; }
  .balance { padding: 10px 0; }
  .balance-num { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
