/**
 * WebGIS Aero — estilos mobile / PWA
 * Carregado automaticamente em todas as páginas HTML.
 */

:root {
    --mobile-nav-height: 56px;
    --mobile-touch-min: 44px;
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-safe-top: env(safe-area-inset-top, 0px);
}

/* Viewport estável no iOS (100vh bug) */
html.is-mobile {
    height: -webkit-fill-available;
}

html.is-mobile body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* Área de toque mínima (WCAG / Apple HIG) */
@media (max-width: 768px) {
    .btn,
    .nav-link,
    .dropdown-item,
    .form-control,
    .form-select,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: var(--mobile-touch-min);
    }

    .btn-sm {
        min-height: 38px;
        padding: 0.4rem 0.75rem;
    }

    /* Navbar colapsável */
    .navbar-app .navbar-collapse {
        max-height: 70vh;
        overflow-y: auto;
        margin-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .navbar-app .navbar-toggler {
        min-width: var(--mobile-touch-min);
        min-height: var(--mobile-touch-min);
    }

    /* Tabelas: scroll horizontal */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* Cards e containers */
    .container,
    .container-fluid {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    /* Modais quase tela cheia */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-fullscreen-sm-down {
        width: 100vw;
        max-width: none;
        height: 100%;
        margin: 0;
    }

    /* Portal */
    .portal-header {
        padding: 1.5rem 0 0.5rem !important;
    }

    .portal-header h1 {
        font-size: 1.5rem;
    }

    .project-card {
        padding: 1.25rem;
    }

    .project-card:active {
        transform: scale(0.98);
    }

    /* Login */
    .login-container {
        padding: max(16px, var(--mobile-safe-top)) 16px
            calc(16px + var(--mobile-nav-height)) !important;
    }

    /* Upload / admin: navbar fixa no topo */
    body.has-mobile-nav {
        padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));
    }

    /* GeoServer / forms */
    .card-body .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .card-body .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .card-body .btn-group .btn {
        border-radius: var(--radius-sm, 6px) !important;
        margin-left: 0 !important;
    }
}

    /* Navbar compacta no mobile (nav inferior substitui menus) */
    body.has-mobile-nav .navbar-app .container-fluid > .d-flex {
        display: none !important;
    }

    body.has-mobile-nav .navbar-app .navbar-brand {
        font-size: 1rem;
    }

    /* Barra de navegação inferior (app-like) */
.webgis-mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10050;
    height: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));
    padding-bottom: var(--mobile-safe-bottom);
    background: rgba(11, 18, 32, 0.96);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}

html.is-mobile .webgis-mobile-nav {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
}

.webgis-mobile-nav a,
.webgis-mobile-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 500;
    border: none;
    background: transparent;
    min-height: var(--mobile-nav-height);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.webgis-mobile-nav a i,
.webgis-mobile-nav button i {
    font-size: 1.35rem;
}

.webgis-mobile-nav a.active,
.webgis-mobile-nav button.active {
    color: #00b2d8;
}

.webgis-mobile-nav a:active,
.webgis-mobile-nav button:active {
    background: rgba(255, 255, 255, 0.06);
}

/* Menu "Mais" overlay */
.webgis-mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10060;
    background: rgba(0, 0, 0, 0.5);
}

.webgis-mobile-menu-overlay.open {
    display: block;
}

.webgis-mobile-menu-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    overflow-y: auto;
    background: #0f172a;
    border-radius: 16px 16px 0 0;
    padding: 1rem 1rem calc(1rem + var(--mobile-safe-bottom));
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

.webgis-mobile-menu-overlay.open .webgis-mobile-menu-sheet {
    transform: translateY(0);
}

.webgis-mobile-menu-sheet h6 {
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1rem 0 0.5rem;
}

.webgis-mobile-menu-sheet a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 12px;
    color: #e2e8f0;
    text-decoration: none;
    border-radius: 10px;
    min-height: var(--mobile-touch-min);
}

.webgis-mobile-menu-sheet button {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 12px;
    color: #e2e8f0;
    text-decoration: none;
    border-radius: 10px;
    min-height: var(--mobile-touch-min);
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 1rem;
}

.webgis-mobile-menu-sheet a:active,
.webgis-mobile-menu-sheet button:active {
    background: rgba(255, 255, 255, 0.08);
}

.webgis-mobile-menu-sheet a i,
.webgis-mobile-menu-sheet button i {
    font-size: 1.2rem;
    color: #00b2d8;
    width: 24px;
    text-align: center;
}

/* Mapas — FAB e painel lateral */
.mobile-map-fab {
    display: none;
    position: fixed;
    z-index: 10040;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #0087A8, #006d8a);
    color: #fff;
    font-size: 1.4rem;
    box-shadow: 0 4px 16px rgba(0, 135, 168, 0.45);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    bottom: calc(16px + var(--mobile-safe-bottom));
    left: 16px;
}

html.is-mobile-on-map .mobile-map-fab {
    display: flex;
    align-items: center;
    justify-content: center;
}

html.is-mobile-on-map body.has-mobile-nav {
    padding-bottom: 0;
}

html.is-mobile-on-map .webgis-mobile-nav {
    display: none !important;
}

