/*
 * Base layer: reset, element defaults, accessibility helpers and a few layout utilities.
 * Everything here uses :where() (specificity 0) wherever it can, so components and pages override it without a fight.
 * No inline styles anywhere in the portal: the Content-Security-Policy only allows style-src 'self'.
 */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background: var(--a2-bg-0);
    scrollbar-color: var(--a2-steel-3) var(--a2-bg-1);
    scrollbar-gutter: stable; /* no layout shift when a page grows past the viewport */
    scroll-padding-top: var(--a2-space-8);
    scroll-padding-bottom: var(--a2-toast-clearance);
    padding-block-end: var(--a2-toast-clearance);
}

/*
 * While toasts are up in the corner, the page can be scrolled past its own end by what they cover, and a control that takes focus is scrolled clear of them: the footer links and a
 * table's pager would otherwise be stuck under them (WCAG 2.2, 2.4.11 Focus Not Obscured). One toast is about 6.5rem with its gap; up to five stack (ToastService.MaxVisible).
 * The padding is on the root element, not on <body>, so a short page does not lift its footer when a toast arrives. A browser without :has() leaves it all at nothing.
 */
:root {
    --a2-toast-clearance: 0px;
}

:root:has(.a2-toasts .a2-toast) { --a2-toast-clearance: 8rem; }
:root:has(.a2-toasts .a2-toast:nth-child(2)) { --a2-toast-clearance: 14.5rem; }
:root:has(.a2-toasts .a2-toast:nth-child(3)) { --a2-toast-clearance: 21rem; }
:root:has(.a2-toasts .a2-toast:nth-child(4)) { --a2-toast-clearance: 27.5rem; }
:root:has(.a2-toasts .a2-toast:nth-child(5)) { --a2-toast-clearance: 34rem; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--a2-text);
    font: 400 var(--a2-text-md) / 1.6 var(--a2-font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-wrap: break-word;
}

::selection {
    background: rgb(46 230 255 / .3);
    color: #fff;
}

/* Typography */
:where(h1, h2, h3, h4, h5, h6) {
    margin: 0 0 var(--a2-space-3);
    font-family: var(--a2-font-display);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: .03em;
    text-wrap: balance;
}

:where(h1) { font-size: var(--a2-text-3xl); letter-spacing: .06em; text-transform: uppercase; }
:where(h2) { font-size: var(--a2-text-2xl); }
:where(h3) { font-size: var(--a2-text-xl); }
:where(h4) { font-size: var(--a2-text-lg); }
:where(h5, h6) { font-size: var(--a2-text-md); letter-spacing: .08em; text-transform: uppercase; }

:where(p) {
    margin: 0 0 var(--a2-space-4);
    text-wrap: pretty;
}

:where(small) { font-size: var(--a2-text-sm); }
:where(strong, b) { font-weight: 600; }

:where(a) {
    color: var(--a2-energy);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .2em;
    transition: color var(--a2-dur-fast) var(--a2-ease), text-shadow var(--a2-dur-fast) var(--a2-ease);
}

:where(a):hover {
    color: #fff;
    text-shadow: var(--a2-energy-glow);
}

:where(code, kbd, samp, pre) {
    font-family: var(--a2-font-mono);
    font-size: .9em;
}

:where(code, kbd) {
    padding: .1em .4em;
    background: var(--a2-bg-1);
    border: 1px solid var(--a2-steel-2);
    border-radius: var(--a2-radius);
}

:where(pre) {
    margin: 0 0 var(--a2-space-4);
    padding: var(--a2-space-4);
    overflow-x: auto;
    background: var(--a2-bg-1);
    border: 1px solid var(--a2-steel-2);
    border-radius: var(--a2-radius);
}

:where(pre code) {
    padding: 0;
    background: none;
    border: 0;
}

:where(hr) {
    height: 1px;
    margin: var(--a2-space-6) 0;
    background: linear-gradient(90deg, transparent, var(--a2-steel-3), transparent);
    border: 0;
}

:where(ul, ol) {
    margin: 0 0 var(--a2-space-4);
    padding-left: 1.5rem;
}

:where(img, video, canvas) {
    display: block;
    max-width: 100%;
    height: auto;
}

:where(table) {
    width: 100%;
    border-collapse: collapse;
}

:where(th) {
    font-family: var(--a2-font-display);
    font-weight: 600;
    letter-spacing: .06em;
    text-align: left;
    text-transform: uppercase;
}

:where(th, td) {
    padding: var(--a2-space-2) var(--a2-space-3);
    border-bottom: 1px solid var(--a2-steel-2);
}

:where(button, input, select, textarea) {
    font: inherit;
    letter-spacing: inherit;
}

:where(button, [role="button"], summary, label[for], select) {
    cursor: pointer;
}

:where(:disabled, [aria-disabled="true"]) {
    cursor: not-allowed;
}

:where(input[type="checkbox"], input[type="radio"], progress) {
    accent-color: var(--a2-energy);
}

:where([hidden]) {
    display: none !important;
}

