:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --line: #dbe2ea;
  --line-strong: #c8d2dd;
  --text: #17212b;
  --muted: #6d7a88;
  --accent: #1f8f76;
  --accent-dark: #146d59;
  --danger: #c94343;
  --shadow: 0 16px 36px rgba(28, 39, 53, 0.08);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body:not(.logged-in) {
  display: grid;
  place-items: center;
}

.layout {
  width: min(1680px, calc(100vw - 24px));
  margin: 28px auto;
}

body:not(.logged-in) .layout {
  width: min(440px, calc(100vw - 32px));
  margin: 0;
}

.hidden {
  display: none !important;
}

.login-card,
.panel,
.topbar,
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card {
  padding: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  font-weight: 800;
  margin-bottom: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px 24px;
  margin-bottom: 18px;
}

.top-actions,
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-actions button,
.actions button {
  width: auto;
  min-width: 128px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 28px;
}

h2 {
  font-size: 18px;
  margin-bottom: 4px;
}

.muted,
.tip,
.result {
  color: var(--muted);
}

.tip {
  font-size: 13px;
  line-height: 1.55;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 18px;
}

.side-panel {
  position: sticky;
  top: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.section-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  margin: 12px 0;
  font-size: 14px;
}

input,
textarea,
button {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
  line-height: 1.55;
  font-family: "Cascadia Mono", Consolas, monospace;
}

button {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button.secondary,
button.tab {
  background: #eef2f6;
  border-color: #d8e0e8;
  color: var(--text);
}

button.secondary:hover,
button.tab:hover {
  background: #e2e8ef;
}

button.small {
  width: auto;
  padding: 7px 10px;
  min-width: 76px;
  margin: 2px 4px 2px 0;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  min-width: 190px;
}

.row-actions button.small {
  margin: 0;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

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

button.tab {
  padding: 11px;
}

button.tab.active {
  background: #17212b;
  border-color: #17212b;
  color: #fff;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

th:last-child,
td:last-child {
  text-align: right;
  min-width: 210px;
}

.table-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
}

.table-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.table-toolbar select {
  width: auto;
  min-width: 82px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.table-toolbar button {
  width: auto;
  min-width: 86px;
}

th {
  background: var(--surface-2);
  color: #3d4a57;
  font-size: 13px;
}

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

.empty {
  padding: 18px;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 13px;
  font-weight: 700;
  background: #eef2f6;
  color: #465360;
}

.status.active {
  background: #e3f6ef;
  color: #147258;
}

.status.disabled,
.status.revoked {
  background: #fde8e8;
  color: #a73535;
}

.status.activated {
  background: #e5f0ff;
  color: #1f5fa8;
}

.status.inactive {
  background: #f1f3f6;
  color: #687586;
}

.result.error {
  color: var(--danger);
}

.detail-list {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.detail-list dt,
.detail-list dd {
  margin: 0;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.detail-list dd {
  word-break: break-all;
}

.detail-list dt:last-of-type,
.detail-list dd:last-of-type {
  border-bottom: 0;
}

.modal-dialog {
  width: min(520px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.wide-dialog {
  width: min(760px, calc(100vw - 32px));
}

.modal-dialog::backdrop {
  background: rgba(23, 33, 43, 0.45);
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  min-width: 0;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .side-panel {
    position: static;
  }
  .metrics,
  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar,
  .top-actions,
  .actions,
  .section-title {
    display: grid;
    align-items: stretch;
  }
  .metrics,
  .tabs {
    grid-template-columns: 1fr;
  }
}
