/* ===========================================================================
   LAYOUT SYSTEM — the shared ap-* rules every portal screen follows.
   UI_CONSISTENCY_NOTES.md records the decisions; DESIGN_SYSTEM.md documents
   the components. Loads after portal.css and every screen's stylesheet, so a
   rule here wins over a screen's one-off styling: each rule below is enforced
   in this one place. Tokens only (tokens.css).

   Contents
     1. Heading rule (uppercase section, card, group, column and tab headings)
     2. Form controls (one height, one radius, no spinners, field order)
     3. Range pairs (ap-range)
     4. Fieldsets and check lists
     5. Lists and tables with aligned columns (ap-list, ap-table)
     6. Badges (one height, icon + word)
     7. Tabs (ap-tabs: full width, divided, scrolls with fade hints)
     8. Buttons in rows
     9. Collapsible sections (ap-collapsible)
    10. Modals (dialog.ap-modal)
    11. Bulk editing (ap-bulk)
    12. Save state (data-dirty-save)
   =========================================================================== */

/* ---- 1. Heading rule -------------------------------------------------------
   Section, panel, card and group headings, column headers, tab labels and
   legends are UPPERCASE via text-transform, so the source text (and what a
   screen reader or a translation sees) stays as written. The page title (h1)
   stays bold Title Case. Text written by people (lessons, theme bodies,
   guides) keeps its own headings: .ap-prose, .ap-richtext, [data-user-content].
   A heading that is the name of a person or thing can opt out with
   [data-heading-plain]. */
.atfal-portal-body :is(
	.ap-section-title, .ap-doc__heading, .ap-card__title, .ap-modal__title,
	.ap-collapsible__title, .ap-fieldset__legend, .ap-list__head, .ap-subhead
):not(h1):not([data-heading-plain]),
.atfal-portal-body .ap-main :is(h2, h3, h4):not([data-heading-plain]):not(:where(.ap-prose, .ap-richtext, .entry-content, [data-user-content]) *) {
	text-transform: uppercase;
	letter-spacing: var(--tracking-caps);
	line-height: var(--lh-snug);
}
.atfal-portal-body :is(.ap-section-title, .ap-doc__heading):not(h1),
.atfal-portal-body .ap-main h2:not(h1):not([data-heading-plain]):not(:where(.ap-prose, .ap-richtext, .entry-content, [data-user-content]) *) {
	font-size: var(--fs-caps-section);
	font-weight: var(--fw-bold);
}
.atfal-portal-body :is(.ap-card__title, .ap-collapsible__title, .ap-modal__title, .ap-subhead):not(h1),
.atfal-portal-body .ap-main :is(h3, h4):not([data-heading-plain]):not(:where(.ap-prose, .ap-richtext, .entry-content, [data-user-content]) *) {
	font-size: var(--fs-caps-card);
	font-weight: var(--fw-bold);
}
/* Column headers, legends and tab labels: the small uppercase label size. */
.atfal-portal-body .ap-main :is(th, legend, .ap-tabs__link, [role="tab"], .ap-list__head),
.atfal-portal-body .ap-fieldset__legend {
	text-transform: uppercase;
	letter-spacing: var(--tracking-caps);
	font-size: var(--fs-caps-label);
	font-weight: var(--fw-bold);
}
/* Text inside headings that is a value, not a heading (a date, a count) keeps its case. */
.atfal-portal-body .ap-keepcase { text-transform: none; letter-spacing: 0; }
/* Headings share the left edge of their content: no centred headings over left-aligned text. */
.atfal-portal-body .ap-main :is(.ap-section-title, .ap-doc__heading, .ap-card__title) { text-align: start; }

/* ---- 2. Form controls ------------------------------------------------------
   Text, number, date, time, select, textarea and search: one height, one
   radius, one border, one padding, one font size, one focus ring. */
