/* KeyGate portal styles — the "calm slate console" design language.
 *
 * Source of truth: KeyGate design system (Pass 1). Dark is primary; the
 * [data-theme="light"] block is the warm-white parallel. Every surface paints
 * from the tokens below — no one-off colours. Framework-free; loaded by the
 * app shell (portal/app.html), the standalone pages (portal/base.html), and
 * the allauth entrance pages (templates/account/). IBM Plex is vendored under
 * fonts/ (SIL OFL 1.1); it degrades to system-ui if the files are absent.
 *
 * The accent is brand-neutral azure — an intentional design-system decision,
 * NOT GMG green. Don't reintroduce a brand-green accent here. */

/* ---- Fonts (vendored) ---------------------------------------------------- */
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-600.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-700.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-600.woff2") format("woff2");
}

/* ---- Tokens -------------------------------------------------------------- */
:root {
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;

  /* surfaces (dark · primary) — elevation by tint, not heavy shadow */
  --bg: #0b0d11;
  --surface: #13161c;
  --surface-2: #1a1e26;
  --surface-3: #222732;
  --border: #262c37;
  --border-strong: #333a47;

  /* text */
  --text: #e9ecf2;
  --text-2: #9aa3b2;
  --text-3: #646d7c;

  /* accent (single, brand-neutral azure) */
  --accent: #5e8bef;
  --accent-hover: #7ba1ff;
  --accent-press: #456fd6;
  --accent-bg: rgba(94, 139, 239, 0.12);

  /* financial semantics — green = earned (== positive delta); rose = negative money only */
  --revenue: #46b07f;
  --payable: #2ba3b0;
  --fee: #d6a23e;
  --discount: #9b7cf0;
  --refund: #e56781;
  --pos: #46b07f;
  --neg: #e56781;

  /* operational semantics — amber→orange→red is a single depletion ramp */
  --healthy: #46b07f;
  --low: #e0b341;
  --critical: #e8843f;
  --depleted: #e5556b;
  --failed: #e5556b;

  /* radius */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 12px;
  --r-pill: 999px;

  /* spacing · 4px base */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* elevation */
  --e1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --e2: 0 6px 18px rgba(0, 0, 0, 0.45);
  --e3: 0 16px 40px rgba(0, 0, 0, 0.55);

  /* motion */
  --dur-fast: 120ms;
  --dur: 180ms;
  --dur-slow: 280ms;
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);

  /* type scale — display/h1/h2/h3/body/small/label (theme-independent) */
  --fs-display: 40px;
  --lh-display: 1.1;
  --fs-h1: 24px;
  --lh-h1: 1.25;
  --fs-h2: 19px;
  --lh-h2: 1.3;
  --fs-h3: 16px;
  --lh-h3: 1.4;
  --fs-body: 14px;
  --lh-body: 1.55;
  --fs-small: 13px;
  --lh-small: 1.5;
  --fs-label: 11px;
  --lh-label: 1.4;
  --tracking-label: 0.08em;
  /* type-scale leaves — sizes the seven steps above don't cover. A control or
     surface that needs a size not here is a gap in the tokens, not the screen:
     add a step rather than hand-rolling a magic px (the colour-token rule,
     applied to type). */
  --fs-btn-sm: 12px; /* .btn--sm */
  --fs-field-label: 12px; /* .field > label, .errorlist, .header-meta, .card__sub */
  --fs-tag: 10px; /* .tag, .tenant-group__label, .nav-group-label */
  --fs-micro: 9px; /* .tenant-kind, .switcher__menu-label */
  --fs-hero: 28px; /* .hero__title — orphan between --fs-h1 (24) and --fs-display (40) */
  --fs-modal-title: 18px; /* .modal__title, .input-code */

  /* control geometry — every interactive control lands on one of two height
     tiers, so buttons / selects / inputs that share a row share a height.
     Height comes from a tier token + box-sizing, never from hand-tuned padding.
     Theme-independent, so it lives only here (not [data-theme="light"]). */
  --ctrl-h-md: 38px; /* default: standalone buttons, form inputs, selects */
  --ctrl-h-sm: 32px; /* compact: table-row actions (btn--sm + select--sm) */
  --ctrl-pad-x: 14px; /* horizontal padding, md tier */
  --ctrl-pad-x-sm: 12px; /* horizontal padding, sm tier */

  /* data-viz ramps (dark) — categorical caps at 8 then "Other"; sequential
     feeds volume visualMaps; diverging runs refund(neg) ↔ positive */
  --cat-1: #5e8bef;
  --cat-2: #46b07f;
  --cat-3: #e0a73e;
  --cat-4: #9b7cf0;
  --cat-5: #e56781;
  --cat-6: #2ba3b0;
  --cat-7: #e8843f;
  --cat-8: #cf6fc0;
  --seq-1: #10243f;
  --seq-2: #163a63;
  --seq-3: #1f5394;
  --seq-4: #2e6fc7;
  --seq-5: #4f8df0;
  --seq-6: #84b0f7;
  --seq-7: #bcd4fb;
  --div-1: #e5556b;
  --div-2: #e0876f;
  --div-3: #c9a98a;
  --div-4: #9aa3b2;
  --div-5: #7fbf9a;
  --div-6: #5bb878;
  --div-7: #2f9e63;

  --sidebar-w: 236px;
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --surface-3: #e6e9ef;
  --border: #e1e4ea;
  --border-strong: #cfd4dd;
  --text: #161a21;
  --text-2: #586173;
  --text-3: #8a92a1;
  --accent: #2f64d8;
  --accent-hover: #1f53c2;
  --accent-press: #1a47a8;
  --accent-bg: rgba(47, 100, 216, 0.1);
  --revenue: #1f9d63;
  --payable: #18909e;
  --fee: #b5821f;
  --discount: #7a57d4;
  --refund: #d63b58;
  --pos: #1f9d63;
  --neg: #d63b58;
  --healthy: #1f9d63;
  --low: #c79320;
  --critical: #d96a1f;
  --depleted: #d63b58;
  --failed: #d63b58;
  /* data-viz ramps (light) */
  --cat-1: #2f64d8;
  --cat-2: #1f9d63;
  --cat-3: #bd8a1d;
  --cat-4: #7a57d4;
  --cat-5: #d63b58;
  --cat-6: #18909e;
  --cat-7: #cf6b1f;
  --cat-8: #b948a8;
  --seq-1: #eaf1fd;
  --seq-2: #c4d8f8;
  --seq-3: #94b6f0;
  --seq-4: #5e8bef;
  --seq-5: #3a66c9;
  --seq-6: #274aa0;
  --seq-7: #16306e;
  --div-1: #d63b58;
  --div-2: #df8a73;
  --div-3: #cbb39a;
  --div-4: #8a92a1;
  --div-5: #7cba94;
  --div-6: #3fa56e;
  --div-7: #1f9d63;
  --e1: 0 1px 2px rgba(20, 30, 55, 0.08);
  --e2: 0 6px 18px rgba(20, 30, 55, 0.1);
  --e3: 0 16px 40px rgba(20, 30, 55, 0.14);
}

