/* D1Pay Egress Relay 管理控制台样式；无外链字体与 CDN。 */
:root {
  color-scheme: light dark;
  --bg: #f4f6fa;
  --bg-elevated: #ffffff;
  --border: #d9dfe9;
  --text: #1c2430;
  --muted: #63708a;
  --accent: #2f6fed;
  --accent-strong: #1d4fc4;
  --good: #12875c;
  --warn: #b26a00;
  --bad: #be2f3a;
  --shadow: 0 1px 2px rgba(20, 32, 56, 0.06), 0 8px 24px rgba(20, 32, 56, 0.06);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c;
    --bg-elevated: #161d28;
    --border: #263145;
    --text: #e6ecf5;
    --muted: #93a1b8;
    --accent: #6c9bff;
    --accent-strong: #9bb9ff;
    --good: #4fd1a1;
    --warn: #f0b45c;
    --bad: #ff7a85;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0f141c;
  --bg-elevated: #161d28;
  --border: #263145;
  --text: #e6ecf5;
  --muted: #93a1b8;
  --accent: #6c9bff;
  --accent-strong: #9bb9ff;
  --good: #4fd1a1;
  --warn: #f0b45c;
  --bad: #ff7a85;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

.topbar {
  align-items: center;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  padding: 18px clamp(16px, 4vw, 40px);
}

.brand {
  align-items: center;
  display: flex;
  gap: 14px;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 10px;
  color: #fff;
  display: inline-flex;
  font-weight: 700;
  height: 42px;
  justify-content: center;
  letter-spacing: 0.04em;
  width: 42px;
}

.brand h1 {
  font-size: 1.18rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 2px 0 0;
}

.topbar-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.meta-item {
  color: var(--muted);
  font-size: 0.82rem;
}

.meta-item strong,
.meta-item code {
  color: var(--text);
}

.badge {
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
}

.badge-ok {
  background: color-mix(in srgb, var(--good) 16%, transparent);
  color: var(--good);
}

.badge-bad {
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  color: var(--bad);
}

.badge-muted {
  background: color-mix(in srgb, var(--muted) 16%, transparent);
  color: var(--muted);
}

.btn {
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
  padding: 7px 14px;
  text-decoration: none;
}

.btn:hover {
  background: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: var(--accent);
}

.toggle {
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.82rem;
  gap: 6px;
}

.toggle input {
  accent-color: var(--accent);
}

.layout {
  display: grid;
  gap: 18px;
  margin: 0 auto;
  max-width: 1280px;
  padding: 22px clamp(16px, 4vw, 40px) 40px;
}

.banner {
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  border-radius: var(--radius);
  color: var(--bad);
  padding: 12px 16px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* 允许卡片在窄屏收缩，超宽表格由 .table-wrap 横向滚动。 */
  min-width: 0;
  padding: 20px clamp(16px, 2.4vw, 26px);
}

.card-head {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 1.02rem;
}

.card h3 {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  gap: 4px;
  padding: 12px 14px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.stat-value {
  font-size: 1.16rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.config-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.config-block dl,
.build-info {
  display: grid;
  gap: 6px 12px;
  grid-template-columns: minmax(88px, max-content) 1fr;
  margin: 8px 0 0;
}

.config-block dt,
.build-info dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.config-block dd,
.build-info dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.88rem;
}

.hint {
  color: var(--muted);
  font-size: 0.76rem;
  margin: 10px 0 0;
}

.runtime-layout {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
}

.runtime-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

/* .field 的 display 会覆盖 UA 的 [hidden] 规则，这里显式恢复隐藏。 */
.field[hidden] {
  display: none;
}

.field label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.field input,
.field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  padding: 8px 10px;
  width: 100%;
}

.field input:focus-visible,
.field select:focus-visible {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 1px;
}

.field input:disabled,
.field select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.field .hint {
  margin: 0;
}

.form-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 2px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn:disabled:hover {
  background: var(--accent);
}

.form-status {
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1.2em;
}

.form-status[data-state="ok"] {
  color: var(--good);
}

.form-status[data-state="error"] {
  color: var(--bad);
}

.form-status[data-state="pending"] {
  color: var(--warn);
}

.form-note {
  border-top: 1px dashed var(--border);
  margin: 2px 0 0;
  padding-top: 10px;
}

.runtime-summary {
  background: color-mix(in srgb, var(--accent) 4%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.runtime-summary dl {
  display: grid;
  gap: 6px 12px;
  grid-template-columns: minmax(96px, max-content) minmax(0, 1fr);
  margin: 10px 0 0;
}

.runtime-summary dt {
  color: var(--muted);
  font-size: 0.8rem;
}

.runtime-summary dd {
  font-size: 0.86rem;
  margin: 0;
  overflow-wrap: anywhere;
}

.copy-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.copy-row .btn {
  flex: none;
}

.url-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  flex: 1 1 280px;
  font: inherit;
  font-size: 0.88rem;
  min-width: 0;
  padding: 8px 10px;
  width: 100%;
}

.url-input:focus-visible {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 1px;
}

.url-input::placeholder {
  color: var(--muted);
}

.warn-text {
  color: var(--warn);
}

/* 复制兜底用的临时 textarea：移出视口，避免内联样式触发 CSP。 */
.copy-helper {
  left: -9999px;
  opacity: 0;
  position: fixed;
  top: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  font-size: 0.84rem;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.empty {
  color: var(--muted);
  text-align: center;
}

.status-ok {
  color: var(--good);
  font-weight: 600;
}

.status-bad {
  color: var(--bad);
  font-weight: 600;
}

.footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.76rem;
  gap: 8px 24px;
  justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 40px);
}

/* D1Pay 接入说明：强调 token 由 Worker 自动携带，不写入地址。 */
.access-note {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--border));
  border-radius: 10px;
  color: var(--text);
  font-size: 0.78rem;
  margin: 12px 0 0;
  padding: 10px 12px;
}

