/* carbonlayer.tech Gateway pages -- the §11 subset from GATEWAY-PHASE3-SPEC.md §C.
   A functional placeholder, not the full design language: §11.1 tokens (system font stack,
   type scale, 8pt spacing, radii), light/dark from prefers-color-scheme (§11.3), a focus ring
   that is never suppressed (§11.1 state deltas), and prefers-reduced-motion respected (§11.5).
   No inline styles anywhere (CSP style-src 'self'), so every visual state is a class or the
   `hidden` attribute. */

:root {
  color-scheme: light dark;

  /* §11.1 spacing (8pt base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;
  /* §11.1 radii */
  --r-sm: 8px; --r-md: 16px; --r-lg: 24px; --r-pill: 999px;
  /* §11.1 type */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --text: #1d1d1f;
  --text-2: #55555c;
  --border: #c9c9d0;
  --field-border: #86868b; /* 3.6:1 on white: WCAG 1.4.11 for the only edge a field has */
  --accent: #0a5bd3;
  --accent-hover: #0b4fb4;
  --on-accent: #ffffff;
  --focus: #0a5bd3;
  --error-bg: #fdecec;
  --error-text: #8a1111;
  --error-border: #c62828;
  --ok-bg: #e8f5ec;
  --ok-text: #11562a;
  --badge-bg: #5b2bb5;
  --badge-text: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --tenant: #3b4a5c; /* monogram default when a tenant has no (valid) accent colour */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --surface: #1c1c21;
    --surface-2: #26262c;
    --text: #f2f2f5;
    --text-2: #b4b4bd;
    --border: #4a4a53;
    --field-border: #86868b; /* 4.7:1 on the dark surface */
    --accent: #5ea0ff;
    --accent-hover: #7fb3ff;
    --on-accent: #0b1320;
    --focus: #8cbcff;
    --error-bg: #3a1618;
    --error-text: #ffc9c9;
    --error-border: #ff6b6b;
    --ok-bg: #12301d;
    --ok-text: #b8f0c8;
    --badge-bg: #b89cff;
    --badge-text: #160a33;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 16px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-family: var(--font); font-size: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 24px;
}

h1 { font-size: 34px; line-height: 41px; font-weight: 700; margin: 0 0 var(--s-4); }
h2 { font-size: 22px; line-height: 28px; font-weight: 600; margin: 0 0 var(--s-3); }
h3 { font-size: 17px; line-height: 24px; font-weight: 600; margin: 0 0 var(--s-2); }
p { margin: 0 0 var(--s-4); }
small, .caption { font-size: 13px; line-height: 18px; color: var(--text-2); }
code, .mono { font-family: var(--mono); font-size: 15px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* §11.1: focus ring always visible, never suppressed. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: 2px solid var(--focus); outline-offset: 2px; }

.skip-link {
  position: absolute; left: var(--s-4); top: -100px; z-index: 1100;
  background: var(--surface); color: var(--text); padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm); box-shadow: var(--shadow);
}
.skip-link:focus { top: var(--s-4); }

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