.atfal-portal-body .ap-main :is(
	input[type="text"], input[type="number"], input[type="email"], input[type="search"],
	input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"],
	input[type="week"], input[type="tel"], input[type="url"], input[type="password"],
	input:not([type]), select, textarea, .ap-input, .ap-msel__button
) {
	box-sizing: border-box;
	min-block-size: var(--control-height);
	padding-block: var(--space-2);
	padding-inline: var(--space-3);
	border: var(--border-input);
	border-radius: var(--radius-control);
	background-color: var(--color-surface);
	color: var(--color-text);
	font: inherit;
	font-size: var(--fs-body);
	line-height: var(--lh-snug);
}
/* One block size for single-line controls, so a select sits level with an input. */
.atfal-portal-body .ap-main :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="color"]), select:not([multiple]):not([size])) {
	block-size: var(--control-height);
}
.atfal-portal-body .ap-main :is(input, select, textarea):focus-visible { border-color: var(--color-primary); box-shadow: var(--focus-ring); outline: none; }
/* Buttons share the control radius and height. */
.atfal-portal-body .ap-btn { border-radius: var(--radius-control); }
/* Native number spinners hidden: plain inputs (type a number). */
.atfal-portal-body input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.atfal-portal-body input[type="number"]::-webkit-inner-spin-button,
.atfal-portal-body input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }

/* Field layout: label, then control, then help text, then error, whatever the
   source order. Older templates put the hint between the label and the field;
   the order below draws it under the control without touching the markup. */
.atfal-portal-body .ap-field { display: flex; flex-direction: column; gap: var(--space-2); min-inline-size: 0; }
.atfal-portal-body .ap-field > .ap-field__label, .atfal-portal-body .ap-field > legend { order: 0; }
.atfal-portal-body .ap-field > :is(input, select, textarea, .ap-input, .ap-range, .ap-cluster, .u-cluster, .ap-checks) { order: 1; }
.atfal-portal-body .ap-field > .ap-field__hint { order: 2; }
.atfal-portal-body .ap-field > .ap-field__error { order: 3; }
/* Labels take the full column width and wrap as sentences, not into odd shapes. */
.atfal-portal-body .ap-field__label { display: block; inline-size: 100%; text-wrap: pretty; }
/* Fields side by side share one grid, so their controls line up on a common baseline. */
/* Fields in a row share the width (each at least --field-min) and sit on one
   bottom line, so controls line up; buttons and links in the row keep their
   natural width. */
.atfal-portal-body .ap-form__row {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: var(--space-3) var(--space-4);
}
.atfal-portal-body .ap-form__row > .ap-field { flex: 1 1 var(--field-min); }
.atfal-portal-body .ap-form__row > .ap-field--narrow { flex: 0 1 var(--field-min); }
.atfal-portal-body .ap-form__row > :is(.ap-btn, a, button, .u-cluster) { flex: none; }
.atfal-portal-body .ap-form__row--aligned { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--field-min), 1fr)); align-items: start; }
/* A row of fields keeps its controls level even when one label wraps to two lines. */
@supports (grid-template-rows: subgrid) {
	.atfal-portal-body .ap-form__row--aligned { grid-template-rows: auto auto auto; }
	.atfal-portal-body .ap-form__row--aligned > .ap-field { display: grid; grid-row: span 3; grid-template-rows: subgrid; gap: var(--space-2); }
}

/* ---- 3. Range pairs (ap-range) ---------------------------------------------
   <div class="ap-field">
     <span class="ap-field__label" id="x">Team size</span>
     <div class="ap-range" role="group" aria-labelledby="x">
       <label class="ap-range__item"><span class="ap-range__label">From</span><input …></label>
       <span class="ap-range__sep" aria-hidden="true">to</span>
       <label class="ap-range__item"><span class="ap-range__label">To</span><input …></label>
     </div>
     <p class="ap-field__hint">…</p>
   </div>
   Two equal-width controls on one row, the separator centred on the controls. */