.access-note code {
  overflow-wrap: anywhere;
}

/* Token 代理路由卡片 */
.profile-head-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hint-list {
  color: var(--muted);
  display: grid;
  font-size: 0.76rem;
  gap: 4px;
  margin: 10px 0 0;
  padding-left: 1.2em;
}

.hint-list code {
  overflow-wrap: anywhere;
}

.profiles-table .proxy-cell {
  max-width: 340px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.profile-id {
  color: var(--muted);
  font-size: 0.72rem;
}

.profile-note {
  color: var(--muted);
  font-size: 0.72rem;
  margin-left: 4px;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-sm {
  font-size: 0.76rem;
  padding: 4px 9px;
}

.btn-danger-ghost:hover {
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  border-color: var(--bad);
  color: var(--bad);
}

.profile-form {
  border-top: 1px dashed var(--border);
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding-top: 16px;
}

/* .profile-form 的 display 会覆盖 UA 的 [hidden] 规则，这里显式恢复隐藏。 */
.profile-form[hidden] {
  display: none;
}

.profile-form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.profile-enabled-field {
  align-content: end;
}

.profile-enabled-field .toggle {
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
}

#profiles-status {
  margin: 8px 0 0;
}

/* 退出登录按钮：危险动作用红色悬停提示，但保持 ghost 外观。 */
.btn-logout:hover {
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  border-color: var(--bad);
  color: var(--bad);
}

/* 登录页 */
.login-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.login-main {
  align-items: center;
  display: flex;
  flex: 1 1 auto;
  justify-content: center;
  padding: 48px 20px;
}

.login-card {
  max-width: 430px;
  width: 100%;
}

.login-brand {
  align-items: center;
  display: flex;
  gap: 14px;
  margin-bottom: 22px;
}

.login-brand h1 {
  font-size: 1.12rem;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-actions {
  display: block;
}

.login-submit {
  padding: 9px 14px;
  width: 100%;
}

.login-status {
  margin: 0;
}

.login-status[hidden] {
  display: none;
}

.login-footer {
  flex: none;
}

@media (max-width: 900px) {
  .runtime-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-meta {
    width: 100%;
  }

  .login-main {
    padding: 28px 16px;
  }

  .login-footer {
    flex-direction: column;
    gap: 6px;
  }

  .config-grid,
  .stats {
    grid-template-columns: 1fr;
  }

  .config-block dl,
  .build-info,
  .runtime-summary dl {
    grid-template-columns: 1fr;
  }

  .config-block dd,
  .build-info dd {
    margin-bottom: 6px;
  }

  .runtime-summary dd {
    margin-bottom: 6px;
  }
}
