:root {
  color-scheme: light;
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  color: #1f2328;
  background: #f5f6f7;
  font-size: 14px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: #f5f6f7; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 216px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 14px; background: #202326; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 26px; font-size: 17px; }
.brand span, .brand-mark { display: grid; place-items: center; width: 30px; height: 30px; margin: 0; background: #d92d20; color: #fff; font-weight: 800; border-radius: 4px; }
nav { display: grid; gap: 4px; }
.nav-item { width: 100%; padding: 10px 12px; border: 0; border-radius: 4px; background: transparent; color: #b9bec4; text-align: left; }
.nav-item:hover, .nav-item.active { background: #32363a; color: #fff; }
.logout { margin-top: auto; }

.workspace { min-width: 0; padding: 28px 36px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 60px; margin-bottom: 28px; }
.topbar h1 { margin: 4px 0 0; font-size: 24px; line-height: 1.2; }
.eyebrow { margin: 0; color: #777d84; font-size: 11px; font-weight: 700; }
.health { color: #16794b; font-size: 13px; }
.health::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #20a66a; }

.view { display: none; }
.view.active { display: block; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; margin-bottom: 34px; }
.stat { padding: 18px; border: 1px solid #dedfe1; border-radius: 6px; background: #fff; }
.stat span { color: #686f77; }
.stat strong { display: block; margin-top: 10px; font-size: 26px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 0 0 14px; }
.section-head h2 { margin: 0; font-size: 17px; }
.section-head p { margin: 6px 0 0; color: #70777f; }
.toolbar { margin-bottom: 12px; }
.toolbar input { width: min(320px, 100%); }

input, select, textarea { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid #cdd0d4; border-radius: 4px; background: #fff; color: #1f2328; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #4f5964; box-shadow: 0 0 0 2px rgb(79 89 100 / 12%); }
label { display: grid; gap: 6px; color: #4b5259; font-size: 13px; }

.primary, .secondary { min-height: 38px; padding: 8px 14px; border-radius: 4px; font-weight: 650; }
.primary { border: 1px solid #bd241a; background: #d92d20; color: #fff; }
.primary:hover { background: #bd241a; }
.secondary { border: 1px solid #cdd0d4; background: #fff; color: #30363c; }
.secondary:hover { background: #f0f1f2; }
.full { width: 100%; }
.icon-button { width: 34px; height: 34px; border: 0; background: transparent; color: #646b73; font-size: 24px; line-height: 1; }
.danger { border: 0; background: transparent; color: #c1271c; padding: 5px; }
.link-button { border: 0; background: transparent; color: #b42318; font-weight: 650; padding: 5px; }

.table-wrap { overflow-x: auto; border: 1px solid #dedfe1; border-radius: 6px; background: #fff; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #eceef0; text-align: left; white-space: nowrap; }
th { background: #f9f9fa; color: #666d75; font-size: 12px; font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfbfc; }
td small { display: block; margin-top: 3px; color: #858b92; }
.badge { display: inline-block; padding: 3px 7px; border-radius: 3px; background: #eceef0; color: #4b5259; font-size: 12px; }
.badge.active, .badge.success, .badge.running { background: #e6f4ec; color: #16794b; }
.badge.suspended, .badge.revoked, .badge.failed, .badge.disabled { background: #fbe9e7; color: #b42318; }
.badge.queued, .badge.submitting { background: #fff2d8; color: #8c5a00; }
.muted { color: #777e86; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #202326; }
.login-panel { width: min(380px, 100%); display: grid; gap: 18px; padding: 32px; border-radius: 6px; background: #fff; }
.login-panel h1 { margin: 0; font-size: 21px; }
.error { min-height: 18px; margin: 0; color: #b42318; }

dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: 6px; box-shadow: 0 18px 60px rgb(0 0 0 / 28%); }
dialog::backdrop { background: rgb(15 17 19 / 55%); }
.dialog-form { display: grid; gap: 20px; padding: 24px; overflow: auto; }
.dialog-form.narrow { max-width: 500px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.wide { grid-column: 1 / -1; }
fieldset { margin: 0; padding: 14px; border: 1px solid #dedfe1; border-radius: 5px; }
legend { padding: 0 6px; font-weight: 650; }
.field-note { margin: 0 0 10px; color: #747b82; font-size: 12px; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 16px; min-height: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.issued-key { display: grid; gap: 10px; padding: 14px; border: 1px solid #e4b3ad; border-radius: 5px; background: #fff7f6; }
.issued-key code { overflow-wrap: anywhere; color: #7f1d16; }
.flash { margin-bottom: 18px; padding: 11px 14px; border: 1px solid #afd9c3; border-radius: 4px; background: #eef8f2; color: #12623d; }
.flash.error { border-color: #edb8b2; background: #fff3f2; color: #a22118; }
.security-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-panel { display: grid; align-content: start; gap: 14px; padding: 20px; border: 1px solid #dedfe1; border-radius: 6px; background: #fff; }
.settings-panel h3 { margin: 0 0 4px; font-size: 15px; }
.settings-panel form, #totp-enroll { display: grid; gap: 14px; }
.settings-panel code { display: block; margin-top: 6px; padding: 10px; background: #f2f3f4; color: #343a40; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { padding: 0 14px 0 0; }
  nav { display: flex; }
  .nav-item { width: auto; white-space: nowrap; }
  .logout { margin: 0 0 0 auto; }
  .workspace { padding: 22px 18px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}

@media (max-width: 560px) {
  .brand strong { display: none; }
  .sidebar { align-items: flex-start; }
  .workspace { padding-inline: 12px; }
  .topbar, .section-head { align-items: flex-start; }
  .stats, .form-grid, .checks, .security-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr; }
}
