:root {
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: #d2d2d7;
  --line-soft: #e8e8ed;
  --canvas: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: rgba(255, 255, 255, 0.88);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: #e8f2ff;
  --danger: #d70015;
  --danger-hover: #b50012;
  --danger-soft: #fff0f1;
  --warning: #8a5b00;
  --warning-soft: #fff7e1;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
  font-optical-sizing: auto;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

button:focus-visible,
input:focus-visible,
a:focus-visible,
code:focus-visible {
  outline: 3px solid rgba(0, 113, 227, 0.28);
  outline-offset: 2px;
}

.sr-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.skip-link {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
  left: 16px;
  padding: 9px 13px;
  position: fixed;
  top: 10px;
  transform: translateY(-160%);
  z-index: 1000;
}
.skip-link:focus { transform: translateY(0); }

.auth-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 28px 18px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-width: 420px;
  padding: 36px;
  width: 100%;
}

.brand-logo {
  display: block;
  height: 56px;
  margin-bottom: 20px;
  object-fit: contain;
  width: 56px;
}

.brand-logo-small {
  flex: 0 0 auto;
  height: 32px;
  margin: 0;
  object-fit: contain;
  width: 32px;
}

.auth-card h1 {
  font-size: 29px;
  font-weight: 650;
  letter-spacing: -0.028em;
  line-height: 1.12;
  margin: 0 0 24px;
}

.auth-tabs {
  background: #f1f1f3;
  border-radius: 9px;
  display: grid;
  gap: 3px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 20px;
  padding: 3px;
}

.auth-tab {
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 560;
  min-height: 35px;
  transition: background-color 100ms ease, color 100ms ease, transform 80ms ease-out;
}
.auth-tab:hover { color: var(--ink); }
.auth-tab:active { transform: scale(0.98); transition-duration: 0ms; }
.auth-tab.is-active { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); color: var(--ink); font-weight: 620; }

.stack-form { display: flex; flex-direction: column; gap: 13px; }

label {
  color: #515154;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 550;
  gap: 6px;
}

