/* Intentional product-level overrides on top of the UniFi-style UI Kit. */

/* Product typography: the kit's Inter stack (kit token, webfonts bundled). */
:root {
    --bs-body-font-family: var(--uf-font);
}
body {
    font-family: var(--uf-font);
    font-optical-sizing: auto;
    font-variation-settings: "GRAD" 0;
}

/* Authentication surface. */
.authentication-bg {
    background-color: var(--uf-auth-bg);
    background-image: linear-gradient(135deg, var(--uf-auth-bg) 0%, var(--uf-bg-subtle) 100%);
}
.authentication-bg .card {
    border: 0;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.06);
}

/* Bootstrap has no max-width utility; keep every login method in one visual column. */
.login-methods {
    width: 100%;
    max-width: 400px;
}

#workos-google-login-form {
    width: 100%;
}

/*
 * Google Identity control rendered with the portal's outline button
 * (btn btn-outline theme-secondary) so it shares the theme's typography,
 * sizing, radius, and interaction states with every other action on the
 * page. Only the official multi-color "G" mark keeps Google's brand
 * colors; its sizing and label spacing live here.
 */
.google-g {
    display: inline-flex;
    width: 1.125rem;
    height: 1.125rem;
    margin-right: 0.625rem;
}

.google-g svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Keep the varied device-card layouts aligned as one calm, scannable grid. */
@media (min-width: 768px) {
    .device-card {
        min-height: 17rem;
    }
}

/* Dense telemetry matrix severity states. Pair the bg-faded-warning /
   bg-faded-danger utilities on the cell with these accents so the label,
   numeric value, and unit read as one coherent state. */
.device-matrix__value {
    font-variant-numeric: tabular-nums;
    color: var(--uf-text-1);
}
.device-matrix__unit {
    font-weight: 600;
    color: var(--uf-text-2);
}
.device-matrix__accent--warning {
    color: var(--uf-orange);
}
.device-matrix__accent--danger {
    color: var(--uf-red);
}

/* Camera preview modal. The video keeps a stable 16:9 canvas while the
   placeholder explains the unconfigured template state. */
.camera-live-stage {
    position: relative;
    aspect-ratio: 16 / 9;
    min-height: 18rem;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.12), transparent 34%),
        #141518;
}
.camera-live-video {
    position: absolute;
    z-index: 2;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: transparent;
}
.camera-stream-placeholder {
    position: absolute;
    z-index: 1;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
}
.camera-stream-placeholder.is-hidden {
    display: none;
}
.camera-placeholder-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4.5rem;
    height: 4.5rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}
.camera-live-meta {
    position: absolute;
    z-index: 3;
    top: 1rem;
    left: 1rem;
    border-radius: 0.4rem;
    padding: 0.4rem 0.65rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.72);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    pointer-events: none;
    backdrop-filter: blur(6px);
}
.camera-live-indicator {
    display: inline-block;
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
    animation: camera-live-pulse 1.8s ease-out infinite;
}

@keyframes camera-live-pulse {
    70%, 100% { box-shadow: 0 0 0 0.35rem rgba(239, 68, 68, 0); }
}

@media (max-width: 575.98px) {
    .camera-live-stage {
        min-height: 14rem;
    }
}

/* Camera movement (PTZ) overlay on the live stage. The panel floats over the
   stream with the same dark-glass treatment as the LIVE badge so both read as
   one chrome layer. Direction buttons are press-and-hold, so they disable
   touch scrolling while pressed. */
.camera-ptz {
    position: absolute;
    z-index: 4;
    top: 1rem;
    right: 1rem;
    width: 11.75rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 0.875rem;
    background: rgba(0, 0, 0, 0.72);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    color: #fff;
    backdrop-filter: blur(6px);
}
.camera-ptz__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem 0.4rem 0.85rem;
}
.camera-ptz__title {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.camera-ptz__title i {
    font-size: 0.9rem;
}
.camera-ptz__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 0;
    border-radius: 0.4rem;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 1rem;
    line-height: 1;
}
.camera-ptz__toggle:hover {
    background: rgba(255, 255, 255, 0.18);
}
.camera-ptz__body {
    display: flex;
    gap: 0.45rem;
    padding: 0.15rem 0.85rem 0.85rem;
}
.camera-ptz.is-collapsed .camera-ptz__body {
    display: none;
}
.camera-ptz-dpad {
    display: grid;
    flex: 1 1 auto;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 2.1rem;
    gap: 0.3rem;
}
.camera-ptz-zoom {
    display: flex;
    flex: 0 0 2.1rem;
    flex-direction: column;
    gap: 0.3rem;
}
.camera-ptz-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 2.1rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 0.55rem;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 1.15rem;
    line-height: 1;
    user-select: none;
    touch-action: none;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.camera-ptz-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}
.camera-ptz-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
}
/* Held state, applied by device-details.js while the command is active.
   Text follows --uf-on-primary so the gray fill keeps AA contrast in dark
   mode (light mode stays white on charcoal). */