/* ---- Reset / base -------------------------------------------------------- */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

::selection {
  background: rgba(94, 139, 239, 0.3);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Numbers: mono + tabular, everywhere money or counts appear. */
.mono,
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.muted {
  color: var(--text-2);
}
.text-3 {
  color: var(--text-3);
}

/* ===========================================================================
   APP SHELL — portal/app.html (sidebar + top bar + scrolling content)
   =========================================================================== */
.app {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
  color: var(--text);
}

/* ---- Sidebar ------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  align-self: flex-start;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 16px;
}

.brand__mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent);
  position: relative;
  flex: none;
  box-shadow: var(--e1);
}
.brand__mark::before {
  content: "";
  position: absolute;
  inset: 7px 9px;
  border-left: 2.5px solid var(--bg);
  border-bottom: 2.5px solid var(--bg);
  border-radius: 0 0 0 3px;
}
.brand__mark::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bg);
}
.brand__name {
  font-size: var(--fs-h3);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.nav-group-label {
  font-size: var(--fs-tag);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
  padding: 0 10px 8px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: var(--fs-small);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-icon {
  width: 17px;
  height: 17px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}
.nav-item.is-active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.is-active .nav-icon {
  opacity: 1;
}

/* ---- Context switcher (company / membership selector) -------------------- */
.switcher {
  position: relative;
  margin: 0 0 18px;
}

.switcher__button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-sans);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease);
}
.switcher__button:hover {
  border-color: var(--border-strong);
}
.switcher__button[disabled] {
  cursor: default;
}
.switcher__button[disabled]:hover {
  border-color: var(--border);
}