input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 11px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  width: 100%;
}
input:hover { border-color: #a1a1a6; }
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
  outline: none;
}
input::placeholder { color: #98989d; }

.password-field { display: block; position: relative; }
.password-field input { padding-right: 58px; }
.password-toggle {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  min-height: 32px;
  padding: 4px 8px;
  position: absolute;
  right: 4px;
  top: 4px;
}
.password-toggle:hover { background: var(--accent-soft); }
.password-toggle:active { transform: scale(0.96); }

.field-hint { color: var(--faint); font-size: 11px; margin: -8px 0 0; }
.form-error { color: var(--danger); font-size: 12px; min-height: 17px; margin: -3px 0 0; }

.button {
  align-items: center;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  font-weight: 600;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  transition: background-color 120ms ease, border-color 120ms ease,
    transform 80ms ease-out;
}
.button:active { transform: scale(0.98); transition-duration: 0ms; }
.button:disabled { cursor: wait; opacity: 0.48; transform: none; }
.button-block { width: 100%; }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-hover); }
.button-secondary { border-color: var(--line); color: var(--accent); }
.button-secondary:hover { background: #f5f5f7; border-color: #b8b8bd; }
.button-quiet { background: transparent; color: var(--muted); }
.button-quiet:hover { background: rgba(0, 0, 0, 0.045); color: var(--ink); }
.button-danger { background: var(--danger); color: #fff; }
.button-danger:hover { background: var(--danger-hover); }
.button-compact { min-height: 34px; padding: 6px 11px; }

.portal { min-height: 100vh; }
.topbar {
  background: rgba(245, 245, 247, 0.84);
  border-bottom: 1px solid rgba(210, 210, 215, 0.72);
  position: sticky;
  top: 0;
  z-index: 20;
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
}

.topbar-inner {
  align-items: center;
  display: flex;
  height: 68px;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1320px;
  padding: 0 28px;
}

.brand {
  align-items: center;
  color: var(--ink);
  display: inline-flex;
  font-size: 16px;
  font-weight: 650;
  gap: 9px;
  letter-spacing: -0.015em;
  text-decoration: none;
}
.account-actions { align-items: center; display: flex; gap: 8px; }
.account-name { color: var(--muted); font-size: 12px; margin-right: 4px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { margin: 0 auto; max-width: 1320px; padding: 36px 28px 54px; }
.page-heading { align-items: flex-end; display: flex; justify-content: space-between; margin-bottom: 22px; }
.page-heading h1 { font-size: 30px; font-weight: 650; letter-spacing: -0.03em; line-height: 1.12; margin: 0; }
.page-heading p { color: var(--muted); margin: 7px 0 0; }
.last-updated { color: var(--faint); font-size: 11px; }

.metric-grid { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  min-height: 126px;
  padding: 18px;
}
.metric-card-primary { border-color: #9bc8f8; }
.metric-card > span { color: var(--muted); display: block; font-size: 11px; font-weight: 600; }
.metric-card > strong { display: block; font-size: 25px; font-variant-numeric: tabular-nums; font-weight: 620; letter-spacing: -0.026em; line-height: 1.15; margin: 13px 0 3px; }
.metric-card > small { color: var(--faint); font-size: 11px; }

.payment-verification {
  align-items: center;
  background: var(--surface);
  border: 1px solid #bddcff;
  border-radius: var(--radius);
  display: flex;
  gap: 13px;
  margin-bottom: 14px;
  min-height: 68px;
  padding: 13px 16px;
}
.payment-verification > div { min-width: 0; }
.payment-verification strong { display: block; font-size: 13px; font-weight: 620; }
.payment-verification p { color: var(--muted); font-size: 11px; margin: 3px 0 0; }
.payment-verification.is-paid { border-color: #9bc8f8; }
.payment-verification.is-error { border-color: #f3b8be; }

.recharge-grid {
  align-items: stretch;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.55fr);
  margin-bottom: 14px;
}
.recharge-panel { min-height: 272px; }
.recharge-form { padding: 16px 17px 17px; }
.money-input { display: block; position: relative; }
.money-input > span {
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
  left: 12px;
  pointer-events: none;
  position: absolute;
  top: 8px;
  z-index: 1;
}
.money-input input {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 560;
  padding-left: 31px;
}
.recharge-meta { color: var(--muted); font-size: 11px; margin: 8px 0 13px; }
.recharge-form .form-error { margin-top: 8px; }
.recharge-unavailable {
  background: #fafafa;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
  margin: 0;
  padding: 12px 17px;
}
.recharge-orders-table { min-width: 610px; }
.recharge-orders-table td:first-child { max-width: 240px; }

.usage-summary {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  min-height: 92px;
  padding: 16px 20px;
}
.usage-summary-heading { min-width: 150px; }
.usage-summary-heading h2 { font-size: 17px; font-weight: 630; letter-spacing: -0.018em; margin: 0 0 3px; }
.usage-summary-heading span { color: var(--faint); font-size: 10px; }
.usage-stats { display: grid; flex: 1; grid-template-columns: repeat(4, 1fr); margin: 0; max-width: 700px; }
.usage-stats > div { border-left: 1px solid var(--line-soft); padding: 2px 20px; }
.usage-stats dt { color: var(--muted); font-size: 10px; }
.usage-stats dd { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 620; margin: 4px 0 0; }

.dashboard-grid { align-items: start; display: grid; gap: 14px; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.8fr); }
.panel { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.panel-heading { align-items: center; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; min-height: 66px; padding: 13px 17px; }
.panel-heading h2 { font-size: 18px; font-weight: 630; letter-spacing: -0.018em; margin: 0; }
.panel-heading p { color: var(--faint); font-size: 11px; margin: 3px 0 0; }
.text-button { background: transparent; border: 0; border-radius: 6px; color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 600; min-height: 32px; padding: 5px 8px; }
.text-button:hover { background: var(--accent-soft); }
.text-button:active { transform: scale(0.96); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; min-width: 650px; width: 100%; }
th { background: #fafafa; color: var(--faint); font-size: 10px; font-weight: 650; letter-spacing: 0.035em; padding: 10px 12px; text-align: left; white-space: nowrap; }
td { border-top: 1px solid var(--line-soft); color: #515154; font-size: 12px; padding: 11px 12px; vertical-align: middle; }
tbody tr { transition: background-color 80ms ease; }
tbody tr:hover { background: #f9f9fb; }
td strong { color: var(--ink); display: block; font-weight: 600; }
td small { color: var(--faint); display: block; font-size: 10px; margin-top: 2px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 10px; }
.money { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.status-chip { align-items: center; background: #f2f2f4; border-radius: 6px; color: var(--muted); display: inline-flex; font-size: 10px; font-weight: 600; gap: 5px; padding: 3px 7px; white-space: nowrap; }
.status-chip::before { background: currentColor; border-radius: 50%; content: ""; height: 5px; width: 5px; }
.status-succeeded, .status-active, .status-paid { background: var(--accent-soft); color: var(--accent); }
.status-failed, .status-revoked, .status-closed, .status-expired { background: var(--danger-soft); color: var(--danger); }
.status-processing, .status-pending, .status-creating { background: var(--warning-soft); color: var(--warning); }

.api-spec-entry {
  align-items: center;
  background: #fafafa;
  border-bottom: 1px solid var(--line-soft);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 15px;
}
.api-spec-copy { min-width: 0; }
.api-spec-kicker { color: var(--accent); display: block; font-size: 10px; font-weight: 650; letter-spacing: 0.035em; margin-bottom: 4px; }
.api-spec-copy strong { display: block; font-size: 13px; font-weight: 620; }
.api-spec-copy > span:not(.api-spec-kicker) { color: var(--muted); display: block; font-size: 11px; margin-top: 3px; }
.api-spec-copy code { background: var(--surface); border: 1px solid var(--line-soft); border-radius: 6px; color: var(--muted); display: block; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 10px; margin-top: 9px; overflow-wrap: anywhere; padding: 6px 8px; }
.api-spec-actions { align-items: center; display: flex; flex-direction: column; gap: 8px; }
.api-spec-action { flex-shrink: 0; gap: 4px; text-decoration: none; white-space: nowrap; }
.api-json-link { color: var(--muted); font-size: 10px; text-decoration: none; }
.api-json-link:hover, .api-json-link:focus-visible { color: var(--accent); text-decoration: underline; }

.key-create-form { border-bottom: 1px solid var(--line-soft); display: grid; gap: 8px; grid-template-columns: 1fr auto; padding: 13px 15px; }
.key-create-form input { min-width: 0; }
.keys-list { display: flex; flex-direction: column; }
.key-row { align-items: center; border-top: 1px solid var(--line-soft); display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr) auto; padding: 13px 15px; }
.key-row:first-child { border-top: 0; }
.key-identity { min-width: 0; }
.key-identity strong { display: block; font-size: 12px; font-weight: 610; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-identity code { color: var(--muted); display: block; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 10px; margin-top: 3px; }
.key-meta { color: var(--faint); font-size: 10px; margin-top: 4px; }
.key-actions { align-items: center; display: flex; gap: 7px; }
.key-revoke { background: transparent; border: 0; border-radius: 6px; color: var(--danger); cursor: pointer; font-size: 11px; font-weight: 600; min-height: 30px; padding: 4px 7px; }
.key-revoke:hover { background: var(--danger-soft); }
.key-revoke:active { transform: scale(0.96); }

.empty-state { align-items: center; color: var(--muted); display: flex; flex-direction: column; gap: 4px; justify-content: center; min-height: 160px; padding: 28px 18px; text-align: center; }
.empty-state strong { color: var(--ink); font-size: 13px; font-weight: 610; }
.empty-state span { font-size: 11px; }
.empty-state-compact { min-height: 120px; }
.footer { color: var(--faint); font-size: 10px; padding: 28px 0 0; text-align: center; }

.icon-button { align-items: center; background: transparent; border: 0; border-radius: 7px; cursor: pointer; display: inline-flex; font-size: 20px; justify-content: center; min-height: 32px; min-width: 32px; padding: 5px 8px; transition: background-color 100ms ease, transform 80ms ease-out; }
.icon-button:hover { background: rgba(0, 0, 0, 0.05); }
.icon-button:active { background: rgba(0, 0, 0, 0.1); transform: scale(0.96); transition-duration: 0ms; }

.dialog { background: transparent; border: 0; max-width: 590px; padding: 0; width: calc(100% - 28px); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.28); }
.dialog-card { background: var(--surface-raised); border: 1px solid rgba(255, 255, 255, 0.72); border-radius: 16px; box-shadow: 0 10px 32px rgba(0, 0, 0, 0.14); padding: 22px; -webkit-backdrop-filter: blur(24px) saturate(150%); backdrop-filter: blur(24px) saturate(150%); }
.dialog-heading { align-items: flex-start; display: flex; justify-content: space-between; margin-bottom: 17px; }
.dialog-heading h2 { font-size: 22px; font-weight: 650; letter-spacing: -0.024em; line-height: 1.2; margin: 0; }
.dialog-heading p { color: var(--muted); font-size: 12px; margin: 5px 0 0; }
.notice { background: #f5f5f7; border-radius: 8px; color: var(--muted); font-size: 12px; margin: 0 0 14px; padding: 10px 11px; }
.copy-field { align-items: stretch; background: #f5f5f7; border: 1px solid var(--line-soft); border-radius: 9px; display: flex; gap: 7px; margin-bottom: 14px; padding: 7px; }
.copy-field code { align-items: center; color: var(--ink); display: flex; flex: 1; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 11px; min-width: 0; overflow-wrap: anywhere; padding: 5px; }
.confirm-card > p { color: var(--muted); margin: 0; }
.dialog-actions { border-top: 1px solid var(--line-soft); display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; }

.toast-region { bottom: 18px; display: flex; flex-direction: column; gap: 7px; max-width: min(360px, calc(100vw - 32px)); position: fixed; right: 18px; z-index: 100; }
.toast { animation: toast-in 120ms ease-out; background: rgba(29, 29, 31, 0.92); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 9px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14); color: #fff; font-size: 12px; padding: 10px 13px; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.toast-error { background: rgba(180, 0, 18, 0.94); }
@keyframes toast-in { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }

.loading-bar { animation: loading 1s ease-in-out infinite; background: var(--accent); height: 2px; left: 0; position: fixed; right: 0; top: 0; transform-origin: left; z-index: 1000; }
@keyframes loading { 0% { transform: scaleX(0); } 45% { transform: scaleX(0.68); } 100% { transform: scaleX(1); } }

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recharge-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .keys-panel { order: -1; }
}

@media (max-width: 720px) {
  .topbar-inner { height: 62px; padding: 0 16px; }
  .content { padding: 26px 16px 42px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .page-heading h1 { font-size: 27px; }
  .payment-verification { align-items: flex-start; }
  .usage-summary { align-items: stretch; flex-direction: column; gap: 13px; }
  .usage-stats { max-width: none; }
  .usage-stats > div:first-child { border-left: 0; padding-left: 0; }
  .account-name { display: none; }
}

@media (max-width: 520px) {
  .auth-card { padding: 28px 22px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 116px; padding: 15px; }
  .metric-card > strong { font-size: 21px; }
  .usage-stats { grid-template-columns: 1fr 1fr; row-gap: 12px; }
  .usage-stats > div { border-left: 0; padding: 0; }
  .api-spec-entry { align-items: stretch; grid-template-columns: 1fr; }
  .api-spec-actions { align-items: stretch; }
  .api-spec-action { width: 100%; }
  .key-create-form { grid-template-columns: 1fr; }
  .copy-field { flex-direction: column; }
  .topbar .button-compact { font-size: 12px; padding: 5px 8px; }
  .dialog-card { padding: 19px 15px; }
}

@media (max-width: 390px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 108px; }
  .brand > span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
  .button:active,
  .auth-tab:active,
  .password-toggle:active,
  .text-button:active,
  .key-revoke:active,
  .icon-button:active { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar,
  .dialog-card,
  .toast {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .topbar { background: var(--canvas); }
  .dialog-card { background: var(--surface); }
  .toast { background: var(--ink); }
  .toast-error { background: var(--danger-hover); }
}

@media (prefers-contrast: more) {
  :root {
    --ink: #000;
    --muted: #3a3a3c;
    --faint: #4a4a4d;
    --line: #747478;
    --line-soft: #9a9a9f;
    --accent: #0057b8;
    --accent-hover: #004a9d;
    --accent-soft: #d9ebff;
  }
  .topbar,
  .dialog-card { background: #fff; border-color: var(--line); }
  .auth-card,
  .panel,
  .metric-card,
  .usage-summary,
  input,
  .button-secondary { border-color: var(--line); }
  .status-chip { border: 1px solid currentColor; }
}

@media (forced-colors: active) {
  .brand-logo,
  .button-primary,
  .loading-bar { forced-color-adjust: none; }
  .status-chip { border: 1px solid currentColor; }
}