.camera-ptz-btn.is-active {
    border-color: transparent;
    background: var(--uf-primary);
    color: var(--uf-on-primary);
}
.camera-ptz-btn--home {
    background: rgba(255, 255, 255, 0.14);
}
/* Diagonals reuse the cardinal chevrons, rotated to their compass heading. */
.camera-ptz-btn--nw > i { transform: rotate(-45deg); }
.camera-ptz-btn--ne > i { transform: rotate(45deg); }
.camera-ptz-btn--sw > i { transform: rotate(45deg); }
.camera-ptz-btn--se > i { transform: rotate(-45deg); }

@media (max-width: 575.98px) {
    .camera-ptz {
        top: 0.75rem;
        right: 0.75rem;
        width: 9.25rem;
    }
    .camera-ptz__body {
        padding: 0.1rem 0.7rem 0.7rem;
    }
    .camera-ptz-dpad {
        grid-auto-rows: 1.85rem;
    }
    .camera-ptz-zoom {
        flex-basis: 1.85rem;
    }
    .camera-ptz-btn {
        height: 1.85rem;
        font-size: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .camera-ptz-btn {
        transition: none;
    }
}

/* Live device state: concentric signals keep the motion calm and purposeful. */
.device-live-card {
    background: linear-gradient(145deg, #fff 58%, rgba(var(--uf-green-rgb), 0.08));
}
.device-status-visual {
    position: relative;
    width: 8.5rem;
    height: 8.5rem;
    margin-right: auto;
    margin-left: auto;
}
.device-status-ring,
.device-status-core {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}
.device-status-ring {
    border: 1px solid rgba(var(--uf-green-rgb), 0.38);
    animation: device-status-ripple 2.4s ease-out infinite;
}
.device-status-ring-inner {
    width: 5.4rem;
    height: 5.4rem;
}
.device-status-ring-outer {
    width: 8rem;
    height: 8rem;
    animation-delay: 0.8s;
}
.device-status-core {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    font-size: 1.8rem;
    animation: device-status-glow 2.4s ease-in-out infinite;
}
.device-live-dot {
    display: inline-block;
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 rgba(var(--uf-green-rgb), 0.4);
    animation: device-live-dot 1.8s ease-out infinite;
}

@keyframes device-status-ripple {
    0% { opacity: 0.8; transform: translate(-50%, -50%) scale(0.72); }
    75%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.08); }
}
@keyframes device-status-glow {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.06); }
}
@keyframes device-live-dot {
    0% { box-shadow: 0 0 0 0 rgba(var(--uf-green-rgb), 0.4); }
    70%, 100% { box-shadow: 0 0 0 0.4rem rgba(var(--uf-green-rgb), 0); }
}

/* The axis-free sparkline bleeds to the card edges inside a clipped, text-free
   plot band. Its data can change freely without crossing readable content. */
.device-trend-card {
    background: linear-gradient(180deg, #fff 0%, #fff 42%, rgba(var(--uf-primary-rgb), 0.045) 100%);
}
.device-trend-reading {
    max-width: 18rem;
}
.device-trend-plot {
    min-height: 6.5rem;
    margin-right: -1.5rem;
    margin-left: -1.5rem;
    overflow: hidden;
}
.device-trend-chart {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.78;
    pointer-events: none;
}
.device-trend-footer {
    position: relative;
    z-index: 2;
    background: rgba(255, 255, 255, 0.72);
}

/* Expanded device trend. The modal chart gets a stable host height so ECharts
   can calculate its canvas when Bootstrap finishes revealing the dialog. */
.device-detail-chart {
    width: 100%;
    height: 28rem;
    min-height: 28rem;
}

/* Leaflet is a decorative location layer on the compact card. The foreground
   gradient guarantees readable device details over every Positron tile. */
.device-map-background,
.device-map-scrim {
    position: absolute;
    inset: 0;
}
.device-map-background {
    z-index: 0;
    background: var(--uf-bg-subtle);
    pointer-events: none;
}
.device-map-background .leaflet-tile-pane {
    filter: grayscale(0.25) saturate(0.55);
    opacity: 0.72;
}
.device-map-scrim {
    z-index: 1;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.58) 0%,
        rgba(255, 255, 255, 0.12) 42%,
        rgba(255, 255, 255, 0.94) 72%,
        #fff 100%
    );
    pointer-events: none;
}
.device-map-card .leaflet-control-container {
    display: none;
}
.device-map-card .leaflet-marker-icon,
.device-map-card .leaflet-interactive {
    filter: none;
}
.device-map-attribution {
    color: var(--uf-text-2);
    font-size: 0.625rem;
    line-height: 1.2;
}
.device-map-attribution a {
    color: inherit;
}

/* Full-screen route explorer for the map card. Desktop keeps the map and
   summary visible together; smaller screens stack them into a natural scroll. */