.atfal-portal-body .ap-range {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	align-items: end;
	gap: var(--space-2) var(--space-3);
	max-inline-size: 24rem;
}
.atfal-portal-body .ap-range__item { display: flex; flex-direction: column; gap: var(--space-1); min-inline-size: 0; }
.atfal-portal-body .ap-range__label { font-size: var(--fs-caption); color: var(--color-text-soft); }
.atfal-portal-body .ap-range__sep {
	display: flex;
	align-items: center;
	block-size: var(--control-height);
	color: var(--color-text-soft);
	font-size: var(--fs-small);
}
.atfal-portal-body .ap-range input { inline-size: 100%; }

/* ---- 4. Fieldsets and check lists ------------------------------------------
   No browser-default border (its notch is what drew the broken corner on
   "Position names"). A grouped set of controls is .ap-fieldset: a divided,
   bordered group with an uppercase legend above it. */
.atfal-portal-body fieldset { min-inline-size: 0; margin: 0; padding: 0; border: 0; }
.atfal-portal-body fieldset > legend { padding: 0; }
.atfal-portal-body .ap-fieldset {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}
/* A floated legend sits inside the box like any heading (no notch in the border). */
.atfal-portal-body .ap-fieldset > .ap-fieldset__legend { float: inline-start; inline-size: 100%; margin: 0; color: var(--color-text-soft); }
.atfal-portal-body .ap-fieldset > .ap-fieldset__legend + * { clear: both; }
.atfal-portal-body .ap-fieldset__body {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	padding: var(--space-4);
	border: var(--border-subtle);
	border-radius: var(--radius-md);
	background: var(--color-surface);
}

/* Checkboxes and switches: one per row, or a fixed two-column grid on wide
   screens (.ap-checks--2col). Never ragged wrapping. */
