:root {
  color-scheme: light;
  --ink: #17191d;
  --muted: #68717d;
  --line: #dfe3e8;
  --paper: #ffffff;
  --soft: #f4f6f8;
  --red: #c81720;
  --red-dark: #971219;
  --green: #16754a;
  --amber: #9b5b09;
  --danger-soft: #fff0f1;
  --shadow: 0 12px 34px rgba(18, 22, 28, .09);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--soft); }
body { margin: 0; color: var(--ink); background: var(--soft); font-family: "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(200, 23, 32, .28); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar, .portal-header { position: sticky; top: 0; z-index: 30; height: 64px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 0 24px; background: rgba(255, 255, 255, .96); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; border-radius: 50%; color: #fff; background: var(--red); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.top-account { max-width: 300px; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.mobile-only { display: none !important; }
.notice { position: fixed; z-index: 80; top: 78px; left: 50%; width: min(520px, calc(100% - 32px)); transform: translateX(-50%); border: 1px solid rgba(200, 23, 32, .3); border-left: 4px solid var(--red); border-radius: 4px; padding: 12px 16px; background: var(--paper); box-shadow: var(--shadow); }
.notice.success { border-color: rgba(22, 117, 74, .35); border-left-color: var(--green); }

.auth-layout { width: min(1180px, calc(100% - 48px)); min-height: calc(100vh - 64px); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 430px); align-items: center; gap: 88px; padding: 48px 0; }
.auth-copy h1 { max-width: 680px; margin: 10px 0 18px; font-size: 48px; line-height: 1.16; letter-spacing: 0; }
.auth-copy > p:not(.eyebrow) { max-width: 600px; margin: 0; color: var(--muted); line-height: 1.8; }
.auth-facts { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 28px; color: var(--ink); font-size: 14px; font-weight: 700; }
.auth-facts span { display: inline-flex; align-items: center; gap: 8px; }
.auth-facts span::before { width: 7px; height: 7px; border-radius: 50%; background: var(--red); content: ""; }
.auth-panel { border: 1px solid var(--line); border-top: 4px solid var(--red); border-radius: 4px; padding: 28px; background: var(--paper); box-shadow: var(--shadow); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.tab { min-height: 44px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; cursor: pointer; }
.tab.active { border-color: var(--red); color: var(--ink); font-weight: 700; }
.form-stack { display: grid; gap: 18px; }
label { display: grid; gap: 8px; min-width: 0; color: var(--ink); font-size: 14px; font-weight: 700; }
input, textarea, select { width: 100%; min-height: 44px; border: 1px solid #c5ccd4; border-radius: 4px; padding: 10px 12px; color: var(--ink); background: var(--paper); outline: none; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(200, 23, 32, .1); }
input[readonly] { color: var(--muted); background: var(--soft); }
.inline-control, .inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.inline-form { margin-top: 16px; }

.primary-button, .secondary-button, .danger-button, .text-button, .link-button, .icon-button, .nav-item, .small-button { border: 0; border-radius: 4px; cursor: pointer; transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .12s ease, opacity .16s ease; }
.primary-button, .secondary-button, .danger-button { min-height: 42px; padding: 9px 15px; font-weight: 700; text-decoration: none; }
.primary-button { color: #fff; background: var(--red); }
.primary-button:hover { background: var(--red-dark); }
.secondary-button { border: 1px solid #b9c1ca; color: var(--ink); background: var(--paper); }
.secondary-button:hover { border-color: #8e98a4; background: var(--soft); }
.danger-button { color: #fff; background: var(--red-dark); }
.text-button, .link-button { padding: 9px 10px; color: var(--red); background: transparent; text-decoration: none; }
.link-button { min-height: 36px; }
.icon-button { display: inline-grid; width: 40px; height: 40px; flex: 0 0 40px; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: var(--paper); font-size: 20px; }
button:active, .primary-button:active, .secondary-button:active { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: .72; }
button[data-state="loading"] { position: relative; color: transparent !important; }
button[data-state="loading"]::after { position: absolute; top: 50%; left: 50%; width: 16px; height: 16px; margin: -9px 0 0 -9px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; color: #fff; content: ""; animation: spin .7s linear infinite; }
.secondary-button[data-state="loading"]::after { color: var(--ink); }
button[data-state="success"] { border-color: var(--green) !important; color: #fff !important; background: var(--green) !important; }
button[data-state="error"] { border-color: var(--red-dark) !important; color: #fff !important; background: var(--red-dark) !important; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-shell { min-height: calc(100vh - 64px); display: grid; grid-template-columns: 256px minmax(0, 1fr); }
.sidebar { position: sticky; top: 64px; height: calc(100vh - 64px); border-right: 1px solid var(--line); padding: 24px 16px; overflow-y: auto; background: var(--paper); }
.account-summary { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 0 8px 22px; }
.account-summary strong, .account-summary small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-summary small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.avatar-initial { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 50%; color: #fff; background: #20242a; font-weight: 800; }
.sidebar nav { display: grid; gap: 5px; margin-top: 22px; }
.nav-item { min-height: 44px; display: grid; grid-template-columns: 28px 1fr; align-items: center; border-left: 3px solid transparent; padding: 9px 12px; color: var(--muted); background: transparent; text-align: left; }
.nav-item span { font-size: 11px; font-weight: 700; }
.nav-item:hover { color: var(--ink); background: var(--soft); }
.nav-item.active { border-color: var(--red); color: var(--ink); background: var(--soft); font-weight: 700; }
.admin-link { display: block; margin: 24px 12px 0; border-top: 1px solid var(--line); padding-top: 18px; color: var(--red); font-weight: 700; text-decoration: none; }
.workspace { min-width: 0; width: 100%; max-width: 1480px; margin: 0 auto; padding: 34px 38px 64px; }
.workspace-panel { min-width: 0; }
.page-heading { min-height: 76px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading h1 { margin: 5px 0 8px; font-size: 30px; line-height: 1.2; letter-spacing: 0; }
.page-heading p:not(.eyebrow), .section-title p { margin: 0; color: var(--muted); line-height: 1.55; }
.eyebrow, .kicker { margin: 0; color: var(--red); font-size: 11px; font-weight: 800; letter-spacing: 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--line); gap: 1px; }
.metric { min-width: 0; min-height: 126px; padding: 20px; background: var(--paper); }
.metric span, .metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 10px 0 7px; overflow-wrap: anywhere; font-size: 25px; letter-spacing: 0; }
.metric-grid.compact .metric { min-height: 104px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); gap: 22px; margin-top: 22px; }
.dashboard-completion { margin-top: 22px; }
.dashboard-insights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-top: 22px; }
.usage-insights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
.section-block { border: 1px solid var(--line); border-radius: 4px; padding: 22px; background: var(--paper); }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-title h2 { margin: 0 0 6px; font-size: 18px; letter-spacing: 0; }
.stack-list { display: grid; gap: 1px; border: 1px solid var(--line); background: var(--line); }
.stack-row { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 14px; background: var(--paper); }
.stack-row strong, .stack-row small { display: block; }
.stack-row small { margin-top: 4px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.empty-state { padding: 26px 16px; color: var(--muted); background: var(--paper); text-align: center; }
.status-badge { display: inline-flex; min-width: max-content; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; font-size: 12px; }
.status-badge.success { border-color: rgba(22, 117, 74, .35); color: var(--green); background: rgba(22, 117, 74, .07); }
.status-badge.warning { border-color: rgba(155, 91, 9, .3); color: var(--amber); background: rgba(155, 91, 9, .07); }
.status-badge.danger { border-color: rgba(200, 23, 32, .3); color: var(--red-dark); background: var(--danger-soft); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 14px; margin-top: 18px; border-top: 1px solid var(--line); padding-top: 18px; }
.form-grid .full { grid-column: 1 / -1; }
.endpoint-bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 4px; padding: 12px 14px; background: var(--paper); }
.endpoint-bar code { min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.table-wrap, .table-scroll { width: 100%; overflow-x: auto; border: 1px solid var(--line); background: var(--paper); }
table { width: 100%; min-width: 820px; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 13px 14px; text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--soft); font-size: 12px; }
td { font-size: 13px; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.small-button { min-height: 32px; border: 1px solid #bcc4cd; padding: 5px 9px; color: var(--ink); background: var(--paper); }
.credential-group-select { min-width: 220px; min-height: 36px; padding: 6px 28px 6px 8px; }
.small-button.danger { border-color: rgba(200, 23, 32, .36); color: var(--red-dark); }
.empty-cell { padding: 30px; color: var(--muted); text-align: center; }
.filter-row { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) auto; align-items: end; gap: 12px; margin: 22px 0 16px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 16px; }
.download-link { display: inline-grid; place-items: center; }
.info-band { display: flex; align-items: center; gap: 18px; margin: 18px 0; border-left: 4px solid var(--red); padding: 14px 16px; background: var(--paper); }
.info-band span { color: var(--muted); }
.profile-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 22px; }
.security-block { grid-column: 1 / -1; }
.security-block img { display: block; width: 180px; height: 180px; margin: 16px 0; border: 1px solid var(--line); }
.recovery-codes { margin-top: 16px; border: 1px solid var(--line); padding: 16px; background: var(--soft); font-family: Consolas, monospace; line-height: 1.8; white-space: pre-wrap; }
.danger-text { color: var(--red-dark); font-weight: 700; }
dialog { width: min(480px, calc(100% - 32px)); border: 1px solid var(--line); border-top: 4px solid var(--red); border-radius: 4px; padding: 0; color: var(--ink); background: var(--paper); box-shadow: 0 24px 70px rgba(0, 0, 0, .22); }
dialog::backdrop { background: rgba(18, 22, 28, .58); }
.dialog-form { display: grid; gap: 18px; padding: 24px; }
.dialog-form h2, .dialog-form p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.admin-main { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 40px 0 64px; }
.admin-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.admin-heading h1 { margin: 5px 0 0; font-size: 30px; }
.filter-bar { display: flex; align-items: end; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.filter { min-height: 42px; border: 0; border-bottom: 3px solid transparent; padding: 8px 14px; color: var(--muted); background: transparent; cursor: pointer; }
.filter.active { border-color: var(--red); color: var(--ink); font-weight: 700; }
.search-field { min-width: 260px; margin: 0 0 8px auto; }
.admin-section { margin-top: 34px; }
.admin-section h2 { font-size: 19px; }
.admin-denied { padding: 80px 0; }

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --ink: #f1f3f5; --muted: #a7b0bb; --line: #363c45; --paper: #1d2127; --soft: #15181d; --red: #ee3942; --red-dark: #c7232c; --green: #56c58d; --amber: #e0a653; --danger-soft: #351d20; --shadow: 0 14px 38px rgba(0, 0, 0, .28); }
  .topbar, .portal-header { background: rgba(29, 33, 39, .96); }
  input, textarea, select { border-color: #4a525e; }
  .avatar-initial { color: #17191d; background: #f1f3f5; }
}

@media (max-width: 1000px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .dashboard-insights, .usage-insights { grid-template-columns: 1fr; }
  .filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-row button { width: max-content; }
}

@media (max-width: 760px) {
  .topbar, .portal-header { height: 58px; padding: 0 14px; }
  .brand small, .top-account { display: none; }
  .mobile-only { display: inline-grid !important; }
  .auth-layout { width: min(100% - 28px, 520px); min-height: calc(100vh - 58px); grid-template-columns: 1fr; align-content: start; gap: 28px; padding: 36px 0; }
  .auth-copy h1 { font-size: 34px; }
  .auth-panel { padding: 22px; }
  .auth-facts { gap: 14px; }
  .app-shell { min-height: calc(100vh - 58px); display: block; }
  .sidebar { position: fixed; z-index: 45; top: 58px; left: 0; width: min(286px, calc(100vw - 52px)); height: calc(100vh - 58px); transform: translateX(-105%); box-shadow: 16px 0 36px rgba(0, 0, 0, .2); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .workspace { padding: 26px 14px 48px; }
  .page-heading { min-height: 0; align-items: flex-start; margin-bottom: 22px; }
  .page-heading h1 { font-size: 26px; }
  .metric { min-height: 105px; padding: 16px; }
  .metric strong { font-size: 21px; }
  .section-block { padding: 17px; }
  .profile-layout { grid-template-columns: 1fr; }
  .security-block { grid-column: auto; }
  .form-grid, .filter-row, .inline-form { grid-template-columns: 1fr; }
  .form-grid button, .filter-row button, .inline-form button { width: 100%; }
  .endpoint-bar { grid-template-columns: 1fr auto; }
  .endpoint-bar span { grid-column: 1 / -1; }
  .table-wrap { overflow: visible; border: 0; background: transparent; }
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; min-width: 0; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .table-wrap tbody { display: grid; gap: 10px; }
  .table-wrap tr { border: 1px solid var(--line); border-radius: 4px; padding: 7px 13px; background: var(--paper); }
  .table-wrap td { display: grid; grid-template-columns: minmax(88px, .7fr) minmax(0, 1.3fr); gap: 12px; border-bottom: 1px solid var(--line); padding: 10px 0; text-align: right; }
  .table-wrap td::before { color: var(--muted); content: attr(data-label); text-align: left; font-size: 12px; font-weight: 700; }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td.empty-cell { display: block; padding: 24px 8px; text-align: center; }
  .row-actions { justify-content: flex-end; }
  .info-band { align-items: flex-start; flex-direction: column; gap: 6px; }
  .pagination { justify-content: space-between; }
  .admin-main { width: min(100% - 28px, 1240px); padding-top: 26px; }
  .filter-bar { flex-wrap: wrap; }
  .search-field { flex-basis: 100%; min-width: 0; margin-left: 0; }
}

@media (max-width: 430px) {
  .brand strong { font-size: 14px; }
  .metric-grid { grid-template-columns: 1fr; }
  .inline-control { grid-template-columns: 1fr; }
  .inline-control .secondary-button { width: 100%; }
  .page-heading { flex-wrap: wrap; }
  .page-heading > .primary-button, .page-heading > .secondary-button { width: 100%; }
  .stack-row { flex-direction: column; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
}
