/*
 * Shared portal rules loaded by the Customer and Admin index.html after MudBlazor.
 * Colours come only from MudBlazor palette variables, which the brand theme fills.
 */

/* ── Target size: WCAG 2.5.5 (AAA) and Apple HIG ask for a 44 × 44 px hit area ────────────────
 * Compact buttons and chip actions keep their look; an invisible ::before layer widens the area that
 * takes the click so dense tables keep their row height. Text buttons (31 and 37 px tall) get it too. */
.mud-icon-button,
.mud-button-root,
.mud-chip.mud-clickable,
.mud-chip-close-button,
.mud-link,
.sb-plain-button,
.sb-card-button {
    position: relative;
}

/* Links get the layer too: a standalone link (a table cell, a banner, a list) is a target in its own right.
 * Inline-block, so a link that would wrap moves to the next line whole and its layer stays one square. */
.mud-link {
    display: inline-block;
    max-width: 100%;
}

.mud-icon-button::before,
.mud-button-root::before,
.mud-chip.mud-clickable::before,
.mud-chip-close-button::before,
.mud-link::before,
.sb-plain-button::before,
.sb-card-button::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: max(100%, 44px);
    height: max(100%, 44px);
    transform: translate(-50%, -50%);
}

/* MudBlazor's .mud-ripple sets overflow: hidden on the same element, which clips the hit layer back to
 * the visible box. Let it overflow; the ripple would then spill past the button, so it is not drawn
 * there. The hover, focus and pressed fills still show the press. */
.mud-ripple:is(.mud-icon-button, .mud-button-root, .mud-chip.mud-clickable) {
    overflow: visible;
}

.mud-ripple:is(.mud-icon-button, .mud-button-root, .mud-chip.mud-clickable) .mud-ripple-effect {
    display: none;
}

/* Side by side, two 44 px layers must not overlap: a click 21 px from one button's centre must land on
 * that button. Small icon buttons are 26 px, so any button next to one (in a row, toolbar, grid header
 * or action group, bare or wrapped in a tooltip or menu) sits 18 px from it: the margin tops up the
 * gap a MudStack or gap-* class already gives. The gap is the direct parent's only: registered as not
 * inherited, so a gap-0 row inside a gap-4 stack reads 0, not 16 px. */
@property --sb-parent-gap {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
}

.gap-1 > * { --sb-parent-gap: 4px; }
.gap-2 > * { --sb-parent-gap: 8px; }
.gap-3 > * { --sb-parent-gap: 12px; }
.gap-4 > * { --sb-parent-gap: 16px; }

:is(.mud-icon-button-size-small, :is(.mud-tooltip-root, .mud-menu):has(.mud-icon-button-size-small)) + :is(.mud-button-root, :is(.mud-tooltip-root, .mud-menu):has(.mud-button-root)),
:is(.mud-button-root, :is(.mud-tooltip-root, .mud-menu):has(.mud-button-root)) + :is(.mud-icon-button-size-small, :is(.mud-tooltip-root, .mud-menu):has(.mud-icon-button-size-small)) {
    margin-inline-start: max(0px, 18px - var(--sb-parent-gap, 0px));
}

/* A date or select field's clear button sat 8 px over its open button (MudBlazor's me-n4); 10 px apart,
 * each keeps its own 44 px square. */
.mud-input-adorned-end > .mud-input-clear-button {
    margin-inline-end: 8px !important; /* beats MudBlazor's me-n4 utility, which is !important */
}

/* Dense grid rows are shorter than 44 px, so the hit layers of buttons in neighbouring rows overlapped: a
 * click just below one row's button landed on the next row's. A row with a control is at least 44 px. */
.mud-table-root :is(.mud-table-body, .mud-table-head) .mud-table-row:has(:is(.mud-button-root, .mud-link)) > .mud-table-cell {
    height: 44px;
}

/* Text fields, selects and grid filter inputs are 32 px tall (29 px in a dense filter row), and the field
 * itself is the target. Its input grows to 44 px with padding the negative margins take back, so the
 * text and the row height stay where they were. MudBlazor sizes the input 1.1876em with 6 px above
 * (3 px dense) and 7 px below. Outlined fields are 56 px already. */
