/*
    The design system's global layer (requirements §5.1, §5.11; ADR 0013).

    Everything a component can own lives in that component's .razor.css. This file holds only what cannot be
    scoped: the typeface, document-level defaults, and the few MudBlazor rules that must apply wherever a
    component happens to render - popovers and scrollbars are not inside any component this app owns.

    There is no colour literal in this file, and there must never be one. Colours are var(--mud-palette-*),
    derived from AppTheme by MudThemeProvider; radii, spacing and brand colours are var(--app-*), derived from
    the same C# constants by DesignTokens.razor. A literal here would be a second source of truth (ADR 0003).
*/

/* ---------------------------------------------------------------------------------------------------------
   Typeface. Inter, variable weight, upright only - the interface sets nothing in italic. Each subset is
   fetched only when a page contains a character in its unicode-range, so an English screen loads one file.
   Licence: SIL Open Font License 1.1, see ../fonts/inter/OFL.txt.
   --------------------------------------------------------------------------------------------------------- */
@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-latin-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-latin-ext-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-cyrillic-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-cyrillic-ext-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-greek-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}

@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-greek-ext-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+1F00-1FFF;
}

@font-face {
    font-family: 'Inter Variable';
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(../fonts/inter/inter-vietnamese-wght-normal.woff2) format('woff2-variations');
    unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

/* ---------------------------------------------------------------------------------------------------------
   Motion. One curve and three durations, so every transition in the app feels like the same hand moved
   it. Components reference these rather than writing their own timing.
   --------------------------------------------------------------------------------------------------------- */
:root {
    --app-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --app-duration-fast: 120ms;
    --app-duration: 180ms;
    --app-duration-slow: 320ms;
}

/* §2.8: a user who asks the platform to reduce motion gets state changes without movement. */
@media (prefers-reduced-motion: reduce) {
    :root {
        --app-duration-fast: 0ms;
        --app-duration: 0ms;
        --app-duration-slow: 0ms;
    }

    /* A loop has no duration token to zero, so every animation ends at once instead; a signal that must stay visible
       shows its still form where it is declared. */
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
    }
}