.device-route-body,
.device-route-layout,
.device-route-map-wrap {
    min-height: 0;
}
.device-route-map-wrap {
    min-height: 30rem;
}
.device-route-map {
    position: absolute;
    inset: 0;
    background: var(--uf-bg-subtle);
}
.device-route-actions {
    position: absolute;
    z-index: 520;
    top: 1rem;
    right: 1rem;
}
.device-route-loading {
    position: absolute;
    z-index: 550;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    background: rgba(var(--uf-primary-rgb), 0.08);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    backdrop-filter: blur(2px);
}
.device-route-loading.is-visible {
    visibility: visible;
    opacity: 1;
}
.device-route-sidebar {
    overflow-y: auto;
    scrollbar-width: thin;
}
.device-route-map .leaflet-control-attribution {
    display: none;
}
.device-route-map .leaflet-popup-content {
    margin: 0.75rem 1rem;
    color: var(--uf-text-1);
    font-family: var(--uf-font);
    font-size: 0.75rem;
    line-height: 1.45;
}

@media (min-width: 992px) {
    .device-route-body {
        overflow: hidden;
    }
    .device-route-layout {
        overflow: hidden;
    }
}

@media (max-width: 991.98px) {
    .device-route-body {
        overflow-y: auto;
    }
    .device-route-map-wrap {
        min-height: 55vh;
    }
    .device-route-sidebar {
        overflow: visible;
    }
}

@media (prefers-reduced-motion: reduce) {
    .device-route-loading {
        transition: none;
    }
}

/* Compact trend hosts for the device details weather history row; mirrors the
   dashboard chart scaffolding but sized to sit three-up in a card grid. */
.device-mini-chart {
    width: 100%;
    height: 13rem;
    min-height: 13rem;
}

/* Purpose-built weather and GPS tracker details templates. */
.device-page-icon,
.metric-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 0.75rem;
}
.device-page-icon {
    width: 4rem;
    height: 4rem;
    font-size: 2rem;
}
.metric-icon {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.25rem;
}
.metric-icon-sm {
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
    border-radius: 50%;
}

/* Weather station: current conditions panel */
.weather-hero-panel {
    background:
        radial-gradient(circle at 8% 0, rgba(var(--uf-primary-rgb), 0.08), transparent 40%),
        linear-gradient(135deg, var(--uf-surface) 58%, var(--uf-bg-subtle));
}
.weather-condition-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    color: var(--uf-primary);
    background: rgba(var(--uf-primary-rgb), 0.1);
    font-size: 2rem;
    flex: 0 0 auto;
}
.weather-temperature {
    color: var(--uf-text-1);
    font-size: clamp(3.75rem, 7vw, 5.5rem);
    font-weight: 600;
    line-height: 0.85;
    letter-spacing: -0.06em;
}

/* Weather station: secondary readings */
.weather-readings {
    border-left: 1px solid var(--uf-border);
    background: var(--uf-bg);
}
.weather-reading {
    padding: 1.5rem 1.75rem;
    border-bottom: 1px solid var(--uf-border);
}
.weather-reading:nth-child(-n+3) { border-bottom: 1px solid var(--uf-border); }
.weather-reading:nth-child(3n+1) { border-left: 0; }
.weather-reading:nth-child(3n) { border-right: 0; }
.weather-reading dt {
    color: var(--uf-text-2);
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.weather-reading dt i { margin-right: 0.35rem; }
.weather-reading dd {
    color: var(--uf-text-1);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    margin: 0;
    font-variant-numeric: tabular-nums;
}
.weather-reading-unit {
    display: block;
    color: var(--uf-text-2);
    font-size: 1rem;
    font-weight: 500;
    margin-top: 0.35rem;
}

/* Weather station: daily summary */
.weather-summary-item {
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    background: var(--uf-bg-subtle);
    text-align: center;
}
.weather-summary-label {
    display: block;
    color: var(--uf-text-2);
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}
.weather-summary-value {
    display: block;
    color: var(--uf-text-1);
    font-size: 0.95rem;
    font-weight: 600;
}

/* Weather station: health list */
.weather-health-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--uf-border);
}
.weather-health-item:last-child { border-bottom: 0; }
.weather-health-item dt { font-size: 0.8rem; }
.weather-health-item dd { font-size: 0.85rem; }

/* Sensor details: telemetry metric cards */
.sensor-metric-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.sensor-metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.08) !important;
}
.sensor-metric-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.75rem;
    font-size: 1.35rem;
    flex: 0 0 auto;
}
.sensor-metric-progress {
    height: 6px;
    border-radius: 3px;
    background-color: var(--uf-bg-muted);
}
.sensor-metric-progress .progress-bar {
    border-radius: 3px;
}