.mud-input-text:not(.mud-input-outlined) > .mud-input-slot:not(textarea) {
    position: relative;
    padding-block: calc(22px - 0.5938em);
    margin-block: calc(0.5938em - 16px) calc(0.5938em - 15px);
}

/* A filter-row input in a narrow column is at least 44 px wide too. */
.mud-input-text.mud-input-margin-dense:not(.mud-input-outlined) > .mud-input-slot:not(textarea) {
    margin-block-start: calc(0.5938em - 19px);
    min-width: 44px;
}

/* The rows-per-page select is 29 × 20 px: its slot grows to 45 × 44 px the same way. MudBlazor sets this
 * slot's padding and top margin with !important. */
.mud-table-pagination-select .mud-input-text > .mud-input-slot.mud-input-root {
    padding: 12px 16px !important;
    margin: -12px -8px !important;
}

/* A switch and its label are 38 px tall: 3 px more above and below, taken back by the margins. */
label.mud-switch {
    padding-block: 4px;
    margin-block: -3px;
}

/* A data grid header puts the sort button and the column menu in one span, with the sort index between them. */
.column-options:has(> .mud-icon-button-size-small) > .mud-menu {
    margin-inline-start: 8px;
}

/* ── Focus ring: WCAG 2.4.7 and 2.4.13 ─────────────────────────────────────────────────────────
 * MudBlazor removes the outline (button:focus and a:focus-visible) and leaves only a faint tint. Every
 * focusable control gets one ring in the link colour, which is 7:1 on the background and surface in
 * both modes. A field shows only an underline (standard, filter-row and search fields) or a border that
 * changes colour (outlined fields and date pickers), so the ring goes on its input box too. Checkboxes
 * and radios focus a hidden input, so the ring goes on their visible button; a switch's goes round the
 * whole switch, track and thumb. */
:is(a, button, summary, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], [role="switch"], [tabindex]:not([tabindex="-1"]), .mud-nav-link, .mud-chip.mud-clickable):not(input, textarea, select, .mud-input-slot):focus-visible,
:is(.mud-icon-button:not(.mud-switch-base), .mud-switch-span):has(input:focus-visible),
.mud-select .mud-input:has(> .mud-input-slot:focus-visible),
.mud-input:has(> :is(input, textarea).mud-input-slot:focus-visible) {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

/* FocusOnNavigate moves focus to each page's h1 (tabindex="-1", never in the tab order) so screen readers announce
 * the page. A heading is not a control, so WCAG 2.4.7 asks for no ring on it, and the browser's default one reads as
 * a stray box round the title. Controls keep the ring above. */
h1[tabindex="-1"]:focus {
    outline: none;
}

/* A select (rows per page, lookback period) focuses a div slot that MudBlazor draws no focus change on,
 * so the ring above goes on its input box. Inside the side navigation the drawer clips anything past its
 * edge, so the ring sits just inside each link, 3 px wide so it still covers more than a 2 px perimeter.
 * Data grid sort buttons are hidden until hovered or sorted; a focused one shows itself so its ring is
 * never drawn on nothing. */
.mud-navmenu :focus-visible {
    outline-width: 3px !important; /* beats the ring rule's :is()/:not() specificity */
    outline-offset: -3px !important;
}

.sort-direction-icon:focus-visible {
    opacity: 1 !important;
}

/* A switch's ring is 3 px: the switch is wider than its thumb, the part that takes focus. The label
 * prefix outranks the ring rule's :is(), which takes its most specific argument. */
label.mud-switch .mud-switch-span:has(input:focus-visible) {
    outline-width: 3px;
}

/* ── App footer: in the page flow, never fixed over content (WCAG 2.4.11) ─────────────────────── */
.sb-main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sb-main-content > main {
    flex: 1 0 auto;
}

.sb-app-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
    padding-top: 12px;
    border-top: 1px solid var(--mud-palette-lines-default);
}

