/* Design system for the membership analytics UI, after docs/specs/05-ui-horizon.md ("Horizon").
   Dark: layered near-black surfaces on charcoal, lime for actions, one teal → lime → yellow
   gradient for data. Light: the same accents on white cards over a warm gray canvas.
   Tokens first: every colour below is a token, so light and dark stay in step. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/inter-variable.woff2") format("woff2");
}

:root {
  color-scheme: light;

  /* brand: the same three colours in both themes */
  --teal: #4DD9C6; --lime: #C6EB72; --yellow: #E8D94C;
  --on-accent: #141414;  /* text on a lime, teal or yellow fill */
  --gradient-accent: linear-gradient(135deg, var(--teal), var(--lime), var(--yellow));
  --gradient-accent-x: linear-gradient(90deg, var(--teal), var(--lime), var(--yellow));
  --gradient-header: linear-gradient(135deg, rgba(197, 228, 243, 0.95), rgba(230, 222, 124, 0.6) 45%, transparent 78%);
  --gradient-card: linear-gradient(135deg, #2A2E45, #4A3F73);

  /* data: the brand colours are too pale to draw on white, so light mode has its own steps */
  --data-low: #0D9488; --data-mid: #5E9C16; --data-high: #A38A00;
  --gradient-data-x: linear-gradient(90deg, var(--data-low), var(--data-mid), var(--data-high));
  --area-opacity: 0.2;
  /* Three series that must be told apart. Checked for colour-blind separation, lightness
     and contrast on each theme's card surface; dark mode has its own steps. */
  --series-joined: #0D9488;
  --series-left: #A38A00;
  --series-removed: #2563C9;

  /* action: lime on charcoal here, charcoal on lime in dark mode */
  --accent-bg: #141414; --accent-bg-hover: #2E2E2E; --accent-fg: #C6EB72;
  --accent-text: #3F6B0A;
  --link: #1A66C9;
  --ring: #3F6B0A;
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--ring);
  --switch-track: #8E9285; --switch-knob: #FFFFFF;

  /* neutrals */
  --bg: #EEF0EA; --surface: #FFFFFF; --surface-deep: #F4F5F0; --surface-raised: #FFFFFF;
  --control: #F4F5F0; --control-hover: #E7E9E1; --field: #FFFFFF;
  --border: #E1E3DB; --border-input: #8E9285; --grid-line: #E3E5DD;
  --text: #141414; --text-body: #33352F;
  --text-muted: #686B62;  /* secondary copy people read: 4.5:1 on every surface */
  --text-faint: #8C8F85;  /* chart axes and meta only: 3:1 */
  --icon-muted: #C4C7BC;

  /* semantic */
  --success: #2DA44E; --warning: #D4B106; --danger: #E5484D;
  --success-soft: #E6F6EA; --success-text: #166C2E;
  --warning-soft: #FBF6D5; --warning-text: #6B5600;
  --danger-soft: #FDECEC; --danger-text: #B42318;

  /* shape and depth */
  --radius-sm: 10px; --radius-md: 12px; --radius-card: 20px; --radius-badge: 5px;
  --card-pad: 24px; --gap: 20px; --control-h: 40px;
  --shadow-card: 0 1px 2px rgba(20, 20, 20, 0.04), 0 6px 20px rgba(20, 20, 20, 0.05);
  --shadow-hover: 0 2px 6px rgba(20, 20, 20, 0.06), 0 14px 36px rgba(20, 20, 20, 0.12);

  /* type and motion */
  --font: "Plus Jakarta Sans", "Inter", "SF Pro Display", -apple-system, "Segoe UI", sans-serif;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms; --dur-base: 200ms; --dur-chart: 600ms;
}

[data-theme="dark"] {
  color-scheme: dark;
  --gradient-header: linear-gradient(135deg, rgba(197, 228, 243, 0.26), rgba(230, 222, 124, 0.16) 45%, transparent 78%);
  --data-low: #4DD9C6; --data-mid: #C6EB72; --data-high: #E8D94C;
  --area-opacity: 0.28;
  --series-joined: #22A594;
  --series-left: #A8961E;
  --series-removed: #5B8DEF;
  --accent-bg: #C6EB72; --accent-bg-hover: #D5F28F; --accent-fg: #141414;
  --accent-text: #C6EB72;
  --link: #3A9BFF;
  --ring: #C6EB72;
  --switch-track: #E8D94C; --switch-knob: #141414;
  --bg: #141414; --surface: #1B1B1B; --surface-deep: #0B0B0B; --surface-raised: #0B0B0B;
  --control: #0B0B0B; --control-hover: #262626; --field: #0B0B0B;
  --border: #2A2A2A; --border-input: #606060; --grid-line: #2A2A2A;
  --text: #FFFFFF; --text-body: #D6D6D6; --text-muted: #8C8C8C; --text-faint: #6E6E6E;
  --icon-muted: #4A4A4A;
  --success: #3FB950; --warning: #E8D94C; --danger: #FF5C5C;
  --success-soft: rgba(63, 185, 80, 0.14); --success-text: #56D364;
  --warning-soft: rgba(232, 217, 76, 0.12); --warning-text: #E8D94C;
  --danger-soft: rgba(255, 92, 92, 0.14); --danger-text: #FF8A8A;
  --shadow-card: none;
  --shadow-hover: 0 16px 40px rgba(0, 0, 0, 0.6);
}