.tenant-initial {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 5px;
  background: var(--accent-bg);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-weight: 600;
  display: grid;
  place-items: center;
}

.switcher__meta {
  min-width: 0;
  flex: 1;
}
.tenant-kind {
  display: block;
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}
.tenant-name {
  display: block;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.switcher__caret {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--text-3);
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--dur-fast) var(--ease);
}

.switcher__menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--e2);
  padding: var(--sp-1);
  display: none;
}
.switcher.is-open .switcher__menu {
  display: block;
}
.switcher.is-open .switcher__caret {
  transform: rotate(180deg);
}

.switcher__group + .switcher__group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.switcher__menu-label {
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
  padding: 8px 8px 6px;
}
.switcher__option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: var(--sp-2);
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  color: var(--text);
  text-align: left;
}
.switcher__option:hover {
  background: var(--surface-3);
}
.switcher__option.is-current {
  background: var(--accent-bg);
}
.switcher__option.is-current .tenant-name {
  color: var(--accent);
}

/* ---- Top bar ------------------------------------------------------------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.page-title {
  font-size: var(--fs-h1);
  line-height: 1.2;
}
.topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Signed-in user + global account actions live top-right. The user is
   identity-only (display, not a link); Settings and Sign out are the two
   icon-buttons beside it. Page-specific actions go in a .section-header. */
.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.topbar-user__name {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}
.icon-btn.is-active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.icon-btn .nav-icon {
  width: 16px;
  height: 16px;
  opacity: 0.9;
}

/* ---- Content ------------------------------------------------------------- */
.content {
  padding: 24px 28px 56px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.content--narrow {
  max-width: 860px;
  width: 100%;
}

/* ===========================================================================
   COMPONENTS
   =========================================================================== */

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e1);
  padding: 20px 22px;
}
.card--center {
  text-align: center;
}
.card__title {
  font-size: var(--fs-h3);
  font-weight: 600;
  margin: 0 0 2px;
}
.card__sub {
  font-size: var(--fs-field-label);
  color: var(--text-3);
  margin: 0 0 14px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

/* A clickable orientation card (home screen) — icon on top, label/title/body
   stacked beneath. */
.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e1);
  padding: 18px 20px;
  color: var(--text);
  text-decoration: none;
  transition:
    border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}
a.tile:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  color: var(--text);
}
.tile__icon {
  width: 40px;
  height: 40px;
  margin-bottom: 6px;
  flex: none;
  border-radius: var(--r-md);
  background: var(--accent-bg);
  color: var(--accent);
  display: grid;
  place-items: center;
}
.tile__icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tile__label {
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}
.tile__title {
  font-size: var(--fs-h3);
  font-weight: 600;
}
.tile__body {
  font-size: var(--fs-small);
  color: var(--text-2);
  line-height: 1.5;
}

