@layer live-button-theme {
    :where(
        button:not([role="switch"], [role="tab"]), [role="button"], [role="menuitem"],
        input[type="button"], input[type="submit"], input[type="reset"],
        a[class*="btn"], a[class*="button"], a[class*="-action"], a[class*="page-link"],
        a.primary, a.secondary, a.danger, a.success, a.warning, [data-live-button],
        .pagination a, .canbus-page-links a,
        .leaflet-bar a:not(.leaflet-draw-toolbar a)
    ):not(:where(
        [data-live-button-theme="off"], [data-live-button-theme="off"] *,
        .sidebar .nav-group-toggle,
        [role="tablist"] > :is(button, a), .code-tabs > button, .camera-channel-tabs > button,
        thead *, th[scope="col"] *, [role="columnheader"], [role="columnheader"] *
    )) {
        --live-button-from: #e4edff;
        --live-button-to: #e7e2fa;
        --live-button-ink: #243662;
        background-color: var(--live-button-from) !important;
        background-image: linear-gradient(115deg, var(--live-button-from), var(--live-button-to)) !important;
        color: var(--live-button-ink) !important;
    }

    :where(button, a, [role="button"], [role="tab"], [role="menuitem"]):where(
        .active, .is-active, .selected, .current, .currentPage,
        [aria-selected="true"], [aria-pressed="true"], [aria-current="page"]
    ) {
        --live-button-from: #c9ddff;
        --live-button-to: #d8cff7;
        --live-button-ink: #1f397e;
    }

    :where(button, a, input, [role="button"]):where(
        .secondary, [class$="-secondary"], [class*="-secondary "]
    ) {
        --live-button-from: #106878;
        --live-button-to: #305b91;
        --live-button-ink: #fff;
    }

    :where(button, a, input, [role="button"]):where(
        .primary, [class$="-primary"], [class*="-primary "], [type="submit"],
        .al-create-btn:not(.auto-service, .sensor), .btn-login, .btn-submit,
        .notif-mark-all, .report-generate-btn, .swal2-confirm
    ) {
        --live-button-from: #2553b8;
        --live-button-to: #4938a1;
        --live-button-ink: #fff;
    }

    :where(button, a, input, [role="button"]):where(
        [data-live-button="success"], .success, [class$="-success"], [class*="-success "],
        .al-create-btn.auto-service.is-active
    ) {
        --live-button-from: #047857;
        --live-button-to: #0f625a;
        --live-button-ink: #fff;
    }

    :where(button, a, input, [role="button"]):where(
        .danger, .del, [class$="-danger"], [class*="-danger "], [data-delete-geofence]
    ) {
        --live-button-from: #b91c1c;
        --live-button-to: #9f1239;
        --live-button-ink: #fff;
    }

    :where(button, a, input, [role="button"]):where(
        .warn, .warning, [class$="-warning"], [class*="-warning "]
    ) {
        --live-button-from: #92400e;
        --live-button-to: #a9510a;
        --live-button-ink: #fff;
    }

    :where(.sidebar .nav-collapse-btn) {
        --live-button-from: #192a51;
        --live-button-to: #252e59;
        --live-button-ink: #e6ecff;
    }

    :where(button, a, input, [role="button"], [role="tab"]):is(:disabled, [aria-disabled="true"]) {
        --live-button-from: #e8ecf4;
        --live-button-to: #dce4f0;
        --live-button-ink: #465775;
    }

    :where(
        button:not([role="switch"], [role="tab"]), [role="button"], [role="menuitem"],
        input[type="button"], input[type="submit"], input[type="reset"],
        a[class*="btn"], a[class*="button"], a[class*="-action"], a[class*="page-link"],
        a.primary, a.secondary, a.danger, a.success, a.warning, [data-live-button],
        .pagination a, .canbus-page-links a,
        .leaflet-bar a:not(.leaflet-draw-toolbar a)
    ):not(:where(
        [data-live-button-theme="off"], [data-live-button-theme="off"] *,
        .sidebar .nav-group-toggle,
        [role="tablist"] > :is(button, a), .code-tabs > button, .camera-channel-tabs > button,
        thead *, th[scope="col"] *, [role="columnheader"], [role="columnheader"] *
    )):hover:not(:disabled, [aria-disabled="true"]) {
        filter: brightness(.93);
    }

    /* Apply the alarm workspace's underline to horizontal section navigation. */
    :where(
        [role="tablist"]:not(.avl-stats, .login-method-switch, .channel-switch, .product-updates-tabs, .report-catalog-groups, .customer-order-tabs),
        .fm-tabs, .fleet-tabs, .fa-tabs, .drvfb-tabs, .drvfm-tabs,
        .rcc-tabs, .rcl-tabs, .rp-status-tabs, .renew-tabs,
        .vi-tabs, .dsr-switcher, .rr-switcher, .va-tabs,
        .mobile-camera-tabs, .chart-tabs
    ) {
        --live-tab-accent: #2563eb;
        display: flex;
        align-items: stretch;
        flex-wrap: nowrap !important;
        gap: 14px !important;
        min-inline-size: 0;
        max-inline-size: 100%;
        overflow-x: auto;
        padding: 0 14px !important;
        border: 0 !important;
        border-block-end: 1px solid var(--border-soft, #e0e4ee) !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;

        & > :where(a, button, [role="tab"]) {
            display: inline-flex;
            flex: 0 0 auto !important;
            align-items: center;
            gap: 6px;
            min-block-size: 44px !important;
            padding: 0 3px !important;
            border: 0 !important;
            border-block-end: 2px solid transparent !important;
            border-radius: 0 !important;
            background: transparent !important;
            box-shadow: none !important;
            color: var(--text-muted, #5c6490) !important;
            font-weight: 500 !important;
            line-height: 1.25;
            text-decoration: none;
            white-space: nowrap;
            filter: none !important;

            &:hover:not(:disabled, [aria-disabled="true"]) {
                color: var(--live-tab-accent) !important;
            }

            &:is([aria-selected="true"], [aria-pressed="true"], [aria-current="page"], .active, .is-active) {
                border-block-end-color: var(--live-tab-accent) !important;
                color: var(--live-tab-accent) !important;
                font-weight: 600 !important;
            }

            &:focus-visible {
                outline: 2px solid var(--live-tab-accent);
                outline-offset: -3px;
            }
        }
    }

    /* Mobile camera navigation stays legible while scrolled over the page. */
    .mobile-camera-tabs {
        background: var(--surface, #fff) !important;
    }

    /* Column headings stay plain text while retaining their sort controls. */
    :where(thead, th[scope="col"], [role="columnheader"]) :where(button:not([role="switch"]), a[role="button"], [role="button"]) {
        appearance: none !important;
        background: transparent !important;
        color: inherit !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        font: inherit !important;
        text-align: inherit;
        filter: none !important;
    }

    :where(thead, th[scope="col"], [role="columnheader"]) :where(button, a[role="button"], [role="button"]):focus-visible {
        outline: 2px solid var(--indigo, #4a53a0);
        outline-offset: 3px;
    }

    /* Keep the map library's sprite visible over the gradient. */
    .leaflet-draw-toolbar, .leaflet-control-layers:not(.leaflet-control-layers-expanded) {
        background-image: linear-gradient(115deg, #e4edff, #e7e2fa) !important;
    }

    .leaflet-draw-toolbar a {
        background-color: transparent !important;
    }
}
