/*
 * identity-portal design system.
 *
 * One stylesheet, no inline styles (the CSP forbids them), which keeps
 * the whole visual surface reviewable in one place. Goals: simple,
 * structured, and accessible — WCAG 2.1 AA contrast, visible focus,
 * honours prefers-color-scheme and prefers-reduced-motion, semantic
 * landmarks, and comfortable touch targets.
 */

/* ---- design tokens ---- */
:root {
  color-scheme: light dark;

  /* spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  --radius: 10px;
  --radius-sm: 6px;
  --maxw: 56rem;
  --maxw-auth: 24rem;

  /* fluid type */
  --text-sm: 0.875rem;
  --text-base: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --text-lg: 1.2rem;
  --text-xl: clamp(1.4rem, 1.3rem + 0.5vw, 1.75rem);

  /* light palette (AA-checked against its pairings) */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #1a1f27;
  --muted: #56616f;
  --border: #d4dae2;
  --accent: #2b4ad7;        /* white text on this ≈ 6.4:1 */
  --accent-strong: #213cb4;
  --accent-text: #214bce;   /* on --surface ≈ 6:1 (links) */
  --focus: #1d4ed8;
  --danger: #b3261e;        /* white text ≈ 6:1 */
  --danger-text: #a3261e;
  --ok-bg: #e6f5ec;
  --ok-text: #14622f;
  --warn-bg: #fdf3e3;
  --warn-text: #8a5a09;
  --bad-bg: #fdeceb;
  --bad-text: #9c241d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --surface: #1b1f27;
    --surface-2: #232833;
    --text: #e8ecf2;
    --muted: #a3adba;        /* on --surface ≈ 7:1 */
    --border: #303744;
    --accent: #4a63e0;
    --accent-strong: #6177e8;
    --accent-text: #93a6ff;  /* on --surface ≈ 6:1 */
    --focus: #93a6ff;
    --danger: #c8453d;
    --danger-text: #f3a39d;
    --ok-bg: #14301f;
    --ok-text: #8fe0ac;
    --warn-bg: #332810;
    --warn-text: #f0c879;
    --bad-bg: #371a18;
    --bad-text: #f3a39d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 var(--space-4);
  font-weight: 650;
}

h1 {
  font-size: var(--text-xl);
}

h2 {
  font-size: var(--text-lg);
  margin-top: var(--space-6);
}

p {
  margin: 0 0 var(--space-4);
}

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

a:hover {
  text-decoration-thickness: 2px;
}

/* one consistent, high-contrast focus indicator everywhere */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ---- skip link ---- */
.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -3rem;
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  color: var(--accent-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: var(--space-3);
}

/* ---- layout ---- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

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

.brand-mark {
  color: var(--accent);
  flex: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.site-nav__user {
  color: var(--muted);
  font-size: var(--text-sm);
}

.site-main {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5);
  flex: 1;
}

/* auth screens get a narrow, centred column */
body.auth .site-main {
  max-width: calc(var(--maxw-auth) + var(--space-5) * 2);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.site-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--text-sm);
}

.site-footer a {
  color: var(--muted);
}

/* ---- panels / cards ---- */
.panel,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
}

.panel {
  margin-bottom: var(--space-5);
}

/* a panel's own padding is the top spacing; don't add the heading's */
.panel > :first-child {
  margin-top: 0;
}

.auth-card h1 {
  margin-bottom: var(--space-5);
}

.stack > * + * {
  margin-top: var(--space-4);
}

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

/* ---- forms ---- */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field label,
.form-label {
  font-weight: 600;
  font-size: var(--text-sm);
}

.req {
  color: var(--danger-text);
}

input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

input:focus-visible {
  border-color: var(--accent);
}

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

.field__hint {
  font-size: var(--text-sm);
  color: var(--muted);
}

.form-note {
  font-size: var(--text-sm);
  color: var(--muted);
  margin: 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-5);
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
}

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

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

.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

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

.btn--danger {
  background: var(--surface);
  color: var(--danger-text);
  border-color: var(--border);
}

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

/* inline action inside a table row or sentence */
.btn--link {
  min-height: 0;
  padding: 0;
  background: none;
  border: 0;
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.inline-form {
  display: inline;
}

/* ---- alerts ---- */
.alert {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
}

.alert--error {
  background: var(--bad-bg);
  color: var(--bad-text);
  border-color: var(--danger);
}

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

.alert--success {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: var(--ok-text);
}

.alert--info {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

.alert :last-child {
  margin-bottom: 0;
}

/* ---- dashboard tiles ---- */
.tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}

.tile {
  display: flex;
  gap: var(--space-3);
  height: 100%;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.tile:hover {
  border-color: var(--accent);
}

.tile__icon {
  flex: none;
  color: var(--accent);
  margin-top: 2px;
}

/* the text column beside the icon */
.tile > span {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.tile__title {
  display: block;
  font-weight: 650;
}

.tile__desc {
  display: block;
  font-size: var(--text-sm);
  color: var(--muted);
}

/* ---- description lists ---- */
.data-list {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(8rem, max-content) 1fr;
  gap: var(--space-2) var(--space-4);
}

.data-list dt {
  font-weight: 600;
  color: var(--muted);
}

.data-list dd {
  margin: 0;
  word-break: break-word;
}

/* ---- tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table caption {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  color: var(--muted);
}

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

.table thead th {
  background: var(--surface-2);
  font-weight: 650;
  white-space: nowrap;
}

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

.table tbody th {
  font-weight: 600;
}

/* ---- badges (text-bearing, never colour-only) ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

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

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

/* ---- code / one-time secrets ---- */
.mono {
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, monospace;
  font-size: 0.85em;
  word-break: break-all;
}

.code-block {
  display: block;
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  user-select: all;
}

.qr {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  background: #fff;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

details > summary {
  cursor: pointer;
  font-weight: 600;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