.gps-route-map-wrap { min-height: 34rem; }
.gps-trip-summary dt { color: var(--uf-text-2); font-size: 0.7rem; font-weight: 400; margin-bottom: 0.3rem; }
.gps-trip-summary dd { color: var(--uf-text-1); font-size: 0.9rem; font-weight: 700; margin: 0; }
.gps-trip-summary > div + div { border-left: 1px solid var(--uf-border); }
.gps-speed-panel {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 1.1rem 1.25rem;
    color: var(--uf-primary);
    background: rgba(var(--uf-primary-rgb), 0.08);
}
.gps-speed-panel > span { color: var(--uf-text-2); font-size: 0.75rem; }
.gps-speed-panel strong { grid-row: span 2; font-size: 2.25rem; line-height: 1; }
.gps-speed-panel strong small { font-size: 0.75rem; font-weight: 600; }
.gps-speed-panel em { color: var(--uf-text-1); font-size: 0.8rem; font-style: normal; font-weight: 600; }

@media (max-width: 991.98px) {
    .weather-readings {
        border-left: 0;
        border-top: 1px solid var(--uf-border);
    }
}

@media (max-width: 767.98px) {
    .weather-reading { padding: 1rem 1.15rem; }
    .weather-reading dd { font-size: 1.25rem; }
    .gps-trip-summary > div:nth-child(3) { border-left: 0; }
    .gps-trip-summary > div:nth-child(-n + 2) { padding-bottom: 1rem; }
    .gps-trip-summary > div:nth-last-child(-n + 2) { padding-top: 1rem; border-top: 1px solid var(--uf-border); }
}

@media (max-width: 575.98px) {
    .device-mini-chart {
        height: 10rem;
        min-height: 10rem;
    }

    /* The 55vh inline-route fallback is generous on phones; tighten it. */
    .device-route-map-wrap {
        min-height: 20rem;
    }
}

/* Compact device conversation. Messages remain inside a bounded log so user
   input cannot cause the card to grow and break the surrounding grid. */
.device-chat-card {
    background: linear-gradient(145deg, #fff 62%, rgba(var(--uf-primary-rgb), 0.055));
}
.device-chat-log {
    min-height: 8.75rem;
    max-height: 8.75rem;
    overflow-y: auto;
    background: var(--uf-bg-subtle);
    scrollbar-width: thin;
}
.device-chat-log.is-scrolled {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 1.35rem, #000 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 1.35rem, #000 100%);
}
.device-chat-message {
    width: fit-content;
    max-width: 88%;
    border-radius: 0.75rem;
    padding: 0.55rem 0.7rem;
    font-size: 0.75rem;
    line-height: 1.4;
}
.device-chat-message + .device-chat-message {
    margin-top: 0.55rem;
}
.device-chat-message-output {
    border: 1px solid var(--uf-border);
    background: #fff;
    color: var(--uf-text-1);
}
.device-chat-message-input {
    margin-left: auto;
    background: var(--uf-primary);
    color: var(--uf-on-primary);
}
/* Dark mode user bubble: same light-fill + dark-text inversion as the solid
   CTA so own messages stay AAA-readable on the dark page. */
[data-bs-theme="dark"] .device-chat-message-input {
    background: #e8e8e8;
}
.device-chat-speaker {
    display: block;
    margin-bottom: 0.15rem;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    opacity: 0.72;
    text-transform: uppercase;
}

/* Predictive health is deliberately glanceable: the conic ring communicates
   the score while the adjacent definition list carries exact diagnostics. */
.device-health-gauge {
    position: relative;
    width: 6.5rem;
    height: 6.5rem;
    border-radius: 50%;
    background: conic-gradient(var(--uf-orange) 0 82%, var(--uf-bg-muted) 82% 100%);
}
.device-health-gauge::before {
    position: absolute;
    inset: 0.65rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: inset 0 0 0 1px var(--uf-border);
    content: "";
}
.device-health-gauge-value {
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    display: flex;
    align-items: baseline;
    transform: translate(-50%, -50%);
}
.device-health-gauge-value strong {
    color: var(--uf-text-1);
    font-size: 1.5rem;
    line-height: 1;
}
.device-health-gauge-value span {
    color: var(--uf-text-2);
    font-size: 0.625rem;
}

@media (prefers-reduced-motion: reduce) {
    .device-status-ring,
    .device-status-core,
    .device-live-dot {
        animation: none;
    }
    .device-status-ring-inner { opacity: 0.55; }
    .device-status-ring-outer { opacity: 0.28; }
}

/* Dashboard analytics. ECharts needs an explicit height on each host element. */
.dashboard-chart {
    width: 100%;
    height: 19rem;
    min-height: 19rem;
}
.dashboard-chart-lg {
    height: 22rem;
    min-height: 22rem;
}
.chart-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 2.5rem;
    border-radius: 0.75rem;
    font-size: 1.25rem;
}

@media (max-width: 575.98px) {
    .device-detail-chart {
        height: 21rem;
        min-height: 21rem;
    }
    .dashboard-chart,
    .dashboard-chart-lg {
        height: 17rem;
        min-height: 17rem;
    }
}