/* Page-section header — title/context on the left, page action(s) on the right.
   Page actions live here, in the content, next to what they act on — NOT in the
   global top bar (which stays breadcrumb + title + global controls). */
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.section-header__title {
  font-size: var(--fs-h3);
  font-weight: 600;
}
.section-header__sub {
  font-size: var(--fs-small);
  color: var(--text-3);
  margin: 2px 0 0;
}
.section-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Hero / welcome block */
.hero {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hero__eyebrow {
  font-size: var(--fs-label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.hero__title {
  font-size: var(--fs-hero);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.hero__sub {
  font-size: var(--fs-body);
  color: var(--text-2);
  max-width: 64ch;
  line-height: 1.6;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--ctrl-h-md);
  padding: 0 var(--ctrl-pad-x);
  font-family: var(--font-sans);
  font-size: var(--fs-small);
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}
.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:hover {
  background: var(--accent-hover);
  color: #fff;
}
.btn--primary:active {
  background: var(--accent-press);
}
.btn--subtle {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn--subtle:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn--danger {
  background: transparent;
  color: var(--neg);
  border-color: color-mix(in srgb, var(--neg) 40%, transparent);
}
.btn--danger:hover {
  background: color-mix(in srgb, var(--neg) 14%, transparent);
  color: var(--neg);
}
.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn--sm {
  min-height: var(--ctrl-h-sm);
  padding: 0 var(--ctrl-pad-x-sm);
  font-size: var(--fs-btn-sm);
}
.btn--block {
  width: 100%;
  justify-content: center;
}
.btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

/* Keyboard focus ring — buttons and links relied on the browser default, which
   is invisible against the accent-filled primary button in the light theme. One
   explicit ring instead: the 2px outline-offset shows the surface behind the
   control, so an accent ring never blends into an accent background, and it
   reads on both themes. :focus-visible keeps it to keyboard nav, not clicks.
   (Inputs/selects keep their own focus style above.) */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* Forms */
.stack > * + * {
  margin-top: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > label,
label.field-label {
  font-weight: 600;
  font-size: var(--fs-field-label);
  letter-spacing: 0.04em;
  color: var(--text-2);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
/* single-line controls sit on the md height tier (shared with .btn / .select) */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
select {
  min-height: var(--ctrl-h-md);
  padding: 0 var(--ctrl-pad-x);
}
/* textarea is multi-line — keep block padding, floor it at the md tier */
textarea {
  min-height: var(--ctrl-h-md);
  padding: 10px var(--ctrl-pad-x);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.errorlist {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  color: var(--neg);
  font-size: var(--fs-field-label);
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: var(--sp-5);
}

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e1);
  /* Corners are rounded on the edge cells (below) so the table can hold row
     dropdowns that extend past its bottom edge without clipping them. */
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}
table.data thead tr {
  background: var(--surface-2);
}
table.data thead tr:first-child th:first-child {
  border-top-left-radius: var(--r-lg);
}
table.data thead tr:first-child th:last-child {
  border-top-right-radius: var(--r-lg);
}
table.data tbody tr:last-child td:first-child {
  border-bottom-left-radius: var(--r-lg);
}
table.data tbody tr:last-child td:last-child {
  border-bottom-right-radius: var(--r-lg);
}
table.data th {
  text-align: left;
  padding: 10px 18px;
  font-size: var(--fs-label);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
table.data td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td {
  border-bottom: none;
}
table.data tbody tr:hover {
  background: var(--surface-2);
}
table.data .num,
table.data .right {
  text-align: right;
}
.cell-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Name + inline "You" tag — the tag stays shorter than the text line so it
   doesn't inflate the row height. */
.cell-user__name {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.35;
}
.tag {
  font-size: var(--fs-tag);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.4;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 1px 7px;
}
.inline-role {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
table.data .right form {
  display: inline-flex;
  margin: 0;
}
/* Space consecutive action forms in a cell (e.g. Resend + Revoke). */
table.data .right form + form {
  margin-left: 6px;
}

/* Custom select — progressively enhances a real <select> so the open menu
   matches the design language (the native option list can't be styled). The
   native <select> is the single source of truth: it submits and is
   keyboard-accessible with no JS, and shows on its own until portal.js adds
   .select--enhanced, which hides it and reveals the styled button + menu. */
.select {
  position: relative;
  display: inline-block;
  min-width: 168px;
}
/* Pre-enhancement (no JS): native control visible, styled chrome hidden. */
.select__native {
  width: 100%;
  min-height: var(--ctrl-h-md);
  padding: 0 var(--ctrl-pad-x);
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
}
.select__button {
  display: none;
}
/* Enhanced: hide the native control, show the styled button. */
.select--enhanced .select__native {
  display: none;
}
.select--enhanced .select__button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: var(--ctrl-h-md);
  padding: 0 var(--ctrl-pad-x);
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease);
}
.select__button:hover {
  border-color: var(--border-strong);
}
.select.is-open .select__button {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
/* Compact tier — drops the select onto --ctrl-h-sm so it lines up with
   .btn--sm in dense rows (e.g. the Members role picker beside Save). Declared
   after the md-tier rules so its higher specificity also wins on source order. */
.select--sm .select__native,
.select--sm.select--enhanced .select__button {
  min-height: var(--ctrl-h-sm);
  padding: 0 var(--ctrl-pad-x-sm);
}
.select__value {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.select__caret {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--text-3);
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--dur-fast) var(--ease);
}
.select.is-open .select__caret {
  transform: rotate(180deg);
}
.select__menu {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 30;
  min-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--e2);
  padding: var(--sp-1);
  display: none;
}
.select.is-open .select__menu {
  display: block;
}
.select__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.select__option:hover,
.select__option:focus-visible {
  background: var(--surface-3);
  outline: none;
}
.select__option.is-selected {
  color: var(--accent);
}
.select__check {
  width: 15px;
  height: 15px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}
.select__option.is-selected .select__check {
  opacity: 1;
}

/* Avatar */
.avatar {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--text-2);
}

/* Empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 40px 24px;
  color: var(--text-2);
}
.empty__mark {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  border: 1.5px dashed var(--border-strong);
}
.empty__title {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
}

/* Messages (django.contrib.messages) */
.messages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.messages li {
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: var(--fs-small);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.messages li.success {
  color: var(--pos);
  border-color: color-mix(in srgb, var(--pos) 38%, transparent);
  background: color-mix(in srgb, var(--pos) 10%, transparent);
}
.messages li.error {
  color: var(--neg);
  border-color: color-mix(in srgb, var(--neg) 38%, transparent);
  background: color-mix(in srgb, var(--neg) 10%, transparent);
}
.messages li.warning {
  color: var(--fee);
  border-color: color-mix(in srgb, var(--fee) 38%, transparent);
  background: color-mix(in srgb, var(--fee) 10%, transparent);
}
.messages li.info {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
  background: var(--accent-bg);
}
/* Light mode: the message tokens are mid-saturation on a near-white tint, so
   text-on-banner falls under AA (4.5:1). Deepen just the text — backgrounds,
   dark mode, and the shared tokens (used for figures/chips) stay as-is. */
[data-theme="light"] .messages li.success {
  color: #17764a;
}
[data-theme="light"] .messages li.error {
  color: #b8334c;
}
[data-theme="light"] .messages li.warning {
  color: #886117;
}
[data-theme="light"] .messages li.info {
  color: #2d5fcd;
}

/* Definition rows (settings read-only facts) */
.deflist {
  display: flex;
  flex-direction: column;
}
.deflist__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.deflist__row:last-child {
  border-bottom: none;
}
.deflist__key {
  color: var(--text-2);
  font-size: var(--fs-small);
}
.deflist__val {
  color: var(--text);
  font-weight: 500;
}

/* Modal — an htmx fragment swapped into #modal-root (e.g. the invite form).
   The overlay is the backdrop; clicking it (or [data-modal-close]) closes.
   Entrance animates on insert; the close handler (portal/app.html) adds
   .closing and removes the node on animationend. No hyperscript needed. */
@keyframes kg-overlay-in {
  from {
    opacity: 0;
  }
}
@keyframes kg-overlay-out {
  to {
    opacity: 0;
  }
}
@keyframes kg-modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}
@keyframes kg-modal-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(2px);
  animation: kg-overlay-in var(--dur-slow) var(--ease);
}
.modal-overlay.closing {
  animation: kg-overlay-out var(--dur-fast) var(--ease) forwards;
}
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--e3);
  padding: var(--sp-6);
  animation: kg-modal-in var(--dur-slow) var(--ease);
}
.modal-overlay.closing .modal {
  animation: kg-modal-out var(--dur-fast) var(--ease) forwards;
}
@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal-overlay.closing,
  .modal,
  .modal-overlay.closing .modal {
    animation: none;
  }
}
.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.modal__title {
  font-size: var(--fs-modal-title);
  font-weight: 600;
}
.modal__close {
  flex: none;
  width: 28px;
  height: 28px;
  margin: -4px -4px 0 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: 20px; /* decorative ✕ glyph, sized to the icon-button, not the type scale */
  line-height: 1;
  cursor: pointer;
}
.modal__close:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ===========================================================================
   STANDALONE PAGES — portal/base.html (chooser, invite accept, invite invalid)
   =========================================================================== */
