*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
}

html[data-gate="locked"] .admin-shell {
  display: none;
}

html[data-gate="locked"] body {
  background: var(--color-sidebar);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: var(--text-md);
  line-height: var(--leading-body);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-secondary);
  opacity: 1;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  line-height: var(--leading-tight);
  letter-spacing: -0.03em;
}

a {
  color: var(--color-primary-dark);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.skip-link {
  position: absolute;
  left: var(--space-md);
  top: -48px;
  z-index: 100;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  background: var(--color-amber);
  color: var(--color-text);
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-md);
}

.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;
}

.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--space-lg) var(--space-md);
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-white);
  font-weight: 700;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand img {
  width: 32px;
  height: 32px;
}

.sidebar-kicker {
  margin: var(--space-lg) var(--space-sm) var(--space-sm);
  color: #8eaeB3;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-nav a {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
}

.side-nav a:hover,
.side-nav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-white);
}

.side-nav a[aria-current="page"] {
  box-shadow: inset 3px 0 0 var(--color-amber);
}

.sidebar-foot {
  margin-top: auto;
  padding-top: var(--space-md);
}

.admin-main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: var(--topbar-height);
  padding: 0 var(--space-lg);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--color-divider);
}

.topbar h1 {
  margin: 0;
  font-size: var(--text-xl);
}

.topbar-status {
  margin-left: auto;
}

.page {
  width: min(1180px, calc(100% - 48px));
  margin: var(--space-lg) auto var(--space-2xl);
}

.page > * + * {
  margin-top: var(--space-md);
}

.card .state,
.card > p {
  margin-top: var(--space-md);
}

.nav-toggle {
  display: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-outline);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  cursor: pointer;
}

.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 16px;
  height: 2px;
  margin: 0 auto;
  background: var(--color-text);
  position: relative;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-toggle-bars::before { top: -5px; }
.nav-toggle-bars::after { top: 5px; }

.metric-grid,
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.card-grid.cols-2 {
  grid-template-columns: 1.2fr 0.8fr;
}

.card {
  padding: var(--space-md);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-white);
  box-shadow: var(--shadow-soft);
}

.card h2 {
  margin-bottom: var(--space-sm);
  font-size: var(--text-lg);
}

.metric strong {
  display: block;
  margin: var(--space-sm) 0 2px;
  font-size: 1.6rem;
  letter-spacing: -0.04em;
}

.metric-kicker {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-note,
.metric-scope {
  margin: 8px 0 0;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
}

.metric-alert { box-shadow: inset 3px 0 0 var(--color-coral); }

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.notice-wrap,
.profile-wrap { position: relative; }

.icon-button,
.profile-chip {
  border: 1px solid var(--color-outline);
  background: var(--color-white);
  cursor: pointer;
}

.icon-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  color: var(--color-text);
}

.notice-count {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--color-coral);
  color: var(--color-white);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  min-height: 44px;
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-pill);
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-white);
  font-size: 12px;
  font-weight: 700;
}

.profile-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: left;
}

.profile-copy strong,
.profile-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-copy span {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
}

.flyout {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  width: min(280px, 80vw);
  padding: var(--space-md);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-white);
  box-shadow: var(--shadow-card);
}

.flyout-title { margin-bottom: 8px; font-weight: 600; }

.flyout ul { margin: 0; padding: 0; list-style: none; }

.flyout li + li { border-top: 1px solid var(--color-divider); }

.flyout a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  text-decoration: none;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.filters .field,
.filters .field-error { margin: 0; }

.filters-actions,
.filters .field-error { grid-column: 1 / -1; }

.freshness,
.lede { margin: 0; }

.lede,
.freshness { color: var(--color-text-secondary); font-size: var(--text-sm); }

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.chart-card h3 { margin: var(--space-md) 0 var(--space-sm); font-size: var(--text-md); }

.chart-svg { display: block; width: 100%; height: auto; }

.chart-label {
  fill: var(--color-text-secondary);
  font-family: var(--font-family);
  font-size: 11px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.legend li { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); }

.swatch { width: 10px; height: 10px; border-radius: 50%; }

.hbar {
  display: grid;
  grid-template-columns: 9.5rem 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  font-size: var(--text-sm);
}

.hbar-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
}

.hbar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-primary);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-tile {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-muted);
}

.stat-tile h3 { margin: 0 0 6px; font-size: var(--text-sm); }

.stat-tile strong { display: block; margin-bottom: 6px; font-size: 1.2rem; }