/* The legal line takes its own row; the links sit together under it, so no separator can be stranded at a wrap. */
.sb-app-footer > .mud-typography {
    flex: 1 1 100%;
    text-align: center;
}

/* The strapline lockup: one logo per footer, never narrower than 180px. */
.sb-app-footer__logo {
    flex: 1 1 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 4px;
}

.sb-app-footer__logo img {
    width: 180px;
    max-width: 100%;
    height: auto;
}

/* The trade mark sign sits high without pushing the line apart. */
.sb-app-footer sup {
    line-height: 0;
}

.sb-app-footer__links {
    display: flex;
    flex-wrap: wrap;
    align-items: center; /* links and the 24px Cookie settings button share one centre line */
    justify-content: center;
    gap: 4px 24px;
}

/* ── Toasts: below the fixed app bar, so a toast never covers the app bar's controls (WCAG 2.4.11) ── */
.mud-snackbar-location-top-right {
    top: calc(var(--mud-appbar-height) + 8px);
}

/* Moved there by layout-a11y.js while the focused control is under a toast (WCAG 2.4.12). */
.mud-snackbar-location-top-right.sb-toasts-below {
    top: auto;
    bottom: calc(16px + var(--sb-cookie-banner-height, 0px));
}

/* ── App bar at 320 px (WCAG 1.4.10) ───────────────────────────────────────────────────────────
 * Toggle, mark, selectors, feedback, help, theme and account must fit a phone's width: tighter gutters
 * and 40 px icon buttons. The 44 px hit layer above still gives each its target. */
@media (max-width: 599.98px) {
    .mud-appbar .mud-toolbar {
        padding-inline: 8px;
    }

    .mud-appbar .mud-icon-button {
        padding: 8px;
    }
}

/* FocusOnNavigate moves focus to each page's h1 (tabindex -1). The heading is not operable, so it draws no ring
 * on load; real tab stops keep the ring above. */
h1[tabindex="-1"]:focus {
    outline: none;
}

/* ── Closed drawers (WCAG 2.1.2, 2.4.3) ──────────────────────────────────────────────────────────
 * MudBlazor keeps a closed blade, chat panel or collapsed nav drawer in the page, slid off-screen: its
 * controls stay in the tab order and its shadow shows on the page edge. Hide it once the slide-out
 * ends (visibility waits 225 ms, MudBlazor's slide time); opening shows it at once. */
.mud-drawer:is(.mud-drawer-temporary, .mud-drawer-responsive).mud-drawer--closed:not(.mud-drawer--initial),
.mud-drawer:is(.mud-drawer-temporary, .mud-drawer-responsive).mud-drawer--closed.mud-drawer--initial {
    visibility: hidden;
    box-shadow: none;
    transition: left 225ms cubic-bezier(0, 0, 0.2, 1), right 225ms cubic-bezier(0, 0, 0.2, 1),
        top 225ms cubic-bezier(0, 0, 0.2, 1), bottom 225ms cubic-bezier(0, 0, 0.2, 1), visibility 0s linear 225ms;
}

/* ── Clickable cards and tiles that are not native buttons ───────────────────────────────────── */
.sb-clickable {
    cursor: pointer;
}

.sb-clickable:focus-visible,
.sb-plain-button:focus-visible,
.sb-card-button:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

/* A <button> with no native chrome that inherits the surrounding text, for panels and cards. */
.sb-plain-button,
.sb-card-button {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: inherit;
    cursor: pointer;
    border-radius: var(--mud-default-borderradius);
}

/* A plain button that wraps a whole card or bar takes the full width of its cell. */
.sb-card-button {
    display: block;
    width: 100%;
}

/* Text for screen readers only, such as the h1 of a page whose heading is not shown. */
.sb-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* A wrapper that only catches keys or holds a reference, without taking part in layout. */
.sb-contents,
.mud-focus-trap.sb-contents > .mud-focus-trap-child-container {
    display: contents;
}

/* A disabled MudBlazor button ignores the pointer, so the tooltip anchor around it needs a box to receive the hover. */
.sb-contents:has(> .mud-button-root[disabled]) {
    display: inline-flex;
}