/*
    Signals (ADR 0027). Small movements that each say something changed: a count arriving, a message landing, a vehicle
    sending its position, an emergency still open. Defined here, outside any component's scope, so every screen plays
    the same one. The glow's strength is --app-glow, which DesignTokens sets per theme: a dark canvas swallows the faint
    glow a light one shows plainly.
*/
@keyframes app-badge-pop {
    from {
        opacity: 0;
        transform: scale(0.6);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes app-rise {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes app-live-ring {
    from {
        opacity: var(--app-glow, 0.3);
        transform: scale(0.7);
    }

    to {
        opacity: 0;
        transform: scale(1.9);
    }
}

/* An outline rather than a shadow, so a card keeps its own elevation while it pulses. */
@keyframes app-alert-pulse {
    0%,
    100% {
        outline: 3px solid rgba(var(--mud-palette-error-rgb), 0);
        outline-offset: 0;
    }

    50% {
        outline: 3px solid rgba(var(--mud-palette-error-rgb), var(--app-glow, 0.3));
        outline-offset: 3px;
    }
}

/*
    Ambience (ADR 0037). The product owner asked for screens that are more alive, so beside the signals there is now a
    quiet layer of movement on the brand's own surfaces, shared by every screen:

    - app-card-in: content arrives - a card, a tile, a grouped list rises a few pixels into place on a small spring,
      and siblings follow one another by a beat;
    - app-sheen: the gloss on a brand surface catches the light - a soft band of white, never stronger than
      --app-brand-gloss, crosses it and then rests for most of the cycle;
    - app-float: an illustration hovers;
    - app-drift: a layer whose drawing repeats halfway along slides by half its width and loops without a seam;
    - app-select: a selection pill grows into place.

    Each is transform and opacity only, so it runs on the compositor and never repaints a page; a page's own column is
    never transformed (MainLayout), so a floating button inside it is never anchored to something moving. With reduced
    motion the rule at the top of this file ends every one of them at once, on its resting frame.
*/
@keyframes app-card-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.985);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes app-sheen {
    0% {
        transform: translateX(-140%) skewX(-18deg);
    }

    26%,
    100% {
        transform: translateX(380%) skewX(-18deg);
    }
}

@keyframes app-float {
    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

@keyframes app-drift {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(-50%);
    }
}

@keyframes app-select {
    from {
        opacity: 0.4;
        transform: scale(0.82);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/*
    The hand-over from the boot splash (ADR 0027, ADR 0037). The first screen renders under the splash, so its entrances
    would play where nobody can see them. While the splash is up and not yet leaving, everything inside the app holds its
    first frame; the moment splash.js marks it as leaving - or takes it away - the screen's entrances play as the splash
    fades over them, so the start-up is one animation from the launcher to the first screen. A host page without a
    splash, or a browser without :has(), simply plays them at once.
*/
body:has(#app-splash:not(.app-splash--leaving)) #app *,
body:has(#app-splash:not(.app-splash--leaving)) #app *::before,
body:has(#app-splash:not(.app-splash--leaving)) #app *::after {
    animation-play-state: paused !important;
}

/*
    The light/dark crossfade (ADR 0027). For one slow beat after the theme flips, colours ease from the old palette to
    the new, so the switch reads as the light changing rather than a cut. RootLayout puts the class on the document root
    as the new palette renders and takes it off again; with reduced motion the duration is zero and the switch is
    instant.
*/
html.app-theme-fade,
html.app-theme-fade *,
html.app-theme-fade *::before,
html.app-theme-fade *::after {
    transition-property: background-color, color, border-color, outline-color, fill, stroke, box-shadow !important;
    transition-duration: var(--app-duration-slow) !important;
    transition-timing-function: var(--app-ease) !important;
}

/* ---------------------------------------------------------------------------------------------------------
   Document defaults.
   --------------------------------------------------------------------------------------------------------- */
html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-text-size-adjust: 100%;
}

body {
    /* Inter's contextual alternates align colons and dashes to cap height in times and ranges. */
    font-feature-settings: 'calt' 1, 'kern' 1;
}

::selection {
    background-color: rgba(var(--mud-palette-primary-rgb), 0.18);
}

/*
    FocusOnNavigate moves focus to each page's h1 so a screen reader announces the new screen. The heading
    is not a control, so the browser's focus ring around it was pure noise - a box drawn round every title
    on every navigation. Keyboard focus on real controls is untouched.
*/
h1[tabindex="-1"]:focus,
[tabindex="-1"]:focus:not(:focus-visible) {
    outline: none;
}

/* Text that is for assistive technology only: chart data tables, live-region announcements. */
.app-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/*
    ADR 0027: a grouped list - a list's rows on one card, with the hairlines between them drawn by the rows
    themselves (RecordRow) - so the canvas shows between groups rather than between every record. Global because
    every list screen, editor and card uses it, and a scoped copy per page is how they drift apart. A form's own inner
    list refines it (EditorFrame).
*/
.list-items {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--app-radius-lg);
    background-color: var(--mud-palette-surface);
    box-shadow: var(--mud-elevation-1);
    animation: app-card-in 460ms var(--app-ease-spring, var(--app-ease)) 60ms backwards;
}

/* Inside a card the list is part of the card: a quieter inner frame, not a second card, and it arrives with it. */
.surface-card-body .list-items {
    border-radius: var(--app-radius-md);
    box-shadow: none;
    animation: none;
}

/* The first rows of a list follow the card in, one beat apart; later rows, and rows that load further down, arrive
   together. A row's hover and press states change its colour, never its transform, so the rise never fights them. */
.list-items > * {
    animation: app-rise var(--app-duration-slow) var(--app-ease) backwards;
}

.list-items > :nth-child(2) {
    animation-delay: 40ms;
}

.list-items > :nth-child(3) {
    animation-delay: 80ms;
}

.list-items > :nth-child(4) {
    animation-delay: 120ms;
}

.list-items > :nth-child(5) {
    animation-delay: 160ms;
}

.list-items > :nth-child(6) {
    animation-delay: 200ms;
}

.list-items > :nth-child(n + 7) {
    animation-delay: 240ms;
}

/* ---------------------------------------------------------------------------------------------------------
   MudBlazor rules that cannot be scoped (ADR 0013, table "Global overrides").
   --------------------------------------------------------------------------------------------------------- */

/*
    Scrollbars. MudThemeProvider paints a square thumb in the input-boundary colour, which is dark enough to
    pass 3:1 as a field outline and therefore far too loud as a scrollbar. A slim rounded thumb in the
    hairline colour reads as the platform's own, and darkens only when the pointer is on it.
*/
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--mud-palette-lines-default);
    background-clip: content-box;
    border: 2px solid transparent;
    border-radius: var(--app-radius-pill);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--mud-palette-text-disabled);
}

/*
    Menus and selects float above the page; in the dark palette a shadow is invisible on a near-black
    ground, so the hairline is what tells the popover apart from what is under it.
*/
.mud-popover.mud-popover-open:not(.mud-tooltip) {
    border: 1px solid var(--mud-palette-lines-default);
}

/* Tooltips are small and quick: the default 4px padding and theme radius make them look like chips. */
.mud-tooltip {
    width: max-content;
    max-width: 280px;
    padding: 6px 10px;
    border-radius: var(--app-radius-sm);
}

/* Dialogs are the largest floating surface, so they take the card radius rather than the control radius. */
.mud-dialog {
    border-radius: var(--app-radius-lg);
}

/*
    Switches. MudBlazor draws Material's thin track with the thumb hanging over its ends, and the "off" track
    at 48% opacity, which reads as disabled rather than as off. A pill with the thumb inside it is the
    convention every current platform uses. The geometry is chosen so the thumb still travels exactly the 20px
    MudBlazor's own checked transform moves it - including the mirrored transform in right-to-left layouts -
    so no transform is overridden here. The whole label stays the tap target.
*/
.mud-switch-span.mud-switch-span-medium {
    width: 44px;
    height: 24px;
    margin: 9px 7px;
    padding: 0;
    overflow: visible;
}

.mud-switch-span .mud-switch-track {
    border-radius: var(--app-radius-pill);
    opacity: 1;
}

.mud-switch-span .mud-switch-track.mud-default {
    background-color: var(--mud-palette-lines-inputs);
}

.mud-switch-base.mud-switch-base-medium {
    padding: 3px;
}

.mud-switch-base:hover,
.mud-switch-base.mud-checked:hover {
    background-color: transparent;
}

.mud-switch-base.mud-checked + .mud-switch-track {
    opacity: 1;
}

.mud-switch-button .mud-switch-thumb-medium {
    width: 18px;
    height: 18px;
    background-color: var(--app-brand-on);
    box-shadow: 0 1px 3px rgba(var(--app-brand-deep-rgb), 0.3);
}

.mud-switch-span:has(.mud-switch-input:focus-visible) .mud-switch-track {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

/*
    Field helper and counter text. MudBlazor sets it at 12px with Material's caption tracking, a size that is
    not on the type ramp (§5.1: at most five styles); it takes the caption style instead.
*/
.mud-input-helper-text {
    font-size: var(--mud-typography-caption-size);
    letter-spacing: normal;
}

/*
    ADR 0025: icons that point along the reading direction - chevrons, back and forward arrows, the boarding and
    drop-off arrows, undo - turn round in Urdu and Arabic, so "next" and "back" still point the way the text runs.
    The class goes on the icon (MudIcon) or on its button (MudIconButton); either way one element is flipped.
*/
[dir="rtl"] .app-mirror-rtl {
    transform: scaleX(-1);
}

/*
    Email addresses, phone numbers, registrations and codes read left to right in every language. Inside a
    right-to-left form they keep their own order but stay aligned to the form's starting edge.
*/
[dir="rtl"] input[type="email"],
[dir="rtl"] input[type="tel"],
[dir="rtl"] input[type="url"],
[dir="rtl"] input[inputmode="email"],
[dir="rtl"] input[inputmode="tel"],
[dir="rtl"] .app-ltr-field input {
    direction: ltr;
    text-align: right;
}

/* A left-to-right value - a code, a time, a registration - set inside a right-to-left sentence. */
.app-ltr {
    direction: ltr;
    unicode-bidi: isolate;
}