.stat-tile p,
.plain-list { margin: 0; }

.plain-list { padding-left: 18px; font-size: var(--text-sm); }

body[data-page="dashboard"] .page { width: min(1280px, calc(100% - 48px)); }

.metric span,
.muted {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 0 14px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.btn-primary:hover { background: var(--color-primary-dark); color: var(--color-white); }

.btn-secondary {
  border-color: var(--color-outline);
  background: var(--color-white);
  color: var(--color-text);
}

.btn-ghost { color: var(--color-primary-dark); }
.btn-danger { background: var(--color-error); color: var(--color-white); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-sm); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-md);
}

.field-label { font-size: var(--text-sm); font-weight: 600; }

.field input,
.field select,
.field textarea,
.toolbar input,
.toolbar select {
  width: 100%;
  min-height: var(--tap-min);
  padding: 10px 12px;
  border: 1.5px solid var(--color-outline);
  border-radius: var(--radius-sm);
  background: var(--color-white);
}

.toolbar input,
.toolbar select { width: auto; min-width: 180px; }

.field textarea { min-height: 120px; resize: vertical; }

.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] { border-color: var(--color-error); }

.hint,
.field-error { margin: 0; font-size: var(--text-sm); }
.hint { color: var(--color-text-secondary); }
.field-error { color: var(--color-error); min-height: 1.2em; }

.check {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
  margin-bottom: var(--space-md);
  font-size: var(--text-sm);
}

.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--color-primary); }

.banner {
  margin-bottom: var(--space-md);
  padding: var(--space-md);
  border: 1px solid #f3ddb0;
  border-radius: var(--radius-md);
  background: var(--color-warning-bg);
}

.banner p { margin: 0; }

.banner-error {
  border-color: #f3c7c7;
  background: var(--color-error-bg);
}

.banner-success {
  border-color: #b7e4cc;
  background: var(--color-success-bg);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-white);
}

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-divider);
}