/* ── Status graphics (scan rules, asset lifecycle, connector health) ─────────────────────────── */
.sb-status-bar {
    display: flex;
    height: 8px;
    overflow: hidden;
    border-radius: var(--jf-radius-sm);
    background: var(--mud-palette-lines-default);
}

.sb-status-dot {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 2px; /* a status dot is smaller than the 6px step: 2px keeps it a rounded square */
}

.sb-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.5rem;
    border-radius: var(--jf-radius-sm);
    font-size: var(--mud-typography-caption-size);
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}

/* ── Unavailable options: the disabled text role instead of opacity, which also dims borders ──── */
.sb-unavailable,
.sb-unavailable .mud-typography {
    color: var(--mud-palette-text-disabled) !important;
}

/* ── Typography helpers ─────────────────────────────────────────────────────────────────────── */
.sb-mono,
.sb-code-block {
    font-family: var(--brand-font);
    font-variant-numeric: tabular-nums;
}

/* Scripts, JSON and rendered templates: wrapped monospace on the grey background. */
.sb-code-block {
    font-size: var(--mud-typography-body2-size);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    overflow-x: auto;
    border-radius: var(--mud-default-borderradius);
    background-color: var(--mud-palette-background-gray);
}

.sb-strong {
    font-weight: 600;
}

/* ── Reduced motion: stop movement, keep colour and opacity feedback ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-property: color, background-color, border-color, outline-color, opacity, box-shadow, fill, stroke !important;
    }

    /* Ripples grow from the click point; drop them entirely. */
    .mud-ripple-effect {
        display: none !important;
    }

    /* Busy indicators must still show progress, so they turn slowly instead of stopping. */
    .mud-progress-circular.mud-progress-indeterminate,
    .mud-progress-circular-circle.mud-progress-indeterminate,
    .mud-progress-linear.mud-progress-indeterminate .mud-progress-linear-bar,
    .loading-spinner,
    .loading-spinner circle {
        animation-duration: 4s !important;
        animation-iteration-count: infinite !important;
    }
}

/* ── Alerts with an action ───────────────────────────────────────────────────────────────────────
 * MudBlazor pins the alert icon to the top. A button in the message makes the row taller than one
 * line, so the icon floats above the text; centre it on the row instead. Alerts without a button
 * keep the icon level with their first line. */
.mud-alert-position:has(.mud-button-root) {
    align-items: center;
}

/* ── Table action cells ──────────────────────────────────────────────────────────────────────────
 * A <td> must stay a table cell: display:flex on it stops it stretching to the row height, so its
 * border and buttons drift out of line with the rest of the row. Align its content right instead. */
td.sb-actions-cell {
    text-align: end;
    vertical-align: middle;
    white-space: nowrap;
}

td.sb-actions-cell > .d-flex,
td.sb-actions-cell > .mud-stack {
    display: inline-flex;
}

/* An icon placed in a line of text (such as the inherited-scope badge after a name) sits on the text. */
.mud-typography > .mud-tooltip-root {
    vertical-align: text-bottom;
}

/* ── Rendered-state contrast (AC2) ──────────────────────────────────────────────────────────────
 * Status text must stay at 7:1 on every ground it can sit on. MudBlazor draws text and outlined chips
 * on a 12% tint when hovered, focused or selected; keep them on the 6% hover tint the theme tests check. */
.mud-chip-text.mud-chip-color-primary.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-primary.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-primary-hover);
}

.mud-chip-text.mud-chip-color-secondary.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-secondary.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-secondary-hover);
}

.mud-chip-text.mud-chip-color-tertiary.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-tertiary.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-tertiary-hover);
}

.mud-chip-text.mud-chip-color-info.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-info.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-info-hover);
}

.mud-chip-text.mud-chip-color-success.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-success.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-success-hover);
}

.mud-chip-text.mud-chip-color-warning.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-warning.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-warning-hover);
}

.mud-chip-text.mud-chip-color-error.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-error.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-error-hover);
}

