:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #eef2ff;
  --line: #d7deea;
  --text: #172033;
  --text-muted: #5f6b85;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #e8f0ff;
  --danger: #dc2626;
  --shadow: 0 22px 50px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
}

.portal-shell,
.admin-shell,
.auth-shell {
  width: min(1120px, calc(100vw - 48px));
  margin: 0 auto;
}

.portal-shell {
  padding: 72px 0 88px;
}

.portal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 36px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.compact-btn {
  min-height: 36px;
  padding: 0 12px;
}

.portal-hero {
  margin-bottom: 44px;
}

.portal-eyebrow {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.portal-hero h1,
.admin-header h1,
.auth-panel h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1.08;
}

.portal-subtitle,
.auth-copy,
.section-head p {
  margin: 14px 0 0;
  max-width: 700px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.7;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.site-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 220px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.site-card h2 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.15;
}

.site-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.7;
}

.site-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}

.site-meta {
  color: var(--text-muted);
  font-size: 13px;
}

.primary-btn,
.secondary-btn,
.secondary-link {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
}

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

.secondary-btn,
.secondary-link {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.secondary-btn:hover,
.secondary-link:hover {
  background: #f8fbff;
}

.admin-body {
  padding: 36px 0 60px;
}

.auth-shell {
  min-height: calc(100vh - 96px);
  display: grid;
  place-items: center;
}

.auth-panel,
.config-section,
.admin-header,
.admin-footer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(520px, 100%);
  padding: 32px;
}

.auth-form,
.provider-card,
.site-override-block {
  display: grid;
  gap: 16px;
}

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

.field span {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 116px;
}

.form-message {
  margin: 0;
  min-height: 24px;
  color: var(--text-muted);
  font-size: 14px;
}

.form-message.is-error {
  color: var(--danger);
}

.form-message.is-success {
  color: #0f766e;
}

.admin-shell {
  display: grid;
  gap: 18px;
}

.admin-header,
.config-section,
.admin-footer {
  padding: 22px 24px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.admin-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.config-section {
  display: grid;
  gap: 18px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-head h2,
.site-override-head h3 {
  margin: 0;
  font-size: 22px;
}

.provider-list,
.site-override-list {
  display: grid;
  gap: 16px;
}

.provider-card,
.site-override-block {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.provider-toolbar,
.site-override-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.provider-title {
  font-size: 16px;
}

.text-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.text-btn.danger {
  color: var(--danger);
  font-weight: 700;
}

.auth-switch {
  margin-top: 16px;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.35);
}

.modal-mask.hidden,
.tab-panel {
  display: none;
}

.modal-panel {
  width: min(460px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-head,
.admin-tabs,
.inline-form,
.mini-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-head {
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-head h2 {
  margin: 0;
}

.admin-tabs {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface);
}

.tab-btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 16px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tab-panel.is-active {
  display: grid;
  gap: 18px;
}

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

.stats-grid div {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.stats-grid strong {
  display: block;
  font-size: 26px;
}

.stats-grid span {
  color: var(--text-muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  background: #f8fbff;
  font-weight: 700;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table .detail-cell {
  max-width: 360px;
  white-space: normal;
  line-height: 1.6;
}

.data-table code {
  font-family: Consolas, "Microsoft YaHei", sans-serif;
  font-size: 12px;
}

.inline-form {
  align-items: end;
  flex-wrap: wrap;
}

.inline-form .field {
  min-width: 140px;
}

.inline-form .grow-field {
  flex: 1 1 280px;
}

.code-output {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font: 13px/1.6 Consolas, "Microsoft YaHei", sans-serif;
  resize: vertical;
}

.split-section {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.is-used {
  background: #fee2e2;
  color: #991b1b;
}

.mini-input {
  width: 90px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
}

.mini-btn {
  min-height: 34px;
  padding: 0 10px;
}

.is-plus {
  color: #0f766e;
  font-weight: 700;
}

.is-minus {
  color: var(--danger);
  font-weight: 700;
}

.site-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.site-toggle input {
  width: 18px;
  height: 18px;
}

.site-override-meta {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.admin-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

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

  .admin-header,
  .section-head,
  .admin-footer,
  .portal-topbar,
  .site-card-footer,
  .site-override-head {
    flex-direction: column;
    align-items: stretch;
  }

  .user-pill,
  .admin-tabs,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

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

  .portal-shell,
  .admin-shell,
  .auth-shell {
    width: min(100vw - 28px, 1120px);
  }
}
