/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  /* Backgrounds — mirrors terrain-governance.com */
  --bg:           #0f1117;
  --surface:      #1a1f2e;
  --panel:        #101b2d;

  /* Borders */
  --border:       #1e2433;
  --border-sub:   #2d3555;

  /* Text */
  --text:         #e2e8f0;
  --muted:        #94a3b8;
  --muted-dark:   #64748b;

  /* Accent colours */
  --indigo:       #6366f1;   /* primary CTA — matches landing page */
  --indigo-hover: #4f51d4;
  --teal:         #60d394;   /* governance / security accent */
  --teal-dim:     rgba(96,211,148,0.15);
  --teal-border:  rgba(96,211,148,0.3);
  --danger:       #ff6b6b;
  --danger-dim:   rgba(255,107,107,0.12);
  --danger-border:rgba(255,107,107,0.3);
  --warn:         #f59e0b;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ──────────────────────────────────────────────────────────────────── */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  font-size: 15px;
}

a {
  color: var(--teal);
  text-decoration: none;
  transition: color 0.15s;
}
a:hover { color: var(--text); }

/* ── Header / nav ──────────────────────────────────────────────────────────── */
header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-shrink: 0;
}

.logo {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.logo span { color: var(--indigo); }

/* ── Defensive fallback: old .logo-img class must never stretch ────────────── */
.tg-admin-header img.logo-img,
.admin-shell img.logo-img,
img.logo-img {
  width: 28px !important;
  height: 28px !important;
  max-width: 28px !important;
  max-height: 28px !important;
  min-width: 28px !important;
  min-height: 28px !important;
  object-fit: contain !important;
  display: block;
  flex: 0 0 28px !important;
}

/* ── Admin partial header ──────────────────────────────────────────────────── */
.tg-admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: 100%;
}

.tg-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
  width: auto;
  max-width: max-content;
  text-decoration: none;
}
.tg-brand:hover { color: inherit; }

/* Belt-and-suspenders sizing — explicit px flex-basis prevents intrinsic-size blowout */
.admin-shell .tg-admin-header .tg-brand-logo,
.tg-admin-header img.tg-brand-logo {
  width: 28px;
  height: 28px;
  max-width: 28px;
  max-height: 28px;
  min-width: 28px;
  min-height: 28px;
  object-fit: contain;
  display: block;
  flex: 0 0 28px;
  border-radius: 5px;
}

.tg-brand-wordmark {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  white-space: nowrap;
  line-height: 1;
}
.tg-brand-wordmark span { color: var(--indigo); }

.tg-admin-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tg-admin-nav::-webkit-scrollbar { display: none; }
.tg-admin-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  white-space: nowrap;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  overflow-x: auto;
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }

nav a, nav .nav-btn {
  color: var(--muted);
  font-size: 0.845rem;
  font-weight: 500;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
nav a:hover, nav .nav-btn:hover,
nav a.active, nav .nav-btn.active {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

nav form { display: contents; }
.signout-btn {
  color: var(--muted);
  font-size: 0.845rem;
  font-weight: 500;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  margin-left: 0.5rem;
  border-left: 1px solid var(--border);
  padding-left: 1rem;
}
.signout-btn:hover { color: var(--text); }

/* ── Main content ──────────────────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 1300px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card:last-child { margin-bottom: 0; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.count-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

/* ── Status badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-active   { color: var(--teal);    background: var(--teal-dim);    border-color: var(--teal-border); }
.badge-disabled { color: var(--muted);   background: rgba(148,163,184,0.08); border-color: var(--border); }
.badge-revoked  { color: var(--danger);  background: var(--danger-dim);  border-color: var(--danger-border); }

/* filter toggle pill */
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--border);
  border: 1px solid var(--border-sub);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  transition: color 0.15s, border-color 0.15s;
}
.filter-toggle:hover { color: var(--text); border-color: var(--indigo); }

/* ── Flash / error notices ─────────────────────────────────────────────────── */
.flash {
  background: var(--teal-dim);
  border: 1px solid var(--teal-border);
  color: var(--teal);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}
.error {
  background: var(--danger-dim);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 0 -1.5rem -1.5rem; }
.table-wrap table { border-radius: 0 0 12px 12px; }

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

thead tr { background: rgba(0,0,0,0.18); }
th {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted-dark);
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}
td {
  font-size: 0.855rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.025); }

td.cell-primary   { font-weight: 600; }
td.cell-muted     { color: var(--muted); font-size: 0.8rem; }
td.cell-mono      { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: 0.78rem; color: var(--muted); }
td.cell-warn      { color: var(--warn); font-weight: 600; }

.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  color: var(--muted-dark);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.875rem; margin-top: 0.35rem; }

/* ── Section headings within cards ────────────────────────────────────────── */
.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1rem;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group { flex: 1; min-width: 180px; }
.form-group-auto { flex: 0 0 auto; }

label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
  display: block;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-sub);
  color: var(--text);
  border-radius: 6px;
  padding: 0.55rem 0.8rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  cursor: pointer;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn, button[type="submit"], button[type="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.855rem;
  padding: 0.55rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.4;
}
.btn-primary, button[type="submit"] {
  background: var(--indigo);
  color: #fff;
  border-color: var(--indigo);
}
.btn-primary:hover, button[type="submit"]:hover {
  background: var(--indigo-hover);
  border-color: var(--indigo-hover);
  color: #fff;
}
.btn-secondary {
  background: transparent;
  color: var(--muted);
  border-color: var(--border-sub);
}
.btn-secondary:hover { border-color: var(--indigo); color: var(--text); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }

/* ── Grid helpers ──────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 1rem; }
@media (min-width: 800px) {
  .grid.two   { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.four  { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.muted       { color: var(--muted); }
small, .small { font-size: 0.8rem; color: var(--muted); }
.mt-1 { margin-top: 0.75rem; }
.mt-2 { margin-top: 1.25rem; }
.mt-3 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.75rem; }
.flex { display: flex; align-items: center; gap: 0.5rem; }