.mud-chip-text.mud-chip-color-dark.mud-clickable:is(:hover, :focus-visible, :active):not(.mud-disabled),
.mud-chip-outlined.mud-chip-color-dark.mud-chip-selected:is(:hover, :focus-visible, :active):not(.mud-disabled) {
    background-color: var(--mud-palette-dark-hover);
}

/* Placeholders are text: MudBlazor fades the input colour to 42% (about 2.7:1). Use the secondary text role. */
.mud-input > input.mud-input-root::placeholder,
.mud-input > textarea.mud-input-root::placeholder,
div.mud-input-slot.mud-input-root::placeholder {
    color: var(--mud-palette-text-secondary);
    opacity: 1;
}

/* Tooltips: MudBlazor's grey (about 5.5:1) becomes body text on the raised surface. The arrow reads
 * --mud-palette-gray-darker, so redefining it here recolours the arrow for every placement. */
.mud-tooltip.mud-tooltip-default {
    --mud-palette-gray-darker: var(--mud-palette-background-gray);
    color: var(--mud-palette-text-primary);
    background-color: var(--mud-palette-background-gray);
    box-shadow: 0 0 0 1px var(--mud-palette-lines-default);
}

/* SbTooltip (WCAG 1.4.13): a transparent bridge over the 10 px gap between anchor and tooltip, so the
 * pointer can move onto the tooltip without leaving both. */
.sb-tooltip-content {
    position: relative;
    display: block;
}

.sb-tooltip-content::before {
    content: "";
    position: absolute;
    inset: -14px -12px;
}

/* A link in running text or an alert is told apart from the text around it by its underline, not by
 * colour alone (WCAG 1.4.1): in a dark info alert the link and the alert text are nearly the same colour. */
.mud-alert-message a:not(.mud-button-root),
p a:not(.mud-button-root),
.mud-typography a:not(.mud-button-root) {
    text-decoration: underline;
}

/* ── Switches (AC5) ──────────────────────────────────────────────────────────────────────────────
 * The track shows in the input-border colour when off and in the link colour when on; the thumb sits
 * left or right and the label names the state, so on and off never rely on hue. */
/* The switch base is an icon button that MudBlazor positions absolutely over the track; the target-size
 * rule above must not pull it back into the flow, which squeezed the track to nothing. */
.mud-switch-base.mud-button-root {
    position: absolute;
}

/* MudBlazor clips the switch to its 38 px box, which would cut the base's 44 px hit layer. */
.mud-switch-span {
    overflow: visible;
}

.mud-switch-span .mud-switch-track {
    display: block;
    flex: 1 0 auto;
    opacity: 1;
    background-color: var(--mud-palette-lines-inputs);
}

.mud-switch-base.mud-checked + .mud-switch-track {
    opacity: 1;
    background-color: var(--mud-palette-primary);
}

.mud-switch-base:not(.mud-switch-disabled) :is(.mud-switch-thumb-small, .mud-switch-thumb-medium, .mud-switch-thumb-large) {
    background-color: var(--mud-palette-surface);
    box-shadow: 0 0 0 1px var(--mud-palette-lines-inputs);
}

.mud-switch-base.mud-checked:not(.mud-switch-disabled) :is(.mud-switch-thumb-small, .mud-switch-thumb-medium, .mud-switch-thumb-large) {
    background-color: var(--mud-palette-primary-text);
    box-shadow: 0 0 0 2px var(--mud-palette-primary);
}

.mud-switch-base.mud-switch-disabled + .mud-switch-track {
    opacity: 1 !important;
    background-color: var(--mud-palette-action-disabled-background);
}

