/* Only what the shell needs before and around MudBlazor. Component colour lives in AppTheme.cs. */

:root {
    --app-loading-bg: #f4f6f8;
    --app-loading-fg: #1a2027;
    --app-loading-muted: #5a6772;
    --app-loading-track: #dde3e8;
    --app-accent: #1976d2;
    --app-error-bg: #fdecea;
    --app-error-fg: #7f2019;
    --app-error-border: #f2b8b3;
    --app-selection-bg: rgba(25, 118, 210, 0.22);
    --app-selection-fg: #1a2027;
}

@media (prefers-color-scheme: dark) {
    :root {
        --app-loading-bg: #12171c;
        --app-loading-fg: #e6edf3;
        --app-loading-muted: #a8b3bd;
        --app-loading-track: #2a333c;
        --app-accent: #64b5f6;
        --app-error-bg: #2a1618;
        --app-error-fg: #f6c9c5;
        --app-error-border: #5c2b2b;
        --app-selection-bg: rgba(100, 181, 246, 0.30);
        --app-selection-fg: #e6edf3;
    }
}

/* Selection was the last browser surface still shipping its default. The caret, the focus ring and
   the scrollbar are already themed; leaving the highlight on the browser's blue is what makes an
   otherwise finished screen look assembled rather than built. */
::selection {
    background: var(--app-selection-bg);
    color: var(--app-selection-fg);
}

h1:focus {
    outline: none;
}

/* Keyboard focus must stay visible everywhere, including inside MudBlazor surfaces. */
:focus-visible {
    outline: 2px solid var(--app-accent);
    outline-offset: 2px;
}

/* ---------- Boot screen (rendered before Blazor starts) ---------- */

.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 1rem;
    background: var(--app-loading-bg);
    color: var(--app-loading-fg);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

.app-loading-logo {
    fill: var(--app-accent);
}

.app-loading-text {
    color: var(--app-loading-muted);
    font-size: 0.95rem;
}

.app-loading-bar {
    width: 220px;
    height: 4px;
    border-radius: 2px;
    background-color: var(--app-loading-track);
    overflow: hidden;
}

/* The fill is driven by Blazor's own --blazor-load-percentage, which arrives as a percentage. That
   rules out transform: scaleX(), whose argument is a unitless number no calc() can derive from a
   percentage — but clip-path takes percentages directly, so inset() reaches the same result without
   animating a layout property and without adding script to a boot screen that otherwise runs on
   markup and CSS alone. Reduced motion is honoured below. */
.app-loading-bar-value {
    width: 100%;
    height: 100%;
    background-color: var(--app-accent);
    clip-path: inset(0 calc(100% - var(--blazor-load-percentage, 0%)) 0 0);
    transition: clip-path 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    .app-loading-bar-value {
        transition: none;
    }
}

/* ---------- No JavaScript ---------- */

.app-noscript {
    max-width: 34rem;
    margin: 4rem auto;
    padding: 0 1.5rem;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--app-loading-fg);
}

.app-noscript h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.app-noscript p {
    color: var(--app-loading-muted);
    line-height: 1.6;
}

/* ---------- Form dialogs ---------- */

/* More room above a group label than below it, so the label reads as attached to the fields
   that follow rather than floating between two blocks. */
.form-section {
    margin: 4px 0 -4px;
}

.form-section--divided {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--mud-palette-divider);
}

.form-section__label {
    display: block;
    line-height: 1.4;
    letter-spacing: 0.09em;
}

.form-section__optional {
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.75;
}

/* The disclosure that holds rarely-used fields. Quiet by default; it is a way in, not a control
   competing with the form. */
.form-disclosure {
    align-self: flex-start;
    margin-left: -8px;
}

/* Tabular figures wherever digits are compared down a column or across a pair of fields.
   The rule was already stated for form fields but the data grids — the place digits are actually
   compared down a column — were still running proportional figures, so serial numbers and dates
   never lined up. `.numeric` is the table-cell half of the same rule; use it instead of an inline
   font-variant-numeric. */
.field-numeric input,
.numeric {
    font-variant-numeric: tabular-nums;
}

/* ---------- Unhandled error bar ---------- */

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 2000;
    box-sizing: border-box;
    padding: 0.75rem 3rem 0.75rem 1.25rem;
    background: var(--app-error-bg);
    color: var(--app-error-fg);
    border-top: 1px solid var(--app-error-border);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9rem;
}

#blazor-error-ui .reload {
    color: inherit;
    font-weight: 600;
    margin-left: 0.75rem;
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
}

/* ---------- Device adaptation ---------- */

/* MudBlazor reflows the layout for us — tables become cards below Sm, the drawer becomes an
   overlay below Lg — but it sizes everything for a mouse and knows nothing about screen cutouts.
   That leftover layer is what this section covers.

   Only four things in the app are pinned to a viewport edge; everything else sits inside the main
   container and inherits its padding. Those four pay back the inset that viewport-fit=cover takes.
   The top inset is deliberately absent: this app is not installed as a PWA, so in a browser tab
   the top inset is zero in portrait and the browser's own chrome owns that band. Growing the app
   bar to cover it would cost real height on every desktop screen to fix a case that cannot occur.
   Landscape is the case that does occur, and it is the left and right insets that bite there. */

.mud-appbar.mud-appbar-fixed-top {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
}

.mud-drawer.mud-drawer-fixed {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
}

[class*="mud-snackbar-location-bottom"] {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.mud-main-content {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
}

/* Touch, not screen width, is what decides how big a control has to be — a laptop with a
   touchscreen needs the same 44px a phone does, and a narrow desktop window needs none of it.
   Hence pointer, not a breakpoint. MudBlazor ships 36px buttons and 24px breadcrumb links, which
   are comfortable under a cursor and too small under a thumb. */
@media (pointer: coarse) {
    .mud-button-root,
    .mud-nav-link,
    .mud-breadcrumbs a {
        min-height: 44px;
    }

    .mud-icon-button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Breadcrumb links are inline text, so a min-height alone would leave the tap area the height
       of the glyphs. The flex box is what makes the reserved space actually tappable. */
    .mud-breadcrumbs a {
        display: inline-flex;
        align-items: center;
        padding-inline: 0.25rem;
    }

    .mud-input-slot,
    .mud-select .mud-input-slot {
        min-height: 44px;
    }
}

/* The app bar's sign-in button, shown only to anonymous visitors. At 375px the bar already carries
   the app name, the theme toggle and the language menu, and the label was clipped mid-word against
   the right edge. Below 600px the button keeps its icon and drops its label; the button's
   aria-label carries the accessible name, and the landing page below has the full call to action. */
@media (max-width: 599.98px) {
    .app-login-label {
        display: none;
    }

    .app-login-button .mud-button-icon-start {
        margin-right: 0;
        margin-left: 0;
    }
}