@media (max-width: 768px) {
    /* Painel lateral do mapa principal */
    #side-panel {
        transition: transform 0.25s ease, opacity 0.25s ease;
    }

    html.is-mobile-on-map #side-panel:not(.mobile-drawer-open) {
        transform: translateX(calc(-100% - 20px));
        opacity: 0;
        pointer-events: none;
    }

    html.is-mobile-on-map #side-panel.mobile-drawer-open {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
        width: min(92vw, 320px) !important;
        max-width: 92vw !important;
    }

    /* Sidebars de outras páginas de mapa */
    .sidebar,
    .app-sidebar,
    #sidebar {
        transition: transform 0.25s ease;
    }

    html.is-mobile-on-map .sidebar:not(.mobile-drawer-open),
    html.is-mobile-on-map .app-sidebar:not(.mobile-drawer-open),
    html.is-mobile-on-map #sidebar:not(.mobile-drawer-open) {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 10030;
        transform: translateX(-100%);
        max-width: 88vw;
    }

    html.is-mobile-on-map .sidebar.mobile-drawer-open,
    html.is-mobile-on-map .app-sidebar.mobile-drawer-open,
    html.is-mobile-on-map #sidebar.mobile-drawer-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }

    .mobile-drawer-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 10025;
        background: rgba(0, 0, 0, 0.45);
    }

    .mobile-drawer-backdrop.visible {
        display: block;
    }

    /* Leaflet controls maiores no mobile */
    .leaflet-control-zoom a,
    .leaflet-bar a {
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
        font-size: 20px !important;
    }

    .leaflet-control {
        margin-top: max(10px, var(--mobile-safe-top)) !important;
    }

    /* Mapa ocupa tela inteira */
    #map,
    .leaflet-container,
    .map-container {
        height: 100vh !important;
        height: -webkit-fill-available !important;
    }
}

/* Banner instalar PWA */
.webgis-install-banner {
    display: none;
    position: fixed;
    bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 8px);
    left: 12px;
    right: 12px;
    z-index: 10045;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    align-items: center;
    gap: 12px;
}

.webgis-install-banner.visible {
    display: flex;
}

.webgis-install-banner p {
    flex: 1;
    margin: 0;
    font-size: 0.85rem;
    color: #e2e8f0;
}

.webgis-install-banner button {
    flex-shrink: 0;
    min-height: 36px;
}

/* Botão flutuante — APK / PWA em todas as páginas mobile */
.webgis-mobile-apps-fab {
    display: none;
    position: fixed;
    right: 14px;
    z-index: 10048;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 52px;
    min-height: 52px;
    padding: 6px 10px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #0087A8, #006d8a);
    color: #fff;
    box-shadow: 0 4px 18px rgba(0, 135, 168, 0.45);
    font-size: 0.62rem;
    font-weight: 600;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    bottom: calc(16px + var(--mobile-safe-bottom));
}

html.is-mobile .webgis-mobile-apps-fab {
    display: flex;
}

body.has-mobile-nav .webgis-mobile-apps-fab {
    bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 10px);
}

html.is-mobile-on-map .webgis-mobile-apps-fab {
    bottom: calc(16px + var(--mobile-safe-bottom));
}

.webgis-mobile-apps-fab i {
    font-size: 1.25rem;
}

.webgis-mobile-apps-fab:active {
    transform: scale(0.96);
}

/* Painel APK / PWA */
.webgis-mobile-apps-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10065;
    background: rgba(0, 0, 0, 0.55);
}

.webgis-mobile-apps-overlay.open {
    display: block;
}

.webgis-mobile-apps-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    overflow-y: auto;
    background: #0b1220;
    border-radius: 16px 16px 0 0;
    padding: 1rem 1rem calc(1rem + var(--mobile-safe-bottom));
    transform: translateY(100%);
    transition: transform 0.25s ease;
    border-top: 1px solid #334155;
}

.webgis-mobile-apps-overlay.open .webgis-mobile-apps-sheet {
    transform: translateY(0);
}

.webgis-apps-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    color: #e2e8f0;
}

.webgis-apps-sheet-desc {
    color: #64748b;
    font-size: 0.85rem;
    margin: 0 0 0.5rem;
}

.webgis-apps-section-label {
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0.75rem 0 0.4rem;
}

.webgis-apps-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.webgis-apps-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    touch-action: manipulation;
}

.webgis-apps-btn i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
}

.webgis-apps-android {
    background: linear-gradient(135deg, #3ddc84, #2eb872);
    color: #0b1220;
}

.webgis-apps-pwa {
    background: #1e293b;
    color: #e2e8f0;
    border: 1px solid #334155;
}

.webgis-apps-ios {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
}

.webgis-apps-expo {
    background: #1a1523;
    color: #e2e8f0;
    border: 1px solid #4630eb;
}

.webgis-apps-hint {
    margin-top: 0.75rem;
    padding: 0.75rem 0.9rem;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 10px;
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.45;
}

.webgis-apps-hint strong {
    color: #e2e8f0;
}

.webgis-apps-installed {
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.35);
    background: rgba(34, 197, 94, 0.1);
}

@media (max-width: 480px) {
    .navbar-portal .navbar-brand {
        font-size: 1rem;
    }

    h1, .h1 { font-size: 1.4rem; }
    h2, .h2 { font-size: 1.2rem; }
}