/* ── Charts (WCAG 1.1.1, 1.4.1): ChartFigure's summary bar, data table and pattern legend ─────── */
.sb-chart-figure {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.sb-chart-figure__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sb-chart-figure__summary {
    margin: 0;
    flex: 1 1 20ch;
}

.sb-chart-figure__table th[scope="row"] {
    font-weight: 400;
    text-align: start;
}

.sb-chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.sb-chart-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* ── Site map and glossary (WCAG 2.4.5, 3.1.3, 3.1.4) ─────────────────────────────────────── */
.sb-site-map-list {
    margin: 0;
    padding-inline-start: 1.25rem;
    line-height: 1.6;
}

/* 20 px apart, so each link's 44 px hit square stays clear of its neighbours' (WCAG 2.5.5). */
.sb-site-map-list > li + li {
    margin-block-start: 24px;
}

.sb-glossary {
    margin: 0;
    max-width: var(--sb-reading-width);
    line-height: 1.6;
}

.sb-glossary dt {
    font-weight: 600;
    margin-block-start: 1em;
}

.sb-glossary dd {
    margin: 0;
}

.sb-glossary abbr {
    text-decoration: none;
}

/* ── Links that open a new tab (WCAG 3.2.5) ─────────────────────────────────────────────────── */
.sb-new-tab-mark {
    font-size: 1em;
    vertical-align: -0.125em;
    margin-inline-start: 0.2em;
}

/* ── Reading width and spacing: WCAG 1.4.8 (AAA) ───────────────────────────────────────────────────
 * Paragraphs, body text, captions, helper text and definitions in the content area: at most 58ch wide,
 * which holds about 75 characters of running text (a ch is the width of a "0", wider than the average
 * letter, so 70ch held 84 to 101). Line height 1.6 (BRAND.md),
 * paragraphs 0.8em apart (1.6em line + 0.8em = 2.4em baseline to baseline, 1.5 times the line
 * spacing). No portal text is justified. */
#main-content :is(p, .mud-typography-body1, .mud-typography-body2, .mud-typography-caption, .mud-input-helper-text, .mud-alert-message) {
    line-height: 1.6;
}

:root {
    --sb-reading-width: 58ch;
}

#main-content :is(p, .mud-typography-body1, .mud-typography-body2, .mud-typography-caption, .mud-input-helper-text, dd):not(.mud-table *) {
    max-width: var(--sb-reading-width);
}

/* Flex stacks space their children with a gap already. */
#main-content p + p:not(.d-flex > p) {
    margin-block-start: 0.8em;
}

/* ── Cookie banner: never over a focused control (WCAG 2.4.12) ─────────────────────────────────────
 * layout-a11y.js sets the banner's height (0 when it is gone). The page keeps that much room below the
 * footer, and focus scrolling keeps that much clear, so the banner covers no control. The padding
 * beats MudBlazor's pa-4 utility, which is !important. */
html {
    scroll-padding-bottom: var(--sb-cookie-banner-height, 0px);
}

.mud-main-content.sb-main-content {
    padding-bottom: calc(16px + var(--sb-cookie-banner-height, 0px)) !important;
}

/* ── "More detail" under a page intro (WCAG 3.1.5) ─────────────────────────────────────────────── */
.sb-more-detail {
    max-width: var(--sb-reading-width);
    line-height: 1.6;
}

.sb-more-detail > summary {
    cursor: pointer;
    color: var(--mud-palette-primary);
    min-height: 44px;
    display: flex;
    align-items: center;
    width: fit-content;
}

/* ── Jofect brand shapes ──────────────────────────────────────────────────────────────────────── */
/* Radius scale (BRAND.md section 6): 6 small controls, 10 buttons and inputs, 14 cards, 20 large panels and
 * dialogs. MudBlazor's --mud-default-borderradius is the button radius (ThemeConfig); the larger surfaces
 * and the smaller controls take their step here. */
.mud-card,
.mud-paper.mud-paper-rounded,
.mud-expansion-panels.mud-expansion-panels-border {
    border-radius: var(--jf-radius-lg);
}

.mud-dialog,
.mud-dialog.mud-dialog-rounded {
    border-radius: var(--jf-radius-xl);
}

.mud-button-root:not(.mud-icon-button, .mud-fab),
.mud-input-outlined .mud-input-outlined-border,
.mud-popover.mud-popover-open:not(.mud-tooltip),
.mud-menu .mud-list-item {
    border-radius: var(--jf-radius-md);
}

