:root {
  --brand: #4d6bfe;
  --brand-hover: #3d5af0;
  --brand-soft: #eef1ff;
  --text: #1a1a1a;
  --text-2: #4d4d4d;
  --muted: #656b76;
  --line: #ececec;
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --fill: #f5f6f7;
  --danger: #e5484d;
  --ok: #18a058;
  --warn: #b7791f;
  --radius-pill: 28px;
  --radius-card: 16px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { opacity: 0.8; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ---------------- 顶部 ---------------- */
nav, .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 17px;
  color: var(--brand);
  letter-spacing: 0.2px;
}
.brand .logo { width: 26px; height: 26px; display: block; }
.nav-links { display: flex; align-items: center; gap: 20px; font-size: 14px; }
.nav-links a { color: var(--text-2); }
.nav-links a:hover { color: var(--brand); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
}
.badge:not(.ok) { background: var(--fill); color: var(--muted); }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.ghost { background: transparent; }
.btn.small { height: 34px; padding: 0 14px; font-size: 13px; border-radius: 999px; }
.btn.block { width: 100%; }

/* ---------------- 卡片 ---------------- */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 22px;
}
.card h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.card p { color: var(--text-2); }

section.block { padding: 36px 0; }
section.block > h2 { font-size: 26px; margin: 0 0 6px; letter-spacing: -0.3px; }
section.block > .sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

/* ---------------- 表单 ---------------- */
.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="email"], #api-key-expiry, textarea, select {
  width: 100%;
  height: 52px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: var(--fill);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
textarea {
  height: auto;
  min-height: 132px;
  padding: 14px 18px;
  border-radius: 14px;
  line-height: 1.7;
  resize: vertical;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); background: #fff; }
input::placeholder, textarea::placeholder { color: #b5b5b5; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); vertical-align: -2px; }

.inline-field { display: flex; gap: 10px; align-items: center; }
.inline-field input { flex: 1; }
.inline-field .btn { flex: 0 0 auto; height: 52px; }

.tabs { display: flex; gap: 22px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tabs button {
  position: relative;
  background: none;
  border: none;
  padding: 0 0 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}
.tabs button.active { color: var(--text); font-weight: 600; }
.tabs button.active::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--brand); border-radius: 2px;
}
.tabs button:not(.active):hover { color: var(--text-2); }

