:root {
  color: #1d2420;
  background: #f5f6f4;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --ink: #1d2420;
  --muted: #667069;
  --line: #d8ddd9;
  --surface: #ffffff;
  --surface-subtle: #f5f6f4;
  --green: #176c45;
  --green-soft: #e7f4ec;
  --red: #b42318;
  --red-soft: #fce9e7;
  --amber: #8a5700;
  --amber-soft: #fff3d6;
  --focus: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--surface-subtle);
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.62; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 430px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgb(29 36 32 / 9%);
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 7px;
  background: #202923;
  color: #fff;
  font-size: 14px;
  font-weight: 750;
}

.brand-mark.small { width: 32px; height: 32px; margin: 0; font-size: 11px; }
.brand-name { margin: 0; color: var(--ink); font-size: 14px; font-weight: 720; }
.login-panel h1 { margin: 4px 0 26px; font-size: 24px; line-height: 1.25; }
.auth-panel h2 { margin: 0 0 20px; font-size: 17px; line-height: 1.3; }
.auth-loading { min-height: 80px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.compact-form { margin-top: 18px; }

.mode-control { min-width: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 0; padding: 0; border: 0; }
.mode-control legend { grid-column: 1 / -1; margin-bottom: 7px; color: #38413b; font-size: 13px; font-weight: 650; }
.mode-control label { position: relative; display: block; }
.mode-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.mode-control span { min-height: 40px; display: grid; place-items: center; border: 1px solid #bcc4be; background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 680; }
.mode-control label:first-of-type span { border-radius: 6px 0 0 6px; }
.mode-control label:last-of-type span { margin-left: -1px; border-radius: 0 6px 6px 0; }
.mode-control input:checked + span { position: relative; z-index: 1; border-color: var(--green); background: var(--green-soft); color: #0f633d; }
.mode-control input:focus-visible + span { outline: 3px solid rgb(37 99 235 / 25%); outline-offset: 2px; }

.auth-links { display: flex; justify-content: space-between; gap: 14px; margin-top: 20px; }
.text-button { min-height: 32px; padding: 2px 0; border: 0; background: transparent; color: #315b45; font-size: 13px; font-weight: 650; }
.text-button:hover { color: var(--green); text-decoration: underline; }
.auth-actions { display: flex; justify-content: flex-end; gap: 10px; }
.auth-actions .button { flex: 1 1 0; }
.binding-qr { display: block; width: 216px; height: 216px; margin: 0 auto 20px; border: 1px solid var(--line); background: #fff; object-fit: contain; }
.inline-output { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.inline-output .button { min-height: 40px; }

.stack-form, .dialog-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: #38413b; font-size: 13px; font-weight: 650; }

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bcc4be;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(37 99 235 / 13%); }

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid #b9c1bb;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 680;
}

.button:hover { background: #eef1ee; }
.button:focus-visible, .icon-button:focus-visible, .tab:focus-visible { outline: 3px solid rgb(37 99 235 / 25%); outline-offset: 2px; }
.button.primary { border-color: var(--green); background: var(--green); color: #fff; }
.button.primary:hover { background: #115a38; }
.button.danger { border-color: var(--red); background: var(--red); color: #fff; }
.button.danger:hover { background: #951d14; }
.button.warning { border-color: #e1b65e; background: var(--amber-soft); color: #704700; }
.button.quiet { min-height: 34px; border-color: transparent; background: transparent; color: #4e5952; }
.button.full { width: 100%; }
.form-error { margin: -6px 0 0; color: var(--red); font-size: 13px; line-height: 1.45; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1320px; min-height: 60px; margin: 0 auto; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand-lockup, .topbar-actions { display: flex; align-items: center; gap: 11px; }
.account-name { max-width: 180px; overflow: hidden; color: #48534b; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.server-status { display: inline-flex; align-items: center; gap: 7px; color: #526057; font-size: 13px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #28a565; box-shadow: 0 0 0 3px #def2e7; }
.server-status.offline .status-dot { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

.workspace { max-width: 1320px; margin: 0 auto; padding: 36px 28px 64px; }
.workspace-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.workspace-heading h1 { margin: 0; font-size: 27px; line-height: 1.2; }
.summary-text { min-height: 20px; margin: 7px 0 0; color: var(--muted); font-size: 14px; }

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); }
.tab { min-height: 43px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-weight: 680; }
.tab.active { border-bottom-color: var(--green); color: var(--ink); }
.table-toolbar { min-height: 68px; display: flex; align-items: center; justify-content: flex-end; }
.search-field { width: min(100%, 340px); display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; }
.search-field input { min-height: 36px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
table { width: 100%; min-width: 960px; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 14px 16px; border-bottom: 1px solid #e5e8e5; text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
th { background: #f7f8f6; color: #59635c; font-size: 12px; font-weight: 750; text-transform: uppercase; }
td { color: #303832; font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfa; }
.primary-cell { display: grid; gap: 4px; font-weight: 700; }
.secondary-line { color: var(--muted); font-size: 12px; font-weight: 500; }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.actions-column { width: 92px; }
.table-action { min-height: 32px; padding: 5px 10px; }

.policy-label, .state-label { display: inline-flex; align-items: center; width: fit-content; min-height: 25px; padding: 3px 8px; border-radius: 5px; font-size: 12px; font-weight: 720; }
.policy-label { background: #edf0f7; color: #3f4d6b; }
.state-label.active { background: var(--green-soft); color: #0f633d; }
.state-label.disabled { background: var(--red-soft); color: #9f2017; }

.state-control { display: flex; align-items: center; gap: 9px; }
.switch { position: relative; width: 44px; height: 44px; flex: 0 0 auto; cursor: pointer; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track { position: absolute; width: 38px; height: 22px; left: 3px; top: 11px; border-radius: 11px; background: #c7cdc9; transition: background 140ms ease; }
.switch-track::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 22%); transition: transform 140ms ease; }
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 3px solid rgb(37 99 235 / 25%); outline-offset: 2px; }

.empty-state { min-height: 180px; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.audit-table { margin-top: 28px; }
.audit-table table { min-width: 780px; }

dialog { width: min(calc(100% - 32px), 610px); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 70px rgb(14 25 18 / 24%); }
dialog::backdrop { background: rgb(20 28 23 / 45%); }
.dialog-form { padding: 24px; overflow-y: auto; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-heading h2 { margin: 0; font-size: 19px; line-height: 1.3; }
.dialog-eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 700; }
.icon-button { width: 34px; height: 34px; flex: 0 0 auto; border: 0; border-radius: 5px; background: transparent; color: #5c665f; font-size: 24px; line-height: 1; }
.icon-button:hover { background: #edf0ed; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding-top: 3px; }
.split-actions { flex-wrap: wrap; }
.action-spacer { flex: 1 1 auto; }
.credential-output { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; background: #f5f7f5; }
.security-sections { display: grid; gap: 24px; }
.security-section { display: grid; gap: 14px; padding-top: 4px; }
.security-section + .security-section { padding-top: 24px; border-top: 1px solid var(--line); }
.security-section h3 { margin: 0; font-size: 15px; }
.security-rebind { display: grid; gap: 16px; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(520px, calc(100% - 32px)); padding: 11px 15px; border-radius: 6px; background: #202923; color: #fff; box-shadow: 0 10px 30px rgb(0 0 0 / 20%); font-size: 13px; }

@media (max-width: 720px) {
  .login-shell { place-items: start center; padding: 18px; }
  .login-panel { margin-top: 10px; padding: 24px 20px; }
  .topbar-inner, .workspace { padding-left: 18px; padding-right: 18px; }
  .workspace { padding-top: 26px; }
  .workspace-heading { align-items: stretch; flex-direction: column; }
  .workspace-heading .button { width: 100%; }
  .server-status { display: none; }
  .account-name { display: none; }
  .table-toolbar { justify-content: stretch; }
  .search-field { width: 100%; grid-template-columns: 1fr; gap: 5px; }
  .table-wrap { overflow: visible; border: 0; background: transparent; }
  table, tbody { display: block; width: 100%; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
  tbody tr:hover { background: var(--surface); }
  td { display: grid; gap: 5px; padding: 0; border: 0; min-width: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 720; text-transform: uppercase; }
  td.primary-cell, td[data-label="App ID"], td[data-label="内部原因"] { grid-column: 1 / -1; }
  td[data-label="状态"], td[data-label="操作"] { align-content: end; }
  .table-action { min-height: 44px; }
  .audit-table { margin-top: 20px; }
  .audit-table table { min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .dialog-actions .button { flex: 1 1 auto; }
  .action-spacer { display: none; }
  #rotateTokenButton { flex-basis: 100%; }
}
