:root {
    --af-moving: #9acd32;
    --af-stopped: #f63e42;
    --af-shell: #12171c;
    --af-brand: #f2555a;
}

html, body {
    height: 100%;
    margin: 0;
    /* Stops the browser's pull-to-refresh and rubber-banding from stealing map drag gestures. */
    overscroll-behavior: none;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
}

.mud-typography, .mud-input, .mud-button-label {
    font-family: inherit;
}

/* ---------- Boot splash (shown until the WASM runtime takes over) ---------- */

.af-splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: radial-gradient(circle at 50% 35%, #1b2430 0%, #0f1317 60%);
    color: #e7edf3;
}

.af-splash__mark {
    width: 84px;
    height: 84px;
}

.af-splash__mark circle {
    fill: none;
    stroke: rgba(242, 85, 90, 0.38);
    stroke-width: 3;
}

.af-splash__mark path {
    fill: var(--af-brand);
}

.af-splash__title {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.af-splash__bar {
    width: 160px;
    height: 3px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.af-splash__bar span {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: 3px;
    background: var(--af-brand);
    animation: af-slide 1.4s ease-in-out infinite;
}

@keyframes af-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20000;
    padding: 0.75rem 1.25rem;
    background: #2b1416;
    color: #ffd7d9;
    box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.5);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

/* ---------- App shell ---------- */

.af-main {
    height: 100dvh;
    overflow: hidden;
}

.af-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.af-brand__mark {
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
}

.af-brand__mark circle {
    fill: none;
    stroke: currentColor;
    stroke-width: 3;
    opacity: 0.45;
}

.af-brand__mark path {
    fill: var(--af-brand);
}

/* ---------- Navigation drawer ---------- */

.af-nav {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0.75rem 0.6rem;
}

.af-nav__item {
    justify-content: flex-start;
    padding: 0.6rem 0.75rem;
    border-radius: 9px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}

.af-nav__footer {
    margin-top: auto;
    padding: 0.75rem;
    opacity: 0.55;
    display: flex;
    flex-direction: column;
}

/* ---------- Map ---------- */

.af-map-page {
    position: relative;
    height: 100%;
    width: 100%;
}

/* Lift Leaflet's own controls clear of the ribbon so the scale bar and attribution stay legible. */
.af-map-page--with-ribbon .leaflet-bottom {
    bottom: 72px;
}

.af-map {
    position: absolute;
    inset: 0;
    background: #0b0e11;
}

.leaflet-container {
    font-family: inherit;
    background: #0b0e11;
}

/* Vehicle markers glide between polls, except while zooming, when Leaflet rewrites every
   transform at once and a transition would make markers visibly slide across the map. */
.leaflet-marker-icon.af-veh-icon {
    transition: transform 0.65s linear;
}

.af-map--zooming .leaflet-marker-icon.af-veh-icon {
    transition: none;
}

.af-veh-icon {
    background: none;
    border: 0;
}

.af-veh {
    position: relative;
    width: 34px;
    height: 34px;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
}

.af-veh__glyph {
    width: 100%;
    height: 100%;
    transform-origin: 50% 50%;
    transition: transform 0.4s ease-out;
}

/* Chevron, pointing along the heading: green while moving, red while standing still. */
.af-veh--moving .af-veh__glyph path {
    fill: var(--af-moving);
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
}

.af-veh--stopped .af-veh__glyph path {
    fill: var(--af-stopped);
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
}

/* Parked: the last report is too old to trust a heading, so the marker is a plain circle. */
.af-veh--parked .af-veh__glyph circle {
    fill: var(--af-stopped);
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
}

.af-veh__label {
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(12, 16, 20, 0.78);
    color: #eef4fa;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
}

.af-map--hide-labels .af-veh__label {
    display: none;
}

.af-poi-icon {
    background: none;
    border: 0;
}

.af-poi {
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50% 50% 50% 2px;
    border: 2px solid #fff;
    transform: rotate(45deg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ---------- POI clusters ----------
   All tiers stay in the POI blue hue so clusters never read as vehicle
   (red) markers; larger clusters use progressively darker blues. */
.marker-cluster-small {
    background-color: rgba(56, 189, 248, 0.25);
}
.marker-cluster-small div {
    background-color: rgba(56, 189, 248, 0.75);
    color: #0f1317;
}
.marker-cluster-medium {
    background-color: rgba(2, 132, 199, 0.3);
}
.marker-cluster-medium div {
    background-color: rgba(2, 132, 199, 0.85);
    color: #fff;
}
.marker-cluster-large {
    background-color: rgba(7, 89, 133, 0.35);
}
.marker-cluster-large div {
    background-color: rgba(7, 89, 133, 0.9);
    color: #fff;
}

/* ---------- Map popups ---------- */

.leaflet-popup-content-wrapper {
    background: #161c22;
    color: #e7edf3;
    border-radius: 10px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}

.leaflet-popup-tip {
    background: #161c22;
}

.leaflet-popup-content {
    margin: 0.7rem 0.9rem;
    min-width: 170px;
}

.leaflet-container a.leaflet-popup-close-button {
    color: #9aa9b8;
}

.af-popup__title {
    font-size: 0.95rem;
    font-weight: 700;
}

.af-popup__sub {
    margin-top: 2px;
    font-size: 0.78rem;
    color: #9aa9b8;
}

.af-popup__tag {
    display: inline-block;
    margin-top: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(242, 85, 90, 0.16);
    color: var(--af-brand);
    font-size: 0.7rem;
    font-weight: 600;
}

.af-popup__rows {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 0.75rem;
    margin: 0.6rem 0 0;
    font-size: 0.8rem;
}

.af-popup__rows dt {
    color: #9aa9b8;
}

.af-popup__rows dd {
    margin: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ---------- Vehicle ribbon ---------- */

.af-ribbon {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 600;
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem calc(0.5rem + env(safe-area-inset-bottom));
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    background: linear-gradient(to top, rgba(10, 13, 16, 0.92), rgba(10, 13, 16, 0.55) 70%, transparent);
    scrollbar-width: thin;
}

.af-ribbon::-webkit-scrollbar {
    height: 5px;
}

.af-ribbon::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 3px;
}

.af-ribbon__card {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-width: 116px;
    /* Buttons centre their content by default, which collapses the two rows onto one line. */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0.45rem 0.6rem;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-left: 3px solid var(--af-stopped);
    border-radius: 9px;
    background: rgba(22, 28, 34, 0.94);
    color: #e7edf3;
    text-align: left;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.2s ease;
}

.af-ribbon__card:hover {
    transform: translateY(-2px);
}

.af-ribbon__card--moving {
    border-left-color: var(--af-moving);
}

/* Red matches the parked marker on the map; the word "parked" carries the distinction. */
.af-ribbon__card--parked {
    border-left-color: var(--af-stopped);
}

.af-ribbon__card--parked .af-ribbon__speed {
    color: #9aa9b8;
}

.af-ribbon__card--selected {
    outline: 2px solid var(--af-brand);
}

.af-ribbon__plate {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.af-ribbon__meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem;
    margin-top: 2px;
    font-size: 0.68rem;
    color: #9aa9b8;
}

.af-ribbon__speed {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.af-ribbon__card--moving .af-ribbon__speed {
    color: var(--af-moving);
}

.af-ribbon__card--stopped .af-ribbon__speed {
    color: var(--af-stopped);
}

/* ---------- Login ---------- */

.af-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1.25rem;
    background: radial-gradient(circle at 50% 20%, #1b2430 0%, #0f1317 65%);
}

.af-login__card {
    width: 100%;
    max-width: 380px;
    padding: 1.75rem 1.5rem;
}

.af-login__mark {
    width: 64px;
    height: 64px;
    margin: 0 auto 0.5rem;
    display: block;
}

.af-login__mark circle {
    fill: none;
    stroke: rgba(242, 85, 90, 0.42);
    stroke-width: 3;
}

.af-login__mark path {
    fill: var(--af-brand);
}

/* ---------- Dialog content ---------- */

.af-dialog-list {
    max-height: min(58dvh, 520px);
    overflow-y: auto;
}

.af-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.af-row:last-child {
    border-bottom: 0;
}

.af-row__main {
    flex: 1 1 auto;
    min-width: 0;
}

.af-row__title {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.af-row__sub {
    font-size: 0.74rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.af-chip-speed {
    flex: 0 0 auto;
    min-width: 62px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.af-chip-speed--moving {
    background: rgba(154, 205, 50, 0.16);
    color: var(--af-moving);
}

.af-chip-speed--stopped {
    background: rgba(246, 62, 66, 0.16);
    color: var(--af-stopped);
}

.af-chip-speed--unknown {
    background: rgba(154, 169, 184, 0.16);
    color: #9aa9b8;
}

@media (max-width: 600px) {
    .af-dialog-list {
        max-height: 62dvh;
    }
}

/* ---------- App bar refresh ---------- */

.af-spin {
    animation: af-rotate 0.9s linear infinite;
}

@keyframes af-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ---------- Plate identity ----------
   Vehicles are recognised by their plate, so plate text gets tabular figures and steady tracking
   to stay readable while the ribbon scrolls and markers move. */

.af-ribbon__plate,
.af-row__title,
.af-veh__label {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.af-settings__heading {
    margin-bottom: 0.25rem;
    opacity: 0.85;
}

.af-row__status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex: 0 0 auto;
}

.af-row__age {
    font-size: 0.68rem;
    opacity: 0.55;
    white-space: nowrap;
}

/* ---------- Quality floor ---------- */

.af-ribbon__card:focus-visible,
.af-nav__item:focus-visible {
    outline: 2px solid var(--af-brand);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .leaflet-marker-icon.af-veh-icon,
    .af-veh__glyph,
    .af-ribbon__card {
        transition: none;
    }

    .af-splash__bar span,
    .af-spin {
        animation: none;
    }
}

/* MudBlazor upper-cases button text by default, which shouts next to the quiet map chrome. */
.mud-button-root {
    text-transform: none;
    letter-spacing: 0;
}