.hint { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.err { color: var(--danger); font-size: 13px; min-height: 20px; line-height: 1.6; margin: 2px 0 10px; }
.err:not(:empty) { background: #fdecec; border-radius: 10px; padding: 8px 12px; }
.ok-msg { color: var(--ok); font-size: 13px; }

/* ---------------- 登录页（对齐 DeepSeek sign_in） ---------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8vh 24px 40px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 40px; color: var(--brand);
  font-size: 21px; font-weight: 600; letter-spacing: 0.2px;
}
.auth-logo img.logo { width: 30px; height: 30px; }

/* 验证码输入框：按钮嵌在胶囊里，和官方一致 */
.pill-field {
  display: flex; align-items: center;
  height: 52px; padding: 0 8px 0 20px;
  border-radius: var(--radius-pill);
  background: var(--fill);
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pill-field:focus-within { border-color: var(--brand); background: #fff; }
.pill-field input {
  flex: 1; height: 100%; padding: 0; border: none; background: transparent;
}
.pill-field input:focus { border: none; background: transparent; }
.pill-field .pill-action {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding-left: 12px; border-left: 1px solid #e3e5e8;
  font-size: 14px; color: var(--brand); background: none; border-top: 0; border-right: 0; border-bottom: 0;
  font-family: inherit; cursor: pointer; height: 26px;
}
.pill-field .pill-action:disabled { color: var(--muted); cursor: default; }

/* 按钮下方的次要链接，居中，和官方一致 */
.auth-secondary {
  display: flex; justify-content: center; gap: 0;
  margin-top: 18px; font-size: 13px; color: var(--muted);
}
.auth-secondary a { color: var(--text-2); }
.auth-secondary span { margin: 0 10px; color: #d9d9d9; }
.auth-body {
  display: grid;
  grid-template-columns: minmax(0, 360px) 240px;
  gap: 24px;
  align-items: start;
  width: 100%;
  max-width: 640px;
}
.auth-main { padding-top: 4px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; margin: 2px 0 18px; }
.auth-alt { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.auth-alt a { margin: 0 6px; }
.agree { font-size: 12.5px; color: var(--muted); line-height: 1.7; margin: 4px 0 18px; text-wrap: balance; }
.auth-side {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: #fff;
  box-shadow: var(--shadow-card);
  padding: 18px;
  font-size: 13px;
  color: var(--text-2);
}
.auth-side h4 { margin: 0 0 10px; font-size: 13px; color: var(--text); font-weight: 600; }
.auth-side ol { margin: 0; padding-left: 16px; color: var(--muted); font-size: 12.5px; line-height: 1.9; }
.auth-foot { margin-top: auto; padding-top: 48px; text-align: center; font-size: 12px; color: #b5b5b5; }
.auth-foot a { color: #b5b5b5; }

@media (max-width: 720px) {
  .auth-body { grid-template-columns: 1fr; max-width: 380px; }
  .auth-logo { margin-bottom: 24px; }
}

/* ---------------- 价格 ---------------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.plan-card { display: flex; flex-direction: column; gap: 16px; border-radius: var(--radius-card); padding: 24px 22px; position: relative; }
.plan-card.hot { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.plan-card .tag {
  position: absolute; top: 16px; right: 16px;
  font-size: 11px; color: #fff; background: var(--brand);
  padding: 2px 9px; border-radius: 999px;
}
.plan-head h3 { margin: 0; font-size: 17px; }
.plan-price { font-size: 34px; font-weight: 700; letter-spacing: -1px; color: var(--text); }
.plan-price span { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.plan-features { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.plan-features li { color: var(--text-2); font-size: 13.5px; display: flex; gap: 8px; line-height: 1.6; }
.plan-features li::before { content: "✓"; color: var(--brand); flex: 0 0 auto; }

/* ---------------- 控制台 ---------------- */
.wallet-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 22px 0; }
.stat { background: var(--bg-soft); border-radius: var(--radius-card); padding: 16px 18px; }
.stat .k { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }

#api-keys-card { margin-bottom: 22px; }
#api-keys-card [hidden] { display: none; }
.api-key-header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px 16px; flex-wrap: wrap; }
.api-key-header h3 { margin: 0; }
.api-key-header span { font-size: 13px; color: var(--muted); }
#api-cash { color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
#api-key-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 18px 0; }
#api-key-form .field { flex: 1 1 210px; min-width: 0; margin: 0; }
#api-key-form input { height: 44px; min-width: 0; }
#api-key-expiry:focus { border-color: var(--brand); background: var(--bg); }
#api-key-status:not(:empty) { margin: 10px 0; }
.api-key-table { overflow-x: auto; }
.api-key-table th, .api-key-table td:last-child { white-space: nowrap; }
#api-key-rows td:first-child { overflow-wrap: anywhere; }
#api-key-rows td:nth-child(2) { font-family: var(--mono); white-space: nowrap; }
#api-key-rows button + button { margin-inline-start: 6px; }
.api-key-examples { margin-top: 16px; }
.api-key-examples summary { cursor: pointer; color: var(--brand); font-size: 14px; }
.api-key-examples h4 { margin: 16px 0 0; }
.api-key-examples p { margin: 6px 0; font-size: 13px; overflow-wrap: anywhere; }
.api-key-examples pre {
  overflow-x: auto; padding: 12px 14px; margin: 8px 0 0; border-radius: 10px;
  background: var(--bg-soft); font: 13px/1.6 var(--mono);
}
#api-key-dialog { width: min(520px, calc(100% - 32px)); color: var(--text); box-shadow: var(--shadow-card); }
#api-key-dialog::backdrop { background: rgba(0, 0, 0, .35); }
#api-key-secret { font-family: var(--mono); }

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td { color: var(--text-2); }
td.num, th.num { text-align: right; font-family: var(--mono); }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 110px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bars .bar i { display: block; width: 100%; border-radius: 6px 6px 2px 2px; background: var(--brand); opacity: 0.75; min-height: 3px; }
.bars .bar span { font-size: 11px; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 12.5px; color: var(--text-2); cursor: pointer;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }

/* ---------------- 收银台 ---------------- */
.pay-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.pay-amount { font-size: 34px; font-weight: 700; letter-spacing: -1px; margin-top: 4px; }

/* ---------------- 其它 ---------------- */
.hidden { display: none !important; }
footer { padding: 32px 0 44px; color: var(--muted); font-size: 12.5px; }
footer .fine { max-width: 780px; line-height: 1.9; }

.chip.active { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

.auth-tabs {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.auth-tab {
  position: relative;
  padding: 0 0 10px;
  border: none;
  background: none;
  font: inherit;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
}

.auth-tab.active {
  color: var(--text);
  font-weight: 600;
}

.auth-tab.active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
}

.forgot-row { text-align: right; margin: -6px 0 14px; font-size: 13px; }
.forgot-row a { color: var(--brand, #4d6bfe); text-decoration: none; }

.plan-card > .btn { margin-top: auto; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
section.block > h1 { font-size: clamp(26px, 4vw, 36px); margin: 0 0 6px; }
#price-status:not(:empty), #refresh-error:not(:empty) { margin: 8px 0; color: var(--text-2); }
#pay-order, #who, .order-email { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .wrap { padding-inline: 16px; }
  nav, .topbar, .nav-links, .admin-head, .order, .pool-row { flex-wrap: wrap; }
  .nav-links { gap: 12px; }
  .grid.two, .grid.three, .plan-grid { grid-template-columns: minmax(0, 1fr); }
  .wallet-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .v { font-size: 19px; overflow-wrap: anywhere; }
  .card { padding: 18px; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

#estimator summary { cursor: pointer; font-weight: 600; }
#monthly-usage {
  width: 8em; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--text); margin-inline-start: 6px;
}
#estimator { margin: 0 0 18px; }
#estimate-result { list-style: none; padding: 0; margin: 12px 0 0; font-variant-numeric: tabular-nums; }
#estimate-result a {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  padding: 10px 4px; color: var(--text); border-top: 1px solid var(--line);
}
#estimate-result a:hover, #estimate-result a:focus-visible { color: var(--brand-hover); }
#estimate-result strong { font-weight: 600; }
#estimate-error:empty { display: none; }
.plan-card button:target, [data-topup]:target { outline: 3px solid var(--brand); outline-offset: 3px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.password-field { position: relative; }
.password-field input { padding-right: 68px; }
.password-toggle {
  position: absolute; right: 8px; top: 4px; height: 44px; min-width: 48px;
  border: 0; border-radius: var(--radius-pill); background: transparent;
  color: var(--brand-hover); font: inherit; font-size: 13px; cursor: pointer;
}
.pill-field input { min-width: 0; }
@media (max-width: 600px) {
  .auth-page { padding-top: max(28px, 5vh); }
  .auth-page input:not([type="checkbox"]) { font-size: 16px; }
}

.order-reference { text-align: right; }
.order-reference code { display: block; font: 12px/1.5 var(--mono); overflow-wrap: anywhere; }
.copy-action {
  min-height: 32px; padding: 2px 6px; border: 0; border-radius: 6px;
  color: var(--brand-hover); background: transparent; font: inherit; font-size: 13px; cursor: pointer;
}
.copy-action:hover { background: var(--brand-soft); }
.payment-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.payment-line b, .payment-line code { font: 600 15px var(--mono); }
.payment-deadline, #copy-status { text-align: center; }
#copy-status:empty { margin: 0; }
.bar {
  appearance: none; border: 1px solid transparent; padding: 4px; min-width: 0;
  border-radius: 8px; background: transparent; font: inherit; cursor: pointer;
}
.bar:hover, .bar[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--brand-soft); }
.bar[aria-pressed="true"], .chip[aria-pressed="true"] { border-color: var(--brand); }
.day-detail { margin: 12px 0 0; font-size: 13px; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
  .bars { gap: 2px; }
  .copy-action { min-height: 40px; }
}

.err[data-tone="success"]:not(:empty) { color: #17643d; background: #eaf7ef; }
.err[data-tone="warning"]:not(:empty) { color: #754b12; background: #fff5df; }
.err[data-tone="info"]:not(:empty) { color: #304baa; background: var(--brand-soft); }