.portal-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.portal-header__inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.portal-header .brand {
  padding: 0;
}
.header-meta {
  color: var(--text-3);
  font-size: var(--fs-field-label);
  margin-left: auto;
}

/* Signed-in identity on the standalone header (chooser, invite accept). Pushed
   to the right edge of the header band so it mirrors the brand's inset. */
.identity {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.identity__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.identity__name {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.identity__email {
  font-size: var(--fs-label);
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-main {
  max-width: 520px;
  margin: 0 auto;
  padding: 56px 20px;
}
.portal-main--wide {
  max-width: 800px;
}

/* Company chooser — each membership is a full-width clickable row */
.tenant-group + .tenant-group {
  margin-top: 20px;
}
.tenant-group__label {
  font-size: var(--fs-tag);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
  margin: 0 0 10px;
}
.tenant-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tenant-list > li + li {
  margin-top: 10px;
}
/* biome-ignore lint/style/noDescendingSpecificity: disjoint context from
   `table.data .right form` — a chooser-list form is never in a data-table cell. */
.tenant-list form {
  margin: 0;
}
.tenant-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.tenant-option:hover {
  border-color: var(--accent);
  box-shadow: var(--e1);
}
.tenant-option__name {
  font-weight: 600;
  flex: 1;
}

/* In a standalone card (chooser, invite accept), the title needs breathing
   room before the body — the app-shell topbar title is spaced by its own
   flex column, so this is scoped to cards only. */
.card > .page-title {
  margin: 0 0 18px;
}

/* ===========================================================================
   ENTRANCE / AUTH PAGES — allauth overrides under templates/account/
   (sign in, request/confirm code, change password, sign out). Self-contained
   centred card; bypasses greenmamba's Bootstrap layouts entirely.
   =========================================================================== */
.entrance-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  position: relative;
  background:
    radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent), var(--bg);
}
.entrance-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--e2);
  padding: var(--sp-8);
}
.entrance-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}
.entrance-brand .brand__mark {
  width: 30px;
  height: 30px;
}
.entrance-brand__name {
  display: block;
  font-size: 15px; /* sign-in card wordmark — deliberate one-off, between --fs-small and --fs-h3 */
  font-weight: 600;
  letter-spacing: -0.01em;
}
.entrance-brand__sub {
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}
.entrance-title {
  font-size: 22px; /* sign-in card heading — deliberate one-off, between --fs-h2 and --fs-h1 */
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.entrance-sub {
  font-size: var(--fs-small);
  color: var(--text-2);
  line-height: 1.55;
  margin: 0 0 22px;
}
.entrance-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 22px;
}
.entrance-actions--secondary {
  margin-top: 10px;
}
.entrance-link {
  margin: 18px 0 0;
  font-size: var(--fs-small);
  color: var(--text-3);
  text-align: center;
}
.input-code {
  font-family: var(--font-mono);
  letter-spacing: 0.35em;
  text-align: center;
  font-size: var(--fs-modal-title);
  text-transform: uppercase;
}
/* input.is-invalid: type+class (0,1,1) ties input:focus and wins on source order
   below, so the error border holds even while focused — no !important needed. */
