/*
 * EVIU — camada responsiva canônica.
 * Carregada depois de style.css para neutralizar regras móveis legadas sem
 * alterar o layout desktop/TV. O shell trabalha em telas estreitas e tablets
 * em retrato, sem interferir no modo paisagem.
 */

@media (max-width: 1024px) {
    body:not(.tv-mode) .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    body:not(.tv-mode) .mobile-header { display: flex !important; }
    body:not(.tv-mode) .header { display: none !important; }
    body:not(.tv-mode) .page-content,
    body:not(.tv-mode) .page-content > * { min-width: 0; max-width: 100%; }
}

/* =====================================================================
   UX móvel v2 — conteúdo primeiro (shell, dashboard, câmeras e mosaico)
   ===================================================================== */
@media (max-width: 1024px) {
    :root {
        --mobile-header-min: 50px; --mobile-nav-min: 50px;
        --mobile-header-h: var(--mobile-header-measured, var(--mobile-header-min));
        --mobile-nav-h: var(--mobile-nav-measured, var(--mobile-nav-min));
    }

    /* Native focus/anchor scrolling must account for the fixed shell bars. */
    html:has(body:not(.tv-mode)) {
        scroll-padding-top: calc(var(--mobile-header-h) + 12px + env(safe-area-inset-top));
        scroll-padding-bottom: calc(var(--mobile-nav-h) + 12px + env(safe-area-inset-bottom));
    }

    body:not(.tv-mode) {
        padding-bottom: 0 !important;
    }
    body:not(.tv-mode) .mobile-header {
        height: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        min-height: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        padding: env(safe-area-inset-top) 8px 0 !important;
        background: var(--bg-secondary) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    body:not(.tv-mode) .mobile-menu-toggle,
    body:not(.tv-mode) .mobile-connection {
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
    }
    body:not(.tv-mode) .mobile-logo { min-width: 0; flex: 1; justify-content: flex-start; }
    body:not(.tv-mode) #mobilePageTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    body:not(.tv-mode) .main-content {
        padding-top: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
    }
    body:not(.tv-mode) .page-content {
        padding-bottom: calc(var(--mobile-nav-h) + 12px + env(safe-area-inset-bottom)) !important;
    }

    body:not(.tv-mode) .mobile-bottom-nav {
        display: flex !important;
        height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        padding: 0 3px env(safe-area-inset-bottom) !important;
        gap: 0 !important;
        background: var(--bg-secondary) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    body:not(.tv-mode) .mobile-bottom-item {
        position: relative;
        flex: 1 1 0;
        width: auto;
        min-width: 0 !important;
        min-height: var(--mobile-nav-h) !important;
        padding: 6px 2px 4px !important;
        gap: 2px !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
    }
    body:not(.tv-mode) .mobile-bottom-item::before {
        content: '';
        position: absolute;
        top: 0;
        left: 27%;
        right: 27%;
        height: 2px;
        border-radius: 0 0 2px 2px;
        background: transparent;
    }
    body:not(.tv-mode) .mobile-bottom-item.active { color: #38bdf8 !important; }
    body:not(.tv-mode) .mobile-bottom-item.active::before { background: #38bdf8; }
    body:not(.tv-mode) .mobile-bottom-icon {
        display: grid;
        place-items: center;
        width: 22px;
        height: 22px;
        font-size: 0 !important;
    }
    body:not(.tv-mode) .mobile-bottom-icon svg {
        width: 21px;
        height: 21px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }
    body:not(.tv-mode) .mobile-bottom-item small { font-size: 9px !important; }
    body:not(.tv-mode) .mobile-bottom-item:focus:not(:focus-visible),
    body:not(.tv-mode) .mobile-menu-toggle:focus:not(:focus-visible) {
        outline: none !important;
        box-shadow: none !important;
        transform: none !important;
    }
}

@media (max-width: 1024px) {
    /* Câmeras: resumo horizontal e ferramentas fechadas por padrão. */
    body:not(.tv-mode) .page-cameras .camera-page-shell { gap: 8px !important; }
    body:not(.tv-mode) .page-cameras .camera-stats {
        display: flex !important;
        grid-template-columns: none !important;
        gap: 6px !important;
        overflow-x: auto;
        padding: 0 0 2px;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
    }
    body:not(.tv-mode) .page-cameras .camera-stats::-webkit-scrollbar { display: none; }
    body:not(.tv-mode) .page-cameras .camera-stat,
    body:not(.tv-mode) .page-cameras .camera-stat:last-child {
        display: flex !important;
        flex: 0 0 auto;
        grid-column: auto !important;
        min-width: 98px !important;
        width: auto !important;
        min-height: 46px !important;
        padding: 6px 9px !important;
        align-items: center;
        gap: 6px;
        scroll-snap-align: start;
        border-top-width: 1px;
        border-left: 2px solid currentColor;
    }
    body:not(.tv-mode) .page-cameras .camera-stat strong { display: inline !important; font-size: 16px !important; }
    body:not(.tv-mode) .page-cameras .camera-stat span { display: inline !important; margin: 0 !important; font-size: 10px !important; white-space: nowrap; }
    body:not(.tv-mode) .page-cameras .camera-command-bar { padding: 7px !important; gap: 7px !important; }
    body:not(.tv-mode) .page-cameras .camera-mobile-command-head {
        display: flex !important;
        align-items: center;
        gap: 6px;
        min-height: 44px;
    }
    body:not(.tv-mode) .page-cameras .camera-mobile-result {
        min-width: 0;
        flex: 1;
        color: var(--text-secondary);
        font-size: 12px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    body:not(.tv-mode) .page-cameras .camera-mobile-add {
        width: 44px !important;
        min-width: 44px !important;
        padding: 0 !important;
        justify-content: center;
        font-size: 22px;
    }
    body:not(.tv-mode) .page-cameras .camera-mobile-tools-toggle { padding: 0 11px !important; }
    body:not(.tv-mode) .page-cameras .camera-command-details { display: flex !important; gap: 7px !important; }
    body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-filter-row > :not(.camera-search),
    body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-filters-collapsible,
    body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-groups-row,
    body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-view-actions {
        display: none !important;
    }
    body:not(.tv-mode) .page-cameras .camera-search {
        width: 100% !important;
        min-width: 0 !important;
        height: 44px !important;
        flex-basis: 100% !important;
    }
    body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-filter-row {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px !important;
    }
    body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-search { grid-column: 1 / -1; }
    body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-filter-select {
        width: 100% !important;
        min-width: 0 !important;
        height: 42px !important;
    }
    body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-clear-filters { grid-column: 1 / -1; }
    body:not(.tv-mode) .page-cameras .camera-groups-row { gap: 5px !important; }
    body:not(.tv-mode) .page-cameras .camera-result-summary { display: none !important; }
    body:not(.tv-mode) .page-cameras .camera-view-actions { padding-top: 7px !important; }
    body:not(.tv-mode) .page-cameras .camera-view-controls,
    body:not(.tv-mode) .page-cameras .camera-primary-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 6px !important;
    }
    body:not(.tv-mode) .page-cameras .camera-layout-select { width: 100% !important; min-width: 0 !important; }
    body:not(.tv-mode) .page-cameras .camera-primary-actions .btn-primary { display: none !important; }

    /* Card: mídia íntegra e menu contextual compacto sobre o vídeo. */
    body:not(.tv-mode) .camera-tile,
    body:not(.tv-mode) .page-dashboard .camera-tile,
    body:not(.tv-mode) .page-cameras .camera-tile {
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        aspect-ratio: auto !important;
        overflow: hidden;
    }
    body:not(.tv-mode) .camera-tile .camera-tile-media {
        position: relative !important;
        width: 100% !important;
        height: 0 !important;
        min-height: 0 !important;
        padding-bottom: 56.25% !important;
    }
    body:not(.tv-mode) .camera-tile .camera-tile-media img,
    body:not(.tv-mode) .camera-tile .camera-tile-media video { object-fit: contain !important; }
    body:not(.tv-mode) .camera-tile .cam-topbar {
        min-height: 40px;
        padding: 7px 94px 12px 9px !important;
        z-index: 10;
    }
    body:not(.tv-mode) .camera-tile .cam-name {
        max-width: 100% !important;
        font-size: 13px !important;
        line-height: 1.2;
    }
    body:not(.tv-mode) .camera-tile .cam-infobar { display: none !important; }
    body:not(.tv-mode) .camera-tile .cam-iot-actions { display: none !important; }
    body:not(.tv-mode) .camera-tile .cam-actions {
        top: 6px !important;
        right: 6px !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        max-width: none !important;
        opacity: 1 !important;
        z-index: 30;
    }
    body:not(.tv-mode) .camera-tile .cam-action-btn {
        width: 40px !important;
        min-width: 40px !important;
        height: 40px !important;
        min-height: 40px !important;
        padding: 0 !important;
        border-radius: 8px !important;
    }
    body:not(.tv-mode) .camera-tile .cam-action-more { display: grid !important; place-items: center; }
    body:not(.tv-mode) .camera-tile .cam-action-menu { display: none !important; }
    body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu {
        position: absolute;
        top: 44px;
        right: 0;
        display: grid !important;
        grid-template-columns: repeat(3, 40px);
        gap: 5px;
        padding: 6px;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: color-mix(in srgb, var(--bg-secondary) 96%, #000);
        box-shadow: 0 12px 30px rgba(0,0,0,.48);
    }
    body:not(.tv-mode) .camera-tile .cam-controls {
        position: relative !important;
        inset: auto !important;
        display: grid !important;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        width: 100%;
        min-height: 0 !important;
        padding: 4px !important;
        gap: 4px !important;
        opacity: 1 !important;
        background: var(--bg-secondary) !important;
        border-top: 1px solid var(--border);
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    body:not(.tv-mode) .camera-tile .cam-ctrl-btn {
        width: 100%;
        min-width: 0 !important;
        min-height: 38px !important;
        padding: 5px 3px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 10px !important;
    }

    /* Dashboard: 46 px fechado; detalhes só aparecem por intenção explícita. */
    body:not(.tv-mode) .page-dashboard .dash-top-bar {
        display: block !important;
        width: 100% !important;
        margin: 0 0 8px !important;
        padding: 0 !important;
        overflow: hidden !important;
        border-radius: 10px !important;
        background: var(--bg-card) !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary {
        display: flex !important;
        width: 100%;
        min-height: 46px !important;
        padding: 0 10px !important;
        align-items: center;
        gap: 10px;
        border: 0;
        color: var(--text-secondary);
        background: transparent;
        font-size: 11px;
        cursor: pointer;
    }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary-item { white-space: nowrap; }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary-item strong { color: var(--text-primary); font-size: 13px; }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary-online { color: var(--success); }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary-attention { color: var(--warning); }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary-chevron { margin-left: auto; transition: transform .18s ease; }
    body:not(.tv-mode) .page-dashboard .dash-top-bar.mobile-expanded .dash-mobile-summary-chevron { transform: rotate(180deg); }
    body:not(.tv-mode) .page-dashboard .dash-tools-content { display: none !important; }
    body:not(.tv-mode) .page-dashboard .dash-top-bar.mobile-expanded .dash-tools-content {
        display: block !important;
        padding: 7px;
        border-top: 1px solid var(--border);
    }
    body:not(.tv-mode) .page-dashboard .dash-tools-content .dash-stats {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 5px !important;
        padding: 0 !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-tools-content .dash-stat,
    body:not(.tv-mode) .page-dashboard .dash-tools-content .dash-stat-action:last-child {
        grid-column: auto !important;
        min-height: 36px !important;
        padding: 4px 6px !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-tools-content .dash-toolbar {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 5px !important;
        margin-top: 6px !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-tools-content #dashPresetLayouts { grid-column: 1 / -1; }

    body:not(.tv-mode) .page-dashboard .widget-header.no-scrollbar {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
        min-height: 48px;
        padding: 5px 7px !important;
        gap: 6px;
        overflow: visible !important;
    }
    body:not(.tv-mode) .page-dashboard .camera-widget-tools-toggle {
        display: inline-flex !important;
        min-height: var(--touch-target) !important;
        padding: 0 10px !important;
    }
    body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) #gridLayout,
    body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) .cam-filters-bar,
    body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) .camera-widget-groups,
    body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) .camera-widget-actions {
        display: none !important;
    }
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded .cam-filters-bar,
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded .camera-widget-groups,
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded .camera-widget-actions {
        grid-column: 1 / -1;
        display: flex !important;
        width: 100%;
        margin: 0 !important;
        overflow-x: auto;
        flex-wrap: nowrap !important;
    }
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded #gridLayout {
        display: block !important;
        max-width: 150px;
    }
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded .cam-filter-btn,
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded .camera-widget-actions > *,
    body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded .camera-widget-groups > * { min-height: var(--touch-target) !important; }

    /* Mosaico: grid em tela inteira e lista como gaveta inferior. */
    body:not(.tv-mode) .page-mosaic {
        padding: 0 !important;
        padding-bottom: 0 !important;
        overflow: hidden !important;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-layout {
        width: 100% !important;
        height: calc(100dvh - var(--mobile-header-h) - var(--mobile-nav-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
        margin: 0 !important;
        overflow: hidden !important;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-grid-container {
        width: 100%;
        min-width: 0;
        padding: 5px !important;
        gap: 5px;
        background: #05070b;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-mobile-toolbar {
        display: flex !important;
        flex: 0 0 44px;
        min-height: 44px;
        align-items: center;
        gap: 5px;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-mobile-toolbar button {
        min-width: var(--touch-target) !important;
        min-height: var(--touch-target) !important;
        padding: 0 8px;
        border: 1px solid var(--border);
        border-radius: 8px;
        color: var(--text-secondary);
        background: var(--bg-secondary);
        font-size: 11px;
        font-weight: 700;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-cameras-button { display: inline-flex; align-items: center; gap: 5px; }
    body:not(.tv-mode) .page-mosaic .mosaic-layout-switcher { display: flex; gap: 3px; margin-left: auto; }
    body:not(.tv-mode) .page-mosaic .mosaic-layout-switcher button { padding: 0 !important; }
    body:not(.tv-mode) .page-mosaic .mosaic-layout-switcher button.active { color: #fff; border-color: var(--accent); background: var(--accent); }
    body:not(.tv-mode) .page-mosaic .mosaic-clear-button { padding: 0 !important; display: grid; place-items: center; }
    body:not(.tv-mode) .page-mosaic #btnOpenMosaicSidebar { display: none !important; }
    body:not(.tv-mode) .page-mosaic #mosaicGrid {
        min-width: 0;
        min-height: 0;
        overflow: hidden;
        grid-template-columns: repeat(var(--mosaic-cols, 2), minmax(0, 1fr)) !important;
        grid-template-rows: repeat(var(--mosaic-cols, 2), minmax(0, 1fr)) !important;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-cell { aspect-ratio: auto !important; min-width: 0; min-height: 0; }
    body:not(.tv-mode) .page-mosaic .mosaic-cell img,
    body:not(.tv-mode) .page-mosaic .mosaic-cell video { object-fit: contain !important; }
    body:not(.tv-mode) .page-mosaic .mosaic-sidebar,
    body:not(.tv-mode) .page-mosaic .mosaic-sidebar.collapsed {
        position: absolute !important;
        z-index: 70;
        top: auto !important;
        right: 0;
        bottom: 0;
        left: 0 !important;
        width: 100% !important;
        height: min(78%, 620px) !important;
        margin: 0 !important;
        border: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -18px 55px rgba(0,0,0,.62);
        transform: translateY(105%) !important;
        transition: transform .22s ease !important;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-sidebar:not(.collapsed) { transform: translateY(0) !important; }
    body:not(.tv-mode) .page-mosaic .mosaic-drawer-backdrop {
        position: absolute;
        z-index: 60;
        inset: 0;
        display: block;
        border: 0;
        background: rgba(0,0,0,.56);
        opacity: 0;
        pointer-events: none;
        transition: opacity .18s ease;
    }
    body:not(.tv-mode) .page-mosaic .mosaic-layout.drawer-open .mosaic-drawer-backdrop { opacity: 1; pointer-events: auto; }
    body:not(.tv-mode) .page-mosaic #mosaicCamSearch { height: 44px !important; font-size: 14px !important; }
    body:not(.tv-mode) .page-mosaic #mosaicCamList { padding: 8px !important; gap: 6px !important; }
    body:not(.tv-mode) .page-mosaic .mosaic-cam-item { min-height: 62px !important; padding: 7px !important; }
    body:not(.tv-mode) .page-mosaic .mosaic-cam-preview { width: 82px; height: 46px; }
    body:not(.tv-mode) .page-mosaic .cell-fs,
    body:not(.tv-mode) .page-mosaic .cell-close { min-width: var(--touch-target) !important; min-height: var(--touch-target) !important; }

    /* O perfil IA é um diálogo completo. Mantê-lo preso ao botão fazia o
       conteúdo começar fora da tela em tablets/celulares na horizontal. */
    body:not(.tv-mode) .engine-popup-backdrop {
        place-items: end center;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom)) !important;
    }
    body:not(.tv-mode) .engine-popup-backdrop .engine-popup {
        position: relative !important;
        inset: auto !important;
        width: min(100%, 760px) !important;
        max-width: 100% !important;
        max-height: calc(100dvh - 16px - env(safe-area-inset-bottom)) !important;
        overflow: hidden !important;
        border-radius: 14px !important;
    }
    body:not(.tv-mode) .engine-popup-header,
    body:not(.tv-mode) .engine-popup-footer { padding: 9px 10px; }
    body:not(.tv-mode) .engine-popup-body { padding: 9px 10px 12px; }
    body:not(.tv-mode) .engine-profile-status {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    body:not(.tv-mode) .engine-profile-status .btn { width: 100%; min-height: var(--touch-target) !important; }
}

@media (max-width: 600px) {
    body:not(.tv-mode) .engine-profile-options { grid-template-columns: 1fr; }
    body:not(.tv-mode) .engine-profile-option-wide { grid-column: 1; }
    body:not(.tv-mode) .engine-popup-footer .btn { min-height: var(--touch-target) !important; }
}

@media (max-width: 1024px) and (orientation: landscape) and (max-height: 540px) {
    body:not(.tv-mode) .engine-popup-backdrop { padding: 5px !important; }
    body:not(.tv-mode) .engine-popup-backdrop .engine-popup {
        width: min(100%, 860px) !important;
        max-height: calc(100dvh - 10px) !important;
        border-radius: 10px !important;
    }
    body:not(.tv-mode) .engine-popup-header,
    body:not(.tv-mode) .engine-popup-footer { padding-block: 6px; }
    body:not(.tv-mode) .engine-popup-close { width: var(--touch-target); height: var(--touch-target); flex-basis: var(--touch-target); }
    body:not(.tv-mode) .engine-popup-body { padding-block: 7px; }
}

@media (max-width: 390px) {
    body:not(.tv-mode) .mobile-brand,
    body:not(.tv-mode) .mobile-title-sep { display: none !important; }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary { gap: 7px; padding-inline: 8px !important; }
    body:not(.tv-mode) .page-dashboard .dash-mobile-summary-item { font-size: 10px; }
    body:not(.tv-mode) .page-mosaic .mosaic-cameras-button { width: 42px; padding: 0 !important; justify-content: center; font-size: 0 !important; }
}

@media (max-width: 1024px) {
    html body:not(.tv-mode) .page-settings .settings-quick-nav {
        flex-wrap:nowrap !important; overflow-x:auto; padding-bottom:3px; scrollbar-width:none;
    }
    html body:not(.tv-mode) .page-settings .settings-quick-nav::-webkit-scrollbar { display:none; }
    html body:not(.tv-mode) .page-settings .settings-quick-nav button { flex:0 0 auto; min-height:44px !important; }
    html body:not(.tv-mode) .page-settings .settings-section-toggle {
        display:grid !important; place-items:center; flex:0 0 44px;
        width:44px; min-width:44px !important; height:44px; min-height:44px !important;
        margin-left:auto; padding:0; border:0; border-radius:8px;
        color:var(--text-secondary); background:var(--bg-hover); cursor:pointer;
    }
    html body:not(.tv-mode) .page-settings .settings-section-toggle svg { transition:transform .18s ease; }
    html body:not(.tv-mode) .page-settings .settings-section-toggle[aria-expanded="true"] svg { transform:rotate(180deg); }
    html body:not(.tv-mode) .page-settings .card.mobile-collapsed > :not(.card-header) { display:none !important; }
    html body:not(.tv-mode) .page-settings .card.mobile-collapsed { padding-bottom:0 !important; }
}

/* O mesmo padrão de densidade é aplicado às demais telas operacionais. */
@media (max-width: 1024px) {
    html body:not(.tv-mode) .page-discovery .discovery-mobile-advanced,
    html body:not(.tv-mode) .page-recordings .recording-mobile-filter-toggle,
    html body:not(.tv-mode) .page-automations .auto-mobile-command-head { display:flex !important; }

    html body:not(.tv-mode) .page-discovery .discovery-toolbar {
        display:grid !important; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px !important; align-items:end;
    }
    html body:not(.tv-mode) .page-discovery .discovery-toolbar > .discovery-field:first-child { grid-column:1 / -1; }
    html body:not(.tv-mode) .page-discovery [data-mobile-disclosure-root]:not(.mobile-disclosure-open) .discovery-advanced { display:none !important; }
    /* Usuário/senha das câmeras ficam SEMPRE visíveis no celular: antes viviam
       sob "Avançado" e a sondagem no campo saía com senha vazia (rejected_205). */
    html body:not(.tv-mode) .page-discovery .discovery-toolbar > .discovery-credential { grid-column:1 / -1; }
    html body:not(.tv-mode) .page-discovery .discovery-toolbar .btn { width:100% !important; min-width:0; }
    html body:not(.tv-mode) .page-discovery .discovery-mobile-advanced { align-items:center; justify-content:center; }
    html body:not(.tv-mode) .page-discovery .discovery-summary {
        display:flex !important; grid-template-columns:none !important; gap:6px !important;
        margin:8px 0 !important; overflow-x:auto; scrollbar-width:thin;
    }
    html body:not(.tv-mode) .page-discovery .discovery-summary::-webkit-scrollbar { height:6px; }
    html body:not(.tv-mode) .page-discovery .discovery-summary::-webkit-scrollbar-thumb { background:var(--border); border-radius:var(--radius-sm); }
    html body:not(.tv-mode) .page-discovery .discovery-summary > div {
        flex:0 0 112px; min-height:50px; padding:7px 8px !important;
    }
    html body:not(.tv-mode) .page-discovery .card { min-width:0; padding:10px !important; }
    html body:not(.tv-mode) .page-discovery .discovery-source-field { min-width:0; }
    html body:not(.tv-mode) .page-discovery .discovery-field input,
    html body:not(.tv-mode) .page-discovery .discovery-field select { width:100%; min-width:0; min-height:44px; }
    html body:not(.tv-mode) .page-discovery .discovery-results-head { margin:10px 0 7px; }
    html body:not(.tv-mode) .page-discovery .discovery-results { grid-template-columns:minmax(0,1fr) !important; gap:8px; }
    html body:not(.tv-mode) .page-discovery .discovery-result-card { width:100%; touch-action:manipulation; }
    html body:not(.tv-mode) .page-discovery .discovery-result-card:hover { border-color:var(--border); }
    html body:not(.tv-mode) .page-discovery .discovery-result-card.is-selected { border-color:var(--accent); }
    html body:not(.tv-mode) .page-discovery .discovery-select-control { min-width:48px; min-height:48px; }
    html body:not(.tv-mode) .page-discovery .discovery-result-footer .btn { min-height:44px !important; }
    html body:not(.tv-mode) .page-discovery .discovery-bulk-actions {
        position:sticky; z-index:34; bottom:calc(var(--mobile-nav-h) + 6px + env(safe-area-inset-bottom));
        display:flex; padding:8px; margin:9px -2px 0;
        box-shadow:0 -8px 24px rgba(0,0,0,.38);
    }
    html body:not(.tv-mode) .page-discovery .discovery-bulk-actions[style*="display: none"] { display:none !important; }
    html body:not(.tv-mode) .page-discovery .discovery-bulk-actions .btn { flex:1 1 210px; }
    html body:not(.tv-mode) .page-discovery .discovery-agent .btn { min-height:var(--touch-target) !important; flex:1 1 130px; }
    html body:not(.tv-mode) .page-discovery .audit-list { max-height:none; }

    html body:not(.tv-mode) .page-recordings #recStatsBar {
        display:flex !important; grid-template-columns:none !important; gap:6px !important;
        margin-bottom:9px !important; overflow-x:auto; scrollbar-width:none;
    }
    html body:not(.tv-mode) .page-recordings #recStatsBar::-webkit-scrollbar { display:none; }
    html body:not(.tv-mode) .page-recordings #recStatsBar .stat-card {
        flex:0 0 116px; min-height:58px; padding:8px 10px !important;
    }
    html body:not(.tv-mode) .page-recordings #recStatsBar .stat-value { font-size:18px !important; }
    html body:not(.tv-mode) .page-recordings #recStatsBar .stat-label { font-size:10px !important; margin-top:2px; }
    html body:not(.tv-mode) .page-recordings .recording-filter-card { padding:7px !important; margin-bottom:10px !important; }
    html body:not(.tv-mode) .page-recordings .recording-mobile-filter-toggle {
        width:100%; align-items:center; justify-content:center;
    }
    html body:not(.tv-mode) .page-recordings .recording-filter-card:not(.mobile-disclosure-open) .filters-bar { display:none !important; }
    html body:not(.tv-mode) .page-recordings .recording-filter-card.mobile-disclosure-open .filters-bar {
        display:grid !important; grid-template-columns:minmax(0,1fr) !important;
        padding:7px 0 0 !important; gap:7px !important;
    }

    html body:not(.tv-mode) .page-automations .auto-summary-grid {
        display:flex !important; grid-template-columns:none !important; gap:6px !important;
        margin-bottom:8px !important; overflow-x:auto; scrollbar-width:none;
    }
    html body:not(.tv-mode) .page-automations .auto-summary-grid::-webkit-scrollbar { display:none; }
    html body:not(.tv-mode) .page-automations .auto-summary-card {
        flex:0 0 105px; min-height:50px !important; padding:6px 8px !important;
    }
    html body:not(.tv-mode) .page-automations .auto-mobile-command-head {
        min-height:44px; margin-bottom:6px; align-items:center; gap:6px; flex-wrap:wrap;
    }
    html body:not(.tv-mode) .page-automations .auto-mobile-command-head > span { flex:1; font-size:12px; font-weight:700; }
    html body:not(.tv-mode) .page-automations .auto-mobile-command-head .btn { padding-inline:10px !important; max-width:100%; white-space:normal; overflow-wrap:anywhere; }
    html body:not(.tv-mode) .page-automations .auto-actions-container { padding:7px !important; margin-bottom:9px !important; }
    html body:not(.tv-mode) .page-automations .auto-actions-container:not(.mobile-disclosure-open) .auto-filters-group > :not(.auto-search-wrapper),
    html body:not(.tv-mode) .page-automations .auto-actions-container:not(.mobile-disclosure-open) .auto-buttons-group,
    html body:not(.tv-mode) .page-automations .auto-actions-container:not(.mobile-disclosure-open) .auto-status-bar { display:none !important; }
    html body:not(.tv-mode) .page-automations .auto-actions-container:not(.mobile-disclosure-open) .auto-actions-row,
    html body:not(.tv-mode) .page-automations .auto-actions-container:not(.mobile-disclosure-open) .auto-filters-group {
        display:block !important; width:100% !important;
    }
}

@media (max-width: 1024px) {
    :root {
        --mobile-header-min: 48px;
        --mobile-nav-min: 50px;
        --mobile-gap: 10px;
        --mobile-control-h: var(--touch-target);
    }

    html {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body:not(.tv-mode) {
        width: 100%;
        max-width: 100%;
        min-height: 100dvh;
        overflow-x: hidden !important;
        padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        font-size: 14px;
        line-height: 1.45;
    }

    body:not(.tv-mode) *,
    body:not(.tv-mode) *::before,
    body:not(.tv-mode) *::after { box-sizing: border-box; }

    body:not(.tv-mode) img,
    body:not(.tv-mode) video,
    body:not(.tv-mode) canvas { max-width: 100%; }

    body:not(.tv-mode) p,
    body:not(.tv-mode) small,
    body:not(.tv-mode) code,
    body:not(.tv-mode) td,
    body:not(.tv-mode) th,
    body:not(.tv-mode) label { overflow-wrap: anywhere; }

    /* Shell: cabeçalho compacto e navegação inferior sem desperdício. */
    body:not(.tv-mode) .mobile-header {
        top: 0;
        height: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        min-height: calc(var(--mobile-header-h) + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 8px 0 !important;
        gap: 6px;
        background: color-mix(in srgb, var(--bg-secondary) 97%, transparent);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 3px 14px rgba(0, 0, 0, .24);
    }

    body:not(.tv-mode) .mobile-menu-toggle {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        padding: 9px !important;
        border: 0 !important;
        border-radius: 9px !important;
        background: transparent !important;
        color: var(--text-primary) !important;
        box-shadow: none !important;
    }
    body:not(.tv-mode) .mobile-menu-toggle:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 1px;
    }
    body:not(.tv-mode) .mobile-menu-toggle svg { width: 22px; height: 22px; }
    body:not(.tv-mode) .mobile-logo { gap: 7px !important; }
    body:not(.tv-mode) .mobile-logo img { width: 21px !important; height: 21px !important; }
    body:not(.tv-mode) .mobile-brand { font-size: 12px !important; }
    body:not(.tv-mode) #mobilePageTitle { font-size: 15px !important; font-weight: 700 !important; }
    body:not(.tv-mode) .mobile-connection {
        width: 38px !important; height: 38px !important; flex-basis: 38px !important;
    }
    body:not(.tv-mode) .mobile-connection-dot { width: 9px; height: 9px; }

    body:not(.tv-mode) .main-content {
        min-height: 100dvh !important;
        padding-top: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        overflow: visible !important;
    }
    body:not(.tv-mode) .page-content {
        width: 100% !important;
        padding: 10px 10px calc(var(--mobile-nav-h) + 14px + env(safe-area-inset-bottom)) !important;
        overflow-x: clip !important;
    }

    body:not(.tv-mode) .mobile-bottom-nav {
        height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)) !important;
        padding: 3px 5px env(safe-area-inset-bottom) !important;
        gap: 2px;
    }
    body:not(.tv-mode) .mobile-bottom-item {
        min-height: 52px !important;
        padding: 4px 2px !important;
        gap: 3px !important;
        border-radius: 9px !important;
    }
    body:not(.tv-mode) .mobile-bottom-item > span { font-size: 18px !important; }
    body:not(.tv-mode) .mobile-bottom-item small {
        font-size: 9px !important;
        line-height: 1.1;
        white-space: nowrap;
    }

    /* Gaveta off-canvas: posicionamento suave, hardware-accelerated e sem cortes */
    body:not(.tv-mode) .sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: min(76vw, 256px) !important;
        height: 100dvh !important;
        padding-top: max(8px, env(safe-area-inset-top)) !important;
        padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
        transform: translateX(-100%) !important;
        transition: transform var(--motion-screen) var(--ease-enter), box-shadow var(--motion-screen) ease !important;
        z-index: 1002 !important;
        display: flex !important;
        flex-direction: column !important;
        box-shadow: none !important;
    }
    body:not(.tv-mode) .sidebar.active {
        transform: translateX(0) !important;
        box-shadow: 12px 0 45px rgba(0, 0, 0, 0.5) !important;
    }
    body:not(.tv-mode) #sidebarModePanel { display: none !important; }
    body:not(.tv-mode) .sidebar-logo {
        min-height: calc(var(--touch-target) + 17px) !important;
        height: auto !important;
        padding: 8px 12px !important;
        display: flex !important;
        flex-direction: row;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        border-bottom: 1px solid var(--border) !important;
        flex-shrink: 0 !important;
    }
    body:not(.tv-mode) .sidebar-logo-brand {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        min-width: 0 !important;
        flex: 1 !important;
    }
    body:not(.tv-mode) .sidebar-logo-brand img {
        width: 28px !important;
        height: 28px !important;
        border-radius: 7px !important;
        flex-shrink: 0 !important;
        object-fit: cover !important;
    }
    body:not(.tv-mode) .sidebar-logo-brand h1 {
        font-size: 13.5px !important;
        font-weight: 750 !important;
        margin: 0 !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        color: var(--text-primary) !important;
    }
    body:not(.tv-mode) .sidebar-mobile-close {
        display: inline-flex !important;
        width: var(--touch-target) !important;
        height: var(--touch-target) !important;
        min-width: var(--touch-target) !important;
        min-height: var(--touch-target) !important;
        padding: 0 !important;
        border-radius: 50% !important;
        border: 1px solid var(--border) !important;
        background: var(--bg-secondary) !important;
        color: var(--text-secondary) !important;
        font-size: 18px !important;
        line-height: 1 !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        margin: 0 !important;
        transition: all 0.15s ease !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
    }
    body:not(.tv-mode) .sidebar-mobile-close:hover,
    body:not(.tv-mode) .sidebar-mobile-close:focus-visible {
        background: var(--bg-hover) !important;
        color: var(--text-primary) !important;
        border-color: var(--accent) !important;
    }
    body:not(.tv-mode) .sidebar-search {
        min-height: 38px !important;
        margin: 6px 8px !important;
        flex-shrink: 0 !important;
    }
    body:not(.tv-mode) .sidebar-search input { font-size: 13px !important; padding: 6px 10px !important; }
    body:not(.tv-mode) .sidebar-nav {
        flex: 1 !important;
        padding: 4px 6px 10px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        scrollbar-width: none !important;
    }
    body:not(.tv-mode) .sidebar-nav::-webkit-scrollbar { display: none !important; }
    body:not(.tv-mode) .nav-section { margin-bottom: 8px !important; }
    body:not(.tv-mode) .nav-section-title {
        padding: 5px 8px 3px !important;
        font-size: 9.5px !important;
        font-weight: 700 !important;
        color: var(--text-muted) !important;
        letter-spacing: .06em !important;
    }
    body:not(.tv-mode) .sidebar .nav-item {
        min-height: 44px !important;
        padding: 8px 10px !important;
        font-size: 13px !important;
        gap: 8px !important;
        border-radius: 8px !important;
        margin-bottom: 2px !important;
    }
    body:not(.tv-mode) .sidebar .nav-item svg { width: 17px !important; height: 17px !important; flex-shrink: 0 !important; }
    body:not(.tv-mode) .sidebar-footer {
        flex-shrink: 0 !important;
        padding: 8px 10px max(8px, env(safe-area-inset-bottom)) !important;
        border-top: 1px solid var(--border) !important;
        background: var(--bg-secondary) !important;
    }

    /* Tipografia, cartões e controles globais. */
    body:not(.tv-mode) h1 { font-size: 21px; line-height: 1.2; }
    body:not(.tv-mode) h2 { font-size: 18px !important; line-height: 1.25; }
    body:not(.tv-mode) h3 { font-size: 15px !important; line-height: 1.3; }
    body:not(.tv-mode) h4 { font-size: 14px; }
    body:not(.tv-mode) .page-header-actions { margin-bottom: 12px !important; gap: 8px !important; }
    body:not(.tv-mode) .page-header-actions p { font-size: 12px !important; line-height: 1.45; }

    body:not(.tv-mode) .card {
        width: 100%;
        min-width: 0;
        margin-bottom: 10px !important;
        border-radius: 10px !important;
    }
    body:not(.tv-mode) .card:not(.card-media) { padding: 12px !important; }
    body:not(.tv-mode) .card > [style*="padding:16px"],
    body:not(.tv-mode) .card > [style*="padding: 16px"] { padding: 10px !important; }
    body:not(.tv-mode) .card-header {
        min-width: 0;
        margin-bottom: 10px !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
    }
    body:not(.tv-mode) .card-header > * { min-width: 0; }
    body:not(.tv-mode) .card-header > div:not(.card-title),
    body:not(.tv-mode) .card-header select,
    body:not(.tv-mode) .card-header button {
        width: auto !important;
        max-width: 100%;
        margin: 0 !important;
    }
    body:not(.tv-mode) .card-title { font-size: 14px !important; line-height: 1.3; }

    body:not(.tv-mode) .btn {
        min-height: var(--mobile-control-h) !important;
        height: auto !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
        line-height: 1.2 !important;
        white-space: normal;
    }
    body:not(.tv-mode) .btn-sm { min-height: var(--touch-target) !important; padding: 7px 10px !important; font-size: 12px !important; }
    body:not(.tv-mode) .btn-icon { width: var(--touch-target); min-width: var(--touch-target); padding-inline: 0 !important; }

    body:not(.tv-mode) .form-row { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
    body:not(.tv-mode) .form-group { min-width: 0; margin-bottom: 10px; }
    body:not(.tv-mode) .form-group label { font-size: 12px; line-height: 1.35; }
    body:not(.tv-mode) .form-group small { display: block; margin-top: 4px; font-size: 10px; line-height: 1.4; }
    body:not(.tv-mode) .form-control,
    body:not(.tv-mode) input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    body:not(.tv-mode) select,
    body:not(.tv-mode) textarea {
        min-width: 0 !important;
        max-width: 100% !important;
        min-height: 44px !important;
        font-size: 16px !important;
    }
    body:not(.tv-mode) textarea:not(.app-dialog-input) { min-height: 96px !important; }
    body:not(.tv-mode) input[type="checkbox"],
    body:not(.tv-mode) input[type="radio"] { width: 20px; height: 20px; flex: 0 0 20px; }
    body:not(.tv-mode) input[type="range"] { min-height: 34px; }

    /* Barras, abas e filtros rolam dentro do componente, nunca na página. */
    body:not(.tv-mode) .filters-bar {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 8px !important;
        padding: 8px 0 !important;
    }
    body:not(.tv-mode) .filters-bar > *,
    body:not(.tv-mode) .filters-bar .form-control { width: 100% !important; min-width: 0 !important; }
    body:not(.tv-mode) .detail-tab-bar,
    body:not(.tv-mode) .reports-tab-bar,
    body:not(.tv-mode) .turret-tabs,
    body:not(.tv-mode) .settings-tabs,
    body:not(.tv-mode) .auto-tabs {
        width: 100%;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 5px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        padding: 4px !important;
        margin-bottom: 10px !important;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    body:not(.tv-mode) .detail-tab-bar::-webkit-scrollbar,
    body:not(.tv-mode) .reports-tab-bar::-webkit-scrollbar,
    body:not(.tv-mode) .turret-tabs::-webkit-scrollbar { display: none; }
    body:not(.tv-mode) .detail-tab-btn,
    body:not(.tv-mode) .reports-tab-btn,
    body:not(.tv-mode) .turret-tab {
        flex: 0 0 auto !important;
        min-height: 38px !important;
        width: auto !important;
        padding: 7px 11px !important;
        font-size: 12px !important;
        white-space: nowrap !important;
    }

    /* Tabelas viram cartões quando possuem rótulos; matrizes continuam roláveis. */
    body:not(.tv-mode) .table-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        border-radius: 8px;
        -webkit-overflow-scrolling: touch;
    }
    body:not(.tv-mode) .responsive-table-mobile { width: 100% !important; min-width: 0 !important; }
    body:not(.tv-mode) .responsive-table-mobile tr {
        margin-bottom: 8px !important;
        padding: 5px !important;
        border-radius: 9px !important;
    }
    body:not(.tv-mode) .responsive-table-mobile td {
        min-width: 0 !important;
        padding: 7px 8px !important;
        gap: 12px;
        font-size: 12px !important;
        align-items: center;
        overflow: visible !important;
        white-space: normal !important;
    }
    body:not(.tv-mode) .responsive-table-mobile td::before {
        flex: 0 0 34%;
        max-width: 34%;
        margin: 0 !important;
        font-size: 10px;
    }
    body:not(.tv-mode) .responsive-table-mobile td[colspan]:not([colspan="1"]) {
        grid-column: 1 / -1;
    }
    body:not(.tv-mode) .responsive-table-mobile td[colspan]:not([colspan="1"])::before {
        content: none;
        display: none;
    }
    body:not(.tv-mode) .responsive-table-mobile td[data-label="Ações"] {
        display: flex !important;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    body:not(.tv-mode) .responsive-table-mobile td[data-label="Ações"] .btn { flex: 1 1 72px; }
    body:not(.tv-mode) table:not(.responsive-table-mobile) { font-size: 12px; }

    /* Modais como bottom sheets, com conteúdo rolável e ações acessíveis. */
    body:not(.tv-mode) .modal-backdrop {
        padding: 0 !important;
        align-items: flex-end !important;
    }
    body:not(.tv-mode) .modal {
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 92dvh !important;
        margin: 0 !important;
        border-radius: 14px 14px 0 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }
    body:not(.tv-mode) .modal-header { flex:0 0 auto; min-height: 52px; padding: 10px 12px !important; gap: 8px; }
    body:not(.tv-mode) .modal-body { flex:1 1 auto; min-width: 0; min-height:0; padding: 12px !important; overflow-y: auto !important; overscroll-behavior:contain; -webkit-overflow-scrolling:touch; }
    body:not(.tv-mode) .modal-footer {
        flex:0 0 auto;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px !important;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) !important;
    }
    body:not(.tv-mode) .modal-footer .btn { width: 100% !important; }

    body:not(.tv-mode) .report-event-modal-backdrop {
        padding: max(4px, env(safe-area-inset-top)) 0 0 !important;
        align-items: stretch !important;
        background: rgba(2, 6, 12, .94) !important;
    }
    body:not(.tv-mode) .report-event-modal {
        width: 100vw !important;
        max-width: 100vw !important;
        height: calc(100dvh - max(4px, env(safe-area-inset-top))) !important;
        max-height: none !important;
        border-radius: 12px 12px 0 0 !important;
        background: var(--bg-card) !important;
    }
    body:not(.tv-mode) .report-event-modal-header { min-height: 54px; padding: 8px 10px 8px 12px !important; }
    body:not(.tv-mode) .report-event-modal-heading h3 { font-size: 15px; }
    body:not(.tv-mode) .report-event-modal-close { min-width: 38px !important; min-height: 38px !important; }
    body:not(.tv-mode) .report-event-modal-body { padding: 10px 10px 18px !important; }
    body:not(.tv-mode) .report-event-modal-footer {
        min-height: 46px;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 7px 10px calc(7px + env(safe-area-inset-bottom)) !important;
    }
    body:not(.tv-mode) .report-event-modal-footer > span { font-size: 10px; }
    body:not(.tv-mode) .report-event-modal-footer .btn { flex: 0 0 auto; width: auto !important; min-height: 34px !important; }
    body:not(.tv-mode) .report-event-summary-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 9px !important; }
    body:not(.tv-mode) .report-event-media,
    body:not(.tv-mode) .report-event-facts,
    body:not(.tv-mode) .report-event-section { padding: 9px !important; border-radius: 9px; }
    body:not(.tv-mode) .report-event-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body:not(.tv-mode) .report-event-actions .btn { width: 100% !important; min-height: 38px !important; padding: 7px 8px !important; }
    body:not(.tv-mode) .report-related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    body:not(.tv-mode) .alert-modal-overlay {
        align-items: flex-start !important;
        justify-content: center;
        padding: max(8px, env(safe-area-inset-top)) 8px calc(var(--mobile-nav-h) + 8px + env(safe-area-inset-bottom)) !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
    body:not(.tv-mode) .alert-modal-container {
        width: 100% !important;
        max-width: 720px !important;
        max-height: none !important;
        margin: auto 0;
        flex: 0 0 auto !important;
    }
    body:not(.tv-mode) .alert-modal-header { position: sticky; top: 0; z-index: 5; flex: 0 0 auto; }
    body:not(.tv-mode) .alert-modal-body {
        flex: 0 0 auto !important;
        width: 100%;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        padding-bottom: 0 !important;
        aspect-ratio: 16 / 9;
    }
    body:not(.tv-mode) .alert-modal-footer { flex: 0 0 auto; }

    /* Dashboard: resumo legível, ações alinhadas e grade igual ao cálculo JS. */
    body:not(.tv-mode) .page-dashboard .dash-top-bar {
        position: relative !important;
        top: auto !important;
        display: block !important;
        width: 100% !important;
        margin: 0 0 10px !important;
        padding: 7px !important;
        border-radius: 9px !important;
        overflow: visible !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-stats {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        min-width: 0 !important;
        width: 100% !important;
        gap: 5px !important;
        overflow: visible !important;
        padding: 0 !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-stat {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 40px !important;
        padding: 6px 8px !important;
        display: grid !important;
        grid-template-columns: 18px auto minmax(0, 1fr);
        gap: 5px !important;
        overflow: hidden !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-stat-action:last-child { grid-column: 1 / -1; }
    body:not(.tv-mode) .page-dashboard .dash-stat > span { font-size: 11px !important; }
    body:not(.tv-mode) .page-dashboard .dash-stat .stat-label,
    body:not(.tv-mode) .page-dashboard .dash-stat > span:last-child {
        display: block !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    body:not(.tv-mode) .page-dashboard .dash-toolbar {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        width: 100% !important;
        gap: 5px !important;
        margin-top: 7px;
        overflow: visible !important;
    }
    body:not(.tv-mode) .page-dashboard #dashLayoutLabel,
    body:not(.tv-mode) .page-dashboard #dashLastUpdated,
    body:not(.tv-mode) .page-dashboard #addWidgetBar,
    body:not(.tv-mode) .page-dashboard #wsIndicator { display: none !important; }
    body:not(.tv-mode) .page-dashboard #dashPresetLayouts {
        grid-column: 1 / -1;
        width: 100% !important;
        height: 40px !important;
        min-height: 40px !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-toolbar > button {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 40px !important;
        padding: 7px 3px !important;
    }
    body:not(.tv-mode) .page-dashboard .dash-toolbar > button .btn-text { display: none !important; }
    body:not(.tv-mode) .page-dashboard .grid-stack.dashboard-mobile-flow { height: auto !important; min-height: 0 !important; }
    body:not(.tv-mode) .page-dashboard .dashboard-mobile-flow > .grid-stack-item {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        transform: none !important;
        margin-bottom: 10px;
    }
    body:not(.tv-mode) .page-dashboard .dashboard-mobile-flow > .grid-stack-item > .grid-stack-item-content {
        position: relative !important;
        inset: auto !important;
        min-height: 0 !important;
    }
    body:not(.tv-mode) .page-dashboard .widget-inner { height: auto !important; min-height: 0 !important; }
    body:not(.tv-mode) .page-dashboard .widget-body { height: auto !important; overflow: visible !important; }
    body:not(.tv-mode) .page-dashboard .widget-header.no-scrollbar {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        gap: 7px !important;
        padding: 8px !important;
        overflow: visible !important;
    }
    body:not(.tv-mode) .page-dashboard .widget-header .cam-filters-bar {
        grid-column: 1 / -1;
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        margin: 0 !important;
        gap: 4px !important;
        overflow: visible !important;
    }
    body:not(.tv-mode) .page-dashboard .widget-header .cam-filter-btn {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 36px !important;
        height: 36px !important;
        padding: 5px 2px !important;
        font-size: 10px !important;
    }
    body:not(.tv-mode) .page-dashboard .camera-grid,
    body:not(.tv-mode) .page-dashboard .camera-grid[class*="grid-"] {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-rows: none !important;
        grid-auto-rows: auto !important;
        width: 100% !important;
        height: auto !important;
        gap: 8px !important;
        padding: 6px !important;
    }
    body:not(.tv-mode) .page-dashboard .camera-tile {
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        aspect-ratio: 16 / 9 !important;
    }
    body:not(.tv-mode) .page-dashboard .camera-tile-media { height: 100% !important; padding-bottom: 0 !important; }

    /* Relatórios: abas em uma linha, busca previsível e chips compactos. */
    body:not(.tv-mode) .page-reports .reports-tab-bar { border-radius: 9px; }
    body:not(.tv-mode) .page-reports .report-search-panel { padding: 10px 0 !important; }
    body:not(.tv-mode) .page-reports #reportCapabilities { font-size: 10px !important; line-height: 1.4; }
    body:not(.tv-mode) .page-reports .report-search-row {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto auto !important;
        gap: 7px !important;
    }
    body:not(.tv-mode) .page-reports .report-search-input { grid-column: 1 / -1; min-width: 0; }
    body:not(.tv-mode) .page-reports .report-visual-toggle {
        min-width: 0;
        white-space: normal !important;
        font-size: 11px !important;
    }
    body:not(.tv-mode) .page-reports .report-search-chips {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    body:not(.tv-mode) .page-reports .report-search-chips .btn { flex: 0 0 auto; min-height: 36px !important; }
    body:not(.tv-mode) .page-reports details { padding: 0 !important; }

    /* Câmeras e detalhes. */
    body:not(.tv-mode) .page-cameras .camera-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    body:not(.tv-mode) .page-cameras .camera-stat { min-height: 54px !important; padding: 8px 10px !important; }
    body:not(.tv-mode) .page-cameras .camera-stat strong { font-size: 18px !important; }
    body:not(.tv-mode) .page-cameras .camera-stat span { margin-top: 4px; font-size: 10px; }
    body:not(.tv-mode) .page-cameras .camera-filter-select { flex: 1 1 calc(50% - 5px); min-width: 0 !important; width: auto !important; }
    body:not(.tv-mode) .page-cameras .camera-primary-actions { flex-direction: row !important; }
    body:not(.tv-mode) .page-cameras .camera-grid { grid-template-columns: minmax(0, 1fr) !important; }

    body:not(.tv-mode) .page-camera .camera-detail-header { gap: 8px !important; margin-bottom: 10px !important; }
    body:not(.tv-mode) .page-camera .camera-detail-header .cam-info h2 { font-size: 17px !important; }
    body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions { gap: 5px !important; margin-top: 3px !important; }
    body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions .btn { width: 40px !important; height: 40px !important; }
    body:not(.tv-mode) .page-camera .stream-controls { display: grid !important; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px !important; }
    body:not(.tv-mode) .page-camera .stream-controls #scLensFoco,
    body:not(.tv-mode) .page-camera .stream-controls #scLight { grid-column: 1 / -1; width: 100% !important; }
    /* Automações. */
    body:not(.tv-mode) .page-automations .auto-page-intro { margin-bottom: 10px; }
    body:not(.tv-mode) .page-automations .auto-page-intro h2 { font-size: 18px !important; }
    body:not(.tv-mode) .page-automations .auto-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px; }
    body:not(.tv-mode) .page-automations .auto-summary-card { min-height: 56px; padding: 9px 10px; }
    body:not(.tv-mode) .page-automations .auto-summary-value { font-size: 18px; }
    body:not(.tv-mode) .page-automations .automations-card-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 9px; }
    body:not(.tv-mode) .page-automations .automation-flow-card { padding: 11px; }
    body:not(.tv-mode) .page-automations .automation-card-flow { grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr); gap: 5px; }
    body:not(.tv-mode) .page-automations .automation-card-actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }

    /* Descoberta, usuários, dispositivos, IA e SDK. */
    body:not(.tv-mode) .page-discovery .discovery-toolbar { align-items: stretch; }
    body:not(.tv-mode) .page-discovery .discovery-field { flex: 1 1 100%; min-width: 0; }
    body:not(.tv-mode) .page-discovery .discovery-options { display: grid; grid-template-columns: 1fr; gap: 8px; }
    body:not(.tv-mode) .page-discovery .discovery-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
    body:not(.tv-mode) .page-discovery .telemetry-row { grid-template-columns: 1fr; gap: 3px; }
    body:not(.tv-mode) .page-users .users-page-container { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
    body:not(.tv-mode) .page-users #cameraChecklist,
    body:not(.tv-mode) .page-users #pageChecklist,
    body:not(.tv-mode) .page-users #permChecklist { grid-template-columns: minmax(0, 1fr) !important; }
    body:not(.tv-mode) .page-engines .card-header > div:last-child { display: grid !important; grid-template-columns: 1fr 1fr; gap: 7px; width: 100% !important; }
    body:not(.tv-mode) .page-engines #enginesList { grid-template-columns: minmax(0, 1fr) !important; }
    body:not(.tv-mode) .page-sdk .grid-3 { grid-template-columns: minmax(0, 1fr) !important; }

    /* Nuvem/FTP, gravações, rostos, placas e analytics. */
    body:not(.tv-mode) .page-cloud .disk-panel-container,
    body:not(.tv-mode) .page-cloud .disk-usage-section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
    body:not(.tv-mode) .page-cloud .disk-card,
    body:not(.tv-mode) .page-cloud .disk-usage-card { min-width: 0; padding: 11px; }
    body:not(.tv-mode) .page-ftp #ftpPageHeader,
    body:not(.tv-mode) .page-ftp .ftp-toolbar-row { gap: 6px; }
    body:not(.tv-mode) .page-ftp #ftpGrid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px !important; }
    body:not(.tv-mode) .page-recordings .stats-grid,
    body:not(.tv-mode) .page-plates > [style*="grid-template-columns"],
    body:not(.tv-mode) .page-analytics .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px !important; }
    body:not(.tv-mode) .page-faces #facesGrid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)) !important; gap: 8px !important; }
    body:not(.tv-mode) .page-analytics .event-detail-grid { grid-template-columns: minmax(0, 1fr) !important; }

    /* Mapa, mosaico e turret ocupam o espaço útil, sem largura desktop. */
    body:not(.tv-mode) .page-mosaic { padding: 0 !important; }
    body:not(.tv-mode) .page-mosaic .mosaic-layout {
        margin: 0 !important;
        height: calc(100dvh - var(--mobile-header-h) - var(--mobile-nav-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    }
    body:not(.tv-mode) .page-mosaic #mosaicGrid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    body:not(.tv-mode) .page-turret .turret-grid { grid-template-columns: minmax(0, 1fr) !important; }
    body:not(.tv-mode) .page-turret .sim-container-wrap { max-width: 100%; overflow-x: auto; }

    /* Configurações/perfil: remove padding duplicado e mantém ações visíveis. */
    body:not(.tv-mode) .page-settings .page-header-actions,
    body:not(.tv-mode) .page-profile .profile-page-container { max-width: 100% !important; }
    body:not(.tv-mode) .page-settings .card > div[style*="padding:16px"] { padding: 8px !important; }

    /* Cobertura final das páginas com estilos locais/inline. */
    body:not(.tv-mode) .page-reports .telemetry-grid,
    body:not(.tv-mode) .page-reports .event-detail-grid,
    body:not(.tv-mode) .page-analytics .event-detail-grid,
    body:not(.tv-mode) .page-plates .plates-main-layout,
    body:not(.tv-mode) .page-plates .plates-detail-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
    body:not(.tv-mode) .page-reports .telemetry-card,
    body:not(.tv-mode) .page-reports .chart-container-telemetry { padding: 12px !important; margin-bottom: 10px !important; }
    body:not(.tv-mode) .page-reports .telemetry-value-large { font-size: 22px !important; }

    body:not(.tv-mode) .page-camera .camera-detail-layout { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
    body:not(.tv-mode) .page-camera .camera-detail-main,
    body:not(.tv-mode) .page-camera .camera-detail-sidebar { min-width: 0 !important; max-width: 100% !important; }
    body:not(.tv-mode) .page-camera .embedded-stream { aspect-ratio: 16 / 9; min-height: 0 !important; height: auto !important; }
    body:not(.tv-mode) .page-camera .grounding-query-container { flex-wrap: wrap; }
    body:not(.tv-mode) .page-camera .grounding-query-container input { flex-basis: calc(100% - 32px) !important; }
    body:not(.tv-mode) .page-camera .grounding-query-container button { flex: 1 1 auto; }
    body:not(.tv-mode) .page-camera .camera-recording-filters,
    body:not(.tv-mode) .page-camera .camera-event-filters,
    body:not(.tv-mode) .page-camera .camera-sd-toolbar { grid-template-columns: minmax(0, 1fr) !important; padding: 8px !important; }
    body:not(.tv-mode) .page-camera .camera-filter-actions { grid-column: 1 !important; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body:not(.tv-mode) .page-camera .camera-filter-actions .btn { width: 100%; }
    body:not(.tv-mode) .page-camera .mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    body:not(.tv-mode) .page-camera .cam-meta { font-size: 10px !important; line-height: 1.4; }
    body:not(.tv-mode) .page-camera .cam-badges { max-width: 100%; flex-wrap: wrap; }

    body:not(.tv-mode) .page-cameras .camera-command-bar { padding: 8px !important; gap: 8px !important; }
    body:not(.tv-mode) .page-cameras .camera-filter-row,
    body:not(.tv-mode) .page-cameras .camera-view-actions { gap: 7px !important; }
    body:not(.tv-mode) .page-cameras .camera-search { flex: 1 1 100% !important; min-width: 0 !important; }
    body:not(.tv-mode) .page-cameras .camera-view-actions { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body:not(.tv-mode) .page-cameras .camera-view-actions > * { min-width: 0 !important; max-width: 100% !important; }
    body:not(.tv-mode) .page-cameras .camera-view-controls,
    body:not(.tv-mode) .page-cameras .camera-primary-actions { grid-column: 1 / -1; width: 100%; }
    body:not(.tv-mode) .page-cameras .camera-primary-actions { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body:not(.tv-mode) .page-cameras .camera-primary-actions .btn { width: 100%; }
    body:not(.tv-mode) .page-cameras .camera-tile { aspect-ratio: 16 / 9; min-height: 0 !important; }
    body:not(.tv-mode) .page-cameras .camera-pagination { flex-wrap: wrap; gap: 5px; }

    body:not(.tv-mode) .page-automations .auto-actions-container { padding: 9px !important; }
    body:not(.tv-mode) .page-automations .auto-actions-row,
    body:not(.tv-mode) .page-automations .auto-status-bar { gap: 7px !important; }
    body:not(.tv-mode) .page-automations .auto-filters-group { grid-template-columns: minmax(0, 1fr) !important; width: 100% !important; }
    body:not(.tv-mode) .page-automations .auto-buttons-group { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100% !important; gap: 5px !important; }
    body:not(.tv-mode) .page-automations .auto-buttons-group .btn { width: 100%; min-width: 0; padding-inline: 5px !important; }
    body:not(.tv-mode) .page-automations .auto-status-bar { align-items: stretch !important; }
    body:not(.tv-mode) .page-automations .auto-status-bar > span { width: 100%; white-space: normal; }
    body:not(.tv-mode) .page-automations .automation-card-flow { grid-template-columns: minmax(0, 1fr) !important; }
    body:not(.tv-mode) .page-automations .automation-flow-arrow { height: 18px; transform: rotate(90deg); }

    body:not(.tv-mode) .page-recordings .filters-bar > div,
    body:not(.tv-mode) .page-analytics .filters-bar > div,
    body:not(.tv-mode) .page-plates .filters-bar > div { min-width: 0 !important; max-width: 100% !important; width: 100% !important; }
    body:not(.tv-mode) .page-recordings .filters-bar > div:last-child { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); }
    body:not(.tv-mode) .page-recordings #videoPlayer { max-height: 38dvh !important; }
    body:not(.tv-mode) .page-plates .card-header .filters-bar { flex: 1 1 100%; }
    body:not(.tv-mode) .page-plates .plate-provider-banner { padding: 10px 11px; margin-bottom: 10px; gap: 9px; }
    body:not(.tv-mode) .page-plates .plate-provider-banner .btn { width: auto !important; min-height: 36px !important; }
    body:not(.tv-mode) .page-plates .plate-page-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px !important; margin-bottom: 10px; }
    body:not(.tv-mode) .page-plates .plate-stat-card { min-height: 58px; padding: 8px 9px !important; gap: 8px; border-radius: 9px; }
    body:not(.tv-mode) .page-plates .plate-stat-icon { width: 30px; height: 30px; flex-basis: 30px; font-size: 14px; }
    body:not(.tv-mode) .page-plates .plate-stat-value { font-size: 18px; }
    body:not(.tv-mode) .page-plates .plate-stat-label { font-size: 8px; letter-spacing: .025em; }
    body:not(.tv-mode) .page-plates .plate-work-card,
    body:not(.tv-mode) .page-plates .plate-history-card { margin-bottom: 10px; padding: 0 !important; overflow: visible !important; }
    body:not(.tv-mode) .page-plates .plate-work-card .card-header,
    body:not(.tv-mode) .page-plates .plate-history-card .card-header { padding: 10px !important; }
    body:not(.tv-mode) .page-plates .plate-primary-filters { margin-left: 0; padding: 0 !important; }
    body:not(.tv-mode) .page-plates .plate-primary-filters .btn { min-height: 38px !important; }
    body:not(.tv-mode) .page-plates .plate-filter-grid { grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 7px !important; padding: 9px !important; }
    body:not(.tv-mode) .page-plates .plate-filter-grid .btn { min-height: 38px !important; }
    body:not(.tv-mode) .page-plates .plate-table-wrap { padding: 0 8px 2px; overflow: visible !important; }
    body:not(.tv-mode) .page-plates .plate-reading-row { display: grid !important; grid-template-columns:minmax(0,1fr); margin-bottom: 8px !important; padding: 7px !important; border-radius: 11px !important; background: var(--bg-card) !important; }
    body:not(.tv-mode) .page-plates .plate-reading-row.is-blacklist { border-color: rgba(239,68,68,.48); background: rgba(239,68,68,.1) !important; }
    body:not(.tv-mode) .page-plates .plate-reading-row.is-whitelist { border-color: rgba(59,130,246,.35); background: rgba(59,130,246,.1) !important; }
    body:not(.tv-mode) .page-plates .plate-reading-row td { min-height: 34px !important; height: auto !important; padding: 6px 2px !important; font-size: 11px !important; order: 4; }
    body:not(.tv-mode) .page-plates .plate-reading-row > td:not(.plate-mobile-reading-summary):not([data-label="Ações"]) { display:none!important; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-summary { display:block!important;min-width:0!important;padding:0 0 6px!important;border:0!important;order:1!important; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-summary::before { display:none!important; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-open { width:100%;min-width:0;display:grid;grid-template-columns:58px minmax(0,1fr);align-items:center;gap:9px;padding:0;border:0;background:transparent;color:var(--text-primary);text-align:left;cursor:pointer; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-preview { width:58px;height:58px;display:grid;place-items:center;overflow:hidden;border:1px solid var(--border);border-radius:9px;background:var(--bg-tertiary);color:var(--accent); }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-preview img { width:100%;height:100%;object-fit:cover; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-copy { min-width:0;display:grid;grid-template-rows:repeat(4,minmax(0,1fr));gap:1px;color:var(--text-muted);font-size:9.5px;line-height:1.18; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-copy>span { min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-title { display:flex;align-items:center;justify-content:space-between;gap:8px;color:var(--text-primary); }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-title strong { overflow:hidden;text-overflow:ellipsis;font:800 15px/1 monospace;letter-spacing:.08em;color:var(--accent); }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-title b { flex:0 0 auto;font-size:10px;color:var(--text-primary); }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-badges { display:flex;gap:4px;flex-wrap:wrap;margin-top:5px; }
    body:not(.tv-mode) .page-plates .plate-mobile-reading-badges .badge { font-size:8px!important;padding:2px 6px!important; }
    body:not(.tv-mode) .page-plates .plate-reading-row td[data-label="Placa"] { order: 1; min-height: 54px !important; align-items: center; border-bottom-color: var(--border) !important; }
    body:not(.tv-mode) .page-plates .plate-reading-row td[data-label="Placa"]::before { display: none; }
    body:not(.tv-mode) .page-plates .plate-reading-row td[data-label="Status"] { order: 2; align-items: flex-start; }
    body:not(.tv-mode) .page-plates .plate-reading-row td[data-label="Data/Hora"] { order: 3; }
    body:not(.tv-mode) .page-plates .plate-reading-row td[data-label="Ações"] { order: 2; display: block !important; min-height:0!important;padding:6px 0 0!important;border-top:1px solid var(--border)!important; }
    body:not(.tv-mode) .page-plates .plate-reading-row td[data-label="Ações"]::before { display:none!important; }
    body:not(.tv-mode) .page-plates .plate-reading-row td::before { flex-basis: 31%; max-width: 31%; font-size: 9px; }
    body:not(.tv-mode) .page-plates .plate-reading-primary { width: 100%; gap: 10px; }
    body:not(.tv-mode) .page-plates .plate-reading-thumb { width: 64px; height: 43px; flex-basis: 64px; }
    body:not(.tv-mode) .page-plates .plate-reading-code { font-size: 18px; }
    body:not(.tv-mode) .page-plates .plate-reading-vehicle,
    body:not(.tv-mode) .page-plates .plate-reading-camera { max-width: 65%; text-align: right; }
    body:not(.tv-mode) .page-plates .plate-card-actions-inline { display:grid;grid-template-columns:minmax(0,1fr) auto;gap:6px; }
    body:not(.tv-mode) .page-plates .plate-card-primary-action { display:block;width:100%;min-height:36px; }
    body:not(.tv-mode) .page-plates .plate-actions-trigger { width: auto !important; min-width:82px!important; min-height: 36px !important; }
    body:not(.tv-mode) .plate-actions-backdrop { background: rgba(2,6,12,.7); }
    body:not(.tv-mode).plate-actions-open { overflow:hidden; }
    body:not(.tv-mode) .plate-actions-menu.is-mobile-sheet { inset: auto 7px calc(var(--mobile-nav-h) + 7px + env(safe-area-inset-bottom)) 7px !important; width: auto !important; max-height:min(72dvh,520px);padding: 8px; border-radius: 15px; overflow-y:auto;overscroll-behavior:contain; }
    body:not(.tv-mode) .plate-actions-menu-header { display:flex;align-items:center;justify-content:space-between;padding:2px 3px 7px 8px;border-bottom:1px solid var(--border);margin-bottom:3px }
    body:not(.tv-mode) .plate-actions-menu-header .plate-modal-close { min-width:36px!important;min-height:36px!important }
    body:not(.tv-mode) .plate-action-item { min-height: 44px; font-size: 13px; }
    body:not(.tv-mode) .plate-modal-backdrop { padding: max(4px,env(safe-area-inset-top)) 0 0!important;align-items:stretch!important;background:rgba(2,6,12,.95)!important }
    body:not(.tv-mode) .plate-modal { width:100vw!important;max-width:100vw!important;height:calc(100dvh - max(4px,env(safe-area-inset-top)))!important;max-height:none!important;margin:0!important;border-radius:12px 12px 0 0!important;background:var(--bg-card)!important }
    body:not(.tv-mode) .plate-list-dialog { height:auto!important;max-height:88dvh!important;margin-top:auto!important }
    body:not(.tv-mode) .plate-modal-header { min-height:52px;padding:7px 9px 7px 11px!important;background:var(--bg-card)!important;border-bottom:1px solid var(--border)!important }
    body:not(.tv-mode) .plate-modal-heading h3 { font-size:15px;color:var(--text-primary)!important }
    body:not(.tv-mode) .plate-modal-close { min-width:38px!important;min-height:38px!important;background:var(--bg-secondary)!important;color:var(--text-primary)!important }
    body:not(.tv-mode) .plate-modal-body { min-height:0;padding:10px!important;overflow-y:auto!important;background:var(--bg-primary)!important;color:var(--text-primary)!important }
    body:not(.tv-mode) .plate-dossier-modal .plate-modal-body { padding:0!important }
    body:not(.tv-mode) .plate-modal-footer { display:flex!important;flex-direction:row!important;flex-wrap:wrap!important;padding:7px 9px calc(7px + env(safe-area-inset-bottom))!important;gap:6px!important;background:var(--bg-card)!important;border-top:1px solid var(--border)!important }
    body:not(.tv-mode) .plate-modal-footer .btn { flex:0 1 auto!important;width:auto!important;min-height:34px!important;padding:6px 9px!important;font-size:10px!important }
    body:not(.tv-mode) .plate-dossier-actions-menu.is-mobile-sheet { inset:auto 8px calc(8px + env(safe-area-inset-bottom)) 8px!important;width:auto!important;max-height:min(72dvh,520px);border-radius:16px;padding:8px;overflow-y:auto;overscroll-behavior:contain }
    body:not(.tv-mode) .plate-dossier-actions-menu .plate-action-item { min-height:50px!important;padding:8px 10px!important }
    body:not(.tv-mode) .plate-dossier-summary { grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:7px!important;padding:9px!important }
    body:not(.tv-mode) .plate-dossier-summary .plate-dossier-metric:first-child { grid-column:1/-1 }
    body:not(.tv-mode) .plate-dossier-metric { padding:8px!important }
    body:not(.tv-mode) .plate-dossier-value { font-size:12px }
    body:not(.tv-mode) .plate-dossier-tab-picker { display:grid!important;position:sticky;top:0;z-index:4;grid-template-columns:auto minmax(0,1fr);align-items:center;gap:8px;padding:7px 9px;background:var(--bg-card)!important;border-bottom:1px solid var(--border)!important }
    body:not(.tv-mode) .plate-dossier-tab-picker .form-control { height:38px!important;margin:0!important;min-width:0!important }
    body:not(.tv-mode) .plate-dossier-tabs { display:none!important }
    body:not(.tv-mode) .plate-dossier-tab { min-height:36px!important;padding:6px 9px!important;font-size:11px!important }
    body:not(.tv-mode) .plate-dossier-panel { padding:9px!important }
    body:not(.tv-mode) .plate-evidence-grid { grid-template-columns:minmax(0,1fr)!important;gap:8px!important }
    body:not(.tv-mode) .plate-evidence-card header { gap:6px;flex-wrap:wrap;font-size:9px }
    body:not(.tv-mode) .plate-person-intro { margin-bottom:8px;padding:9px;font-size:10px }
    body:not(.tv-mode) .plate-person-footer { align-items:stretch;flex-direction:column }
    body:not(.tv-mode) .plate-person-actions { display:grid;grid-template-columns:repeat(2,minmax(0,1fr));width:100% }
    body:not(.tv-mode) .plate-person-footer .btn { width:100%!important;min-width:0!important;min-height:34px!important }
    body:not(.tv-mode) .plate-lookup-heading { align-items:stretch;flex-direction:column;padding:11px }
    body:not(.tv-mode) .plate-lookup-heading .btn { width:100%!important;min-height:38px!important }
    body:not(.tv-mode) .plate-lookup-grid { grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:7px }
    body:not(.tv-mode) .plate-lookup-grid article { padding:8px }
    body:not(.tv-mode) .plate-lookup-actions { display:grid;grid-template-columns:repeat(2,minmax(0,1fr)) }
    body:not(.tv-mode) .plate-lookup-actions .btn { width:100%!important;min-width:0!important }
    body:not(.tv-mode) .plate-review-grid { grid-template-columns:minmax(0,1fr)!important;gap:8px!important }
    body:not(.tv-mode) .plate-review-grid .wide { grid-column:1!important }
    body:not(.tv-mode) #plateHistoryBody > div[style*="grid-template-columns"] { grid-template-columns:minmax(0,1fr)!important }
    body:not(.tv-mode) .plate-list-row { align-items:flex-start;flex-direction:column;padding:9px 10px }
    body:not(.tv-mode) .plate-list-actions { width:100%;display:grid;grid-template-columns:repeat(2,minmax(0,1fr)) }
    body:not(.tv-mode) .plate-list-actions .btn { width:100%!important;min-height:36px!important }

    html.native-app body:not(.tv-mode) .plate-modal-backdrop { padding-top:max(18px,env(safe-area-inset-top))!important }
    html.native-app body:not(.tv-mode) .plate-modal { height:calc(100dvh - max(18px,env(safe-area-inset-top)))!important }

    body:not(.tv-mode) .page-engines #engineStats,
    body:not(.tv-mode) .page-recordings #recStatsBar,
    body:not(.tv-mode) .page-reports #reportStats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px !important; }

    body:not(.tv-mode) .page-cloud .storage-dashboard-grid,
    body:not(.tv-mode) .page-cloud .ftp-status-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px !important; }
    body:not(.tv-mode) .page-cloud .cloud-tabs { max-width: 100%; overflow-x: auto; flex-wrap: nowrap !important; }
    body:not(.tv-mode) .page-cloud .cloud-tabs > * { flex: 0 0 auto; }
    body:not(.tv-mode) .page-ftp .ftp-toolbar-row { max-width: 100%; flex-wrap: wrap; }
    body:not(.tv-mode) .page-ftp #ftpDateArea { flex: 1 1 160px; min-width: 0; max-width: 100%; }
    body:not(.tv-mode) .page-ftp #ftpDatePicker { width: 100%; }
    body:not(.tv-mode) .page-ftp :is(#ftpTypeFilter, .ftp-search-controls) { flex: 1 1 100%; }
    body:not(.tv-mode) .page-ftp .ftp-toolbar-divider { display: none; }

    body:not(.tv-mode) .page-sdk pre,
    body:not(.tv-mode) .page-sdk code,
    body:not(.tv-mode) .page-settings pre { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

    /* Inline layouts antigos não podem impor largura desktop no WebView. */
    body:not(.tv-mode) .page-content [style*="min-width:200px"],
    body:not(.tv-mode) .page-content [style*="min-width: 200px"],
    body:not(.tv-mode) .page-content [style*="min-width:280px"],
    body:not(.tv-mode) .page-content [style*="min-width: 280px"] { min-width: 0 !important; }
}

/* Tablets em retrato têm espaço para duas câmeras, mas mantêm o fluxo vertical
   dos widgets para não herdar posições e larguras do dashboard desktop. */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    body:not(.tv-mode) .page-dashboard .camera-grid,
    body:not(.tv-mode) .page-dashboard .camera-grid[class*="grid-"] {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 380px) {
    body:not(.tv-mode) .page-content { padding-inline: 8px !important; }
    body:not(.tv-mode) .mobile-brand,
    body:not(.tv-mode) .mobile-title-sep { display: none !important; }
    body:not(.tv-mode) .page-dashboard .widget-header .cam-filter-btn { font-size: 9px !important; }
    body:not(.tv-mode) .page-reports .report-search-row { grid-template-columns: minmax(0, 1fr) minmax(68px, auto); }
    body:not(.tv-mode) .page-reports .report-visual-toggle { grid-column: 1 / -1; }
    body:not(.tv-mode) .page-cameras .camera-filter-select { flex-basis: 100%; }
    body:not(.tv-mode) .modal-footer { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 1024px) {
    :root { --mobile-header-min: 44px; --mobile-nav-min: 52px; }
    body:not(.tv-mode) .mobile-bottom-item { min-height: 44px !important; flex-direction: row; gap: 6px !important; }
    body:not(.tv-mode) .mobile-bottom-item > span { font-size: 16px !important; }
    body:not(.tv-mode) .page-content { padding-top: 7px !important; }
    body:not(.tv-mode) .modal { max-height: 96dvh !important; }
}

/* Camada final compartilhada pelo navegador móvel e pelo WebView Android. */
@media (max-width: 1024px) {
    body:not(.tv-mode) .page-content,
    body:not(.tv-mode) .page-content > *,
    body:not(.tv-mode) .page-content .card,
    body:not(.tv-mode) .page-content .card-body { min-width: 0 !important; }
    body:not(.tv-mode) .page-content :is(img,video,canvas,svg) { max-width: 100%; }
    body:not(.tv-mode) .page-content :is(button,.btn,a[role="button"],.detail-tab-btn,.reports-tab-btn,.camera-chip),
    body:not(.tv-mode) .page-content .leaflet-control a { min-height: 44px !important; }
    body:not(.tv-mode) .page-content :is(.btn-icon,.cam-action-btn,.auto-view-switch button,.sidebar-close-btn),
    body:not(.tv-mode) .page-content .leaflet-control a { min-width: 44px !important; }
    body:not(.tv-mode) .page-content input[type="checkbox"],
    body:not(.tv-mode) .page-content input[type="radio"] {
        width: 22px !important; min-width: 22px !important; height: 22px !important; min-height: 22px !important;
    }
    body:not(.tv-mode) .page-content small,
    body:not(.tv-mode) .page-content [style*="font-size:9px"],
    body:not(.tv-mode) .page-content [style*="font-size:10px"] { font-size: 11px !important; line-height: 1.35; }
    body:not(.tv-mode) .ux-table-container { max-width: 100%; overflow: auto; overscroll-behavior-inline: contain; }
}

/* Prioridade final da UX v2. Mantida no fim para vencer os blocos legados. */
@media (max-width: 1024px) {
    html body:not(.tv-mode) { padding-bottom: 0 !important; }
    html body:not(.tv-mode) .mobile-header {
        height: auto !important;
        min-height: calc(var(--mobile-header-min) + env(safe-area-inset-top)) !important;
        background: var(--bg-secondary) !important;
    }
    html body:not(.tv-mode) .mobile-menu-toggle,
    html body:not(.tv-mode) .mobile-connection { width:44px !important; min-width:44px !important; height:44px !important; min-height:44px !important; }
    html body:not(.tv-mode) .mobile-bottom-nav {
        display:flex !important; height:auto !important;
        padding:0 3px env(safe-area-inset-bottom) !important; gap:0 !important;
        background:var(--bg-secondary) !important; backdrop-filter:none !important; -webkit-backdrop-filter:none !important;
    }
    html body:not(.tv-mode) .mobile-bottom-item {
        flex:1 1 0 !important; min-width:0 !important; min-height:var(--mobile-nav-min) !important;
        padding:3px 2px 2px !important; border-radius:0 !important;
        background:transparent !important; box-shadow:none !important; transform:none !important;
    }
    html body:not(.tv-mode) .mobile-bottom-icon { display:grid !important; place-items:center; width:19px; height:19px; font-size:0 !important; }
    html body:not(.tv-mode) .mobile-bottom-icon svg { width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.8; }
    html body:not(.tv-mode) .mobile-bottom-item small { font-size:8px!important;line-height:1.2!important; white-space:normal; overflow-wrap:anywhere; }
    html body:not(.tv-mode) #mobilePageTitle { white-space:normal; overflow-wrap:anywhere; line-height:1.25; }
    html body:not(.tv-mode).modal-open .mobile-bottom-nav,
    html body:not(.tv-mode).report-event-actions-open .mobile-bottom-nav {
        visibility:hidden!important;
        opacity:0!important;
        pointer-events:none!important;
        transform:translateY(100%)!important;
    }
    html body:not(.tv-mode) .modal-backdrop { z-index:1600!important; }
    html body:not(.tv-mode) #cameraModal .camera-location-head { align-items:stretch!important;flex-direction:column; }
    html body:not(.tv-mode) #cameraModal .camera-location-actions { display:grid!important;grid-template-columns:minmax(0,1fr)!important;width:100%; }
    html body:not(.tv-mode) #cameraModal .camera-location-actions .btn { width:100%!important;min-height:40px!important; }
    html body:not(.tv-mode) #cameraModal .camera-location-fields { grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important; }
    html body:not(.tv-mode) #cameraModal .camera-location-angle { grid-column:1/-1; }

    /* Editor da câmera: fluxo em etapas, sem colunas desktop no WebView. */
    html body:not(.tv-mode) #cameraModal,
    html body:not(.tv-mode) #cameraConfigModal {
        align-items:stretch!important; padding:max(0px, env(safe-area-inset-top)) 0 0!important;
        background:rgba(2,6,12,.88)!important;
    }
    html body:not(.tv-mode) #cameraModal .camera-editor-modal,
    html body:not(.tv-mode) #cameraConfigModal .camera-config-modal {
        width:100vw!important; max-width:100vw!important; height:calc(100dvh - env(safe-area-inset-top))!important;
        max-height:none!important; border-radius:14px 14px 0 0!important; background:var(--bg-card)!important;
    }
    html body:not(.tv-mode) #cameraModal .camera-editor-header,
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header {
        min-height:58px!important; padding:8px 10px 8px 12px!important; background:var(--bg-card)!important;
        border-bottom:1px solid var(--border)!important;
    }
    html body:not(.tv-mode) :is(#cameraModal,#cameraConfigModal) .camera-modal-heading h3 {
        max-width:min(72vw,520px); overflow:hidden; font-size:15px!important; text-overflow:ellipsis; white-space:nowrap;
    }
    html body:not(.tv-mode) :is(#cameraModal,#cameraConfigModal) .camera-modal-heading small {
        max-width:min(72vw,520px); overflow:hidden; font-size:9px!important; text-overflow:ellipsis; white-space:nowrap;
    }
    html body:not(.tv-mode) :is(#cameraModal,#cameraConfigModal) .camera-modal-eyebrow { font-size:8px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-nav {
        min-height:43px; padding:5px 8px!important; gap:5px; background:var(--bg-secondary)!important;
    }
    html body:not(.tv-mode) #cameraModal .camera-editor-nav-btn {
        flex:0 0 auto; min-width:88px!important; min-height:34px!important; padding:5px 10px!important; font-size:10px!important;
    }
    html body:not(.tv-mode) #cameraModal .camera-editor-body {
        display:block!important; min-height:0!important; padding:10px!important; background:var(--bg-primary)!important;
    }
    html body:not(.tv-mode) #cameraModal .camera-editor-section { display:none; width:100%; margin:0!important; padding:11px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-section.active { display:block; }
    html body:not(.tv-mode) #cameraModal .camera-editor-section-head { margin-bottom:11px; }
    html body:not(.tv-mode) #cameraModal .camera-editor-section-head h4 { font-size:13px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-section-head p { font-size:9px!important; }
    html body:not(.tv-mode) #cameraModal .form-row,
    html body:not(.tv-mode) #cameraModal .camera-editor-option-grid { grid-template-columns:minmax(0,1fr)!important; gap:8px!important; }
    html body:not(.tv-mode) #cameraModal .form-group { min-width:0; margin-bottom:10px; }
    html body:not(.tv-mode) #cameraModal .form-control { width:100%!important; min-width:0!important; min-height:42px!important; font-size:13px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-segmented { display:grid!important; grid-template-columns:minmax(0,1fr)!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-segmented .btn { width:100%!important; min-height:40px!important; }
    html body:not(.tv-mode) #cameraModal #protoButtons { display:grid!important; grid-template-columns:repeat(2,minmax(0,1fr))!important; }
    html body:not(.tv-mode) #cameraModal #protoButtons .btn { width:100%!important; min-width:0!important; min-height:38px!important; white-space:normal!important; }
    html body:not(.tv-mode) #cameraModal #xmeyeCloudFlow > div[style*="display:flex"] { flex-wrap:wrap!important; align-items:stretch!important; }
    html body:not(.tv-mode) #cameraModal #xmeyeCaptchaCode { max-width:none!important; flex:1 1 150px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-switch-grid { grid-template-columns:minmax(0,1fr)!important; gap:7px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-switch { min-height:58px; padding:9px!important; }
    html body:not(.tv-mode) #cameraModal .camera-editor-switch > input,
    html body:not(.tv-mode) #cameraModal .camera-identity-confirm > input { margin-top:1px; }
    html body:not(.tv-mode) #cameraModal .camera-editor-footer {
        grid-template-columns:minmax(0,.8fr) minmax(0,1.2fr)!important; padding:8px 10px calc(8px + env(safe-area-inset-bottom))!important;
    }
    html body:not(.tv-mode) #cameraModal .camera-editor-footer .btn { min-height:40px!important; }

    /* Configuração do hardware: seletor único no celular e conteúdo integralmente rolável. */
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header { align-items:flex-start!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header-actions { gap:4px!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header-actions .btn:not(.btn-icon) {
        width:auto!important; min-width:0!important; min-height:36px!important; padding:5px 7px!important;
        font-size:0!important; white-space:nowrap;
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header-actions .btn:not(.btn-icon)::before { font-size:15px; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header-actions .btn:nth-child(1)::before { content:'✓'; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-header-actions .btn:nth-child(2)::before { content:'⇩'; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-mobile-nav {
        display:grid!important; grid-template-columns:auto minmax(0,1fr); align-items:center; gap:8px;
        flex:0 0 auto; padding:7px 10px; background:var(--bg-secondary); border-bottom:1px solid var(--border);
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-mobile-nav label { margin:0; color:var(--text-muted); font-size:9px; font-weight:800; text-transform:uppercase; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-mobile-nav select { min-height:38px!important; font-size:12px!important; }
    html body:not(.tv-mode) #cameraConfigModal .config-modal-layout { display:block!important; min-height:0!important; margin:0!important; overflow:hidden!important; }
    html body:not(.tv-mode) #cameraConfigModal .config-modal-sidebar { display:none!important; }
    html body:not(.tv-mode) #cameraConfigModal .config-modal-content {
        width:100%!important; height:100%!important; min-height:0!important; padding:10px!important;
        overflow-x:hidden!important; overflow-y:auto!important; background:var(--bg-primary)!important;
        overscroll-behavior:contain; -webkit-overflow-scrolling:touch;
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-content-head {
        top:-10px; margin:-10px -10px 10px; padding:9px 11px; background:var(--bg-primary)!important;
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-content-head strong { font-size:13px; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-content-head span { font-size:9px!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane,
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane > * { min-width:0!important; max-width:100%!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane [style*="grid-template-columns:1fr 1fr"],
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns:minmax(0,1fr)!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane :is(input:not([type="checkbox"]):not([type="radio"]),select,textarea) {
        width:100%!important; max-width:100%!important; min-width:0!important; min-height:42px!important; font-size:13px!important;
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane input[type="range"] { min-height:28px!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane-actions {
        display:grid!important; grid-template-columns:minmax(0,1fr)!important; gap:7px!important;
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane-actions .btn { width:100%!important; min-height:40px!important; white-space:normal!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane [style*="justify-content:space-between"][style*="padding:12px"][style*="background:var(--bg-secondary)"] {
        flex-direction:column!important; align-items:stretch!important; gap:10px!important;
    }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane [style*="justify-content:space-between"][style*="padding:12px"] .btn { width:100%!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-table-wrap { width:100%; overflow:auto!important; }
    html body:not(.tv-mode) #cameraConfigModal .camera-config-pane table { min-width:560px; }
}

@media (max-width: 1024px) {
    html body:not(.tv-mode) .page-cameras .camera-stats {
        display:flex !important; grid-template-columns:none !important; gap:6px !important;
        overflow-x:auto !important; padding-bottom:2px !important;
    }
    html body:not(.tv-mode) .page-cameras .camera-stat,
    html body:not(.tv-mode) .page-cameras .camera-stat:last-child {
        display:flex !important; flex:0 0 auto !important; grid-column:auto !important;
        width:auto !important; min-width:98px !important; min-height:46px !important;
        padding:6px 9px !important; align-items:center; gap:6px;
    }
    html body:not(.tv-mode) .page-cameras .camera-stat strong { display:inline !important; font-size:16px !important; }
    html body:not(.tv-mode) .page-cameras .camera-stat span { display:inline !important; margin:0 !important; font-size:10px !important; }
    html body:not(.tv-mode) .page-cameras .camera-mobile-command-head { display:flex !important; }
    html body:not(.tv-mode) .page-cameras .camera-command-details { display:flex !important; }
    html body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-filter-row > :not(.camera-search),
    html body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-filters-collapsible,
    html body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-groups-row,
    html body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) .camera-view-actions { display:none !important; }
    html body:not(.tv-mode) .page-cameras .camera-search { width:100% !important; min-width:0 !important; height:44px !important; flex-basis:100% !important; }
    html body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-filter-row {
        display:grid !important; grid-template-columns:repeat(2,minmax(0,1fr)) !important; gap:7px !important;
    }
    html body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-search { grid-column:1 / -1; }
    html body:not(.tv-mode) .page-cameras .camera-command-details.is-open .camera-filter-select { width:100% !important; min-width:0 !important; }
    html body:not(.tv-mode) .page-cameras .camera-primary-actions .btn-primary { display:none !important; }

    html body:not(.tv-mode) .camera-tile,
    html body:not(.tv-mode) .page-dashboard .camera-tile,
    html body:not(.tv-mode) .page-cameras .camera-tile {
        width:100% !important; height:auto !important; min-height:0 !important; aspect-ratio:auto !important; overflow:hidden !important;
    }
    html body:not(.tv-mode) .camera-tile .camera-tile-media {
        width:100% !important; height:0 !important; min-height:0 !important; padding-bottom:56.25% !important;
    }
    html body:not(.tv-mode) .camera-tile .camera-tile-media :is(img,video) { object-fit:contain !important; }
    html body:not(.tv-mode) .camera-tile .cam-infobar,
    html body:not(.tv-mode) .camera-tile .cam-iot-actions { display:none !important; }
    html body:not(.tv-mode) .camera-tile .cam-topbar { padding:7px 94px 12px 9px !important; }
    html body:not(.tv-mode) .camera-tile .cam-name { max-width:100% !important; font-size:13px !important; }
    html body:not(.tv-mode) .camera-tile .cam-actions {
        top:6px !important; right:6px !important; display:flex !important; flex-wrap:nowrap !important;
        max-width:none !important; gap:4px !important; opacity:1 !important; z-index:30 !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-action-btn {
        width:40px !important; min-width:40px !important; height:40px !important; min-height:40px !important;
        padding:0 !important; border-radius:8px !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-action-more { display:grid !important; place-items:center; }
    html body:not(.tv-mode) .camera-tile .cam-action-menu { display:none !important; }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu {
        position:absolute !important; top:44px; right:0; display:grid !important;
        grid-template-columns:repeat(3,40px); gap:5px; padding:6px;
        border:1px solid var(--border); border-radius:10px;
        background:var(--bg-secondary); box-shadow:0 12px 30px rgba(0,0,0,.48);
    }
    html body:not(.tv-mode) .camera-tile .cam-controls {
        position:relative !important; inset:auto !important; display:grid !important;
        grid-template-columns:repeat(4,minmax(0,1fr)) !important; width:100% !important;
        min-height:0 !important; padding:4px !important; gap:4px !important; opacity:1 !important;
        background:var(--bg-secondary) !important; border-top:1px solid var(--border);
    }
    html body:not(.tv-mode) .camera-tile .cam-ctrl-btn {
        width:100% !important; min-width:0 !important; min-height:38px !important;
        padding:5px 3px !important; font-size:10px !important;
    }

    html body:not(.tv-mode) .page-dashboard .dash-top-bar {
        display:block !important; width:100% !important; margin:0 0 8px !important;
        padding:0 !important; overflow:hidden !important; border-radius:10px !important;
    }
    html body:not(.tv-mode) .page-dashboard .dash-mobile-summary { display:flex !important; }
    html body:not(.tv-mode) .page-dashboard .dash-tools-content { display:none !important; }
    html body:not(.tv-mode) .page-dashboard .dash-top-bar.mobile-expanded .dash-tools-content { display:block !important; padding:7px; }
    html body:not(.tv-mode) .page-dashboard .dash-tools-content .dash-stats {
        display:grid !important; grid-template-columns:repeat(3,minmax(0,1fr)) !important; gap:5px !important;
    }
    html body:not(.tv-mode) .page-dashboard .dash-tools-content .dash-toolbar {
        display:grid !important; grid-template-columns:repeat(3,minmax(0,1fr)) !important; gap:5px !important;
    }
    html body:not(.tv-mode) .page-dashboard .widget-header.no-scrollbar {
        display:grid !important; grid-template-columns:minmax(0,1fr) auto !important;
        min-height:48px !important; padding:5px 7px !important; overflow:visible !important;
    }
    html body:not(.tv-mode) .page-dashboard .widget-header.no-scrollbar > div:first-child {
        grid-column:1 !important; grid-row:1 !important; align-self:center;
    }
    html body:not(.tv-mode) .page-dashboard .camera-widget-tools-toggle {
        display:inline-flex !important; grid-column:2 !important; grid-row:1 !important;
        width:auto !important; min-height:var(--touch-target) !important; justify-self:end;
    }
    html body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) #gridLayout,
    html body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) .cam-filters-bar,
    html body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) .camera-widget-groups,
    html body:not(.tv-mode) .page-dashboard .widget-header:not(.mobile-expanded) .camera-widget-actions { display:none !important; }
    html body:not(.tv-mode) .page-dashboard .widget-header.mobile-expanded :is(.cam-filters-bar,.camera-widget-groups,.camera-widget-actions) {
        grid-column:1 / -1; display:flex !important; width:100% !important; margin:0 !important; overflow-x:auto !important; flex-wrap:nowrap !important;
    }
    html body:not(.tv-mode) .page-dashboard .camera-tile .cam-actions .cam-action-more { display:grid !important; }
    html body:not(.tv-mode) .page-dashboard .camera-tile .cam-actions.is-open .cam-action-menu .cam-action-btn:not([hidden]) { display:grid !important; }
    html body:not(.tv-mode) .page-dashboard .camera-tile .cam-controls { grid-template-columns:repeat(2,minmax(0,1fr)) !important; }

    html body:not(.tv-mode) .page-mosaic { padding:0 !important; overflow:hidden !important; }
    html body:not(.tv-mode) .page-mosaic .mosaic-layout {
        width:100% !important; height:calc(100dvh - var(--mobile-header-h) - var(--mobile-nav-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
        margin:0 !important; overflow:hidden !important;
    }
    html body:not(.tv-mode) .page-mosaic .mosaic-grid-container { width:100% !important; min-width:0 !important; padding:5px !important; gap:5px; }
    html body:not(.tv-mode) .page-mosaic .mosaic-mobile-toolbar { display:flex !important; }
    html body:not(.tv-mode) .page-mosaic #btnOpenMosaicSidebar { display:none !important; }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid {
        min-width:0 !important; min-height:0 !important; overflow-x:hidden !important; overflow-y:auto !important;
        grid-template-columns:repeat(var(--mosaic-cols,2),minmax(0,1fr)) !important;
        grid-template-rows:none !important; grid-auto-rows:auto !important; align-content:start;
    }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="9"],
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="16"] { --mosaic-cols:2 !important; }
    html body:not(.tv-mode) .page-mosaic .mosaic-cell { aspect-ratio:16 / 9 !important; }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="4"] .mosaic-cell { aspect-ratio:1 / 1 !important; }
    html body:not(.tv-mode) .page-mosaic .mosaic-sidebar,
    html body:not(.tv-mode) .page-mosaic .mosaic-sidebar.collapsed {
        position:absolute !important; z-index:70 !important; inset:auto 0 0 0 !important;
        width:100% !important; height:min(78%,620px) !important; margin:0 !important;
        transform:translateY(105%) !important; border-radius:16px 16px 0 0 !important;
    }
    html body:not(.tv-mode) .page-mosaic .mosaic-sidebar:not(.collapsed) { transform:translateY(0) !important; }
    html body:not(.tv-mode) .page-mosaic .mosaic-drawer-backdrop { display:block; }
}

@media (max-width: 390px) {
    html body:not(.tv-mode) .page-mosaic .mosaic-cameras-button {
        width:auto !important; min-width:82px !important; padding:0 8px !important;
        justify-content:center; font-size:11px !important;
    }
}

@media (max-width: 360px) {
    /* Keep all six actions on one row without shrinking their hit areas. */
    html body:not(.tv-mode) .page-mosaic .mosaic-cameras-button {
        width: var(--touch-target) !important;
        min-width: var(--touch-target) !important;
        padding: 0 !important;
        font-size: 0 !important;
    }
}

/* Detalhe da câmera: cabeçalho compacto, ações sob demanda e mídia prioritária. */
@media (max-width: 1024px) {
    html body:not(.tv-mode).camera-detail-actions-open { overflow: hidden !important; }

    html body:not(.tv-mode) .page-camera .camera-detail-header {
        position: relative;
        display: grid !important;
        grid-template-areas:
            "back info more"
            "badges badges badges" !important;
        grid-template-columns: 44px minmax(0, 1fr) auto !important;
        align-items: center !important;
        gap: 6px 8px !important;
        margin: 0 0 9px !important;
        min-width: 0;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .back-btn {
        grid-area: back !important;
        display: inline-flex !important;
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        margin: 0 !important;
        padding: 0 !important;
        align-items: center;
        justify-content: center;
        border-radius: 9px !important;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .back-btn span { display: none !important; }
    html body:not(.tv-mode) .page-camera .camera-detail-header .back-btn svg { width: 20px; height: 20px; }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-info {
        grid-area: info !important;
        width: auto !important;
        min-width: 0;
        margin: 0 !important;
        align-items: flex-start;
        text-align: left;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-header-quick-actions {
        grid-area: more;
        min-width: 0;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-info h2 {
        margin: 0 !important;
        width: 100%;
        overflow: hidden;
        font-size: 16px !important;
        line-height: 1.2 !important;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-meta { display: none !important; }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-badges {
        grid-area: badges !important;
        display: flex !important;
        width: 100%;
        min-width: 0;
        margin: 0 !important;
        padding-bottom: 1px;
        gap: 5px !important;
        flex-wrap: nowrap !important;
        justify-self: stretch !important;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-badges::-webkit-scrollbar { display: none; }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-badge {
        flex: 0 0 auto;
        padding: 3px 8px !important;
        white-space: nowrap;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-more {
        grid-area: more !important;
        display: inline-flex !important;
        width: auto !important;
        min-width: 72px !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 10px !important;
        align-items: center;
        justify-content: center;
        gap: 6px;
        color: var(--text-primary);
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 9px;
        font-size: 12px !important;
        font-weight: 700;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-more[aria-expanded="true"] {
        color: #fff;
        background: var(--accent);
        border-color: var(--accent);
    }

    html body:not(.tv-mode) .page-camera .camera-detail-actions-backdrop {
        position: fixed !important;
        z-index: 1900;
        inset: 0 !important;
        display: none !important;
        width: 100vw !important;
        height: 100dvh !important;
        margin: 0 !important;
        padding: 0 !important;
        appearance: none;
        background: rgba(2, 6, 23, .68) !important;
        border: 0 !important;
        border-radius: 0 !important;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header.actions-open .camera-detail-actions-backdrop {
        display: block !important;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions {
        position: fixed !important;
        z-index: 1901;
        right: auto !important;
        bottom: 0 !important;
        left: 50% !important;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        width: min(100%, 620px) !important;
        max-height: min(78dvh, 590px);
        margin: 0 !important;
        padding: 8px 10px calc(12px + env(safe-area-inset-bottom)) !important;
        gap: 7px !important;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transform: translate(-50%, 105%);
        transition: transform .2s ease, opacity .15s ease, visibility 0s linear .2s;
        background: var(--bg-secondary) !important;
        border: 1px solid var(--border);
        border-bottom: 0;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -18px 48px rgba(0, 0, 0, .48);
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header.actions-open .cam-actions {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transform: translate(-50%, 0);
        transition-delay: 0s;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-actions-head {
        position: sticky;
        z-index: 1;
        top: -8px;
        grid-column: 1 / -1;
        display: flex !important;
        min-height: 52px;
        margin: -8px -10px 1px;
        padding: 8px 10px;
        align-items: center;
        justify-content: space-between;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border);
    }
    html body:not(.tv-mode) .page-camera .camera-detail-actions-head button {
        display: inline-grid;
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 !important;
        place-items: center;
        color: var(--text-primary);
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 9px;
        font-size: 25px;
        line-height: 1;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions > .btn:not([hidden]) {
        display: inline-flex !important;
        width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 44px !important;
        padding: 9px 8px !important;
        align-items: center;
        justify-content: center;
        border-radius: 9px !important;
        font-size: 12px !important;
        line-height: 1.25 !important;
        white-space: normal;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions .btn .btn-text {
        display: inline !important;
    }

    html body:not(.tv-mode) .page-camera .camera-detail-main { gap: 10px !important; }
    html body:not(.tv-mode) .page-camera .embedded-stream {
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        padding-bottom: 0 !important;
        aspect-ratio: 16 / 9 !important;
        background: #000 !important;
        border-radius: 9px !important;
    }
    html body:not(.tv-mode) .page-camera .embedded-stream > :is(img, video) {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
        background: #000;
    }
    html body:not(.tv-mode) .page-camera .stream-controls {
        display: flex !important;
        width: 100%;
        min-width: 0;
        margin: 0 !important;
        padding: 6px !important;
        gap: 6px !important;
        flex-flow: row nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x proximity;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 9px;
    }
    html body:not(.tv-mode) .page-camera .stream-controls::-webkit-scrollbar { display: none; }
    html body:not(.tv-mode) .page-camera .stream-controls #cameraCapabilitySummary { display: none !important; }
    html body:not(.tv-mode) .page-camera .stream-controls > .sc-btn:not(#cameraCapabilitySummary) {
        flex: 0 0 auto !important;
        grid-column: auto !important;
        width: auto !important;
        min-width: 44px !important;
        max-width: min(78vw, 270px);
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 12px !important;
        justify-content: center;
        scroll-snap-align: start;
        font-size: 12px !important;
        line-height: 1.2 !important;
        white-space: nowrap;
    }
    html body:not(.tv-mode) .page-camera .stream-controls > :is(#scLensFoco, #scLight) {
        flex-basis: auto !important;
        width: auto !important;
        min-width: 170px !important;
    }
    html body:not(.tv-mode) .page-camera .stream-controls #scVolume {
        flex: 0 0 112px !important;
        width: 112px !important;
        min-width: 112px !important;
        height: 44px !important;
        min-height: 44px !important;
        margin: 0 4px;
    }

    html body:not(.tv-mode) .page-camera .detail-tab-bar {
        display: flex !important;
        width: 100%;
        min-width: 0;
        margin-bottom: 9px !important;
        padding: 3px !important;
        gap: 4px !important;
        flex-flow: row nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        background: var(--bg-card);
        border: 1px solid var(--border) !important;
        border-radius: 9px;
    }
    html body:not(.tv-mode) .page-camera .detail-tab-bar::-webkit-scrollbar { display: none; }
    html body:not(.tv-mode) .page-camera .detail-tab-btn {
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 8px 12px !important;
        white-space: nowrap !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions { transition: none !important; }
}

/* Menu dos cards fora da imagem: bandeja contextual acima da navegação. */
@media (max-width: 1024px) {
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu {
        position: fixed !important;
        z-index: 980 !important;
        top: auto !important;
        right: auto !important;
        bottom: calc(var(--mobile-nav-h) + 8px + env(safe-area-inset-bottom)) !important;
        left: 50% !important;
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        width: min(calc(100vw - 16px), 520px) !important;
        max-width: none !important;
        padding: 8px !important;
        gap: 6px !important;
        transform: translateX(-50%);
        background: color-mix(in srgb, var(--bg-secondary) 96%, #000) !important;
        border: 1px solid var(--border) !important;
        border-radius: 13px !important;
        box-shadow: 0 16px 44px rgba(0, 0, 0, .62) !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu .cam-action-btn:not([hidden]) {
        display: flex !important;
        width: 100% !important;
        min-width: 0 !important;
        height: 56px !important;
        min-height: 56px !important;
        padding: 6px 3px !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
        border-radius: 9px !important;
        background: var(--bg-card) !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu .cam-action-btn.danger {
        color: #fff;
        background: color-mix(in srgb, var(--danger) 72%, var(--bg-card)) !important;
        border-color: color-mix(in srgb, var(--danger) 68%, transparent);
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-label {
        display: block !important;
        max-width: 100%;
        overflow: hidden;
        font-size: 10px;
        line-height: 1;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Celular deitado: preserva o primeiro quadro útil sem sacrificar os controles. */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 1024px) {
    html body:not(.tv-mode) .page-dashboard .dash-top-bar { margin-bottom: 5px !important; }
    html body:not(.tv-mode) .page-dashboard .dash-mobile-summary { min-height: 44px !important; }
    html body:not(.tv-mode) .page-dashboard .widget-header.no-scrollbar { min-height: 44px !important; }
    html body:not(.tv-mode) .page-dashboard .camera-grid,
    html body:not(.tv-mode) .page-dashboard .camera-grid[class*="grid-"] {
        grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)) !important;
        gap: 5px !important;
        padding: 4px !important;
    }
    html body:not(.tv-mode) .page-dashboard .camera-tile .cam-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    html body:not(.tv-mode) .page-dashboard .camera-tile .cam-controls > :nth-child(n + 3) {
        display: none !important;
    }

    html body:not(.tv-mode) .page-cameras .camera-stats { display: none !important; }
    html body:not(.tv-mode) .page-cameras .camera-command-bar {
        margin-bottom: 6px !important;
        padding: 5px !important;
    }
    html body:not(.tv-mode) .page-cameras .camera-command-details:not(.is-open) { display: none !important; }
    html body:not(.tv-mode) .page-cameras .camera-grid,
    html body:not(.tv-mode) .page-cameras .camera-grid[class*="grid-"] {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) !important;
        gap: 6px !important;
    }

    html body:not(.tv-mode) .page-mosaic #mosaicGrid {
        height: 100% !important;
        overflow: hidden !important;
        align-content: stretch !important;
    }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="1"] {
        --mosaic-cols: 1 !important;
        grid-template-rows: minmax(0, 1fr) !important;
    }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="4"] {
        --mosaic-cols: 2 !important;
        grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
    }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="9"] {
        --mosaic-cols: 3 !important;
        grid-template-rows: repeat(3, minmax(0, 1fr)) !important;
    }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid[data-layout="16"] {
        --mosaic-cols: 4 !important;
        grid-template-rows: repeat(4, minmax(0, 1fr)) !important;
    }
    html body:not(.tv-mode) .page-mosaic #mosaicGrid .mosaic-cell {
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        aspect-ratio: auto !important;
    }
}

@media (max-width: 1024px) {
    html body:not(.tv-mode) #pageContent.page-camera .stream-controls .sc-btn .btn-text {
        display: inline !important;
    }
}

@media (max-width: 768px) {
    html body:not(.tv-mode) .page-content { padding-inline: 10px !important; }
    html body:not(.tv-mode) .page-content.page-mosaic { padding-inline: 0 !important; }
}

/* ===== Cards de câmera mobile-first: mídia limpa + menu em bottom sheet ===== */
@media (max-width: 1024px) {
    html body:not(.tv-mode) .camera-tile.cam-menu-open { overflow: visible !important; z-index: 60; }
    html body:not(.tv-mode) .camera-tile .cam-controls,
    html body:not(.tv-mode) .camera-tile .cam-iot-actions { display: none !important; }

    html body:not(.tv-mode) .camera-tile .cam-topbar {
        padding: 8px 58px 14px 9px !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-actions {
        position: absolute !important;
        top: 6px !important;
        right: 6px !important;
        display: block !important;
        width: 44px !important;
        max-width: 44px !important;
        opacity: 1 !important;
        z-index: 42 !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-action-more {
        display: grid !important;
        place-items: center !important;
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 !important;
        border: 1px solid rgba(255,255,255,.24) !important;
        border-radius: 10px !important;
        background: rgba(0,0,0,.68) !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-action-menu { display: none !important; }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu {
        position: fixed !important;
        z-index: 992 !important;
        top: auto !important;
        right: auto !important;
        bottom: calc(var(--mobile-nav-h) + 8px + env(safe-area-inset-bottom)) !important;
        left: 50% !important;
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        width: min(calc(100vw - 16px), 560px) !important;
        max-width: none !important;
        max-height: min(68dvh, 570px) !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        padding: 9px !important;
        gap: 7px !important;
        transform: translateX(-50%) !important;
        border: 1px solid var(--border) !important;
        border-radius: 15px !important;
        background: color-mix(in srgb, var(--bg-secondary) 97%, #000) !important;
        box-shadow: 0 18px 48px rgba(0,0,0,.7) !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu .cam-action-btn:not([hidden]) {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        min-width: 0 !important;
        height: 62px !important;
        min-height: 62px !important;
        padding: 7px 4px !important;
        gap: 6px !important;
        border: 1px solid color-mix(in srgb, var(--border) 82%, transparent) !important;
        border-radius: 10px !important;
        background: var(--bg-card) !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu .cam-action-label {
        display: block !important;
        max-width: 100% !important;
        overflow: hidden !important;
        font-size: 10px !important;
        line-height: 1.15 !important;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap !important;
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-danger-zone {
        grid-column: 1 / -1 !important;
        padding-top: 7px;
        border-top: 1px solid color-mix(in srgb, var(--danger) 48%, var(--border));
    }
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-danger-zone .danger {
        color: #fff !important;
        background: color-mix(in srgb, var(--danger) 72%, var(--bg-card)) !important;
        border-color: color-mix(in srgb, var(--danger) 68%, transparent) !important;
    }
    html body:not(.tv-mode) .camera-card-action-backdrop:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 990;
        display: block;
        width: 100%;
        height: 100%;
        min-height: 100%;
        padding: 0;
        border: 0;
        background: rgba(0,0,0,.48);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    html body:not(.tv-mode) .camera-tile .cam-recording-indicator {
        top: auto !important;
        bottom: 8px !important;
        left: 8px !important;
        max-width: calc(100% - 16px) !important;
        min-height: 26px;
        padding: 5px 8px !important;
        font-size: 10px !important;
    }

    /* A bandeja e portada para o body para que transforms do grid/card nao
       alterem o referencial de position:fixed. */
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled {
        position: fixed !important;
        z-index: 992 !important;
        inset: auto auto calc(var(--mobile-nav-h) + 8px + env(safe-area-inset-bottom)) 50% !important;
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        width: min(calc(100vw - 16px), 560px) !important;
        max-width: none !important;
        max-height: min(68dvh, 570px) !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        box-sizing: border-box;
        padding: 9px !important;
        gap: 7px !important;
        transform: translateX(-50%) !important;
        border: 1px solid var(--border) !important;
        border-radius: 15px !important;
        background: color-mix(in srgb, var(--bg-secondary) 97%, #000) !important;
        box-shadow: 0 18px 48px rgba(0,0,0,.7) !important;
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-menu-header {
        position: sticky;
        top: -9px;
        z-index: 2;
        grid-column: 1 / -1;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        min-height: 46px;
        padding: 5px 4px 8px;
        color: var(--text-primary);
        background: color-mix(in srgb, var(--bg-secondary) 97%, #000);
        border-bottom: 1px solid var(--border);
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-menu-header strong {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 13px;
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-menu-close {
        display: grid !important;
        place-items: center;
        flex: 0 0 42px;
        width: 42px;
        height: 42px;
        padding: 0;
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--text-primary);
        background: var(--bg-card);
        font-size: 24px;
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-btn:not([hidden]) {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        min-width: 0 !important;
        height: 62px !important;
        min-height: 62px !important;
        padding: 7px 4px !important;
        gap: 6px !important;
        border: 1px solid color-mix(in srgb, var(--border) 82%, transparent) !important;
        border-radius: 10px !important;
        background: var(--bg-card) !important;
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-label {
        display: block !important;
        max-width: 100% !important;
        overflow: hidden !important;
        font-size: 10px !important;
        line-height: 1.15 !important;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap !important;
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-danger-zone {
        grid-column: 1 / -1 !important;
        padding-top: 7px;
        border-top: 1px solid color-mix(in srgb, var(--danger) 48%, var(--border));
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled .cam-action-danger-zone .danger {
        color: #fff !important;
        background: color-mix(in srgb, var(--danger) 72%, var(--bg-card)) !important;
        border-color: color-mix(in srgb, var(--danger) 68%, transparent) !important;
    }
}

/* Telefone, inclusive deitado: um card por linha. 600dp já é perfil tablet. */
@media (max-width: 540px), (orientation: landscape) and (max-height: 540px) and (max-width: 1024px) {
    html body:not(.tv-mode) .page-cameras .camera-grid,
    html body:not(.tv-mode) .page-cameras .camera-grid[class*="grid-"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}
@media (min-width: 541px) and (max-width: 1024px) and (orientation: portrait) {
    html body:not(.tv-mode) .page-cameras .camera-grid,
    html body:not(.tv-mode) .page-cameras .camera-grid[class*="grid-"] {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}
@media (min-width: 541px) and (min-height: 541px) and (max-width: 1024px) and (orientation: landscape) {
    html body:not(.tv-mode) .page-cameras .camera-grid,
    html body:not(.tv-mode) .page-cameras .camera-grid[class*="grid-"] {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}
@media (max-width: 360px) {
    html body:not(.tv-mode) .camera-tile .cam-actions.is-open .cam-action-menu {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    html body:not(.tv-mode) > .cam-action-menu.cam-action-menu-portaled {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* ==========================================================================
   Smart Mobile APK Banner & Quick Actions Bottom-Sheet
   ========================================================================== */

.mobile-app-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1005;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 8px 12px;
    animation: slideDownBanner 0.3s ease-out;
    transition-property: none;
}
/* Preserve banner height while a navigation overlay owns focus. */
body.sidebar-open .mobile-app-banner,
body.quick-sheet-open .mobile-app-banner {
    visibility: hidden;
    pointer-events: none;
}
.m-banner-content {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) max-content var(--touch-target);
    align-items: center;
    gap: 6px 8px;
    max-width: 100%;
}
.m-banner-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
    object-fit: cover;
}
.m-banner-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.m-banner-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.25;
    white-space: normal;
    overflow-wrap: break-word;
    overflow-wrap: anywhere;
}
.m-banner-desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: break-word;
    overflow-wrap: anywhere;
}
.m-banner-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-target);
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--on-accent) !important;
    background: var(--accent) !important;
    border-radius: 8px;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}
.m-banner-close {
    width: var(--touch-target);
    height: var(--touch-target);
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* Baseline for WebViews without container queries: keep the full installation
   message and move its action to a second row on narrow windows. */
@media (max-width: 540px) {
    .m-banner-content {
        grid-template-columns: 32px minmax(0, 1fr) var(--touch-target);
    }
    .m-banner-icon { grid-column: 1; grid-row: 1; }
    .m-banner-info { grid-column: 2; grid-row: 1; }
    .m-banner-btn { grid-column: 1 / 3; grid-row: 2; justify-self: stretch; }
    .m-banner-close { grid-column: 3; grid-row: 1; align-self: start; }
}

/* Enhancement follows available space relative to text size. Keep all layout
   resets inside the queries so unsupported queries cannot erase the fallback. */
@supports (container-type: inline-size) {
    .mobile-app-banner {
        container-type: inline-size;
        container-name: mobile-app-banner;
    }
    @container mobile-app-banner (min-width: 20em) {
        .m-banner-content {
            grid-template-columns: 32px minmax(0, 1fr) max-content var(--touch-target);
        }
        .m-banner-icon,
        .m-banner-info,
        .m-banner-btn,
        .m-banner-close {
            grid-column: auto;
            grid-row: auto;
        }
        .m-banner-close { align-self: center; }
    }
    @container mobile-app-banner (max-width: 20em) {
        .m-banner-content {
            grid-template-columns: 32px minmax(0, 1fr) var(--touch-target);
        }
        .m-banner-icon { grid-column: 1; grid-row: 1; }
        .m-banner-info { grid-column: 2; grid-row: 1; }
        .m-banner-btn { grid-column: 1 / 3; grid-row: 2; justify-self: stretch; }
        .m-banner-close { grid-column: 3; grid-row: 1; align-self: start; }
    }
}

/* Mobile Quick Actions Bottom Sheet */
.mobile-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1003;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: surfaceFadeIn 0.2s ease-out;
}
.mobile-sheet-content {
    width: 100%;
    max-width: 540px;
    max-height: 85dvh;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
    animation: slideUpSheet 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.m-sheet-grabber {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 12px;
}
.m-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.m-sheet-user {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.m-sheet-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--ixi-brand-softest);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 1px solid var(--border);
}
.m-sheet-avatar > svg { width: 22px; height: 22px; flex-shrink: 0; }
.m-sheet-user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.m-sheet-user-meta strong {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.m-sheet-role-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.m-sheet-close {
    width: var(--touch-target);
    height: var(--touch-target);
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.m-sheet-section {
    margin-bottom: 14px;
}
.m-sheet-section-title {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}
.m-theme-segment {
    display: flex;
    gap: 8px;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
}
.m-theme-btn {
    flex: 1;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.m-theme-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.m-sheet-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.m-sheet-item {
    display: flex;
    min-height: var(--touch-target);
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-primary) !important;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 550;
    transition: all 0.15s ease;
    cursor: pointer;
}
.m-sheet-item svg {
    color: var(--text-secondary);
    flex-shrink: 0;
}
.m-sheet-item:hover,
.m-sheet-item:active {
    background: var(--bg-hover);
    border-color: var(--border);
}
.m-sheet-item.m-sheet-apk {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.25);
    color: var(--accent) !important;
}
.m-sheet-item.m-sheet-apk svg {
    color: var(--accent);
}
.m-sheet-item.m-sheet-logout {
    margin-top: 6px;
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger) !important;
    border-color: rgba(239, 68, 68, 0.2);
}
.m-sheet-item.m-sheet-logout svg {
    color: var(--danger);
}

/* O banner de instalação é fixo: reserve sua altura no shell para ele não
   cobrir o cabeçalho móvel nem o topo da página da câmera. */
@media (max-width: 1024px) {
    html:has(body:not(.tv-mode).mobile-app-banner-visible) {
        scroll-padding-top: calc(
            var(--mobile-app-banner-height, 64px) + var(--mobile-header-h) +
            12px + env(safe-area-inset-top)
        );
    }
    html body:not(.tv-mode).mobile-app-banner-visible .mobile-header {
        top: var(--mobile-app-banner-height, 64px) !important;
    }
    html body:not(.tv-mode).mobile-app-banner-visible .main-content {
        padding-top: calc(
            var(--mobile-header-h) + env(safe-area-inset-top) +
            var(--mobile-app-banner-height, 64px)
        ) !important;
    }

    /* A engrenagem abre um painel abaixo do cabeçalho. O antigo bottom-sheet
       era ancorado no rodapé e por isso parecia crescer para cima, encobrindo
       nome, banner e vídeo. */
    html body:not(.tv-mode) .page-camera .camera-detail-header.actions-open {
        z-index: 1902;
        overflow: visible !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header .cam-actions {
        position: absolute !important;
        top: calc(100% + 6px) !important;
        right: 0 !important;
        bottom: auto !important;
        left: auto !important;
        width: min(calc(100vw - 24px), 420px) !important;
        max-height: min(70dvh, 590px) !important;
        border: 1px solid var(--border) !important;
        border-radius: 12px !important;
        box-shadow: 0 18px 48px rgba(0, 0, 0, .48) !important;
        transform: translateY(-8px) scale(.98) !important;
        transform-origin: top right;
    }
    html body:not(.tv-mode) .page-camera .camera-detail-header.actions-open .cam-actions {
        transform: translateY(0) scale(1) !important;
    }
}
