/* ==========================================================================
   Material Design 3 — token-based theme (plain CSS, no @material/web).

   Layer 1 below (--club-primary / --club-secondary) is set inline per club
   in base.html. Layer 2 derives the full M3 color-role system from those
   two brand colors using color-mix(), so every club gets a real M3 tonal
   relationship (containers, on-* pairs, outlines, tinted neutrals) without
   needing a build step to run real HCT tonal-palette generation. Error and
   the "extended" success/warning roles are fixed, not brand-derived — M3
   itself treats error this way, and success/warning aren't roles M3
   defines at all, so there's nothing brand-specific to derive them from.
   ========================================================================== */

:root {
  /* Layer 1: brand seeds. Overridden per-club inline in base.html — these
     are just a neutral fallback for pages that render with no club resolved. */
  --club-primary: #0059A0;
  --club-secondary: #0C3C60;

  /* ---- Layer 2a: color roles derived from the brand seeds ---- */
  --md-sys-color-primary: var(--club-primary);
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: color-mix(in oklch, var(--club-primary) 28%, white 72%);
  --md-sys-color-on-primary-container: color-mix(in oklch, var(--club-primary) 75%, black 25%);

  --md-sys-color-secondary: var(--club-secondary);
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: color-mix(in oklch, var(--club-secondary) 28%, white 72%);
  --md-sys-color-on-secondary-container: color-mix(in oklch, var(--club-secondary) 75%, black 25%);

  --md-sys-color-tertiary: color-mix(in oklch, var(--club-primary) 50%, var(--club-secondary) 50%);
  --md-sys-color-on-tertiary: #FFFFFF;
  --md-sys-color-tertiary-container: color-mix(in oklch, var(--md-sys-color-tertiary) 28%, white 72%);
  --md-sys-color-on-tertiary-container: color-mix(in oklch, var(--md-sys-color-tertiary) 75%, black 25%);

  /* Neutral surfaces are a standard M3 neutral scale, tinted a little
     towards the brand hue (M3's own neutral/neutral-variant palettes carry
     a hint of the primary's chroma rather than being pure gray). */
  --md-sys-color-surface: color-mix(in oklch, var(--club-primary) 3%, #FFFBFE 97%);
  --md-sys-color-surface-dim: color-mix(in oklch, var(--club-primary) 6%, #DDD9E0 94%);
  --md-sys-color-surface-bright: color-mix(in oklch, var(--club-primary) 3%, #FFFBFE 97%);
  --md-sys-color-surface-container-lowest: #FFFFFF;
  --md-sys-color-surface-container-low: color-mix(in oklch, var(--club-primary) 4%, #F7F3FA 96%);
  --md-sys-color-surface-container: color-mix(in oklch, var(--club-primary) 5%, #F1ECF4 95%);
  --md-sys-color-surface-container-high: color-mix(in oklch, var(--club-primary) 6%, #EBE6EE 94%);
  --md-sys-color-surface-container-highest: color-mix(in oklch, var(--club-primary) 7%, #E5E0E9 93%);
  --md-sys-color-on-surface: color-mix(in oklch, var(--club-primary) 6%, #1C1B1E 94%);
  --md-sys-color-on-surface-variant: color-mix(in oklch, var(--club-primary) 8%, #48454B 92%);
  --md-sys-color-outline: color-mix(in oklch, var(--club-primary) 10%, #78767A 90%);
  --md-sys-color-outline-variant: color-mix(in oklch, var(--club-primary) 8%, #C9C5CE 92%);
  --md-sys-color-inverse-surface: color-mix(in oklch, var(--club-primary) 6%, #313033 94%);
  --md-sys-color-inverse-on-surface: color-mix(in oklch, var(--club-primary) 3%, #F4EFF4 97%);
  --md-sys-color-scrim: #000000;
  --md-sys-color-shadow: #000000;

  /* ---- Layer 2b: fixed roles (not brand-derived, same as upstream M3) ---- */
  --md-sys-color-error: #B3261E;
  --md-sys-color-on-error: #FFFFFF;
  --md-sys-color-error-container: #F9DEDC;
  --md-sys-color-on-error-container: #410E0B;

  /* Extended (app-specific) semantic roles, in the M3 "extended color"
     style — success/warning aren't part of the M3 spec, so they get their
     own fixed, non-brand-derived palettes rather than being invented from
     primary/secondary. */
  --md-extended-color-success: #2E7D32;
  --md-extended-color-on-success: #FFFFFF;
  --md-extended-color-success-container: #C9F0C6;
  --md-extended-color-on-success-container: #072109;
  --md-extended-color-warning: #7A5900;
  --md-extended-color-on-warning: #FFFFFF;
  --md-extended-color-warning-container: #FFDEA6;
  --md-extended-color-on-warning-container: #271900;

  /* ---- Shape scale ---- */
  --md-sys-shape-corner-none: 0px;
  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 999px;

  /* ---- Elevation (key + ambient shadow pairs) ---- */
  --md-sys-elevation-0: none;
  --md-sys-elevation-1: 0 1px 2px 0 rgba(0, 0, 0, 0.30), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-2: 0 1px 2px 0 rgba(0, 0, 0, 0.30), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-3: 0 1px 3px 0 rgba(0, 0, 0, 0.30), 0 4px 8px 3px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-4: 0 2px 3px 0 rgba(0, 0, 0, 0.30), 0 6px 10px 4px rgba(0, 0, 0, 0.15);
  --md-sys-elevation-5: 0 4px 4px 0 rgba(0, 0, 0, 0.30), 0 8px 12px 6px rgba(0, 0, 0, 0.15);

  /* ---- State-layer opacities (hover/focus/pressed, per M3 spec) ---- */
  --md-sys-state-hover-opacity: 0.08;
  --md-sys-state-focus-opacity: 0.12;
  --md-sys-state-pressed-opacity: 0.12;

  /* ---- Type scale: size / line-height / weight / tracking per role ---- */
  --md-sys-typescale-headline-large-size: 2rem;
  --md-sys-typescale-headline-large-line-height: 2.5rem;
  --md-sys-typescale-headline-large-weight: 400;

  --md-sys-typescale-headline-medium-size: 1.75rem;
  --md-sys-typescale-headline-medium-line-height: 2.25rem;
  --md-sys-typescale-headline-medium-weight: 400;

  --md-sys-typescale-headline-small-size: 1.5rem;
  --md-sys-typescale-headline-small-line-height: 2rem;
  --md-sys-typescale-headline-small-weight: 400;

  --md-sys-typescale-title-large-size: 1.375rem;
  --md-sys-typescale-title-large-line-height: 1.75rem;
  --md-sys-typescale-title-large-weight: 400;

  --md-sys-typescale-title-medium-size: 1rem;
  --md-sys-typescale-title-medium-line-height: 1.5rem;
  --md-sys-typescale-title-medium-weight: 500;
  --md-sys-typescale-title-medium-tracking: 0.009375rem;

  --md-sys-typescale-title-small-size: 0.875rem;
  --md-sys-typescale-title-small-line-height: 1.25rem;
  --md-sys-typescale-title-small-weight: 500;
  --md-sys-typescale-title-small-tracking: 0.00625rem;

  --md-sys-typescale-body-large-size: 1rem;
  --md-sys-typescale-body-large-line-height: 1.5rem;
  --md-sys-typescale-body-large-weight: 400;
  --md-sys-typescale-body-large-tracking: 0.03125rem;

  --md-sys-typescale-body-medium-size: 0.875rem;
  --md-sys-typescale-body-medium-line-height: 1.25rem;
  --md-sys-typescale-body-medium-weight: 400;
  --md-sys-typescale-body-medium-tracking: 0.015625rem;

  --md-sys-typescale-body-small-size: 0.75rem;
  --md-sys-typescale-body-small-line-height: 1rem;
  --md-sys-typescale-body-small-weight: 400;
  --md-sys-typescale-body-small-tracking: 0.025rem;

  --md-sys-typescale-label-large-size: 0.875rem;
  --md-sys-typescale-label-large-line-height: 1.25rem;
  --md-sys-typescale-label-large-weight: 500;
  --md-sys-typescale-label-large-tracking: 0.00625rem;

  --md-sys-typescale-label-medium-size: 0.75rem;
  --md-sys-typescale-label-medium-line-height: 1rem;
  --md-sys-typescale-label-medium-weight: 500;
  --md-sys-typescale-label-medium-tracking: 0.03125rem;

  --md-sys-typescale-label-small-size: 0.6875rem;
  --md-sys-typescale-label-small-line-height: 1rem;
  --md-sys-typescale-label-small-weight: 500;
  --md-sys-typescale-label-small-tracking: 0.03125rem;

  /* Club-brand highlight stripe colour for "box" components (header,
     .profile-card, .empty-state, .config-panel, .table-scroll,
     .info-dialog). Defaults to secondary; a box nested inside another box
     switches this to primary (see the nested-box `:is()` rule in "Cards &
     panels" below) so two nested stripes read as distinct layers instead
     of just doubling up on the same colour. */
  --box-accent: var(--md-sys-color-secondary);
}

/* ==========================================================================
   Base
   ========================================================================== */

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
}

h1 {
  font-size: var(--md-sys-typescale-headline-small-size);
  line-height: var(--md-sys-typescale-headline-small-line-height);
  font-weight: var(--md-sys-typescale-headline-small-weight);
  color: var(--md-sys-color-on-surface);
  margin: 0 0 0.25rem;
}

h2 {
  font-size: var(--md-sys-typescale-title-large-size);
  line-height: var(--md-sys-typescale-title-large-line-height);
  font-weight: var(--md-sys-typescale-title-large-weight);
  color: var(--md-sys-color-on-surface);
  margin: 0 0 0.5rem;
}

h3 {
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line-height);
  font-weight: var(--md-sys-typescale-title-medium-weight);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
  color: var(--md-sys-color-on-surface);
  margin: 0 0 0.5rem;
}

a {
  color: var(--md-sys-color-primary);
}

/* ==========================================================================
   Top app bar + navigation
   ========================================================================== */

header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: -1rem -1rem 1rem;
  padding: 0.875rem 1rem;
  background: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  /* Club-brand highlight stripe. A box-shadow rather than border-top so it
     survives the desktop breakpoint's `border` shorthand below untouched,
     and so it follows the header's border-radius there instead of
     squaring off the corners. */
  box-shadow: inset 0 3px 0 0 var(--box-accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--md-sys-color-on-surface);
  text-decoration: none;
  font-size: var(--md-sys-typescale-title-large-size);
  line-height: var(--md-sys-typescale-title-large-line-height);
  font-weight: 500;
}

.club-logo {
  height: 32px;
  width: auto;
  border-radius: var(--md-sys-shape-corner-small);
}

.brand-club-name {
  font-weight: 500;
}

/* The "Fill-In Finder" module label next to a club's own name is
   de-emphasized because the club identifies the tenant. On platform-only
   pages .brand-club-name instead renders the full-weight Clubsie wordmark. */
.brand-tagline {
  font-size: var(--md-sys-typescale-body-medium-size);
  font-weight: 400;
  color: var(--md-sys-color-on-surface-variant);
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 -0.5rem;
}

nav a {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line-height);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
}

nav a:hover,
nav a:focus-visible {
  background: color-mix(in oklch, var(--md-sys-color-on-surface) 8%, transparent);
}

/* "Admin" nav menu — a <details>/<summary> disclosure (same pattern as
   .withdrawn-profiles) rather than JS, so it works with no script and
   degrades to a plain expanding block if positioning isn't supported. */
nav details {
  position: relative;
}

nav summary {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line-height);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  cursor: pointer;
  list-style: none;
}

nav summary::-webkit-details-marker {
  display: none;
}

nav summary::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  margin-top: -0.15rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

nav summary:hover,
nav summary:focus-visible {
  background: color-mix(in oklch, var(--md-sys-color-on-surface) 8%, transparent);
}

nav details[open] > summary {
  background: color-mix(in oklch, var(--md-sys-color-primary) 12%, transparent);
  color: var(--md-sys-color-primary);
}

nav details[open] > summary::after {
  margin-top: 0.15rem;
  transform: rotate(-135deg);
}

.nav-menu-items {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 11rem;
  padding: 0.4rem;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-small);
  box-shadow: var(--md-sys-elevation-2);
}

.nav-menu-items a,
.nav-menu-items button {
  min-height: 2.5rem;
  border-radius: var(--md-sys-shape-corner-extra-small);
}

/* Cog / account-settings menu — same disclosure as "Admin" above, but
   icon-only (no label, no expand arrow) and pinned to the row's right
   edge so it reads as a persistent account control rather than a nav
   link. */
.nav-menu-cog {
  margin-left: auto;
}

.nav-menu-cog > summary {
  gap: 0;
  padding: 0 0.6rem;
}

.nav-menu-cog > summary::after {
  content: none;
}

.nav-menu-items-right {
  left: auto;
  right: 0;
}

.nav-menu-items form {
  margin: 0;
}

/* Matches "nav a"'s label-large typescale explicitly, since that rule
   only targets <a> elements and this button (Reset Password) otherwise
   falls back to the inherited body font, reading visibly smaller/lighter
   than "Log out" right next to it. */
.nav-menu-items button {
  display: flex;
  align-items: center;
  /* The generic "button" rule below sets justify-content: center for
     regular buttons; this one needs to read as a left-aligned menu row
     like "Log out" next to it, not have its label centered. */
  justify-content: flex-start;
  width: 100%;
  padding: 0 0.75rem;
  border: none;
  background: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line-height);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.nav-menu-items button:hover,
.nav-menu-items button:focus-visible {
  background: color-mix(in oklch, var(--md-sys-color-on-surface) 8%, transparent);
}

@media (min-width: 600px) {
  header {
    border-radius: var(--md-sys-shape-corner-large);
    margin: 0 0 1.5rem;
    border: 1px solid var(--md-sys-color-outline-variant);
  }
}

/* ==========================================================================
   Flash messages (M3 banner-style)
   ========================================================================== */

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: grid;
  gap: 0.5rem;
}

.flashes li {
  padding: 0.75rem 1rem;
  border-radius: var(--md-sys-shape-corner-medium);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  /* Default/uncategorized flashes (e.g. Flask-Login's own
     login-required redirect, category "message") get a neutral tonal
     background — only .flash-error/.flash-success override this. */
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
}

.flash-error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.flash-success {
  background: var(--md-extended-color-success-container);
  color: var(--md-extended-color-on-success-container);
}

span.flash-error {
  display: block;
  background: none;
  padding: 0;
  color: var(--md-sys-color-error);
  font-size: var(--md-sys-typescale-body-small-size);
}

/* ==========================================================================
   Notice banner (site-wide, e.g. open help requests)
   ========================================================================== */

.notice-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-extended-color-warning-container);
  color: var(--md-extended-color-on-warning-container);
  font-size: var(--md-sys-typescale-body-medium-size);
}

.notice-banner p {
  margin: 0;
}

.notice-banner a {
  color: inherit;
  font-weight: var(--md-sys-typescale-label-large-weight);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

button,
input[type="submit"],
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  padding: 0.5rem 1.5rem;
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
input[type="submit"]:hover,
.button:hover {
  background: color-mix(in oklch, var(--md-sys-color-primary) 92%, var(--md-sys-color-on-primary) 8%);
  box-shadow: var(--md-sys-elevation-1);
}

button:focus-visible,
input[type="submit"]:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.button-secondary {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.button-secondary:hover {
  background: color-mix(in oklch, var(--md-sys-color-primary) 8%, transparent);
  box-shadow: none;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  background: none;
  color: var(--md-sys-color-error);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 0.4rem;
}

.icon-button:hover {
  background: color-mix(in oklch, var(--md-sys-color-error) 8%, transparent);
  border-color: var(--md-sys-color-error);
  box-shadow: none;
}

.icon-button-neutral {
  color: var(--md-sys-color-primary);
}

.icon-button-neutral:hover {
  background: color-mix(in oklch, var(--md-sys-color-primary) 8%, transparent);
  border-color: var(--md-sys-color-primary);
  box-shadow: none;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* ==========================================================================
   Cards & panels
   ========================================================================== */

.profile-card,
.empty-state,
.profile-form fieldset,
.consent-box,
.config-panel {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 1rem;
}

/* Club-brand highlight, same technique as header's top stripe. */
.profile-card,
.empty-state {
  box-shadow: inset 0 3px 0 0 var(--box-accent);
}

.config-panel {
  margin-bottom: 1rem;
  box-shadow: inset 0 3px 0 0 var(--box-accent);
}

/* A box nested inside another box (e.g. a .table-scroll or .empty-state
   inside a .config-panel, both used throughout the admin pages) switches
   to the primary colour for its own stripe, so the two don't just double
   up on an identical secondary line. */
:is(.profile-card, .empty-state, .config-panel, .table-scroll, .info-dialog)
  :is(.profile-card, .empty-state, .config-panel, .table-scroll, .info-dialog) {
  --box-accent: var(--md-sys-color-primary);
}

.config-panel h2 {
  color: var(--md-sys-color-on-surface);
  margin-top: 0;
}

.consent-box {
  background: var(--md-sys-color-surface-container);
}

.page-heading,
.profile-card-heading,
.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Breathing room before whatever boxed content (.config-panel,
   .profile-card, .table-scroll, ...) follows the page's unboxed intro
   heading/text — without this, that first box sits right up against the
   intro paragraph with no visual separation. */
.page-heading {
  margin-bottom: 1.5rem;
}

.page-heading h1,
.page-heading h2,
.profile-card h2 {
  margin-bottom: 0;
}

.page-heading p,
.profile-card-heading p {
  margin: 0.25rem 0 0;
  color: var(--md-sys-color-on-surface-variant);
}

.profile-list {
  display: grid;
  gap: 1rem;
  margin: 0 0 1rem;
}

.profile-details {
  display: grid;
  gap: 0.6rem;
  margin: 0;
}

.profile-details div {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.1rem;
}

.profile-details dt {
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.profile-details dd {
  margin: 0;
}

.withdraw-form {
  margin-top: 1rem;
}

.withdrawn-profiles {
  margin-top: 1.5rem;
}

.withdrawn-profiles summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.form-intro {
  color: var(--md-sys-color-on-surface-variant);
}

/* ==========================================================================
   Forms (M3 outlined text field, simplified for server-rendered markup —
   labels stay static above the field rather than the JS-free floating-label
   trick, since WTForms doesn't reliably emit placeholders to hook it on)
   ========================================================================== */

.role-choice {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}

.role-choice legend {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  padding: 0 0.25rem;
}

.role-option {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.5rem;
  align-items: baseline;
  padding: 0.35rem 0;
  cursor: pointer;
}

.role-name {
  font-weight: 600;
}

.role-description {
  grid-column: 2;
  font-size: var(--md-sys-typescale-body-small-size);
  color: var(--md-sys-color-on-surface-variant);
}

.profile-form {
  display: grid;
  gap: 1rem;
}

.profile-form fieldset {
  margin: 0;
}

.profile-form legend {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  padding: 0 0.25rem;
}

.form-field {
  display: grid;
  gap: 0.35rem;
}

.form-field > label {
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
  font-weight: 500;
}

.form-field input,
.form-field select,
.form-field textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.75rem;
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  padding: 0.6rem 0.75rem;
  font: inherit;
}

.form-field textarea {
  min-height: 4.5rem;
}

.form-field input:focus-visible,
.form-field select:focus-visible,
.form-field textarea:focus-visible {
  outline: none;
  border: 2px solid var(--md-sys-color-primary);
  padding: calc(0.6rem - 1px) calc(0.75rem - 1px);
}

.choice-list {
  display: grid;
  gap: 0.5rem;
}

.choice-list label,
.consent-box > label {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  min-height: 2.5rem;
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--md-sys-color-primary);
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
}

.field-hint {
  display: block;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
}

.form-actions {
  justify-content: flex-start;
}

.inline-form {
  display: flex;
  align-items: end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inline-form .form-field {
  flex: 1 1 14rem;
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table-scroll {
  overflow-x: auto;
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  /* Actual border, not the box-shadow trick used elsewhere: the sticky
     first/last column cells paint their own opaque background right at
     this container's top edge, which would hide an inset shadow there. A
     real border sits outside the padding box, so it stays visible. */
  border-top: 3px solid var(--box-accent);
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-scroll table {
  white-space: nowrap;
}

/* Every .table-scroll table here follows the same shape: an identifying
   first column (name/label) and an actions/details last column, with
   whatever's in between (status, dates, config values) being the part
   that's fine to scroll past. Pinning those two ends means a narrow
   screen never has to horizontally scroll just to see which row this is
   or reach the button that acts on it — the scrollable middle columns
   are still reachable by swiping, they just aren't load-bearing for
   identifying the row or acting on it. Inert (no visible effect) whenever
   the table already fits without scrolling, e.g. on wider screens. */
.table-scroll th:first-child,
.table-scroll td:first-child,
.table-scroll th:last-child,
.table-scroll td:last-child {
  position: sticky;
  background: var(--md-sys-color-surface-container-low);
}

.table-scroll th:first-child,
.table-scroll td:first-child {
  left: 0;
}

.table-scroll th:last-child,
.table-scroll td:last-child {
  right: 0;
}

/* Opt-out for a table whose last column isn't an actions/details column
   (see the comment above) -- e.g. global_admin/emails.html, where the last
   column is just one more tracking-status field, arbitrarily last rather
   than load-bearing the way a Manage/Edit action is elsewhere. Pinning it
   would just be a stray fixed column with no purpose. */
.table-scroll.table-no-sticky-last th:last-child,
.table-scroll.table-no-sticky-last td:last-child {
  position: static;
  background: none;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
}

th {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  font-size: var(--md-sys-typescale-label-large-size);
}

/* Sortable column headers (e.g. admin/competitions.html's Age Groups
   table): the whole header is a link so its full width/height is
   clickable, not just the text. */
.sortable-header {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: inherit;
  text-decoration: none;
}

.sortable-header:hover {
  text-decoration: underline;
}

.sort-indicator {
  font-size: 0.7em;
  color: var(--md-sys-color-outline);
}

.sortable-header-active .sort-indicator {
  color: var(--md-sys-color-on-surface-variant);
}

/* ==========================================================================
   Status pills (M3 "assist chip"-style, using role/extended container pairs)
   ========================================================================== */

.status-pill {
  display: inline-block;
  border-radius: var(--md-sys-shape-corner-full);
  padding: 0.15rem 0.65rem;
  font-size: var(--md-sys-typescale-label-medium-size);
  font-weight: var(--md-sys-typescale-label-medium-weight);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
}

.status-active,
.status-accepted,
.status-open,
.status-closed-filled,
.status-available,
.status-clear,
.status-sent {
  background: var(--md-extended-color-success-container);
  color: var(--md-extended-color-on-success-container);
}

.status-inactive,
.status-expired,
.status-superseded,
.status-closed-enough,
.status-resolved,
.status-unknown {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

.status-pending,
.status-discussion-needed {
  background: var(--md-extended-color-warning-container);
  color: var(--md-extended-color-on-warning-container);
}

.status-cancelled,
.status-not-available,
.status-clash,
.status-revoked,
.status-failed {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

/* ==========================================================================
   Info dialog (M3-styled native <dialog> — no JS beyond the one-line
   showModal() call in the trigger button's onclick; closing is a plain
   method="dialog" form, handled natively by the browser)
   ========================================================================== */

.info-dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: none;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: inset 0 3px 0 0 var(--box-accent), var(--md-sys-elevation-3);
  /* Undo the ancestor <table>'s white-space: nowrap (for its own
     horizontal-scroll behavior) — a <dialog> renders in the top layer but
     is still a DOM descendant for inheritance, so without this its content
     would try to render as one unbreakable line too. */
  white-space: normal;
}

.info-dialog::backdrop {
  background: color-mix(in oklch, var(--md-sys-color-scrim) 32%, transparent);
}

.info-dialog h4 {
  margin: 0 0 1rem;
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line-height);
  font-weight: var(--md-sys-typescale-title-medium-weight);
  overflow-wrap: break-word;
}

.info-dialog .form-actions {
  margin-top: 1.25rem;
}

/* ==========================================================================
   Misc
   ========================================================================== */

.graphic-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.graphic-preview form {
  margin: 0;
}

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

/* ==========================================================================
   Responsive breakpoints (mobile-first; base rules above already target
   phone width — these widen things out for tablet/desktop, roughly M3's
   compact / medium / expanded window-size classes)
   ========================================================================== */

@media (min-width: 600px) {
  body {
    padding: 1.5rem;
  }

  h1 {
    font-size: var(--md-sys-typescale-headline-medium-size);
    line-height: var(--md-sys-typescale-headline-medium-line-height);
  }

  .profile-details div {
    grid-template-columns: minmax(7rem, 1fr) 2fr;
    gap: 0.75rem;
  }

  .profile-form {
    max-width: 30rem;
  }
}

@media (min-width: 905px) {
  body {
    /* 840px was still capping desktop uncomfortably narrow for the
       data-heavy admin tables (Age Groups, Emails, Clubs, ...); wide
       screens have the room. */
    max-width: 1100px;
  }
}