/* --- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-body);
  font: 400 14px/20px var(--font);
  font-feature-settings: "tnum", "cv11";
  -webkit-font-smoothing: antialiased;
  transition: background-color 250ms, color 250ms;
}
::selection { background: var(--lime); color: var(--on-accent); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
h1 { font-size: 24px; line-height: 30px; margin: 0; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
h2 { font-size: 20px; line-height: 26px; margin: 0; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
h3 { font-size: 15px; line-height: 20px; margin: 20px 0 8px; font-weight: 600; color: var(--text); }
p { margin: 0; }
strong { color: var(--text); font-weight: 600; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid transparent; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
.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;
}
.muted, .note { color: var(--text-muted); }
.note { display: block; font-size: 13px; line-height: 18px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 50; }
.skip-link:focus { left: 8px; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); box-shadow: var(--shadow-hover); }

/* --- Top navigation ------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg); border-bottom: 1px solid var(--border);
  transition: background-color 250ms;
}
.topbar-inner {
  max-width: 1760px; margin: 0 auto; padding: 0 40px;
  display: flex; align-items: center; gap: 32px; min-height: 68px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); font-size: 18px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .glyph {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 10px; background: var(--gradient-accent); color: var(--on-accent);
}
.brand .glyph svg { width: 20px; height: 20px; }
/* The current page is a darker pill, with no accent colour. */
.nav { display: flex; gap: 6px; flex: 1; min-width: 0; }
.nav > a, .nav-menu > summary {
  position: relative; height: 40px; padding: 0 14px; display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--radius-md);
  color: var(--text-muted); font-size: 14px; line-height: 20px; font-weight: 600; white-space: nowrap;
  cursor: pointer; transition: color var(--dur-fast), background-color var(--dur-fast);
}
.nav > a:hover, .nav-menu > summary:hover, .nav-menu[open] > summary { color: var(--text); text-decoration: none; }
.nav > a:focus-visible, .nav-menu > summary:focus-visible { box-shadow: inset 0 0 0 2px var(--ring); }
.nav > a[aria-current="page"], .nav-menu.current > summary {
  color: var(--text); background: var(--surface-raised); box-shadow: var(--shadow-card);
}
/* Features opens one panel with a section for Events and one for Analytics. */
.nav-menu > summary svg { width: 14px; height: 14px; flex: none; transition: transform var(--dur-base) var(--ease-out); }
.nav-menu[open] > summary svg { transform: rotate(180deg); }
.nav-menu > .menu-list { left: 0; right: auto; top: calc(100% + 10px); min-width: 230px; }
.menu-list a[aria-current="page"] { background: var(--surface-deep); font-weight: 600; }
.menu-list a[aria-current="page"]::after { content: "✓"; margin-left: auto; padding-left: 12px; color: var(--accent-text); font-weight: 700; }
.menu-sep { height: 1px; margin: 4px 0; background: var(--border); }
.menu-list.menu-groups { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 0 8px; padding: 12px; }
.menu-group { display: flex; flex-direction: column; }
.menu-group + .menu-group { padding-left: 8px; border-left: 1px solid var(--border); }
.menu-title { padding: 4px 12px 8px; color: var(--text-muted); font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.topbar-end { display: flex; align-items: center; gap: 20px; }
.topbar form { margin: 0; }

/* Sun · switch · moon */
.theme-switch { display: inline-flex; align-items: center; gap: 10px; color: var(--text-faint); }
.theme-switch svg { width: 20px; height: 20px; flex: none; transition: color var(--dur-base); }
:root:not([data-theme="dark"]) .theme-switch .sun, [data-theme="dark"] .theme-switch .moon { color: var(--text); }
.theme-switch button {
  position: relative; width: 44px; min-height: 0; height: 24px; padding: 0; border: 0; border-radius: 999px;
  background: var(--switch-track); box-shadow: none; cursor: pointer;
}
.theme-switch button:hover { background: var(--switch-track); filter: brightness(1.08); }
.theme-switch button:focus-visible { box-shadow: var(--focus-ring); border-radius: 999px; }
.theme-switch button::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--switch-knob); transition: transform var(--dur-base) var(--ease-out);
}
[data-theme="dark"] .theme-switch button::after { transform: translateX(20px); }

