/* Insula license admin. Colour tokens follow the landing site (navy + amber);
   system fonts only, because the CSP allows no external font hosts. */

:root {
  --bg: #0c1526;
  --band: #0f1b31;
  --surface: #13213a;
  --surface-hi: #182a49;
  --line: #26354f;
  --ink: #e8edf5;
  --ink-muted: #9eabc1;
  --accent: #f0b44c;
  --accent-strong: #f7c977;
  --on-accent: #1b1304;
  --stop: #f08a7e;
  --stop-bg: rgb(240 138 126 / 0.12);
  --ok: #8fd6b0;
  --ok-bg: rgb(143 214 176 / 0.12);
  --warn: #f0b44c;
  --warn-bg: rgb(240 180 76 / 0.12);
  --info: #9db8e8;
  --info-bg: rgb(157 184 232 / 0.12);
  --focus: #f7c977;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9;
    --band: #e8ecf3;
    --surface: #ffffff;
    --surface-hi: #f6f8fc;
    --line: #cfd7e4;
    --ink: #101c30;
    --ink-muted: #47566e;
    --accent: #8f5300;
    --accent-strong: #6f4000;
    --on-accent: #ffffff;
    --stop: #b23a2e;
    --stop-bg: rgb(178 58 46 / 0.08);
    --ok: #1d7a4c;
    --ok-bg: rgb(29 122 76 / 0.09);
    --warn: #8f5300;
    --warn-bg: rgb(143 83 0 / 0.09);
    --info: #2f5597;
    --info-bg: rgb(47 85 151 / 0.08);
    --focus: #8f5300;
    --shadow: 0 1px 2px rgb(16 28 48 / 0.06), 0 8px 24px rgb(16 28 48 / 0.06);
    color-scheme: light;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2 {
  margin: 0;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.05rem;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-strong);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[tabindex="-1"]:focus {
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

.small {
  font-size: 0.85rem;
}

.mono {
  font-family: var(--mono);
  font-size: 0.9em;
}

.selectable {
  user-select: all;
  word-break: break-all;
}

.prewrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.noscript {
  padding: 2rem 1rem;
  text-align: center;
}

/* ---- Shell ------------------------------------------------------------ */

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 20;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--band);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  color: var(--ink);
}

.brand img {
  border-radius: 6px;
}

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--ink-muted);
  font-size: 0.9rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--line);
}

.nav {
  flex: 1 1 auto;
}

.nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav a {
  display: block;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
}

.nav a:hover {
  color: var(--ink);
  background: var(--surface);
}

.nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--surface-hi);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.whoami {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.whoami-email {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1rem 4rem;
}

.main-bare {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem 1rem;
}

.loading {
  padding: 2rem 0;
}

/* ---- Page structure ----------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.page-title {
  font-size: 1.5rem;
  overflow-wrap: anywhere;
}

.title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.page-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.crumbs {
  margin-bottom: -0.75rem;
  color: var(--ink-muted);
  font-size: 0.875rem;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card-danger {
  border-color: var(--stop);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-narrow {
  max-width: 40rem;
  width: 100%;
}

.empty {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink-muted);
}

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.35rem;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-hi);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
}

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

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

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
}

.btn-danger {
  background: transparent;
  border-color: var(--stop);
  color: var(--stop);
}

.btn-danger:hover {
  background: var(--stop-bg);
  border-color: var(--stop);
  color: var(--stop);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-hi);
  border-color: var(--line);
}

.btn-sm {
  min-height: 2rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

/* ---- Forms -------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field label {
  font-weight: 600;
  font-size: 0.9rem;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.4rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

textarea {
  resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--ink-muted);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}

[aria-invalid="true"] {
  border-color: var(--stop);
}

.field-hint {
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.field-error {
  color: var(--stop);
  font-size: 0.85rem;
  font-weight: 500;
}

.alert,
.notice {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stop);
  background: var(--stop-bg);
  color: var(--ink);
}

.notice {
  border-color: var(--warn);
  background: var(--warn-bg);
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 11rem 11rem;
  gap: 0.75rem;
  align-items: end;
}

/* ---- Badges ------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  white-space: nowrap;
}

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

.badge-expired {
  color: var(--warn);
  background: var(--warn-bg);
}

.badge-revoked {
  color: var(--stop);
  background: var(--stop-bg);
}

.badge-enterprise,
.badge-admin {
  color: var(--info);
  background: var(--info-bg);
}

.badge-community,
.badge-operator {
  color: var(--ink-muted);
  background: transparent;
}

/* ---- Tiles -------------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  height: 100%;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: border-color 0.12s, background-color 0.12s;
}

a.tile:hover {
  color: var(--ink);
  background: var(--surface-hi);
  border-color: var(--ink-muted);
}

.tile-ok {
  border-left-color: var(--ok);
}

.tile-warn {
  border-left-color: var(--warn);
}

.tile-stop {
  border-left-color: var(--stop);
}

.tile-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.tile-label {
  color: var(--ink-muted);
  font-size: 0.875rem;
}

/* ---- Tables ------------------------------------------------------------- */

.table-wrap {
  /* Contain absolutely positioned children (.sr-only) so they scroll with the table. */
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.table th,
.table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: var(--surface-hi);
  color: var(--ink-muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.table tbody tr:hover {
  background: var(--surface-hi);
}

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

.table time {
  white-space: nowrap;
}

.table td:first-child {
  min-width: 11rem;
}

.row-link {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.actions-cell {
  white-space: nowrap;
  text-align: right;
}

.actions-cell .btn + .btn {
  margin-left: 0.35rem;
}

.confirm-text {
  margin-right: 0.5rem;
  font-size: 0.875rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 0 0;
}

.results {
  display: flex;
  flex-direction: column;
}

.results[aria-busy="true"] {
  opacity: 0.6;
}

/* ---- Details list ------------------------------------------------------- */

.details {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) 1fr;
  gap: 0.6rem 1.5rem;
  margin: 0;
}

.details dt {
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---- Login -------------------------------------------------------------- */

.login {
  width: 100%;
  max-width: 24rem;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.75rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.login-brand img {
  border-radius: 8px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-title {
  font-size: 1.35rem;
}

/* ---- Toasts ------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(26rem, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm);
  background: var(--surface-hi);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.toast-error {
  border-left-color: var(--stop);
}

.toast span {
  flex: 1;
}

.toast-close {
  padding: 0 0.25rem;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover {
  color: var(--ink);
}

/* ---- Responsive --------------------------------------------------------- */

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

@media (max-width: 720px) {
  .topbar {
    position: static;
  }

  .nav {
    order: 3;
    flex-basis: 100%;
  }

  .whoami {
    margin-left: auto;
  }

  .whoami-email {
    max-width: 10rem;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .filters .field-grow {
    grid-column: 1 / -1;
  }

  .main {
    padding-top: 1.25rem;
  }

  .page-title {
    font-size: 1.3rem;
  }
}

@media (max-width: 480px) {
  .details {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .details dd {
    margin-bottom: 0.6rem;
  }

  .tile-value {
    font-size: 1.45rem;
  }

  .brand-sub {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
