:root { --sidebar-width: 380px; --primary: #008037; --primary-rgb: 0, 128, 55; }
body { font-family: 'Inter', sans-serif; background: #f8fafc; color: #1e293b; overflow: hidden; height: 100vh; margin: 0; }

/* Global Navigation Sidebar */
.nav-sidebar { 
    position: fixed; top: 0; left: 0; bottom: 0; width: 45px; 
    background: var(--primary); display: flex; flex-direction: column; 
    align-items: center; padding-top: 15px; z-index: 2000; 
    box-shadow: 2px 0 10px rgba(0,0,0,0.1); 
}
.nav-item { 
    color: rgba(255,255,255,0.6); font-size: 1.1rem; margin-bottom: 12px; 
    transition: all 0.2s; cursor: pointer; text-decoration: none; 
    width: 32px; height: 32px; display: flex; align-items: center; 
    justify-content: center; border-radius: 8px; 
}
.nav-item:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-item.active { background: rgba(255,255,255,0.2); color: white; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.3); }

/* Layout Containers */
.app-container { display: flex; height: 100vh; margin-left: 45px; width: calc(100% - 45px); }
.sidebar { width: var(--sidebar-width); background: white; border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; z-index: 1000; box-sizing: border-box; }
.map-view { flex: 1; position: relative; }

/* Sidebar Elements */
.brand { display: flex; align-items: center; gap: 12px; padding: 16px 24px; background: var(--primary); color: white; width: 380px; box-sizing: border-box; border-right: 1px solid var(--primary); }
.brand h1 { font-size: 1.1rem; font-weight: 700; margin: 0; color: white; letter-spacing: -0.02em; }
.sidebar-header { padding: 20px; border-bottom: 1px solid #f1f5f9; }
.sidebar-header strong { color: var(--primary); }
.street-list { flex: 1; overflow-y: auto; padding: 10px 0; }
.street-item { height: 42px; padding: 0 24px; cursor: pointer; display: flex; align-items: center; gap: 12px; border-left: 4px solid transparent; text-decoration: none; color: inherit; font-size: 0.8rem; box-sizing: border-box; }
.street-item.active { background: #eff6ff; border-left-color: var(--primary); }
.street-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; width: 58px; justify-content: flex-end; flex-shrink: 0; }
.focus-icon { color: var(--primary); background: #f1f5f9; width: 26px; height: 26px; display: grid; place-items: center; visibility: hidden; border-radius: 50%; font-size: 0.95rem; transition: all 0.2s; cursor: pointer; }
.street-item.active .focus-icon { visibility: visible; }
.focus-icon:hover { background: var(--primary); color: white; opacity: 1 !important; }
.point-count-badge { background: var(--primary); color: white; font-size: 0.75rem; font-weight: 700; width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 50%; flex-shrink: 0; display: block; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

body.rotating-map, body.rotating-map #map canvas { cursor: grabbing !important; }

#map { height: 100%; width: 100%; background: #f1f5f9; }

/* Map Options - Content Driven Width & Fixed Height Header */
.map-controls { position: absolute; top: 10px; right: 50px; z-index: 1200; display: flex; flex-direction: column; align-items: flex-end; }
.map-options-wrapper {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: all 0.3s ease;
    width: max-content;
    min-width: 120px;
    max-height: 32px; /* CLOSED STATE */
    pointer-events: auto;
}
.map-options-wrapper.active { 
    max-height: 600px; /* Effectively AUTO height */
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); 
}
.map-options-header {
    height: 30px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    color: #475569;
    user-select: none;
    gap: 15px;
}
.map-options-header:hover { color: var(--primary); }
.map-options-header span { font-size: 0.65rem; font-weight: 800; text-transform: uppercase; white-space: nowrap; }
.map-options-header i { font-size: 0.85rem; }
.map-options-header .arrow-icon { transition: transform 0.3s ease; font-size: 0.6rem; }
.map-options-content { padding: 8px 12px 15px 12px; border-top: 1px solid rgba(0,0,0,0.05); opacity: 0; visibility: hidden; transition: opacity 0.2s; }
.map-options-wrapper.active .map-options-content { opacity: 1; visibility: visible; }
.map-options-wrapper.active .arrow-icon { transform: rotate(180deg); }
.map-options-wrapper.active .map-options-header { color: var(--primary); }

.image-upload-wrapper { position: relative; width: 100%; border-radius: 8px; overflow: hidden; margin-bottom: 15px; border: 1px solid #e2e8f0; }
.image-upload-wrapper img { width: 100%; height: auto; display: block; cursor: pointer; transition: transform 0.2s; }
.image-upload-wrapper img:hover { transform: scale(1.02); }
.remove-img-btn { position: absolute; top: 8px; right: 8px; background: rgba(239, 68, 68, 0.9); color: white; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: all 0.2s; }
.remove-img-btn:hover:not(.disabled) { background: #ef4444; transform: scale(1.1); }
.remove-img-btn.disabled { background: #94a3b8 !important; opacity: 0.5; cursor: not-allowed !important; transform: none !important; }

/* Overlay UI */
.overlay-stack { 
    position: absolute; 
    top: 0; 
    left: 0; 
    padding: 20px 30px 60px 20px;
    z-index: 1100; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    pointer-events: none; 
    max-height: 100vh;
    width: 350px; /* Suficiente para o cartão + sombras */
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.overlay-stack::-webkit-scrollbar {
    display: none;
}
.eval-card, .point-card { position: relative; background: white; padding: 20px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.12); width: 275px; border: 1px solid rgba(0,0,0,0.05); display: none; pointer-events: auto; }

/* Uniform Close Button */
.btn-close-custom {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1rem;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 50%;
    line-height: 1;
}
.btn-close-custom:hover {
    color: #ef4444;
    background: #fef2f2;
}
.btn-close-custom i {
    font-size: 1rem;
}

.meta-grid { 
 display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 15px; padding-top: 15px; border-top: 1px dashed #e2e8f0; }
.meta-item { font-size: 0.75rem; color: #64748b; }
.meta-label { font-weight: 700; color: var(--primary); display: block; margin-bottom: 2px; text-transform: uppercase; font-size: 0.65rem; }

/* Selection & Activation */
.selection-overlay { 
    position: fixed; 
    top: 0; 
    left: 45px; 
    width: calc(100% - 45px); 
    height: 100%; 
    background: white; 
    z-index: 3000; 
    display: flex; 
    flex-direction: column; 
    overflow-y: auto;
}
.selection-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    width: 100%;
}
.selection-spacer {
    flex: 1;
    min-height: 40px;
}
.selection-main {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 0 40px;
}
.selection-footer {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 40px;
    min-height: 150px;
}
.selection-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); 
    gap: 20px; 
    width: 100%; 
    max-width: 1200px; 
    margin-top: 40px; 
}
.subarea-card { background: #f8fafc; border: 2px solid #e2e8f0; border-radius: 16px; padding: 20px; text-align: center; cursor: pointer; transition: all 0.2s ease; }
.subarea-card:hover { border-color: var(--primary); background: rgba(var(--primary-rgb), 0.05); }
.subarea-card.selected { border-color: var(--primary); background: rgba(var(--primary-rgb), 0.1); box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.1); }

.activate-btn-inline { 
    position: fixed;
    bottom: 40px;
    left: calc(45px + (100% - 45px) / 2); /* Centrado na área útil do PC */
    transform: translateX(-50%);
    padding: 15px 40px; 
    border-radius: 50px; 
    box-shadow: 0 10px 30px rgba(var(--primary-rgb), 0.3); 
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0;
    pointer-events: none;
    z-index: 6000;
}
.activate-btn-inline.visible {
    opacity: 1;
    pointer-events: auto;
}
.activate-btn-inline:hover {
    transform: translateX(-50%) translateY(-2px);
}
.btn-primary { background-color: var(--primary) !important; border-color: var(--primary) !important; color: white !important; }
.btn-primary:hover { filter: brightness(0.9) !important; }

/* Street View Tabs */
.gsv-tab { background: #e2e8f0; color: #64748b; border: none; font-weight: 700; transition: all 0.2s; }
.gsv-tab.active { background: var(--primary); color: white; }
.gsv-tab:hover:not(.active) { background: #cbd5e1; }

.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

/* Enforce Valongo-Green on all Progress Bars */
.progress-bar { background-color: var(--primary) !important; }

.progress-bar-striped-static {
    background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
    background-size: 1rem 1rem;
}

/* Enforce Valongo-Green on all Buttons */
.btn-primary { background-color: var(--primary) !important; border-color: var(--primary) !important; color: white !important; }
.btn-primary:hover { filter: brightness(0.9) !important; }
.btn-outline-primary { color: var(--primary) !important; border-color: var(--primary) !important; }
.btn-outline-primary:hover { background-color: var(--primary) !important; color: white !important; }

/* Global Color Overrides */
.text-primary { color: var(--primary) !important; }

.silhouette-container { height: 150px; display: flex; align-items: center; justify-content: center; margin-bottom: 15px; }
.silhouette-container svg { max-height: 100%; max-width: 100%; fill: var(--primary); fill-opacity: 0.15; transition: fill 0.2s; }

/* Search & Filters Section */
.search-section { padding: 10px 20px; border-bottom: 1px solid #f1f5f9; background: #fff; }

.search-wrapper { position: relative; display: flex; align-items: center; height: 36px; }
.search-icon { position: absolute; left: 14px; color: #94a3b8; font-size: 0.8rem; pointer-events: none; }
.search-input {
    width: 100%;
    height: 36px;
    padding: 0 15px 0 38px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s ease;
    outline: none;
}
.search-input:focus {
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.08);
}

.filter-group { margin-top: 10px; }
.filter-label { font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: #94a3b8; }
.filter-clear { font-size: 0.6rem; font-weight: 700; color: var(--primary); cursor: pointer; transition: opacity 0.2s; }
.filter-clear:hover { opacity: 0.7; }

/* Filter Bar - Minimalist */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    background: #f8fafc;
    padding: 3px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-sizing: border-box;
}

.filter-btn {
    flex: 1;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    color: #94a3b8;
    font-size: 0.75rem;
    position: relative;
}
.filter-btn:hover { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.filter-btn.active { background: white; color: var(--primary); box-shadow: 0 2px 5px rgba(0,0,0,0.08); }

.filter-btn .status-dot { width: 10px; height: 10px; border: 2px solid transparent; }
.filter-btn.active .status-dot { transform: scale(1.2); border-color: rgba(0,0,0,0.1); }

/* Separator */
.filter-sep { width: 1px; height: 14px; background: #e2e8f0; margin: 0 2px; }

/* Eval Card Segmented Bar Redesign */
.state-segmented-bar {
    display: flex;
    width: 100%;
    background: #f8fafc;
    padding: 3px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    gap: 3px;
    box-sizing: border-box;
}
.state-segment {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.5;
    border: 1px solid transparent; /* Adicionado para evitar tremura */
}
.state-segment:hover { opacity: 1; background: rgba(255,255,255,0.6); }
.state-segment.active {
    opacity: 1;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    border-color: #e2e8f0; /* Apenas muda a cor, o tamanho mantém-se */
}
.state-segment .status-dot { width: 10px; height: 10px; border-radius: 50%; }
.state-segment.active .status-dot { transform: scale(1.1); }

/* Demo Mode Styles */
.demo-locked .state-segment {
    cursor: not-allowed !important;
    opacity: 0.3;
}
.state-segment-wrapper {
    cursor: pointer;
}
.demo-locked .state-segment-wrapper {
    cursor: not-allowed !important;
}
.demo-locked .state-segment:hover {
    background: transparent !important;
    opacity: 0.3 !important;
}
.demo-locked .state-segment.active {
    opacity: 1 !important;
    background: white !important;
    border-color: #e2e8f0 !important;
}

textarea:disabled, button:disabled {
    cursor: not-allowed !important;
}

/* Road Detail Overlay (SPA style) */
.road-detail-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f8fafc;
    z-index: 1500;
    overflow-y: auto;
    padding-top: 20px;
}
.road-detail-partial-content { width: 90%; max-width: 1600px; margin: 0 auto; }

/* Reuse Road Detail styles from previous version */
.road-card { background: white; border-radius: 16px; padding: 30px; border: 1px solid #e2e8f0; margin-bottom: 30px; }
.kpi-road { padding: 20px; border-radius: 12px; background: #fff; border: 1px solid #e2e8f0; height: 100%; }
.occ-card { border-radius: 12px; overflow: hidden; border: 1px solid #e2e8f0; height: 100%; transition: transform 0.2s; background: #fff; }
.occ-img { height: 180px; width: 100%; object-fit: cover; background: #f1f5f9; }

/* Loader & Modals */
.loader { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.9); backdrop-filter: blur(4px); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 2000; }
.loader-content { text-align: center; max-width: 400px; }

.image-modal { display: none; position: fixed; z-index: 4000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.9); align-items: center; justify-content: center; }
.image-modal-content { margin: auto; display: block; max-width: 95%; max-height: 90vh; border-radius: 8px; }
.image-modal-close { position: absolute; top: 15px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; cursor: pointer; }

.btn-zoom-mobile {
    display: none;
    background: #f0fdf4;
    border: 1px solid #e2e8f0;
    color: var(--primary);
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.btn-zoom-mobile:hover { background: #dcfce7; border-color: var(--primary); }

.app-version {
    position: fixed;
    bottom: 8px;
    right: 25px;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    color: #94a3b8;
    z-index: 9999;
    pointer-events: none;
    letter-spacing: 0.05em;
    opacity: 1;
    background: transparent !important;
}

.maplibregl-ctrl-attrib {
    display: none !important;
}
.demo-text {
    color: #ef4444;
    font-weight: 800;
}

/* Mobile Header & Hamburger */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--primary);
    z-index: 2500;
    align-items: center;
    padding: 0 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.hamburger-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.1); }
.mobile-brand-title { color: white; font-weight: 700; margin-left: 10px; font-size: 0.9rem; }

.menu-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 2900; /* Abaixo dos menus mas acima do header */
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    body { overflow-y: auto !important; height: auto !important; }
    .mobile-header { 
        display: flex; 
        position: fixed; 
        top: 0; 
        left: 0;
        right: 0;
        width: 100%; 
        z-index: 4000; /* O mais alto de todos */
    }
    .btn-zoom-mobile { display: flex; }
    .nav-sidebar { 
        position: fixed;
        left: -60px;
        top: 0;
        transition: left 0.3s ease;
        padding-top: 56px; /* Começa abaixo da navbar */
        height: 100vh;
        z-index: 3100;
    }
    .sidebar { 
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: calc(100% - 45px) !important;
        max-width: 320px;
        height: 100vh !important;
        z-index: 3000;
        transition: left 0.3s ease;
        box-shadow: 5px 0 20px rgba(0,0,0,0.1);
        padding-top: 56px; /* Começa abaixo da navbar */
    }
    .brand { width: 100%; display: none; }
    .app-container { 
        margin-left: 0 !important; 
        width: 100% !important; 
        margin-top: 56px !important; /* Espaço para a navbar fixa */
        height: auto !important; 
        display: block;
        overflow: visible !important;
    }
    .content-area { margin-left: 0 !important; width: 100% !important; }
    .map-view { height: calc(100vh - 56px) !important; position: relative; }
    
    /* Quando o menu está aberto, bloqueamos o scroll do body */
    body.mobile-menu-open { overflow: hidden !important; }
    body.mobile-menu-open .nav-sidebar { left: 0; }
    body.mobile-menu-open .sidebar { left: 45px; }
    body.mobile-menu-open .menu-backdrop { display: block; }
    
    .selection-overlay { 
        left: 0; 
        top: 0; 
        width: 100% !important;
        height: 100vh; 
        padding: 0; /* Remove padding lateral do contentor pai */
        justify-content: flex-start; 
        overflow-y: auto; 
        z-index: 5000; 
    }
    .selection-wrapper {
        padding: 40px 15px !important; /* Padding mais apertado nas laterais para ganhar width */
    }
    .selection-spacer {
        flex: 0 0 20px !important; /* Reduz drasticamente o espaço do topo para subir o conteúdo */
        min-height: 20px !important;
    }
    .selection-main {
        padding: 0 5px !important; /* Mais largura para a grelha */
    }
    .selection-grid { 
        gap: 10px; /* Reduz gap entre cartões para ganhar espaço */
    }
    #closeSelectionBtn { top: 15px !important; right: 15px !important; font-size: 1.2rem !important; z-index: 3100; }
    .selection-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; width: 100%; }
    .subarea-card { padding: 12px; border-radius: 12px; min-height: 120px; }
    .subarea-card h3 { font-size: 0.85rem; margin-top: 8px; font-weight: 700; }
    .silhouette-container { height: 60px; }
    
    .selection-main h1 { font-size: 1.4rem !important; }
    .selection-main p { font-size: 0.8rem !important; }

    .activate-btn-inline { 
        bottom: 30px !important;
        left: 50% !important;
        padding: 12px 30px !important; 
        font-size: 0.9rem !important;
    }
    
    .selection-footer {
        padding: 0 !important;
        min-height: 20px !important;
    }

    .overlay-stack { top: 10px; left: 10px; width: calc(100% - 20px); }
    .eval-card, .point-card { 
        position: fixed; 
        bottom: 30px !important; 
        left: 10px !important; 
        width: calc(100% - 20px) !important; 
        max-height: calc(100vh - 100px);
        overflow-y: auto;
        border-radius: 16px; 
        box-shadow: 0 -5px 25px rgba(0,0,0,0.15); 
        z-index: 1200;
    }
    
    #gsv-container { height: 200px !important; border-radius: 16px !important; border-width: 2px !important; }
    
    .activate-btn { bottom: 30px; left: 50%; padding: 10px 30px; font-size: 0.85rem; width: auto; }
    .silhouette-container { height: 60px; }

    /* Table Mobile Optimizations */
    .table-responsive { border: none !important; }
    .table th, .table td { padding: 10px 12px !important; font-size: 0.75rem !important; }
    .status-dot { width: 5px !important; height: 6px !important; }

    .selection-button-spacer {
        padding-top: 30px !important;
        padding-bottom: 30px !important;
    }

    .app-version {
        right: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        text-align: center;
        font-size: 9px !important;
        width: 100%;
        padding: 8px 10px 5px 10px !important;
        white-space: nowrap;
        background: rgba(248, 250, 252, 0.9);
        backdrop-filter: blur(5px);
        border-top: 1px solid rgba(0,0,0,0.05);
    }
}