/* Avatar and its menu */
.user-menu { padding-left: 20px; border-left: 1px solid var(--border); }
.user-menu > summary.avatar {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; min-height: 0;
  padding: 0; border-radius: 50%; background: var(--gradient-card); color: #FFFFFF;
  font-weight: 700; font-size: 15px; cursor: pointer; text-transform: uppercase;
}
.user-menu > summary.avatar:focus-visible { border-radius: 50%; }
.user-menu .menu-who { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-menu .menu-who strong { display: block; }
.user-menu .menu-who span { color: var(--text-muted); font-size: 13px; }

main { max-width: 1760px; margin: 0 auto; padding: 28px 40px 48px; }
footer { max-width: 1760px; margin: 0 auto; padding: 0 40px 32px; color: var(--text-muted); font-size: 13px; line-height: 18px; }
/* The page title sits on a soft sky → pale-yellow glow that fades into the page. */
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px;
  margin-bottom: var(--gap); padding: 24px 28px; border-radius: var(--radius-card);
  background: var(--gradient-header);
}
.page-head p { color: var(--text-body); margin-top: 4px; }
.narrow { max-width: 420px; margin: 64px auto; }
.stack-lg > * + * { margin-top: 16px; }

/* Settings: a short list of sections beside the page they open. */
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--gap) 32px; align-items: start; }
.side-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 92px; }
.side-nav-title { margin: 16px 12px 4px; color: var(--text-muted); font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.side-nav-title:first-child { margin-top: 0; }
.side-nav a {
  padding: 9px 12px; border-radius: var(--radius-md); color: var(--text-muted); font-weight: 600;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.side-nav a:hover { color: var(--text); text-decoration: none; }
.side-nav a[aria-current="page"] { background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-card); }
.settings-body > :first-child { margin-top: 0; }
.settings-body > .banner:first-child + * { margin-top: 0; }
.settings-body .panel > h2 + .facts, .settings-body .panel > .stack { margin-top: 16px; }
.settings-body .panel > .note { margin-top: 12px; }
.check-list { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 12px; }
.check-list li { display: grid; grid-template-columns: 20px minmax(0, 1fr); column-gap: 8px; }
.check-list li::before { content: "✓"; grid-row: span 2; color: var(--success-text); font-weight: 700; }
.check-list li span { grid-column: 2; color: var(--text-muted); font-size: 13px; line-height: 18px; }
.role-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.role-cards .panel { margin: 0; }
.kpi-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
th.center, td.center { text-align: center; }
table.matrix { min-width: 620px; }
table.matrix th[scope="row"] { font-weight: 400; white-space: normal; font-size: 14px; line-height: 20px; color: var(--text-body); }
table.matrix .yes { color: var(--success-text); font-weight: 700; }
table.matrix .no { color: var(--text-faint); }
.tag.role-admin { background: var(--lime); color: var(--on-accent); }
.tag.role-analyst { background: var(--teal); color: var(--on-accent); }
.tag.role-viewer { background: var(--control); color: var(--text-body); box-shadow: inset 0 0 0 1px var(--border); }
/* Accounts: each row opens in place and its forms take the full width of the card. */
.user-head, .user-row > summary {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.5fr) auto;
  gap: 8px 16px; align-items: center; padding: 14px var(--card-pad);
}
.user-head { padding-top: 0; padding-bottom: 12px; color: var(--text-muted); font-size: 12px; line-height: 16px; font-weight: 600; border-bottom: 1px solid var(--border); }
.user-head span:last-child { width: 76px; }
.user-row { border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.user-row > summary { list-style: none; cursor: pointer; transition: background-color var(--dur-fast); }
.user-row > summary::-webkit-details-marker { display: none; }
.user-row > summary:hover, .user-row[open] > summary { background: var(--surface-deep); }
.user-row > summary:focus-visible { box-shadow: inset 0 0 0 2px var(--ring); }
.user-row .who .sub { display: block; color: var(--text-muted); font-size: 13px; line-height: 18px; }
.user-row .when { color: var(--text-body); }
.user-row .manage { width: 76px; }
.user-row[open] .manage { background: var(--accent-bg); color: var(--accent-fg); border-color: transparent; }
.row-forms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; padding: 20px var(--card-pad) 28px; background: var(--surface-deep); }
.row-forms h3 { margin: 0; }
.row-forms .stack > * { max-width: none; }