input.is-invalid {
  border-color: var(--neg);
}
.field-error {
  display: block;
  margin-top: 6px;
  font-size: var(--fs-field-label);
  color: var(--neg);
}

/* Alerts (auth pages + anywhere) */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: var(--fs-small);
  line-height: 1.5;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.alert svg {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 2px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}
.alert-danger,
.alert-error {
  color: var(--neg);
  background: color-mix(in srgb, var(--neg) 10%, transparent);
  border-color: color-mix(in srgb, var(--neg) 38%, transparent);
}
.alert-warning {
  color: var(--fee);
  background: color-mix(in srgb, var(--fee) 10%, transparent);
  border-color: color-mix(in srgb, var(--fee) 38%, transparent);
}
.alert-success {
  color: var(--pos);
  background: color-mix(in srgb, var(--pos) 10%, transparent);
  border-color: color-mix(in srgb, var(--pos) 38%, transparent);
}
.alert-info {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
}

/* Passkey management pages */
.passkey-list__header {
  margin-bottom: 18px;
}
.passkey-name {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.passkey-name strong {
  overflow-wrap: anywhere;
}
.passkey-meta {
  color: var(--text-3);
  font-size: 12px;
}
.passkey-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* Narrow screens: the sidebar is an icon-only rail — labels/meta are hidden
   while icons, the company initial and nav stay reachable. The switcher menu
   pops out wider than the rail. */
@media (max-width: 820px) {
  :root {
    --sidebar-w: 66px;
  }
  .sidebar {
    padding: 16px 10px;
  }
  .brand {
    justify-content: center;
    padding: 2px 0 14px;
  }
  .brand__name,
  .nav-group-label,
  .nav-item__label,
  .switcher__button .switcher__meta,
  .switcher__caret,
  .topbar-user__name {
    display: none;
  }
  .nav-item {
    justify-content: center;
    gap: 0;
    padding: 10px 0;
  }
  .switcher {
    margin-bottom: 14px;
  }
  .switcher__button {
    justify-content: center;
    padding: var(--sp-2);
  }
  .switcher__menu {
    right: auto;
    width: 232px;
  }
  .content {
    padding: 20px 16px 48px;
  }
  .topbar {
    padding: 14px 16px;
  }
}
