﻿/* ============================
   Mapa SIG â€” estilos para o mapa
   dentro do layout admin padrÃ£o
   ============================ */

/* Container que nega o padding do admin (article.content.px-4) */
.mapasig-content {
    margin: -1.1rem -1.5rem 0 -1.5rem; /* nega padding-top e px-4 */
    height: calc(100vh - 3.5rem);       /* viewport menos topbar */
    overflow: hidden;
    position: relative;
}

@media (min-width: 641px) {
    .mapasig-content {
        margin: -1.1rem -1.5rem 0 -2rem; /* desktop: px-left=2rem, px-right=1.5rem */
    }
}

#map, #map-v2 {
    height: 100%;
    width: 100%;
    position: relative;
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    font-weight: 500;
    color: #2c3e50;
}

    .loading.hidden {
        display: none;
    }

/* Spinner grande (overlay do mapa) */
.seg-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto;
    border: 4px solid #e0e0e0;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: seg-spin 0.8s linear infinite;
}

/* Spinner pequeno (painel lateral) */
.seg-spinner-sm {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2.5px solid #e0e0e0;
    border-top: 2.5px solid #3498db;
    border-radius: 50%;
    animation: seg-spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes seg-spin {
    to { transform: rotate(360deg); }
}

.controls-panel {
    position: fixed;
    top: 70px;
    right: 0;
    transform: none;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    border-radius: 15px 0 0 15px;
    box-shadow: -5px 0 25px rgba(0,0,0,0.15);
    z-index: 1000;
    width: 350px;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid rgba(0,0,0,0.1);
    transition: max-height 0.3s ease;
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #fff;
    border-radius: 15px 0 0 0;
}

    .controls-header h3 {
        margin: 0;
        font-size: 1.1rem;
    }

.controls-panel.collapsed {
    max-height: 50px;
    overflow-y: hidden;
}

    .controls-panel.collapsed .controls-content {
        display: none;
    }

.toggle-btn {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}


.controls-panel.collapsed .toggle-btn {
    transform: rotate(180deg);
}

.toggle-btn:hover {
    background: linear-gradient(135deg, #2980b9, #1f5f99);
    transform: scale(1.05);
}

.controls-content {
    padding: 15px;
    width: 100%;
}

    .controls-content h3 {
        margin: 0 0 15px 0;
        color: #2c3e50;
        font-size: 1.1rem;
        font-weight: 600;
        border-bottom: 2px solid #ecf0f1;
        padding-bottom: 8px;
    }

.checkbox-group {
    margin-bottom: 25px;
}

    .checkbox-group label {
        display: flex;
        align-items: center;
        margin-bottom: 12px;
        padding: 8px 12px;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
        background: rgba(255, 255, 255, 0.7);
        border: 1px solid rgba(0,0,0,0.05);
    }

        .checkbox-group label:hover {
            background: rgba(52, 152, 219, 0.1);
            transform: translateX(2px);
        }

    .checkbox-group input[type="checkbox"] {
        margin-right: 10px;
        width: 18px;
        height: 18px;
        accent-color: #3498db;
        cursor: pointer;
    }

.checkbox-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    border-radius: 4px;
    object-fit: cover;
}

.remove-layer-btn {
    margin-left: auto;
    background: transparent;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
}

    .remove-layer-btn:hover {
        color: #c0392b;
    }

.measure-btn {
    margin-top: 10px;
    width: 100%;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px;
    cursor: pointer;
}

.measure-btn-active {
    background: #dc3545;
}

.measure-btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

/* Custom Info Window Styles */
.custom-info-window {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    width: 480px;
    padding: 0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.info-header {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    padding: 15px 20px;
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

    .info-close:hover {
        color: #ffb3b3;
    }

.info-content {
    padding: 20px;
    background: white;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #ecf0f1;
}

    .info-item:last-child {
        border-bottom: none;
    }

.info-label {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9rem;
}

.info-value {
    color: #34495e;
    font-size: 0.9rem;
    text-align: right;
    max-width: 60%;
}

.photo-gallery {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid #ecf0f1;
}

    .photo-gallery h5 {
        margin: 0 0 10px 0;
        color: #2c3e50;
        font-size: 0.95rem;
        font-weight: 600;
    }

.photo-thumbnails {
    display: flex;
    gap: 10px;
}

.photo-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid #ecf0f1;
    transition: all 0.3s ease;
}

    .photo-thumb:hover {
        border-color: #3498db;
        transform: scale(1.05);
        box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    }

/* Modal Styles */
.photo-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
}

.photo-modal .photo-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90%;
    max-height: 90%;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-image {
    width: 100%;
    height: auto;
    display: block;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

    .modal-close:hover {
        background: rgba(255, 0, 0, 0.7);
        transform: scale(1.1);
    }

/* SegmentaÃ§Ã£o - BotÃ£o de ajuda */
.seg-help-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px solid #3498db;
    background: transparent;
    color: #3498db;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

    .seg-help-btn:hover {
        background: #3498db;
        color: white;
    }

/* SegmentaÃ§Ã£o - Modal de metodologia */
.seg-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seg-modal {
    background: white;
    border-radius: 12px;
    width: 560px;
    max-width: 92vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: seg-modal-in 0.2s ease-out;
}

@keyframes seg-modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.seg-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    font-size: 1.05em;
    font-weight: 600;
    color: #2c3e50;
}

.seg-modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

    .seg-modal-close:hover {
        background: #f0f0f0;
        color: #333;
    }

.seg-modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 0.9em;
    line-height: 1.6;
    color: #444;
}

    .seg-modal-body h4 {
        margin: 14px 0 6px;
        color: #2c3e50;
        font-size: 0.95em;
    }

    .seg-modal-body h4:first-child {
        margin-top: 0;
    }

    .seg-modal-body p {
        margin: 4px 0 8px;
    }

    .seg-modal-body ul {
        margin: 4px 0 8px;
        padding-left: 20px;
    }

    .seg-modal-body li {
        margin: 2px 0;
    }