/* --- Buttons --------------------------------------------------------------- */
.btn, button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 16px;
  font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer;
  color: var(--text); background: var(--control);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  transition: background-color var(--dur-fast), border-color var(--dur-fast), opacity var(--dur-fast);
}
.btn:hover, button:hover, .button:hover { background: var(--control-hover); text-decoration: none; }
.btn-primary, button[type="submit"]:not(.btn):not(.btn-ghost):not(.link), button.primary {
  background: var(--accent-bg); color: var(--accent-fg); border-color: transparent;
}
.btn-primary:hover, button[type="submit"]:not(.btn):not(.btn-ghost):not(.link):hover, button.primary:hover {
  background: var(--accent-bg-hover);
}
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-deep); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger-text); border-color: transparent; }
.btn-danger:hover { background: var(--danger-soft); filter: brightness(0.96); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn svg, button svg { width: 16px; height: 16px; flex: none; }
button:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
button.link { min-height: 0; padding: 0; background: none; border: 0; color: var(--link); font-weight: 600; border-radius: 4px; }
button.link:hover { background: none; text-decoration: underline; }

/* --- Forms ----------------------------------------------------------------- */
label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 18px; font-weight: 600; color: var(--text-body); }
input, select, textarea {
  min-height: var(--control-h); padding: 0 12px; width: 100%;
  font: inherit; font-size: 14px; font-weight: 400; color: var(--text); background: var(--field);
  border: 1px solid var(--border-input); border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { padding: 10px 12px; resize: vertical; }
input[type="file"] { padding: 6px 12px 6px 6px; height: auto; color: var(--text-muted); }
input[type="file"]::file-selector-button {
  margin-right: 12px; min-height: 28px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px; color: var(--text); background: var(--control);
}
input[type="file"]::file-selector-button:hover { background: var(--control-hover); }
input[type="checkbox"], input[type="radio"] { width: 16px; min-height: 0; height: 16px; padding: 0; accent-color: var(--ring); }
input:disabled, select:disabled { opacity: 0.6; cursor: not-allowed; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: 13px; font-weight: 600; color: var(--text-body); margin-bottom: 6px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack > * { max-width: 460px; }
.inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 12px; }
.inline .grow { flex: 1 1 200px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; align-items: start; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid .actions { margin-top: 0; }
.form-grid .date-pair > label { flex: 1; }

/* Filters: a card of controls; dropdowns are dark chips */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 20px var(--card-pad); box-shadow: var(--shadow-card);
}
.filter-bar .field, .filter-bar label { min-width: 150px; }
.filter-bar .grow { flex: 1 1 180px; }
.filter-bar .chip { min-width: 0; }
.filter-bar .end { margin-left: auto; display: flex; gap: 8px; align-items: flex-end; }
.filter-bar input, .filter-bar .btn, .filter-bar button { min-height: 36px; }
.filter-bar select, select.chip-select {
  appearance: none; -webkit-appearance: none; min-height: 36px; padding: 0 36px 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  background-color: var(--control); color: var(--text); font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23141414' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
[data-theme="dark"] .filter-bar select, [data-theme="dark"] select.chip-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23FFFFFF' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.filter-bar select:hover, select.chip-select:hover { background-color: var(--control-hover); }
.filter-bar select option, select.chip-select option { color: var(--text); background: var(--surface); }
.date-pair { display: flex; align-items: flex-end; gap: 8px; }
.date-pair .arrow { color: var(--text-faint); padding-bottom: 10px; }
/* Segmented chips: the selected ones take the accent. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; display: inline-flex; flex-direction: row; align-items: center; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-weight: 600; font-size: 13px; background: var(--control); box-shadow: inset 0 0 0 1px var(--border);
  transition: background-color var(--dur-base), color var(--dur-base);
}
.chip input:checked + span { background: var(--accent-bg); color: var(--accent-fg); box-shadow: none; }
.chip input:checked + span::before { content: "✓"; margin-right: 6px; font-weight: 700; }
.chip input:focus-visible + span { box-shadow: var(--focus-ring); }
.range-line { margin: 20px 4px; color: var(--text-body); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.range-line strong { color: var(--text); font-size: 15px; line-height: 20px; }
.toolbar .range-line { margin: 0; }

/* --- Menus ----------------------------------------------------------------- */
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-hover); padding: 8px; display: flex; flex-direction: column;
  animation: pop var(--dur-base) var(--ease-out);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.menu-list a, .menu-list button {
  display: flex; align-items: center; justify-content: flex-start; min-height: 36px; padding: 8px 12px;
  color: var(--text); border: 0; border-radius: var(--radius-sm); background: none; font-weight: 500; width: 100%;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-deep); text-decoration: none; }