.atfal-portal-body .ap-checks {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	align-items: start;
	gap: 0 var(--space-5);
}
@media (min-width: 900px) {
	.atfal-portal-body .ap-checks--2col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.atfal-portal-body .ap-checks > .ap-check { display: flex; align-items: flex-start; padding-block: var(--space-3); }
.atfal-portal-body .ap-checks > .ap-check > input { margin-block-start: var(--space-half); }
.atfal-portal-body .ap-checks--divided > .ap-check + .ap-check { border-block-start: var(--border-subtle); }
.atfal-portal-body .ap-checks__head { grid-column: 1 / -1; margin: 0; padding-block-start: var(--space-3); color: var(--color-text-soft); }

/* ---- 5. Lists and tables with aligned columns ------------------------------
   ap-list: rows that show a name plus status, count, date and actions. The
   column count is a modifier (--3, --4, --5, --select), never an inline style.
     <div class="ap-list ap-list--3" role="table" aria-label="Departments">
       <div class="ap-list__row ap-list__head" role="row">
         <span role="columnheader">Department</span> …
       </div>
       <div class="ap-list__row" role="row">
         <span class="ap-list__cell ap-list__name" role="cell">Talim</span>
         <span class="ap-list__cell" role="cell" data-label="Team">…badge…</span>
         <span class="ap-list__cell ap-list__actions" role="cell">…buttons…</span>
       </div>
     </div>
   Every row is a subgrid of the list, so each column starts at the same left
   edge on every row. Phones: rows stack into labelled cards. */
.atfal-portal-body .ap-list {
	--ap-list-cols: minmax(0, 1fr) auto;
	display: grid;
	grid-template-columns: var(--ap-list-cols);
	margin: 0;
	padding: 0;
	list-style: none;
	border: var(--border-subtle);
	border-radius: var(--radius-md);
	background: var(--color-surface);
	font-size: var(--fs-small); /* the same body size as .ap-table */
	line-height: var(--lh-snug);
}
.atfal-portal-body .ap-list--3 { --ap-list-cols: minmax(0, 1fr) auto auto; }
.atfal-portal-body .ap-list--4 { --ap-list-cols: minmax(0, 1fr) auto auto auto; }
.atfal-portal-body .ap-list--5 { --ap-list-cols: minmax(0, 1fr) auto auto auto auto; }
.atfal-portal-body .ap-list--select { --ap-list-cols: var(--list-select-col) minmax(0, 1fr) auto; }
.atfal-portal-body .ap-list--select.ap-list--3 { --ap-list-cols: var(--list-select-col) minmax(0, 1fr) auto auto; }
.atfal-portal-body .ap-list--select.ap-list--4 { --ap-list-cols: var(--list-select-col) minmax(0, 1fr) auto auto auto; }
.atfal-portal-body .ap-list__row {
	display: grid;
	grid-column: 1 / -1;
	grid-template-columns: subgrid;
	align-items: center;
	gap: var(--space-2) var(--space-5);
	min-block-size: var(--row-min);
	padding-block: var(--space-3);
	padding-inline: var(--space-4);
}
.atfal-portal-body .ap-list__row + .ap-list__row { border-block-start: var(--border-subtle); }
.atfal-portal-body .ap-list__row:not(.ap-list__head):hover { background: var(--color-canvas); }
.atfal-portal-body .ap-list__head {
	min-block-size: 0;
	padding-block: var(--space-2);
	background: var(--color-canvas);
	border-start-start-radius: var(--radius-md);
	border-start-end-radius: var(--radius-md);
	color: var(--color-text-soft);
}
.atfal-portal-body .ap-list__head + .ap-list__row { border-block-start: var(--border-default); }
.atfal-portal-body .ap-list__cell { display: flex; align-items: center; gap: var(--space-2); min-inline-size: 0; overflow-wrap: anywhere; }
.atfal-portal-body .ap-list__name { font-weight: var(--fw-semibold); }
.atfal-portal-body .ap-list__sub { display: block; font-size: var(--fs-caption); font-weight: var(--fw-regular); color: var(--color-text-mute); }
.atfal-portal-body .ap-list__actions { justify-content: flex-end; flex-wrap: wrap; }
.atfal-portal-body .ap-list__select input { inline-size: 1.5rem; block-size: 1.5rem; margin: 0; accent-color: var(--color-primary); }
.atfal-portal-body .ap-list__row.is-selected { background: var(--color-primary-tint); }
/* Without subgrid (older browsers) the columns fall back to fixed tracks. */
@supports not (grid-template-columns: subgrid) {
	.atfal-portal-body .ap-list__row { grid-template-columns: var(--ap-list-cols); }
}
@media (max-width: 640px) {
	.atfal-portal-body .ap-list { display: block; }
	.atfal-portal-body .ap-list__row { display: flex; flex-direction: column; align-items: stretch; gap: var(--space-2); }
	/* The header row becomes a "Select all" strip (or disappears when there is nothing to select). */
	.atfal-portal-body .ap-list__row.ap-list__head { display: none; }
	.atfal-portal-body .ap-list--select .ap-list__row.ap-list__head { display: flex; min-block-size: var(--tap-target); }
	.atfal-portal-body .ap-list__head > .ap-list__cell:not(.ap-list__select) { display: none; }
	.atfal-portal-body .ap-list__head > .ap-list__select[data-label] { position: static; display: flex; justify-content: space-between; inline-size: 100%; }
	.atfal-portal-body .ap-list__head > .ap-list__select[data-label]::before { content: attr(data-label); font-size: var(--fs-caps-label); font-weight: var(--fw-bold); letter-spacing: var(--tracking-caps); text-transform: uppercase; }
	.atfal-portal-body .ap-list__cell[data-label] { justify-content: space-between; }
	.atfal-portal-body .ap-list__cell[data-label]::before { content: attr(data-label); font-size: var(--fs-caption); font-weight: var(--fw-semibold); color: var(--color-text-soft); }
	.atfal-portal-body .ap-list__actions { justify-content: flex-start; }
	.atfal-portal-body .ap-list__select { position: absolute; inset-inline-end: var(--space-4); }
	.atfal-portal-body .ap-list--select .ap-list__row { position: relative; padding-inline-end: calc(var(--space-4) + var(--list-select-col)); }
}

/* Plain row lists across the portal (insights, notices, report history, ranks,
   what a Tifl learned): one subtle divider between rows. */
.atfal-portal-body .ap-main :is(.arep-insights__list, .tt-list:not(.ap-cards), .arep-notices__list, .arep-mr-history, .tt-learned, .arep-mt-reports__list, .ap-dash__rank, .ap-lesson-list, .ap-courses:not(.ap-cards)) > li + li {
	border-block-start: var(--border-subtle);
	padding-block-start: var(--space-2);
}

/* Divided settings lists (Sign-in & Security pattern) keep their dividers and
   push the row's action to the end, aligned on every row. */
.atfal-portal-body .ap-secure__row + .ap-secure__row { border-block-start: var(--border-subtle); }

/* ap-table: a stronger header row, visible row dividers, optional zebra,
   one row height, actions in a final end-aligned column. */
.atfal-portal-body .ap-table th {
	color: var(--color-text-soft);
	background: var(--color-canvas);
	border-block-end: var(--border-default);
}
.atfal-portal-body .ap-table td { min-block-size: var(--row-min); border-block-end: var(--border-subtle); }
.atfal-portal-body .ap-table--zebra tbody tr:nth-child(even) > td { background: var(--color-canvas); }
.atfal-portal-body .ap-table :is(th, td).ap-table__actions { text-align: end; white-space: nowrap; inline-size: 1%; }
.atfal-portal-body .ap-table td.ap-table__actions > .u-cluster { justify-content: flex-end; }
.atfal-portal-body .ap-table :is(th, td).ap-table__select { inline-size: var(--list-select-col); text-align: center; }
.atfal-portal-body .ap-table tr.is-selected > td { background: var(--color-primary-tint); }
/* Long column headers (consent choices) wrap as sentences instead of widening the table. */
.atfal-portal-body .ap-table--wrapheads th { white-space: normal; min-inline-size: 8rem; vertical-align: bottom; }

/* ---- 6. Badges --------------------------------------------------------------
   One component (.ap-pill; .ap-badge is the same thing), one height. Status
   is a word plus an icon, never colour alone. Inside an aligned column a badge
   has a fixed minimum width so the column reads as one. */
.atfal-portal-body .ap-badge { display: inline-flex; align-items: center; gap: var(--space-1); block-size: 1.5rem; padding-inline: var(--space-2); border: var(--border-width) solid var(--color-neutral-border); border-radius: var(--radius-pill); background: var(--color-neutral-bg); color: var(--color-neutral); font-size: var(--fs-caption); font-weight: var(--fw-semibold); line-height: 1; white-space: nowrap; }
.atfal-portal-body :is(.ap-pill, .ap-badge):is(.ap-pill--success, .ap-pill--info, .ap-pill--warning, .ap-pill--danger, .ap-pill--neutral, .ap-pill--outline)::before {
	content: "";
	flex: none;
	inline-size: 0.875em;
	block-size: 0.875em;
	background: currentColor;
	-webkit-mask: var(--ap-badge-icon) center / contain no-repeat;
	mask: var(--ap-badge-icon) center / contain no-repeat;
}
.atfal-portal-body :is(.ap-pill, .ap-badge).ap-pill--success { --ap-badge-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6.2 11.6 2.8 8.2l1.1-1.1 2.3 2.3 5.9-5.9 1.1 1.1z'/%3E%3C/svg%3E"); }
.atfal-portal-body :is(.ap-pill, .ap-badge):is(.ap-pill--warning, .ap-pill--danger) { --ap-badge-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7 3h2v6H7zm0 8h2v2H7z'/%3E%3C/svg%3E"); }
.atfal-portal-body :is(.ap-pill, .ap-badge).ap-pill--info { --ap-badge-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7 7h2v6H7zm0-4h2v2H7z'/%3E%3C/svg%3E"); }
.atfal-portal-body :is(.ap-pill, .ap-badge):is(.ap-pill--neutral, .ap-pill--outline) { --ap-badge-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='3'/%3E%3C/svg%3E"); }
/* Only a cell's single badge gets the fixed width; a cell with several badges stays compact. */
.atfal-portal-body :is(.ap-list__cell, .ap-table td) > :is(.ap-pill, .ap-badge):only-child { min-inline-size: var(--badge-min); }

/* ---- 7. Tabs (ap-tabs) ------------------------------------------------------
   Spans the content width; tabs share it evenly; a divider between tabs; the
   active tab is bold with a 3px bar (not colour alone); narrow screens scroll
   sideways with fade hints (portal-ui.js sets .is-scroll-start/.is-scroll-end).
   The same component draws page tabs, section tabs and wizard step bars. */
.atfal-portal-body .ap-tabs {
	position: relative;
	display: flex;
	flex-wrap: nowrap;
	align-items: stretch;
	gap: 0;
	inline-size: 100%;
	border-block-end: var(--border-default);
	overflow-x: auto;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}
.atfal-portal-body .ap-tabs::-webkit-scrollbar { display: none; }
.atfal-portal-body .ap-tabs > :is(.ap-tabs__link, [role="tab"]) {
	flex: 1 1 0;
	min-inline-size: max-content;
	justify-content: center;
	padding-inline: var(--space-4);
	border-block-end: 3px solid transparent;
	text-align: center;
}
.atfal-portal-body .ap-tabs > :is(.ap-tabs__link, [role="tab"]) + :is(.ap-tabs__link, [role="tab"]) {
	border-inline-start: var(--border-subtle);
}
.atfal-portal-body .ap-tabs > :is(.ap-tabs__link, [role="tab"]):is(.is-active, [aria-current="page"], [aria-current="step"], [aria-selected="true"]) {
	border-block-end-color: var(--color-primary);
	color: var(--color-text) !important;
	font-weight: var(--fw-heavy);
	background: var(--color-surface);
}
/* Utility links (Help, Export) at the end of a tab bar stay their natural width. */
.atfal-portal-body .ap-tabs > :is(.ap-tabs__spacer, .ap-tabs__util) { flex: none; }
/* Fade hints while there is more to scroll. */
.atfal-portal-body .ap-tabs.is-scroll-start { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.atfal-portal-body .ap-tabs.is-scroll-end { -webkit-mask-image: linear-gradient(to left, #000 85%, transparent); mask-image: linear-gradient(to left, #000 85%, transparent); }
.atfal-portal-body .ap-tabs.is-scroll-start.is-scroll-end { -webkit-mask-image: linear-gradient(to right, transparent, #000 10%, #000 90%, transparent); mask-image: linear-gradient(to right, transparent, #000 10%, #000 90%, transparent); }
[dir="rtl"] .atfal-portal-body .ap-tabs.is-scroll-start { -webkit-mask-image: linear-gradient(to left, #000 85%, transparent); mask-image: linear-gradient(to left, #000 85%, transparent); }

/* ---- 8. Buttons in rows ------------------------------------------------------
   "Edit", "View", "Manage", "Add" in a list or table are real buttons (border
   or fill, padding, hover, focus, 44px target on touch). True navigation stays
   a link. Buttons in one row share one height. */
.atfal-portal-body .ap-btn--tertiary { background: transparent; border-color: transparent; color: var(--color-primary) !important; }
.atfal-portal-body .ap-btn--tertiary:hover { background: var(--color-primary-tint); }
.atfal-portal-body :is(.ap-list__actions, .ap-table__actions, .ap-secure__row) .ap-btn:is(.ap-btn--ghost, .ap-btn--tertiary),
.atfal-portal-body .ap-main :is(tr, li, .ap-list__row) .ap-btn:is(.ap-btn--ghost, .ap-btn--tertiary) {
	border-color: var(--color-border);
	background: var(--color-surface);
}
.atfal-portal-body :is(.ap-list__actions, .ap-table__actions, .ap-form__actions, .ap-modal__foot, .ap-bulk) > .ap-btn,
.atfal-portal-body :is(.ap-list__actions, .ap-table__actions, .ap-form__actions, .ap-modal__foot, .ap-bulk) > form > .ap-btn {
	min-block-size: var(--control-height);
}

/* ---- 9. Collapsible sections (ap-collapsible) ------------------------------
   <section class="ap-collapsible" data-collapsible="amila-rules-limits" data-collapsible-default="closed">
     <h2 class="ap-collapsible__heading">
       <button type="button" class="ap-collapsible__toggle" aria-expanded="true" aria-controls="id">
         <span class="ap-collapsible__title">Team limits</span>
         <span class="ap-collapsible__summary">Up to 2 teams per Tifl · 1 secretary per team</span>
       </button>
     </h2>
     <div class="ap-collapsible__body" id="id">…</div>
   </section>
   Rendered open, so it works with JavaScript off. portal-ui.js applies the
   default and each person's remembered state, and keeps a panel with an
   error open. */
.atfal-portal-body .ap-collapsible {
	border: var(--border-subtle);
	border-radius: var(--radius-md);
	background: var(--color-surface);
}
.atfal-portal-body .ap-collapsible + .ap-collapsible { margin-block-start: 0; }
.atfal-portal-body .ap-collapsibles { display: flex; flex-direction: column; gap: var(--space-3); }
.atfal-portal-body .ap-collapsible__heading { margin: 0; font-size: inherit; text-transform: none; letter-spacing: 0; }
.atfal-portal-body .ap-collapsible__toggle {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: var(--space-1) var(--space-4);
	inline-size: 100%;
	min-block-size: var(--tap-target);
	padding: var(--space-3) var(--space-4);
	border: 0;
	border-radius: var(--radius-md);
	background: transparent;
	color: var(--color-text);
	font: inherit;
	text-align: start;
	cursor: pointer;
}
.atfal-portal-body .ap-collapsible__toggle:hover { background: var(--color-canvas); }
.atfal-portal-body .ap-collapsible__toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.atfal-portal-body .ap-collapsible__title { grid-column: 1; }
.atfal-portal-body .ap-collapsible__summary { grid-column: 1; font-size: var(--fs-small); color: var(--color-text-soft); text-transform: none; letter-spacing: 0; font-weight: var(--fw-regular); }
.atfal-portal-body .ap-collapsible__toggle::after {
	content: "";
	grid-column: 2;
	grid-row: 1 / span 2;
	inline-size: 0.6rem;
	block-size: 0.6rem;
	border-inline-end: 2px solid currentColor;
	border-block-end: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform var(--motion-fast) ease;
}
.atfal-portal-body .ap-collapsible__toggle[aria-expanded="true"]::after { transform: rotate(-135deg); }
.atfal-portal-body .ap-collapsible__toggle[aria-expanded="true"] .ap-collapsible__summary { display: none; }
.atfal-portal-body .ap-collapsible__body {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	padding: var(--space-2) var(--space-4) var(--space-4);
	border-block-start: var(--border-subtle);
	padding-block-start: var(--space-4);
}
.atfal-portal-body .ap-collapsible__body[hidden] { display: none; }

/* ---- 10. Modals (dialog.ap-modal) -------------------------------------------
   The native <dialog> opened with showModal(): the rest of the page is inert,
   Escape closes it, and portal-ui.js returns focus and locks page scroll.
   A clear title, a scrolling body and a sticky footer with Cancel and Save.
   Phones: a full-screen sheet. The verse splash keeps .ap-modal (div). */
.atfal-portal-body dialog.ap-modal {
	position: fixed;
	inset: 0;
	display: none;
	flex-direction: column;
	inline-size: min(100% - 2 * var(--space-4), var(--modal-max));
	max-block-size: calc(100dvh - 2 * var(--space-6));
	margin: auto;
	padding: 0;
	border: 0;
	border-radius: var(--radius-lg);
	background: var(--color-surface);
	color: var(--color-text);
	box-shadow: var(--shadow-3);
	text-align: start;
	place-items: initial;
	overflow: hidden;
}
.atfal-portal-body dialog.ap-modal[open] { display: flex; }
.atfal-portal-body dialog.ap-modal::backdrop { background: var(--color-overlay); }
.atfal-portal-body .ap-modal__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3);
	padding: var(--space-4) var(--space-5);
	border-block-end: var(--border-subtle);
}
.atfal-portal-body .ap-modal__close { min-inline-size: var(--tap-target); }
.atfal-portal-body .ap-modal__body {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	padding: var(--space-5);
	overflow-y: auto;
}
.atfal-portal-body .ap-modal__foot {
	position: sticky;
	inset-block-end: 0;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-end;
	gap: var(--space-3);
	padding: var(--space-3) var(--space-5);
	border-block-start: var(--border-subtle);
	background: var(--color-surface);
}
.atfal-portal-body .ap-modal__foot .ap-modal__note { margin-inline-end: auto; font-size: var(--fs-small); color: var(--color-text-soft); }
.atfal-portal-body dialog.ap-modal form { display: contents; }
html.ap-scroll-locked, html.ap-scroll-locked body { overflow: hidden; }
@media (max-width: 640px) {
	.atfal-portal-body dialog.ap-modal { inline-size: 100%; max-inline-size: none; block-size: 100dvh; max-block-size: none; border-radius: 0; }
	.atfal-portal-body .ap-modal__body { flex: 1; }
}

/* ---- 11. Bulk editing (ap-bulk) ---------------------------------------------
   A list with a checkbox column (data-bulk-item) and a "Select all" header
   checkbox (data-bulk-all). With one or more rows selected, the bar appears:
   "N selected" and "Edit selected", which opens a modal where each field
   starts as "Leave unchanged" (data-bulk-field toggles it on). */
.atfal-portal-body .ap-bulk {
	position: sticky;
	inset-block-end: var(--space-3);
	z-index: 5;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-3) var(--space-4);
	border: var(--border-width) solid var(--color-primary-line);
	border-radius: var(--radius-md);
	background: var(--color-primary-tint);
	box-shadow: var(--shadow-2);
}
.atfal-portal-body .ap-bulk[hidden] { display: none; }
.atfal-portal-body .ap-bulk__count { margin-inline-end: auto; font-weight: var(--fw-semibold); }
.atfal-portal-body .ap-bulkfield { display: flex; flex-direction: column; gap: var(--space-2); padding-block: var(--space-3); }
.atfal-portal-body .ap-bulkfield + .ap-bulkfield { border-block-start: var(--border-subtle); }
.atfal-portal-body .ap-bulkfield__control[aria-disabled="true"] { opacity: 0.55; }
.atfal-portal-body .ap-bulk__summary { margin: 0; font-weight: var(--fw-semibold); }

/* ---- 12. Save state -----------------------------------------------------------
   form[data-dirty-save]: the Save button is disabled until something changes;
   a saved notice confirms it (the server's notice, plus a live region). */
.atfal-portal-body .ap-savestate { font-size: var(--fs-small); color: var(--color-text-soft); }
.atfal-portal-body .ap-savestate.is-saved { color: var(--color-success); font-weight: var(--fw-semibold); }