.seg-modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
    margin: 6px 0 10px;
}

    .seg-modal-table th,
    .seg-modal-table td {
        padding: 6px 10px;
        border: 1px solid #e0e0e0;
        text-align: left;
    }

    .seg-modal-table th {
        background: #f5f7fa;
        font-weight: 600;
        color: #2c3e50;
    }

    .seg-modal-table td:last-child {
        text-align: center;
        font-weight: 600;
        white-space: nowrap;
    }

/* Responsive Design */
@media (max-width: 768px) {
    .controls-panel {
        position: fixed;
        top: 60px;
        right: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        max-height: none;
        height: auto;
        transition: transform 0.3s ease;
    }

        .controls-panel.collapsed {
            max-height: 50px;
        }

    .toggle-btn {
        position: fixed;
        top: 65px;
        right: 15px;
        left: auto;
        border-radius: 50%;
        z-index: 1001;
    }

    .controls-content {
        min-width: auto;
        max-width: none;
        padding: 15px 20px;
    }

    #map, #map-v2 {
        height: 100%;
    }
}

@media (max-width: 480px) {
    .controls-content {
        padding: 15px;
    }

    .checkbox-group label {
        padding: 6px 10px;
        font-size: 0.9rem;
    }

    .custom-info-window {
        max-width: 280px;
    }

    .info-content {
        padding: 15px;
    }
}


/* Modal Animation */
.photo-modal {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-content {
    animation: modalZoom 0.3s ease;
}

@keyframes modalZoom {
    from {
        transform: translate(-50%, -50%) scale(0.7);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.mapasig-content button,
.mapasig-content input[type="checkbox"],
.mapasig-content .photo-thumb,
.mapasig-content .toggle-btn {
    transition: all 0.3s ease;
}

/* Hide default Google Maps close button */
.gm-style-iw > button.gm-ui-hover-effect {
    display: none !important;
}

/* Distance measurement modal */
.distance-modal {
    display: none;
    position: fixed;
    z-index: 11000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.distance-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    text-align: center;
}

.distance-confirm-btn {
    margin-top: 10px;
    background: #28a745;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
}

.distance-cancel-btn {
    margin-top: 10px;
    margin-left: 10px;
    background: #dc3545;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
}

/* ===== InfoWindow de Detalhes =====  */
.gm-style-iw-d {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 0.92rem;
}

.iw-row {
    display: flex;
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
}

.iw-row:last-child {
    border-bottom: none;
}

.iw-label {
    font-weight: 600;
    color: #555;
    margin-right: 8px;
    min-width: 130px;
}

.iw-value {
    color: #333;
    flex: 1;
}

/* BotÃ£o de fechar padrÃ£o do InfoWindow */
.gm-style-iw button.gm-ui-hover-effect {
    top: 2px !important;
    right: 2px !important;
}


/* ===== Galeria de Fotos (InfoWindow) ===== */
.iw-photo-gallery {
    margin-top: 10px;
    padding-top: 8px;
}

.iw-photo-gallery h6 {
    margin-bottom: 10px;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.95rem;
}

.iw-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.iw-photo-thumb {
    cursor: pointer;
    overflow: hidden;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    transition: all 0.2s ease;
    aspect-ratio: 4/3;
    background: #f8f9fa;
    position: relative;
}

.iw-photo-thumb:hover {
    border-color: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.iw-photo-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    padding: 2px 4px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.iw-photo-thumb.no-photo {
    cursor: default;
    opacity: 0.5;
}

.iw-photo-thumb.no-photo:hover {
    border-color: #e0e0e0;
    transform: none;
    box-shadow: none;
}

/* Spinner de loading enquanto a foto carrega via fetch autenticado */
.iw-photo-thumb .iw-photo-loading {
    opacity: 0;
}

.iw-photo-thumb[data-photo-api]:not([data-photo-loaded]) {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.iw-photo-thumb[data-photo-api]:not([data-photo-loaded])::after {
    content: '';
    position: absolute;
    width: 28px;
    height: 28px;
    border: 3px solid #e0e0e0;
    border-top-color: #3498db;
    border-radius: 50%;
    animation: iw-photo-spin 0.8s linear infinite;
}

@keyframes iw-photo-spin {
    to { transform: rotate(360deg); }
}

.iw-photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ===== Overlay de foto ampliada ===== */
.photo-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 20000;
}

.photo-overlay-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
}

.photo-overlay-content {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    max-height: 90vh;
}

.photo-overlay-image {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    display: block;
    border-radius: 4px;
}

.photo-overlay-close {
    position: absolute;
    top: -40px; right: 0;
    background: transparent;
    border: none;
    color: white;
    font-size: 2.5rem;
    cursor: pointer;
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.photo-overlay-close:hover {
    color: #ff4444;
    transform: rotate(90deg);
}

@media (max-width: 768px) {
    .iw-photo-grid.count-1 { max-width: 150px; }
    .iw-photo-grid.count-3plus { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
    .photo-overlay-close {
        top: 10px; right: 10px;
        font-size: 2rem;
        background: rgba(0,0,0,0.7);
        border-radius: 50%;
    }
}