.menu-list .menu-note { padding: 8px 12px 4px; color: var(--text-muted); font-size: 13px; border-top: 1px solid var(--border); margin-top: 4px; }

/* --- Cards ----------------------------------------------------------------- */
.card, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  transition: background-color 250ms, box-shadow var(--dur-base);
}
.panel { padding: var(--card-pad); margin: var(--gap) 0; }
.panel > h2 + * { margin-top: 20px; }
/* The sign-in card wears the signature gradient as its outline. */
.narrow.panel {
  margin: 64px auto; border: 2px solid transparent;
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--gradient-accent) border-box;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: var(--card-pad) var(--card-pad) 0; }
.card-head .sub { color: var(--text-muted); font-size: 13px; line-height: 18px; font-weight: 400; letter-spacing: 0; }
.card-body { padding: 20px var(--card-pad) var(--card-pad); }
.card-body.flush { padding: 16px 0 8px; }
.card-foot { padding: 16px var(--card-pad); border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.section { margin-top: var(--gap); }
/* A titled part of a page that holds several cards, such as analytics on the dashboard. */
.section-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin: 32px 4px 0; }
.section-head p { margin-top: 4px; }
.section-head + * { margin-top: var(--gap); }
.grid-2 > .section { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--gap); margin-top: var(--gap); }
.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.split > .panel { margin: 0; }
.tag-quiet { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--radius-badge); background: var(--surface-deep); color: var(--text-muted); font-size: 12px; font-weight: 600; }

/* --- Stat tiles ------------------------------------------------------------ */
/* A deep card outlined by the signature gradient, with its icon in a small square. */
.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--gap); }
.kpi {
  padding: 20px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
  border: 2px solid transparent; box-shadow: none;
  background: linear-gradient(var(--surface-raised), var(--surface-raised)) padding-box, var(--gradient-accent) border-box;
}
.kpi .icon {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none;
  margin-bottom: 8px; border-radius: 10px; background: var(--surface-deep); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
[data-theme="dark"] .kpi .icon { background: var(--surface); }
.kpi .icon svg { width: 18px; height: 18px; }
.kpi .label { color: var(--text-muted); font-size: 13px; line-height: 18px; font-weight: 600; }
.kpi .value { font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.kpi .meta { color: var(--text-muted); font-size: 12px; line-height: 16px; min-height: 16px; }
.kpi .delta { color: var(--text-body); font-size: 12px; line-height: 16px; font-weight: 600; }
.kpi.hero .value { font-size: 34px; line-height: 40px; letter-spacing: -0.02em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--gap); margin: var(--gap) 0; }

/* --- Notices --------------------------------------------------------------- */
/* Rounded rows with a 3px stripe in the status colour. */
.banner { border-radius: var(--radius-md); padding: 12px 16px 12px 19px; margin: var(--gap) 0; background: var(--surface-deep); box-shadow: inset 3px 0 0 var(--border-input); }
.banner.ok { background: var(--success-soft); color: var(--success-text); box-shadow: inset 3px 0 0 var(--success); }
.banner.warn { background: var(--warning-soft); color: var(--warning-text); box-shadow: inset 3px 0 0 var(--warning); }
.banner.error { background: var(--danger-soft); color: var(--danger-text); box-shadow: inset 3px 0 0 var(--danger); }
.banner strong { color: inherit; }
.banner ul { margin: 6px 0 0; padding-left: 18px; }
.banner a { color: inherit; text-decoration: underline; }
.banner .actions { margin-top: 10px; }
.card-body > .banner:first-child { margin-top: 0; }
details.banner > summary { cursor: pointer; font-weight: 600; }
details.banner > summary span { font-weight: 400; text-decoration: underline; margin-left: 6px; }
details.banner[open] > summary { margin-bottom: 6px; }
.state {
  text-align: center; padding: 48px 24px; color: var(--text-body);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.state svg { width: 32px; height: 32px; color: var(--icon-muted); margin-bottom: 4px; }
.state strong { font-size: 15px; line-height: 20px; }
.state p { max-width: 52ch; }
.state .btn { margin-top: 12px; }
.empty { color: var(--text-muted); padding: 32px 16px; text-align: center; }

/* --- Tables ---------------------------------------------------------------- */
/* Positioned, so a visually hidden label inside a wide table scrolls with it instead of widening the page. */
.table-wrap { overflow-x: auto; position: relative; }
.table-wrap.framed { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: 8px 0; }
.table-wrap.tall { max-height: 70vh; overflow: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 13px var(--card-pad); border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; line-height: 16px; color: var(--text-muted); font-weight: 600; white-space: nowrap; background: var(--surface); }
td { color: var(--text-body); }
.table-wrap.tall thead th { position: sticky; top: 0; z-index: 1; }
td:first-child { white-space: nowrap; }
tbody tr { transition: background-color var(--dur-fast); }
tbody tr:hover td { background: var(--surface-deep); }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tfoot td { font-weight: 600; color: var(--text); border-top: 1px solid var(--border); border-bottom: 0; }
th.num, td.num { text-align: right; }
th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
th a:hover { color: var(--text); text-decoration: none; }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--text); font-weight: 700; }
td .sub, th[scope="row"] .sub { display: block; color: var(--text-muted); font-size: 13px; line-height: 18px; }
td strong, td a strong { font-weight: 600; }