th {
  background: #f7fafa;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tr:last-child td { border-bottom: 0; }
[hidden] { display: none !important; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.pagination p { margin: 0; color: var(--color-text-secondary); font-size: var(--text-sm); }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  font-size: var(--text-xs);
  font-weight: 600;
}

.chip-ok { background: var(--color-success-bg); color: #146847; }
.chip-warn { background: var(--color-warning-bg); color: #8a5a10; }
.chip-bad { background: #ffe8e5; color: #9c3a32; }
.chip-muted { background: var(--color-surface-muted); color: var(--color-text-secondary); }

.state {
  padding: var(--space-xl) var(--space-md);
  border: 1px dashed var(--color-outline);
  border-radius: var(--radius-md);
  background: var(--color-white);
  text-align: center;
}

.state p { color: var(--color-text-secondary); }

.state-error {
  border-style: solid;
  border-color: #f3c7c7;
  background: var(--color-error-bg);
}

.loader {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-text-secondary);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-divider);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.skeleton-stack { display: grid; gap: 10px; }
.skeleton {
  height: 42px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #e7eeee, #f8fbfb, #e7eeee);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.modal {
  width: min(460px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.modal::backdrop { background: rgba(14, 42, 46, 0.62); }
.modal-body { padding: var(--space-lg); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-sm); }

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(340px, calc(100% - 32px));
}

.toast {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-sidebar);
  color: var(--color-white);
}

.toast-success { background: #146847; }
.toast-error { background: #9d3030; }

.auth-screen,
.gate-screen {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: var(--space-lg);
  background:
    radial-gradient(circle at top left, rgba(8, 127, 140, 0.18), transparent 36%),
    var(--color-sidebar);
}

.auth-screen {
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  padding: 28px 20px 20px;
  background:
    radial-gradient(ellipse 70% 42% at 50% 0%, rgba(8, 127, 140, 0.42), transparent 58%),
    var(--color-sidebar);
}

.auth-stack {
  grid-row: 2;
  display: grid;
  width: min(420px, 100%);
}

.auth-card .brand {
  margin-bottom: var(--space-lg);
  color: var(--color-text);
  text-decoration: none;
}

.auth-kicker {
  margin: 0 0 var(--space-sm);
  color: var(--color-primary-dark);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.auth-screen .auth-card {
  border: 1px solid rgba(14, 42, 46, 0.06);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.auth-screen .btn-row .btn-primary {
  flex: 1 1 160px;
}

.auth-return {
  grid-row: 3;
  align-self: end;
  margin: 0;
  text-align: center;
}

.auth-return a,
.auth-return a:hover,
.auth-return a:focus-visible {
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
}

.auth-return a:hover,
.auth-return a:focus-visible {
  text-decoration: underline;
}

.auth-card,
.gate-card {
  width: min(440px, 100%);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  background: var(--color-white);
  box-shadow: var(--shadow-card);
}

.gate-card { width: min(560px, 100%); }

.auth-card h1,
.gate-card h1 { margin-bottom: var(--space-sm); font-size: var(--text-2xl); }

.stack { display: grid; gap: var(--space-md); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@media (min-width: 1100px) {
  .filters { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (max-width: 1024px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid.cols-2,
  .chart-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
  .admin-shell { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    z-index: 40;
    width: min(300px, 88vw);
    transform: translateX(-105%);
    transition: transform var(--motion-fast) var(--ease);
  }
  .sidebar:not(.is-open) { visibility: hidden; }
  .sidebar.is-open { transform: none; visibility: visible; }
  .page,
  body[data-page="dashboard"] .page,
  body[data-page="users"] .page,
  body[data-page="user"] .page,
  body[data-page="verifications"] .page,
  body[data-page="verification"] .page,
  body[data-page="analytics"] .page { width: min(100% - 32px, 1280px); }
  .topbar { padding-inline: var(--space-md); }
  .profile-copy { display: none; }
  .profile-chip { padding-right: 4px; }
  .topbar h1 { font-size: 1.05rem; }
  .pagination { flex-direction: column; align-items: stretch; }
  .table-wrap thead { display: none; }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }
  .table-wrap tr { border-bottom: 1px solid var(--color-divider); }
  .table-wrap td {
    display: flex;
    justify-content: space-between;
    gap: var(--space-md);
    border-bottom: 0;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--color-text-secondary);
    font-weight: 600;
  }
}

@media (max-width: 720px) {
  .filters,
  .metric-grid,
  .stat-row { grid-template-columns: 1fr; }
  .hbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name value" "track track";
  }
  .hbar > :first-child { grid-area: name; }
  .hbar-track { grid-area: track; }
  .hbar > :last-child { grid-area: value; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

body[data-page="users"] .page,
body[data-page="user"] .page,
body[data-page="verifications"] .page,
body[data-page="verification"] .page { width: min(1280px, calc(100% - 48px)); }

@media (min-width: 801px) {
  body[data-page="users"] .table-wrap table { min-width: 1180px; }
body[data-page="reports"] .table-wrap table { min-width: 1180px; }
  body[data-page="users"] td.mono { white-space: nowrap; }
}

.directory-note { margin: 0; color: var(--color-text-secondary); font-size: var(--text-sm); }
.filters > .hint { grid-column: 1 / -1; margin: 0; }

.audit-change {
  margin: 0;
  white-space: pre-wrap;
  font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.faq-editor { display: grid; gap: var(--space-md); }

.person { display: flex; align-items: center; gap: 10px; min-width: 10rem; }
.person-photo,
.avatar.lg {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-surface-muted);
}
.avatar.lg { width: 72px; height: 72px; display: grid; place-items: center; font-weight: 700; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85em; overflow-wrap: anywhere; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.9fr); gap: var(--space-md); }

@media (max-width: 800px) {
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
.meta { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: 8px 12px; margin: 0; }
.meta dt { margin: 0; color: var(--color-text-secondary); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.photo-row { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-row img { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; background: var(--color-surface-muted); }
.ticket-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.stack-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.stack-list li, .note { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--color-surface-muted); }
.identity-head { display: flex; gap: 14px; align-items: center; margin-bottom: var(--space-md); }

.queue-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 var(--space-md); }
.queue-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--color-outline);
  border-radius: var(--radius-pill);
  background: var(--color-white);
  color: var(--color-text);
  text-decoration: none;
}
.queue-tabs a[aria-current="page"] { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-white); }
.evidence-shot { display: block; max-width: min(100%, 420px); max-height: 320px; border-radius: 12px; background: var(--color-surface-muted); }

@media (min-width: 801px) {
  body[data-page="analytics"] .page { width: min(1120px, calc(100% - 48px)); }
}
body[data-page="analytics"] .metric-grid { margin-top: var(--space-md); }
.signal-alert td:first-child { box-shadow: inset 3px 0 0 var(--color-coral); }
.signal-observed td:first-child { box-shadow: inset 3px 0 0 var(--color-amber); }

body.density-compact .page { font-size: 0.875rem; }
body.density-compact td,
body.density-compact th { padding-block: 8px; }
