:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #e3e6ea;
  --text: #1c2024;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-soft: #e6f4f1;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1b1f23;
    --surface-alt: #20252a;
    --border: #2c3238;
    --text: #e8eaed;
    --muted: #9aa2ab;
    --accent: #2dd4bf;
    --accent-soft: #16302e;
    --danger: #f97066;
    --danger-soft: #3a1d1b;
    --warn: #fdb022;
    --warn-soft: #33260f;
    --ok: #47cd89;
    --ok-soft: #12291d;
  }
}

* {
  box-sizing: border-box;
}

/* Keep the hidden attribute authoritative over component display rules. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  width: 10px;
  height: 18px;
  border-radius: 3px;
  background: var(--accent);
}

.brand-name {
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.agent-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12px;
  color: var(--muted);
}

.agent-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.agent-pill[data-state="online"] .dot {
  background: var(--ok);
}

.agent-pill[data-state="offline"] .dot {
  background: var(--danger);
}

.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat {
  background: var(--surface);
  padding: 16px 18px;
  min-width: 0;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.meter-band {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  flex-wrap: wrap;
}

.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s ease;
}

.meter-fill[data-level="warn"] {
  background: var(--warn);
}

.meter-fill[data-level="danger"] {
  background: var(--danger);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel-head h1,
.panel-head h2 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
}

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

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

.table th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-alt);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table .actions-col {
  text-align: right;
}

.profile-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-name strong {
  font-weight: 600;
}

.profile-name code {
  color: var(--muted);
  font-size: 12px;
}

.sub {
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
}

.tag[data-state="active"] {
  background: var(--ok-soft);
  color: var(--ok);
}

.tag[data-state="pending"],
.tag[data-state="revoke_pending"],
.tag[data-state="delete_pending"] {
  background: var(--warn-soft);
  color: var(--warn);
}

.tag[data-state="revoked"],
.tag[data-state="failed"],
.tag[data-state="delete_failed"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.tag[data-state="deleted"] {
  background: var(--surface-alt);
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.btn:hover {
  background: var(--surface-alt);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
}

.btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  padding: 7px 9px;
}

.input {
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  min-width: 0;
}

.input:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#search {
  width: 200px;
}

.empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card h1 {
  font-size: 18px;
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.field > span {
  color: var(--muted);
}

.btn.full {
  justify-content: center;
  width: 100%;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(420px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.dialog h2 {
  font-size: 16px;
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 20;
  max-width: calc(100vw - 32px);
}

@media (max-width: 720px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content {
    padding: 16px 12px 40px;
  }

  .topbar {
    padding: 10px 12px;
  }

  #search {
    width: 100%;
  }

  .panel-actions {
    width: 100%;
  }
}