/* --- Badges ---------------------------------------------------------------- */
/* Small, squared and uppercase: lime with dark text unless a rule below says otherwise. */
.badge, .tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px;
  border-radius: var(--radius-badge); background: var(--lime);
  color: var(--on-accent); font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; white-space: nowrap;
}
/* Event types: the glyph and the word carry the meaning, the fill only groups them. */
.badge::before { font-weight: 700; line-height: 1; }
.badge.type-join::before { content: "→"; }
.badge.type-add { background: var(--teal); } .badge.type-add::before { content: "+"; }
.badge.type-leave { background: var(--yellow); } .badge.type-leave::before { content: "←"; }
.badge.type-remove { background: var(--danger-soft); color: var(--danger-text); } .badge.type-remove::before { content: "×"; }
.badge.type-unknown { background: var(--control); color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--border); }
.badge.type-unknown::before { content: "?"; }
.tag.ok, .tag.status-committed { color: var(--success-text); background: var(--success-soft); }
.tag.warn, .tag.status-preview { color: var(--warning-text); background: var(--warning-soft); }
.tag.status-failed { color: var(--danger-text); background: var(--danger-soft); }
.tag.status-cancelled, .tag.status-pending, .tag.neutral { color: var(--text-muted); background: var(--control); box-shadow: inset 0 0 0 1px var(--border); }
/* Rank badges: the first three wear the brand colours. */
.rank {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; flex: none;
  border-radius: 10px; background: var(--control); color: var(--text); font-size: 13px; font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--border);
}
.rank-1, .rank-2, .rank-3 { color: var(--on-accent); box-shadow: none; }
.rank-1 { background: var(--lime); } .rank-2 { background: var(--teal); } .rank-3 { background: var(--yellow); }

/* --- Charts ---------------------------------------------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 13px; color: var(--text-body); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i, .tip i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; flex: none; }
.key-joined { background: var(--series-joined); }
.key-left { background: var(--series-left); }
.key-removed { background: var(--series-removed); }
.key-accent { background: var(--gradient-data-x); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
.chart .gridline { stroke: var(--grid-line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--text-faint); font-size: 12px; }
.chart .tick.on { fill: var(--text); font-weight: 600; }
.chart .end-label { fill: var(--text-body); font-size: 12px; font-weight: 600; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .s-joined { stroke: var(--series-joined); }
.chart .s-left { stroke: var(--series-left); }
.chart .s-removed { stroke: var(--series-removed); }
.chart .f-joined { fill: var(--series-joined); }
.chart .f-left { fill: var(--series-left); }
.chart .f-removed { fill: var(--series-removed); }
.chart .crosshair { stroke: var(--border-input); stroke-width: 1; }
/* Single-series charts: colour follows the value, yellow at the top of the plot, teal at the
   bottom, over an area that fades to nothing. */