.mud-tooltip,
.mud-chip,
.mud-checkbox .mud-icon-root {
    border-radius: var(--jf-radius-sm);
}

/* Avatars are rounded squares, echoing the seat in the logo (10px, the button step). */
.mud-avatar:not(.mud-avatar-square):not(.mud-avatar-rounded),
.mud-avatar.mud-avatar-large:not(.mud-avatar-square):not(.mud-avatar-rounded) {
    border-radius: var(--jf-radius-md);
}

/* Stepper step markers are rounded squares like every other seat shape, not circles. */
.mud-stepper-nav .mud-step-label-icon,
.mud-stepper-nav .mud-avatar {
    border-radius: var(--jf-radius-sm);
}

/* Chips and status pills are rounded rectangles, not capsules. */
.mud-chip.mud-chip-size-small,
.mud-chip.mud-chip-size-medium,
.mud-chip.mud-chip-size-large {
    border-radius: var(--jf-radius-sm);
}

/* "All sources" badge: pack icon in the primary colour on the alternate surface, as a rounded square. */
.mud-avatar.sb-all-sources-badge {
    width: 24px;
    height: 24px;
    background-color: var(--brand-raised);
    color: var(--brand-action);
}

.sb-pip {
    display: inline-flex;
    flex-shrink: 0;
}

/* The standard error state (PipErrorState): a centred sibling of the empty state. Pip is static. */
/* Sibling of EmptyState: the full-size error state sits on the same surface card (Elevation 0). */
.sb-error-state:not(.sb-error-state--compact) {
    background: var(--mud-palette-surface);
    border-radius: var(--mud-default-borderradius);
}

.sb-error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 32px;
    text-align: center;
}

.sb-error-state__text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: 48ch;
}

.sb-error-state__icon {
    color: var(--mud-palette-text-secondary);
}

/* A Retry that reads as a button at rest: outlined in the primary token, 44px target. */
.sb-error-state .sb-error-state__retry {
    min-height: 44px;
    min-width: 44px;
    border: 1px solid var(--mud-palette-primary);
    color: var(--mud-palette-primary);
}

.sb-error-state--compact {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    text-align: left;
}

.sb-error-state--compact .sb-error-state__text {
    align-items: flex-start;
    gap: 2px;
    max-width: none;
    flex: 1 1 12ch;
}

/* A loader stays invisible for 400ms, so a fast response never flashes Pip (BRAND.md section 8). */
.sb-pip-loading {
    opacity: 0;
    animation: sb-pip-appear 150ms ease-out 400ms forwards;
}

/* Progress text under a loader: appears after 5 seconds (400ms delay plus the long wait). */
.sb-pip-progress {
    opacity: 0;
    margin-left: 12px;
    animation: sb-pip-appear 150ms ease-out 5s forwards;
}

@keyframes sb-pip-appear {
    to {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sb-pip-loading,
    .sb-pip-progress {
        animation-duration: 0.01ms;
    }
}

/* Seat-field watermark behind a whole page (landing and welcome only: the page renders <SeatFieldWatermark />,
   an empty marker element). While it is on the page the pattern is painted on the viewport itself, fixed, behind
   everything, and the body background steps aside so it shows through. The pattern files fade out toward the left,
   where the copy sits, and carry no amber seat, so the page keeps its one amber element. The app bar, drawer and
   cards keep their solid surfaces. Leaving the page removes the marker and the pattern with it. */
.sb-seat-watermark {
    display: none;
}

html:has(.sb-seat-watermark) {
    background-image: url("../brand/patterns/seat-field-hero-light.svg");
    background-position: right center;
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

html:has(.sb-seat-watermark) body {
    background: transparent;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):has(.sb-seat-watermark) {
        background-image: url("../brand/patterns/seat-field-hero-dark.svg");
    }
}

:root[data-theme="dark"]:has(.sb-seat-watermark) {
    background-image: url("../brand/patterns/seat-field-hero-dark.svg");
}

/* Landing hero: headline and copy, then Pip with a speech bubble underneath, left-aligned. The slot keeps its
   size while the sign-in check runs, so the loading Pip and the idle Pip swap in place and nothing jumps. */
.sb-landing-hero {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 24px;
}

.sb-landing-hero__copy {
    min-width: 0;
}

.sb-landing-pipline {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 100%;
}

.sb-landing-pip-slot {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
}

.sb-landing-pip-slot > .pip {
    width: 100%;
    height: 100%;
}

/* The bubble comes out of Pip to the right; the tail points back at Pip. */
.sb-landing-bubble {
    position: relative;
    margin: 0;
    min-width: 0;
    padding: 10px 16px;
    border: 1px solid var(--jf-border);
    border-radius: var(--jf-radius-lg);
    background: var(--brand-surface);
    box-shadow: var(--jf-shadow);
    color: var(--mud-palette-text-primary);
    font-size: 1rem;
    line-height: 1.5;
    animation: sb-bubble-in 360ms ease-out both;
}

.sb-landing-bubble::before,
.sb-landing-bubble::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 0;
    height: 0;
    border-style: solid;
    transform: translateY(-50%);
}