/* Device dashboard discovery toolbar. Search remains wider than sort while
   the sort and display controls stay anchored to the right on larger screens. */
.device-toolbar {
    display: flex;
    align-items: end;
    gap: 1rem;
    width: 100%;
}

.device-toolbar__search {
    flex: 1 1 36rem;
    max-width: 36rem;
}

.device-toolbar__controls {
    display: flex;
    align-items: end;
    gap: 1rem;
    flex: 0 0 auto;
    margin-left: auto;
}

.device-toolbar__sort {
    flex: 0 0 18rem;
    max-width: 18rem;
}

.device-toolbar__view {
    flex: 0 0 auto;
    min-width: 0;
}

.device-view-switch {
    display: inline-flex;
}

@media (max-width: 767.98px) {
    .device-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .device-toolbar__search {
        flex-basis: auto;
        max-width: none;
    }

    .device-toolbar__controls {
        justify-content: space-between;
        width: 100%;
    }

    .device-toolbar__sort {
        flex: 1 1 auto;
        max-width: none;
    }
}

/* =========================================================================
   Combined map + telemetry card (production VMM dashboard reference).
   Reuses the `.device-map-*` map layer and scrim classes above so a
   decorative, non-interactive CARTO background stays the visual baseline;
   the classes below add the instrument foreground only.
   Source: VMMDashboard app/static/css/app.css and js/dashboard.js buildCard().
   ========================================================================= */

/* Combined card. The map host fills the card and the body floats over the
   white scrim so telemetry keeps strong foreground contrast over every tile. */
.vmm-card {
    min-height: 18rem;
}
.vmm-card__map {
    position: absolute;
    inset: 0;
    z-index: 0;
}
.vmm-card__scrim {
    /* Inherits the device-map-scrim gradient; keep it above the map tiles. */
    z-index: 1;
}
.vmm-card__body {
    position: relative;
    z-index: 2;
    /* Raise the body above the map so the lower metrics band always clears the
       marker, which is shifted into the upper visual third by dashboard.js. */
    justify-content: flex-end;
}
.vmm-card__name {
    font-weight: 600;
    line-height: 1.25;
}
.vmm-card__received {
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    /* On phones, prioritize device information over the decorative map field. */
    .vmm-card {
        min-height: 0;
    }
    .vmm-card__body {
        justify-content: flex-start;
    }
}

/* Prominent electrical readings. Each value carries its own accent color so
   voltage/power/battery stay distinguishable in the muted map field. */
.vmm-card__metrics {
    margin-top: 0.75rem;
}
.vmm-metric {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.vmm-metric__value {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    letter-spacing: -0.01em;
}
.vmm-metric__label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--uf-text-2);
}

/* Neutral fallback when a device has no GPS coordinates: a calm electrical-grid
   texture instead of a broken/empty map pane. No glyph is injected here (a
   hardcoded icon codepoint would be unverifiable); the layered grid + soft
   instrument glows read as a deliberate, non-broken fallback surface. */
.vmm-card__map--neutral {
    background-color: var(--uf-bg-subtle);
    background-image:
        linear-gradient(0deg, rgba(var(--uf-primary-rgb), 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(var(--uf-primary-rgb), 0.06) 1px, transparent 1px),
        radial-gradient(circle at 30% 25%, rgba(var(--uf-primary-rgb), 0.10), transparent 55%),
        radial-gradient(circle at 75% 80%, rgba(34, 197, 94, 0.08), transparent 60%);
    background-size: 26px 26px, 26px 26px, auto, auto;
}

/* Compact VMM list-view row. Identity is allowed to shrink so long names are
   truncated while the latest readings and action buttons remain aligned. */
.vmm-list-card__name {
    font-weight: 600;
    line-height: 1.25;
}

.vmm-list-card__status-dot {
    display: inline-block;
    flex-shrink: 0;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
}

.vmm-list-card__status-dot--online {
    background-color: var(--uf-green);
}

.vmm-list-card__status-dot--offline {
    background-color: var(--uf-red);
}

.vmm-list-card__value {
    font-size: 1.1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    white-space: nowrap;
}

.vmm-list-card__reading {
    flex-shrink: 0;
}

.vmm-list-card__identity {
    min-width: 0;
}

/* Five compact-row concepts. The kit's stock list-group, card-body, badge,
   button, border, background, spacing, and typography utilities provide the
   shared visual language; only the layouts without kit equivalents live here. */
.device-list > .list-group-item {
    min-height: 5.5rem;
    /* List rows are standalone cards (they carry shadow-sm + rounded-3), so
       they need the card surface. `.list-group-item` defaults to
       `--bs-list-group-bg` (= `--bs-body-bg` = `--uf-bg`), which makes the
       rows read as one flat block against the page and drops the elevation
       the shadow implies. Use the same surface as `.card` so the group cards
       match the processing-overview and worker-status cards. `--bs-card-bg`
       is declared on `.card` itself, so the underlying token is used here. */
    background-color: var(--uf-surface);
}

/* Spaced-card lists (dashboard/groups `list-group gap-3`): Bootstrap zeroes
   the top border of every item after the first to merge flush list rows
   (`.list-group-item + .list-group-item { border-top-width: 0 }`). With
   `gap-3` the items are standalone cards, so each one needs all four
   borders — without this the 2nd+ card (e.g. dashboard "Test") loses its
   top edge. */
.device-list > .list-group-item + .list-group-item {
    border-top-width: var(--bs-list-group-border-width);
}

/* A warning rail is not available as a one-sided border utility when
   the list-group item already owns a neutral border on all four sides. */
.device-list-alert {
    border-left-color: var(--uf-orange) !important;
    border-left-width: 0.25rem !important;
}

.list-inline-reading {
    align-items: center;
    gap: 0.65rem;
    min-width: 8.5rem;
}

.list-inline-reading > i {
    font-size: 1.5rem;
}

.list-inline-reading strong,
.list-inline-reading span,
.list-primary-reading strong,
.list-primary-reading span,
.list-alert-reading strong,
.list-alert-reading span {
    display: block;
    white-space: nowrap;
}

.list-inline-reading strong {
    font-size: 0.9rem;
}

.list-inline-reading span,
.list-primary-reading span,
.list-alert-reading span {
    color: var(--uf-text-2);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.list-metric-layout {
    display: grid;
    grid-template-columns: minmax(13rem, 1fr) auto auto;
    align-items: stretch;
}

.list-metric-identity {
    align-self: center;
    min-width: 0;
}

.list-metric-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(6rem, 1fr));
}