.chart .stop-high { stop-color: var(--data-high); }
.chart .stop-mid { stop-color: var(--data-mid); }
.chart .stop-low { stop-color: var(--data-low); }
.chart .stop-area-top { stop-color: var(--data-mid); stop-opacity: var(--area-opacity); }
.chart .stop-area-bottom { stop-color: var(--data-mid); stop-opacity: 0; }
.chart .halo { fill: var(--data-high); fill-opacity: 0.25; }
.chart .guide { stroke: var(--data-high); stroke-opacity: 0.5; stroke-width: 1; }
.chart .data-tag { fill: var(--text); font-size: 12px; font-weight: 700; }
/* Entry: lines draw left to right, once. */
.chart .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw var(--dur-chart) var(--ease-out) forwards; }
.chart .rise { animation: rise var(--dur-chart) var(--ease-out) both; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes rise { from { opacity: 0; } }
.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 170px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-hover); padding: 8px 12px; font-size: 13px; line-height: 18px;
}
.tip .tip-title { color: var(--text-muted); margin-bottom: 4px; }
.tip .tip-row { display: flex; align-items: center; gap: 8px; padding: 1px 0; color: var(--text-muted); }
.tip .tip-row b { margin-left: auto; padding-left: 16px; color: var(--text); font-size: 14px; font-weight: 700; }
details.data-table { margin-top: 16px; }
details.data-table > summary { cursor: pointer; color: var(--link); font-size: 13px; font-weight: 600; width: fit-content; border-radius: 4px; }
details.data-table .table-wrap { margin-top: 12px; max-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
details.data-table th, details.data-table td { padding: 8px 16px; }
.multiples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 32px; }
.multiples h3 { margin-top: 0; color: var(--text-muted); font-size: 13px; line-height: 18px; font-weight: 600; }

/* Bars: thin, rounded at the data end, one gradient across the whole track. */
.bars { display: flex; flex-direction: column; gap: 16px; }
.bar-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: 16px; }
.bars.named .bar-row { grid-template-columns: 32px minmax(0, 11rem) minmax(0, 1fr) auto; }
.bar-row > .badge { justify-self: start; }
.bar-track { height: 10px; background: var(--surface-deep); border-radius: 0 5px 5px 0; overflow: hidden; }
.bar-fill {
  height: 100%; border-radius: 0 5px 5px 0; min-width: 0;
  background-image: var(--gradient-data-x); background-size: var(--span, 100%) 100%; background-repeat: no-repeat;
  transition: width var(--dur-chart) var(--ease-out);
}
.bar-label { font-size: 14px; line-height: 20px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-value { white-space: nowrap; color: var(--text); font-weight: 700; min-width: 5.5rem; text-align: right; }
.bar-value span { color: var(--text-muted); font-weight: 400; font-size: 13px; margin-left: 8px; }
.flow-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 24px 0 0; padding-top: 20px; border-top: 1px solid var(--border); }
.flow-totals dt { color: var(--text-muted); font-size: 13px; line-height: 18px; }
.flow-totals dd { margin: 4px 0 0; font-size: 20px; line-height: 26px; font-weight: 700; color: var(--text); }

.panel > h2 + .note { margin: 8px 0 20px; }
.panel > form + .banner { margin-bottom: 0; }
/* Messages */
.messages td { vertical-align: top; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 72ch; }
details.msg-more > summary { cursor: pointer; overflow-wrap: anywhere; max-width: 72ch; }
details.msg-more[open] > summary { color: var(--text-muted); margin-bottom: 6px; }
.card-body > .inline { margin-top: 0; }

/* --- Loading --------------------------------------------------------------- */
.progress { position: fixed; left: 0; top: 0; height: 3px; width: 100%; z-index: 60; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity 0.15s; }
.progress::after { content: ""; display: block; height: 100%; width: 35%; background: var(--gradient-accent-x); animation: slide 1s ease-in-out infinite; }
[data-loading="true"] .progress { opacity: 1; }
[data-loading="true"] .fade-on-load, .htmx-request.fade-on-load, .htmx-request .fade-on-load { opacity: 0.5; transition: opacity 0.15s; pointer-events: none; }
.fade-on-load { transition: opacity var(--dur-base); }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.skeleton { display: block; border-radius: 6px; background: var(--control-hover); position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.sk-line { height: 12px; margin: 8px 0; }
.sk-value { height: 32px; width: 55%; margin: 6px 0; }
.sk-chart { height: 260px; }
.sk-w40 { width: 40%; } .sk-w60 { width: 60%; } .sk-w80 { width: 80%; }
@media (prefers-reduced-motion: reduce) {
  .skeleton::after, .progress::after, .menu-list, .chart .draw, .chart .rise { animation: none; }
  .chart .draw { stroke-dasharray: none; stroke-dashoffset: 0; }
  * { transition: none !important; }
}

/* --- Misc ------------------------------------------------------------------ */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin: var(--gap) 0 12px; }
.pager { display: flex; gap: 12px; justify-content: center; align-items: center; margin: 16px 0; color: var(--text-muted); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 24px; margin: 12px 0 16px; }
dl.facts dt { color: var(--text-muted); }
dl.facts dd { margin: 0; color: var(--text); }
dl.facts dd.indent, dl.facts dt.indent { padding-left: 16px; }
details.panel > summary { cursor: pointer; font-weight: 600; }

