:root {
  --ink: #1d1f21;
  --muted: #66686b;
  --line: #e3e0da;
  --bg: #faf8f5;
  --card: #ffffff;
  --field: #ffffff;
  --accent: #2aa5b8;
  --accent-ink: #ffffff;
  --warn: #8a4b00;
  --warn-bg: #fff4e3;
  --warn-line: #f0c98a;
  --danger: #a4241b;
  --ok-bg: #e6faf4;
  --ok-ink: #0e644e;
  --bad-bg: #fdeceb;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04);
}

html[data-theme="dark"] {
  --ink: #e8e6e1;
  --muted: #a2a09a;
  --line: #35332f;
  --bg: #161614;
  --card: #1e1e1b;
  --field: #262620;
  --accent: #4cc3d4;
  --accent-ink: #10201f;
  --warn: #f0c98a;
  --warn-bg: #2b2317;
  --warn-line: #5a4626;
  --danger: #f08a80;
  --ok-bg: #12332a;
  --ok-ink: #7fe0c0;
  --bad-bg: #3a1c19;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.env {
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.actor {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.actor.admin {
  color: var(--accent);
  border-color: var(--accent);
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  display: grid;
  /* minmax(0,…) stops a wide table from widening the whole page. */
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.card {
  /* Grid children default to min-width:auto, which lets a wide table stretch
     the page instead of scrolling inside .scroll. */
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

[role="tabpanel"] > .card + .card {
  margin-top: 20px;
}

h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

h2 {
  margin: 0 0 12px;
  font-size: 17px;
}

h3 {
  margin: 20px 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.lede {
  margin: 0 0 16px;
  color: var(--muted);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

label.inline {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 4px;
}

input,
select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--field);
  color: var(--ink);
}

select {
  padding-right: 6px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
[role="tabpanel"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  margin-top: 10px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
  margin-top: 0;
}

button.danger {
  background: transparent;
  border-color: var(--line);
  color: var(--danger);
  font-weight: 500;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button[hidden] {
  display: none;
}

.note,
.hint,
.empty {
  color: var(--muted);
  font-size: 13px;
}

.note {
  margin: 12px 0 0;
}

.hint {
  display: block;
  margin: 4px 0 0;
}

.req,
.opt {
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-head h2 {
  margin: 0;
}

.status {
  margin: 0;
  min-height: 22px;
  color: var(--muted);
}

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

.issued {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  border-radius: 10px;
}

.issued p {
  margin: 0 0 10px;
  color: var(--warn);
}

.issue-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.issue-row button {
  margin-top: 0;
}

.key {
  flex: 1 1 320px;
  padding: 8px 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  margin: 0 0 -1px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
}

.tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-top: 14px;
}

.toolbar > div {
  flex: 1 1 140px;
  min-width: 120px;
}

.toolbar button {
  margin-top: 0;
}

.scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

th,
td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.num {
  text-align: right;
}

td.num {
  font-variant-numeric: tabular-nums;
}

td.actions {
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.active {
  background: var(--ok-bg);
  color: var(--ok-ink);
}

.badge.suspended {
  background: var(--bad-bg);
  color: var(--danger);
}

td button {
  margin: 0 4px 0 0;
  padding: 5px 10px;
  font-size: 13px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 0;
}

.facts div {
  min-width: 0;
}

.facts dt {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.facts dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  main {
    padding: 16px 12px 48px;
  }

  .card {
    padding: 16px;
  }

  .topbar {
    flex-wrap: wrap;
    padding: 12px;
  }

  .env {
    display: none;
  }
}