/* Focus: a 2 px cyan ring with a glow, 13:1 against the page. Outlines survive forced-colors mode, which box-shadows do not. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--a2-energy);
    outline-offset: 2px;
    box-shadow: var(--a2-energy-glow);
}

/* Elements focused by script only (the heading after a navigation, the skip link's target) are not controls: no ring */
[tabindex="-1"]:focus {
    outline: none;
    box-shadow: none;
}

/* Accessibility helpers */
.a2-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    white-space: nowrap;
    border: 0;
    clip-path: inset(50%);
}

.a2-skip-link {
    position: fixed;
    top: var(--a2-space-2);
    left: var(--a2-space-2);
    z-index: var(--a2-z-overlay);
    padding: var(--a2-space-2) var(--a2-space-4);
    color: var(--a2-on-energy);
    font-family: var(--a2-font-display);
    font-weight: 700;
    letter-spacing: .06em;
    text-decoration: none;
    text-transform: uppercase;
    background: var(--a2-energy);
    transform: translateY(-200%);
}

.a2-skip-link:focus {
    transform: none;
}

/* Layout utilities */
.a2-container {
    width: min(100% - 2 * var(--a2-gutter), 80rem);
    margin-inline: auto;
}

/* The page frame (header, main, footer): the footer stays at the bottom of a short page */
.a2-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.a2-shell__main {
    flex: 1;
    min-width: 0;
}

/* The content column of a page that sits on the full-width public layout */
.a2-page {
    width: min(100% - 2 * var(--a2-gutter), 80rem);
    margin-inline: auto;
    padding-block: var(--a2-space-7);
}

.a2-stack {
    display: flex;
    flex-direction: column;
    gap: var(--a2-stack-gap, var(--a2-space-4));
}

.a2-stack--tight { --a2-stack-gap: var(--a2-space-2); }
.a2-stack--loose { --a2-stack-gap: var(--a2-space-6); }

.a2-cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--a2-cluster-gap, var(--a2-space-3));
}

.a2-cluster--between { justify-content: space-between; }

.a2-dim { color: var(--a2-text-dim); }
.a2-mono { font-family: var(--a2-font-mono); }
.a2-nowrap { white-space: nowrap; }

/* Cards or panels that wrap by themselves: as many columns as fit, none narrower than --a2-grid-min */
.a2-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--a2-grid-min, 18rem)), 1fr));
    gap: var(--a2-grid-gap, var(--a2-space-4));
    align-items: start;
}

/* Facts about one thing: a dimmed term and its value side by side where there is room, one over the other where there is not */
.a2-facts {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: var(--a2-space-2) var(--a2-space-5);
    margin: 0;
}

.a2-facts dt { color: var(--a2-text-dim); }
.a2-facts dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 30rem) {
    .a2-facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .a2-facts dd { margin-bottom: var(--a2-space-3); }
}

/* Rendered Markdown (the legal documents, news posts): the markup is not ours to put classes on */
.a2-prose {
    max-width: 70ch;
}

.a2-prose > * + * { margin-top: var(--a2-space-4); }
.a2-prose :where(h1, h2, h3, h4) { margin-top: var(--a2-space-6); margin-bottom: 0; color: #fff; }
.a2-prose :where(p, ul, ol) { margin-bottom: 0; }
.a2-prose :where(li + li) { margin-top: var(--a2-space-1); }

.a2-prose blockquote {
    margin-inline: 0;
    padding: var(--a2-space-2) var(--a2-space-4);
    color: var(--a2-text-dim);
    background: rgb(255 255 255 / .03);
    border-left: 3px solid var(--a2-energy);
}

/* Blazor's own markup: validation messages and the error boundary */
.validation-message,
.validation-errors {
    color: var(--a2-danger-text);
    font-size: var(--a2-text-sm);
}

.blazor-error-boundary {
    padding: var(--a2-space-4) var(--a2-space-4) var(--a2-space-4) var(--a2-space-7);
    color: var(--a2-on-danger-fill);
    background: var(--a2-danger-fill);
    clip-path: var(--a2-clip-sm);
    position: relative;
}

.blazor-error-boundary::before {
    content: "\26A0"; /* warning sign */
    position: absolute;
    left: var(--a2-space-4);
    font-size: var(--a2-text-xl);
    line-height: 1;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* Shown by Blazor (it sets display through the CSSOM, which the policy allows) when a circuit hits an unhandled exception */
#blazor-error-ui {
    position: fixed;
    inset: auto 0 0;
    z-index: var(--a2-z-toast);
    display: none;
    padding: var(--a2-space-3) var(--a2-gutter);
    color: var(--a2-on-danger-fill);
    background: var(--a2-danger-fill);
    box-shadow: 0 -4px 16px rgb(0 0 0 / .5);
}

#blazor-error-ui :where(a) { color: inherit; font-weight: 600; }
#blazor-error-ui .dismiss { float: right; margin-left: var(--a2-space-4); color: inherit; cursor: pointer; background: none; border: 0; }