/* ------------------------------------------------------------------ layout */
.topbar {
  display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap;
  padding: var(--s-3) var(--s-5); background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
/* Brand (operator, 2026-10-01): "CarbonLayer" with a smaller "by CY", the two sizes in the
   golden ratio (1.618 : 1) -- 21/13 px in headers, 26/16 px above the sign-in form. */
.brand { display: inline-flex; align-items: baseline; gap: .38em; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-name { font-size: 21px; line-height: 1; font-weight: 600; letter-spacing: -.015em; }
.brand-by { font-size: 13px; line-height: 1; font-weight: 400; color: var(--text-2); letter-spacing: .01em; }
.topbar .spacer { flex: 1; }
.topbar nav ul { display: flex; gap: var(--s-4); list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.topbar nav a, .topbar .link-button { color: var(--text); text-decoration: none; font-size: 15px; }
.topbar nav a:hover, .topbar .link-button:hover { color: var(--accent); }

.page { max-width: 960px; margin: 0 auto; padding: var(--s-6) var(--s-5) var(--s-8); }
.page-narrow { max-width: 520px; }
.page-wide { max-width: 1200px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-5); box-shadow: var(--shadow); margin-bottom: var(--s-5);
}

/* Sign-in (infra/UI-WRITING-GUIDE.md §3): one centred column and one form, no cards -- the way
   Apple, Google and Microsoft lay out sign-in. Password and passkey stay equally reachable
   (§11.6): the passkey is in the username autofill AND one full-width button. */
.auth-body { background: var(--surface); }
.auth { max-width: 400px; margin: 0 auto; padding: var(--s-8) var(--s-5) var(--s-7); }
.auth-brand { display: flex; justify-content: center; margin-bottom: var(--s-6); }
.auth-brand .brand-name { font-size: 26px; }
.auth-brand .brand-by { font-size: 16px; }
.auth h1 { text-align: center; font-size: 32px; line-height: 40px; margin-bottom: var(--s-6); }
.auth .divider { margin: var(--s-4) 0; }
.auth-help { text-align: center; margin: var(--s-4) 0 0; }
.auth-status { text-align: center; margin: var(--s-3) 0 0; }
.password-field { position: relative; }
.password-field input { padding-right: 76px; }
.field-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: 15px; font-weight: 600; color: var(--accent); background: none; border: 0;
  min-height: 44px; min-width: 64px; padding: 0 var(--s-3); border-radius: var(--r-sm); cursor: pointer;
}
.field-toggle:hover { color: var(--accent-hover); }
.auth-help .link-button { text-decoration: none; min-height: 44px; padding: 0 var(--s-2); }
.label-row { display: flex; align-items: center; justify-content: space-between; }
.label-row .link-button { font-size: 15px; font-weight: 400; text-decoration: none; min-height: 44px; padding: 0 0 0 var(--s-2); }
.label-row .link-button:hover { text-decoration: underline; }
.admin-signin { max-width: 400px; margin: var(--s-7) auto; text-align: center; }
.admin-signin .btn { width: 100%; }
.auth-help .link-button:hover { text-decoration: underline; }
.btn-icon { flex: none; }
/* The other single-task pages (invitation, recovery, hand-off) share this column. */
.auth-step h2 { text-align: center; }
.auth-step > p { text-align: center; color: var(--text-2); }
.auth .actions { flex-direction: column; align-items: stretch; }
.auth-step > .btn, .auth .actions .btn { width: 100%; }
.auth-step ul { list-style: none; padding: 0; text-align: center; }
.auth-step li { margin: var(--s-2) 0; }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-4); }
label, legend { font-weight: 600; }
.hint { font-size: 13px; line-height: 18px; color: var(--text-2); font-weight: 400; }
input[type="text"], input[type="password"], input[type="search"], input[type="url"], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--field-border); border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3); min-height: 48px; width: 100%;
}
input:focus-visible, select:focus-visible { border-color: var(--focus); }
input[readonly] { background: var(--surface-2); }
input:disabled, select:disabled { opacity: .4; }
.check { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-4); font-weight: 400; }
.check input { width: 20px; height: 20px; margin: 0; }
.check input:disabled + span { opacity: .4; }
fieldset { border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); margin: 0 0 var(--s-4); }
fieldset .check { margin-bottom: var(--s-2); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 var(--s-4); }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.copy-row { display: flex; gap: var(--s-2); align-items: stretch; }
.copy-row input { flex: 1; font-family: var(--mono); font-size: 14px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: var(--s-2) var(--s-5); border-radius: var(--r-pill);
  border: 1px solid transparent; text-decoration: none;
  transition: background-color .15s ease-in-out;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-small { min-height: 32px; padding: var(--s-1) var(--s-3); font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.link-button { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
.actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------------ messages */
.alert {
  border: 1px solid var(--error-border); background: var(--error-bg); color: var(--error-text);
  border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4);
}
.alert { display: flex; gap: var(--s-2); align-items: flex-start; }
/* Never colour alone (§5): a warning sign, read out as "Error:" (GOV.UK's hidden prefix). The
   first declaration is the fallback for browsers without CSS alt text. */
.alert::before { content: "\26A0\FE0E"; font-weight: 700; }
.alert::before { content: "\26A0\FE0E" / ""; }
.status { min-height: 24px; color: var(--text-2); margin-bottom: var(--s-4); }
.success { background: var(--ok-bg); color: var(--ok-text); border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4); }
.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--text-2); margin: var(--s-4) 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------------ workspace cards (§11.2) */
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: var(--s-4); }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .cards { grid-template-columns: 1fr 1fr 1fr; } }
.card {
  font: inherit; color: var(--text); text-align: left; cursor: pointer; width: 100%;
  display: flex; align-items: center; gap: var(--s-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-4); box-shadow: var(--shadow); min-height: 88px;
}
.card:hover { border-color: var(--accent); }
.card:disabled { opacity: .4; cursor: progress; }
.card-name { font-weight: 600; display: block; }
.card-slug { font-size: 13px; line-height: 18px; color: var(--text-2); display: block; }
.monogram {
  flex: none; width: 48px; height: 48px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px; background: var(--tenant); color: #ffffff;
}
.logo { flex: none; width: 48px; height: 48px; border-radius: var(--r-sm); object-fit: contain; background: var(--surface-2); }
.brand-mark { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }

/* ------------------------------------------------------------------ admin (dense profile) */
.badge {
  display: inline-flex; align-items: center; gap: var(--s-1);
  background: var(--badge-bg); color: var(--badge-text); font-weight: 700; font-size: 13px; line-height: 18px;
  padding: var(--s-1) var(--s-3); border-radius: var(--r-pill); letter-spacing: .02em;
}
.badge::before { content: "\25C6"; } /* shape, not colour alone (§13 distinct treatment) */
.admin-nav ul { display: flex; gap: var(--s-2); list-style: none; padding: 0; margin: 0 0 var(--s-5); flex-wrap: wrap; }
.admin-nav a { display: inline-block; padding: var(--s-1) var(--s-3); border-radius: var(--r-pill); border: 1px solid var(--border); text-decoration: none; color: var(--text); background: var(--surface); }
.admin-nav a:hover { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3); margin: 0; }
.stats div { background: var(--surface-2); border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); }
.stats dt { font-size: 13px; line-height: 18px; color: var(--text-2); }
.stats dd { margin: 0; font-size: 22px; line-height: 28px; font-weight: 600; }
.table-wrap { overflow-x: auto; margin-bottom: var(--s-4); }
table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 20px; }
caption { text-align: left; font-weight: 600; padding-bottom: var(--s-2); }
th, td { text-align: left; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--text-2); }
.chip { display: inline-flex; align-items: center; gap: var(--s-1); background: var(--surface-2); border-radius: var(--r-pill); padding: 0 var(--s-2) 0 var(--s-3); margin: 0 var(--s-1) var(--s-1) 0; }
.chip button { font: inherit; background: none; border: 0; color: var(--text-2); cursor: pointer; min-width: 24px; min-height: 24px; }
.state-disabled::before { content: "\25CB  "; } /* hollow circle + the word, never colour alone */
.state-active::before { content: "\25CF  "; }
.grant-form { display: flex; gap: var(--s-1); flex-wrap: wrap; }
.grant-form select { width: auto; min-height: 32px; padding: 0 var(--s-2); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-4); margin: 0 0 var(--s-4); }
dl.facts dt { color: var(--text-2); }
dl.facts dd { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (prefers-contrast: more) {
  :root { --border: #767676; --text-2: var(--text); }
}

/* Deploy 2 (F6): the account page's passkey list */
.passkey-list { list-style: none; margin: 0; padding: 0; }
.passkey-row { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-3) 0; border-top: 1px solid var(--border); }
.passkey-row:first-child { border-top: 0; }
.passkey-text { flex: 1; min-width: 0; }
.passkey-name { display: block; font-weight: 600; }
.passkey-meta { display: block; color: var(--text-2); font-size: 13px; line-height: 18px; }
.passkey-row .btn { min-height: 36px; padding: var(--s-1) var(--s-4); font-size: 15px; }