/* --- Responsive ------------------------------------------------------------ */
@media (max-width: 1500px) {
  .topbar-inner { gap: 24px; }
}
@media (max-width: 1279px) {
  :root { --card-pad: 20px; }
  .topbar-inner, main, footer { padding-left: 24px; padding-right: 24px; }
  main { padding-top: 24px; }
  .page-head { padding: 20px; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  h2 { font-size: 18px; line-height: 24px; }
  .nav { gap: 4px; }
}
@media (max-width: 959px) {
  .grid-2, .split, .multiples, .role-cards { grid-template-columns: minmax(0, 1fr); }
  /* The menu moves to its own row under the logo. */
  .topbar-inner { flex-wrap: wrap; gap: 0 16px; min-height: 0; padding-top: 12px; padding-bottom: 8px; }
  .nav { order: 3; flex-basis: 100%; margin-top: 8px; }
  .nav > a, .nav-menu > summary { height: 36px; padding: 0 12px; }
  .topbar-end { margin-left: auto; gap: 16px; }
  /* The settings sections become a row of pills above the page. */
  .settings { grid-template-columns: minmax(0, 1fr); }
  .side-nav { position: static; flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .side-nav-title { display: none; }
  .side-nav a { background: var(--control); box-shadow: inset 0 0 0 1px var(--border); }
  .side-nav a[aria-current="page"] { background: var(--accent-bg); color: var(--accent-fg); box-shadow: none; }
  .row-forms { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .user-head { display: none; }
  .user-row > summary { grid-template-columns: minmax(0, 1fr) auto; }
  .user-row .who { grid-column: 1; }
  .user-row .manage { grid-column: 2; grid-row: 1; }
  .user-row > summary > span:not(.who):not(.manage) { grid-column: 1; }
  .kpi-grid, .kpi-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 599px) {
  :root { --card-pad: 16px; --gap: 16px; }
  .topbar-inner, main, footer { padding-left: 16px; padding-right: 16px; }
  .topbar-inner { gap: 0 12px; }
  .page-head { padding: 16px; }
  /* On a phone the menu may wrap, and a list opens across the full width under it. */
  .nav { position: relative; flex-wrap: wrap; gap: 4px; }
  details.nav-menu { position: static; }
  details.nav-menu > .menu-list { left: 0; right: 0; top: calc(100% + 4px); }
  /* The two sections stack, and the panel scrolls if the screen is short. */
  .menu-list.menu-groups { grid-auto-flow: row; grid-auto-columns: auto; gap: 8px 0; max-height: calc(100vh - 140px); overflow-y: auto; }
  .menu-group + .menu-group { padding-left: 0; border-left: 0; padding-top: 12px; border-top: 1px solid var(--border); }
  .brand { font-size: 16px; gap: 8px; }
  .brand .glyph { width: 32px; height: 32px; border-radius: 9px; }
  .theme-switch svg { display: none; }
  .topbar-end { gap: 12px; }
  .user-menu { padding-left: 0; border-left: 0; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  /* Two date inputs side by side are wider than a phone; let them shrink into the card. */
  .filter-bar > * { max-width: 100%; }
  .filter-bar label, .filter-bar .field, .filter-bar input, .filter-bar select { min-width: 0; }
  .date-pair > label { min-width: 0; }
  .filter-bar .grow { flex: 0 0 auto; }
  .filter-bar .end { margin-left: 0; }
  .filter-bar .end > *, .filter-bar .end .btn, .filter-bar button { width: 100%; }
  .date-pair > label { flex: 1; }
  .menu-list { left: 0; right: auto; }
  .user-menu .menu-list { left: auto; right: 0; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid, .kpi-grid.three, .kpi-grid.four { grid-template-columns: minmax(0, 1fr); }
  .kpi.hero .value { font-size: 30px; line-height: 36px; }
  th, td { padding: 12px 10px; }
  th:first-child, td:first-child { padding-left: var(--card-pad); }
  th:last-child, td:last-child { padding-right: var(--card-pad); }
  .bar-row { grid-template-columns: 84px minmax(0, 1fr); }
  .bar-value { grid-column: 2; text-align: left; min-width: 0; }
  .bars.named .bar-row { grid-template-columns: 32px minmax(0, 1fr) auto; }
  .bars.named .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .bars.named .bar-value { grid-column: auto; text-align: right; }
}