.list-metric-strip > div {
    display: flex;
    flex-direction: column-reverse;
    justify-content: center;
    min-width: 6rem;
    padding: 0.85rem 1rem;
    text-align: center;
}

.list-metric-strip dt {
    color: var(--uf-text-2);
    font-size: 0.6875rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.list-metric-strip dd {
    margin: 0 0 0.15rem;
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.list-metric-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.list-alert-reading strong,
.list-primary-reading strong {
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
}

.list-primary-reading {
    min-width: 7.5rem;
}

@media (max-width: 767.98px) {
    .list-metric-layout {
        grid-template-columns: 1fr auto;
    }

    .list-metric-strip {
        grid-column: 1 / -1;
        grid-row: 2;
        border-left: 0 !important;
        border-top: 1px solid var(--uf-border-light);
    }

    .list-metric-actions {
        grid-column: 2;
        grid-row: 1;
    }
}

@media (max-width: 575.98px) {
    .device-list .card-body {
        gap: 0.75rem !important;
    }

    .list-metric-strip {
        grid-template-columns: repeat(3, 1fr);
    }

    .list-metric-strip > div {
        min-width: 0;
        padding: 0.7rem 0.4rem;
    }

    .list-metric-strip dd {
        font-size: 0.875rem;
    }

}

/* List/grid view toggle (groups, dashboard groups, workers).
 *
 * List stays the default: the existing Design 3 metric-strip rows (groups)
 * and the workers table. Grid reuses the same kit pieces (card, soft
 * identity tile, metric strip, dots/badges, btn-default) in a responsive
 * Bootstrap row; the rules below only adapt the strip to a stacked card
 * and keep long names truncated inside grid columns. */
.group-grid-card .list-metric-strip {
    border-top: 1px solid var(--uf-border-light);
}

.group-grid-card .list-metric-strip > div {
    min-width: 0;
    padding: 0.7rem 0.5rem;
}

.group-grid-card .vmm-list-card__identity,
.worker-grid-card .worker-grid-identity {
    min-width: 0;
}

@media (max-width: 575.98px) {
    .group-grid-card .list-metric-strip dd {
        font-size: 0.875rem;
    }
}

/* Skeleton placeholders for a first load, if a live implementation reuses this
   card. The shimmer is disabled under prefers-reduced-motion (see below). */
.vmm-card--skeleton .card-body {
    pointer-events: none;
}
.vmm-skeleton-bar {
    position: relative;
    overflow: hidden;
    background: linear-gradient(100deg, var(--uf-bg-muted) 30%, var(--uf-bg-subtle) 50%, var(--uf-bg-muted) 70%);
    background-size: 200% 100%;
    animation: vmm-skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes vmm-skeleton-shimmer {
    0% { background-position: 180% 0; }
    100% { background-position: -180% 0; }
}

@media (max-width: 575.98px) {
    .vmm-metric__value {
        font-size: 1.15rem;
    }
}

/* Respect reduced-motion across the combined card surface: stop the skeleton
   shimmer and any Leaflet decorative animation. Keep content fully legible. */
@media (prefers-reduced-motion: reduce) {
    .vmm-skeleton-bar {
        animation: none;
        background: var(--uf-bg-muted);
    }
    .vmm-card,
    .vmm-card__map {
        transition: none;
    }
}

/*
 * Restore the `hidden` attribute against Bootstrap display utilities
 * (portal bug found in the first real browser pass, 10 September 2026).
 *
 * Some themes define `[hidden] { display: none !important }` in their reboot
 * section, and every display utility (`.d-flex` … ) later in the stylesheet
 * with the same !important tier wins by source order — so any element
 * combining `hidden` with a `d-*` utility would stay visible. This file loads
 * after the theme, so this rule restores the attribute everywhere. Known affected element: the job page's late-result banner
 * (#job-result-late), which was permanently visible.
 */
[hidden] {
    display: none !important;
}

/*
 * Worker allocation picker (group detail "Manage workers" modal).
 * Locked rows — the worker belongs to another process group or is
 * reserved by an active attempt — mute only the NAME; the reason tag
 * ("Assigned to <group>" / "Busy") renders at full contrast so the
 * blocker reads at a glance. The narrow leading column hosts the tick
 * boxes. (The former `.worker-picker-col-select .form-check-input`
 * centering rule was dropped with the Bootstrap 6 migration: no template
 * or script references the class in this portal, and BS6 inputs are
 * .check / .radio anyway.)
 */
.worker-picker-col-select {
    width: 2.75rem;
}

.worker-picker-row-locked .worker-picker-name {
    color: var(--bs-secondary-color, #707070);
}

.worker-picker-tag {
    font-weight: 500;
    white-space: nowrap;
}

#group-workers-error {
    white-space: pre-wrap;
}

/*
 * Group detail Error column (queue + processed tables): inline code plus a
 * clamped message so the Failed badge always ships with a visible reason.
 * The column keeps a bounded width so long backend messages wrap/clamp
 * instead of stretching the table; the full text stays in the cell's
 * title/aria-label and on the job-detail page.
 */
.vpp-error-cell {
    max-width: 22rem;
    min-width: 10rem;
}

.vpp-error-cell .min-w-0 {
    min-width: 0;
}

.vpp-error-msg {
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Card table filter bar: search stays left, filters stick right on wide
   rows; the search wraps to its own full-width row on narrow cards and the
   filters continue on the following row. */
.table-filterbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 1rem;
    width: 100%;
}

.table-filterbar__search {
    flex: 1 1 20rem;
    max-width: 24rem;
    min-width: 0;
}

.table-filterbar__search .form-control {
    min-width: 0;
}

.table-filterbar__filters {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 1rem;
    margin-left: auto;
}

.table-filterbar__filter {
    flex: 0 0 auto;
    min-width: 0;
}

/* Right-sized controls: selects shrink to their content instead of filling
   the row; text inputs keep the wrapper's defined width. */
.table-filterbar__filter > .form-control {
    width: auto;
    max-width: 100%;
}

/*
 * Audit log table: fixed layout with defined column widths so each fixed
 * column (timestamp, user, action, resource type) fully fits its content
 * on one line while the smaller resource-id truncates and the content
 * (JSON) column takes the remainder. The time column must fully
 * contain the nowrap "DD/MM/YYYY HH:mm:ss UTC+8" absolute line — an
 * undersized fixed column paints its overflow into the User column.
 * The action column fits the longest action
 * ("config.app_settings_updated", 27 chars) with no truncation.
 * Timestamp/user/ids stay on one line with ellipsis; content wraps
 * anywhere instead of stretching.
 */
.audit-table {
    table-layout: fixed;
    width: 100%;
    min-width: 80rem;
}

.audit-col-time { width: 15rem; }
.audit-col-user { width: 14rem; }
.audit-col-action { width: 16rem; }
/* Every column except Content is fixed: under table-layout:fixed, an
   unspecified width shares the leftover space with the auto column, which
   on wide screens stretched Resource type into a huge empty band between
   it and Resource ID. Content (the widest data) absorbs all spare space. */
.audit-col-type { width: 8.5rem; }
.audit-col-resource { width: 7rem; }
.audit-col-content { width: auto; }

.audit-table th,
.audit-table td {
    vertical-align: middle;
}

.audit-cell-action {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Long action names clamp inside the fixed column (ellipsis) instead of
   painting into the Resource column; the badge title carries the full
   action for hover reads. */
.audit-cell-action .uf-badge {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

.audit-cell-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-cell-time {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audit-cell-time .audit-time-absolute {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audit-cell-content {
    min-width: 0;
}

.audit-cell-content code {
    display: block;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 0.75rem;
}

/*
 * Stream detection table: fixed layout with defined column widths so the
 * Artifacts column stays a minimal icon-only gutter stuck to the right —
 * Time keeps one line for the wall-clock timestamp, Names takes the
 * remainder. The file name lives in the button title/aria-label and in
 * the preview modal title.
 */
.stream-events-table {
    table-layout: fixed;
    width: 100%;
}

.stream-col-time { width: 12rem; }
.stream-col-names { width: auto; }
.stream-col-artifacts { width: 3.25rem; }

.stream-events-table th:last-child,
.stream-events-table td:last-child {
    text-align: right;
}

.stream-artifact-btn {
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    vertical-align: middle;
}

.stream-artifact-btn + .stream-artifact-btn {
    margin-left: 0.25rem;
}

/* Always-light markdown docs (api-docs, worker-docs).
 *
 * The references are authored as Markdown and styled by the pinned
 * github-markdown-light stylesheet, which paints the document canvas white
 * with dark text. The canvas keeps winning in dark mode, but the headings
 * do not: Bootstrap's reboot colors h1-h6 directly from
 * --bs-heading-color, and the kit (unifi-ui.css) resolves that token onto
 * the theme text color per mode — near-white in dark mode. A direct element
 * rule beats the inherited .markdown-body color, so h1-h5 rendered
 * white-on-white whenever the portal was in dark mode.
 *
 * Keep the whole card isolated in the light scheme instead of tracking the
 * portal theme: form controls and scrollbars inside the doc stay light via
 * color-scheme, and the heading colors are re-asserted here (this file loads
 * last, so the scope beats the reboot rule in both themes). h6 keeps the
 * GitHub gray on purpose.
 *
 * The card chrome itself is pinned too: the kit resolves --bs-card-bg and
 * --bs-card-border-color onto theme tokens (dark surface + dark border in
 * dark mode), which framed the white document in a dark card. The light
 * values below equal the kit's light --uf-surface/--uf-border, so light
 * mode looks unchanged. */
.docs-light-scope {
    color-scheme: light;
    --bs-card-bg: #ffffff;
    --bs-card-border-color: #dedede;
    background-color: #ffffff;
    border-color: #dedede;
    color: #1f2328;
}

.docs-light-scope .markdown-body h1,
.docs-light-scope .markdown-body h2,
.docs-light-scope .markdown-body h3,
.docs-light-scope .markdown-body h4,
.docs-light-scope .markdown-body h5 {
    color: #1f2328;
}

/* Compact soft toasts (see static/js/toast.js). The header tint comes from
   the kit's .toast-success / .toast-danger / … soft rules in unifi-ui.css;
   here the toast is only made smaller and calmer: narrower than Bootstrap's
   350px default, smaller type, tighter header padding and a soft shadow so
   it sits quietly in the bottom-right corner in both themes. */
.toast-compact {
    width: auto;
    max-width: 20rem;
    font-size: 0.8125rem;
    border-radius: 0.625rem;
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.12);
}
.toast-compact .toast-header {
    padding: 0.45rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
}
.toast-compact .toast-header .fs-lg {
    font-size: 1rem;
}
.toast-compact .toast-body {
    padding: 0.55rem 0.7rem;
}

/* Toast container in the top layer (see static/js/toast.js): the container
   is a manual popover so toasts paint above native <dialog> overlays
   (Dialog/Drawer via showModal) and their ::backdrops, which ignore z-index.
   The UA popover stylesheet centers with inset:0/margin:auto and adds a
   bordered box — reset it so the Bootstrap position utilities (bottom-0 /
   top-0 + end-0) keep pinning the corner, and never show a backdrop.
   WORKAROUND — retire with the toast.js popover promotion once the kit
   top-layers toasts itself; see the comment there. */
#toast-container[popover] {
    margin: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}
/* UA popover styles center with inset:0/margin:auto. Pin the corner
   explicitly for each placement: unlayered author rules beat the layered
   position utilities (.bottom-0/.top-0/.end-0), so every side is set here
   instead of relying on those utilities in the popover case. (Without
   Popover API support toast.js drops the attribute and the utilities apply
   normally.) */
#toast-container[popover].bottom-0 {
    top: auto;
    bottom: 0;
    left: auto;
    right: 0;
}
#toast-container[popover].top-0 {
    top: 0;
    bottom: auto;
    left: auto;
    right: 0;
}
#toast-container::backdrop {
    display: none;
    background: transparent;
}

/* ==========================================================================
   Compatibility utility retained from the pre-kit stylesheets: page
   controllers toggle a `hidden` class through classList all over the
   codebase, so it must keep working alongside Bootstrap's d-* utilities
   (hence !important).
   ========================================================================== */
.hidden { display: none !important; }

/* ==========================================================================
   Page header actions on phones. Natural-width buttons in the wrapping
   flex row leave ragged rows with button labels breaking mid-word, so the
   remaining buttons stack as uniform full-width rows. The square refresh
   button drops out — mobile browsers pull-to-refresh, and the icon square
   never matches the text buttons beside it.
   ========================================================================== */
@media (max-width: 575.98px) {
    .uf-page-actions.d-flex {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }
    .uf-page-actions > .btn {
        width: 100%;
        justify-content: center;
        white-space: nowrap;
        padding-left: 8px;
        padding-right: 8px;
    }
    .uf-page-actions > .uf-icon-btn { display: none; }
}