.sb-landing-bubble::before {
    left: -9px;
    border-width: 8px 9px 8px 0;
    border-color: transparent var(--jf-border) transparent transparent;
}

.sb-landing-bubble::after {
    left: -8px;
    border-width: 7px 8px 7px 0;
    border-color: transparent var(--brand-surface) transparent transparent;
}

@keyframes sb-bubble-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .sb-landing-bubble {
        animation: none;
    }
}

@media (min-width: 37.5rem) {
    .sb-landing-pip-slot {
        width: 112px;
        height: 112px;
    }
}

/* Pip launcher in the app bar: a visible focus ring on the rounded seat shape. */
.sb-pip-launcher:focus-visible {
    outline: 2px solid var(--brand-link);
    outline-offset: 2px;
    border-radius: var(--jf-radius-md);
}

/* Numbers line up in tables (BRAND.md section 5). */
.mud-table-root .mud-table-cell,
.mud-table-root td,
.mud-table-root th {
    font-variant-numeric: tabular-nums;
}

/* Full-page status screens (404, 403, 500): centred, the heading takes programmatic focus without a ring. */
.sb-status-page {
    min-height: calc(100vh - 8rem);
}

.sb-status-page__title {
    margin: 0 0 16px;
}

.sb-status-page__title:focus {
    outline: none;
}

/* Boot error banner (#blazor-error-ui). It renders before or without Blazor, so it uses brand tokens and
   an inline static Pip (sorry) rather than components. Blazor shows it by setting display:block. */
#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    box-sizing: border-box;
    align-items: center;
    gap: 12px;
    padding: 12px 56px 12px 16px;
    background: var(--brand-surface);
    color: var(--brand-fg);
    border-top: 1px solid var(--brand-line);
    font-family: var(--brand-font);
    font-size: 0.875rem;
}

#blazor-error-ui[style*="block"] {
    display: flex;
}

#blazor-error-ui .sb-boot-pip {
    flex: none;
    width: 40px;
    height: 40px;
}

#blazor-error-ui .sb-boot-pip__body {
    fill: var(--brand-line-strong);
}

#blazor-error-ui .sb-boot-pip__eye {
    stroke: var(--brand-fg);
    stroke-width: 5;
    stroke-linecap: round;
    fill: none;
}

#blazor-error-ui .sb-boot-error__text {
    flex: 1;
}

#blazor-error-ui .reload {
    flex: none;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid var(--brand-link);
    border-radius: 8px;
    color: var(--brand-link);
    font-weight: 600;
    text-decoration: none;
}

#blazor-error-ui .reload:focus-visible,
#blazor-error-ui .dismiss:focus-visible {
    outline: 2px solid var(--brand-link);
    outline-offset: 2px;
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--brand-fg-2);
}

#blazor-error-ui .dismiss:hover {
    color: var(--brand-fg);
}

@media (max-width: 599px) {
    #blazor-error-ui {
        flex-wrap: wrap;
    }

    #blazor-error-ui .sb-boot-error__text {
        flex-basis: calc(100% - 120px);
    }
}
