: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: stretch; padding-top: 15px; z-index: 9500;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    padding-bottom: 20px;
    overflow: visible;
}

.nav-sidebar .nav-item {
    color: rgba(255,255,255,0.6); font-size: 1.05rem; margin-bottom: 4px;
    transition: background 0.2s, color 0.2s;
    cursor: pointer; text-decoration: none;
    height: 38px; display: flex; align-items: center;
    position: relative; flex-shrink: 0;
    margin-left: 4px; margin-right: 4px;
    border-radius: 8px;
}
.nav-sidebar .nav-item i {
    width: 37px; /* largura fixa para centrar o ícone na barra de 45px (45 - 4*2 de margem) */
    display: flex; justify-content: center; align-items: center;
    flex-shrink: 0; font-size: 1.1rem;
}
.nav-sidebar .nav-item:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-sidebar .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); }
.nav-sidebar .nav-item.nav-item--disabled { color: rgba(255,255,255,0.25); pointer-events: none; cursor: default; }
.nav-sidebar .nav-item.nav-item--disabled:hover { background: none; }

/* Grupos (div) precisam de largura explícita para o background renderizar corretamente */
.nav-sidebar .nav-group {
    width: calc(100% - 8px);
    box-sizing: border-box;
}

.nav-sidebar .nav-divider {
    width: 25px; height: 1px;
    background: rgba(255,255,255,0.2);
    margin: 8px auto 12px; flex-shrink: 0;
}

/* Flyout */
.nav-flyout {
    position: absolute;
    left: calc(100% + 8px);
    top: 0;
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    min-width: 210px;
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-6px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    pointer-events: none;
    z-index: 9600;
}
.nav-flyout-up {
    top: auto;
    bottom: 0;
}
.nav-flyout-single {
    min-width: auto;
    height: 38px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    border-radius: 8px;
}
/* Ponte invisível que preenche o gap entre o ícone e o flyout, evitando que o hover se perca */
.nav-flyout::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 0;
    bottom: 0;
    width: 12px;
}
.nav-item:hover .nav-flyout {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
}
.nav-flyout-title {
    font-size: 0.58rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary);
    padding: 4px 10px 6px;
}
.nav-flyout-single span {
    font-size: 0.8rem;
    font-weight: 600;
    color: #1e293b;
}
.nav-flyout-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 7px;
    text-decoration: none;
    color: #475569;
    font-size: 0.82rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-flyout-item i {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.9rem;
}
.nav-flyout-item:hover { background: rgba(var(--primary-rgb), 0.08); color: var(--primary); }
.nav-flyout-item.active { background: rgba(var(--primary-rgb), 0.12); color: var(--primary); font-weight: 600; }
.nav-flyout-item.disabled { opacity: 0.35; pointer-events: none; cursor: default; }


/* 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; transition: opacity 0.3s ease, filter 0.3s ease; }
.sidebar.disabled-mode, .sidebar.sidebar-disabled { 
    opacity: 0.4; 
    pointer-events: none; 
    filter: grayscale(0.8); 
    user-select: none;
}
.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); }

/* Progress Section Revamp */
.progress-section {
    padding: 0 4px;
}
.progress-bar-striped-static {
    background-image: linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
    background-size: 1rem 1rem;
}

/* Filter Bar V2 */
.filter-bar-v2 {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-group {
    display: flex;
    background: white;
    padding: 3px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    gap: 2px;
}
.filter-btn-v2 {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.85rem;
}
.filter-btn-v2:hover {
    background: #f1f5f9;
    color: var(--primary);
}
.filter-btn-v2.active {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(var(--primary-rgb), 0.2);
}
.filter-btn-v2.color-pill {
    width: 28px; /* Ligeiramente mais pequeno para as cores */
}
.filter-btn-v2 .status-dot {
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.05);
}
.filter-btn-v2.active .status-dot {
    transform: scale(1.2);
    box-shadow: 0 0 0 2px white, 0 0 0 3px 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: none; cursor: pointer; }
.street-item:hover .focus-icon { visibility: visible; }
.street-item.active .focus-icon { visibility: visible; }
.focus-icon:hover { background: var(--primary); color: white; opacity: 1 !important; }
.btn-xs { padding: 1px 5px; font-size: 0.65rem; line-height: 1.5; border-radius: 3px; }
.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; 
    bottom: 15px; 
    right: 70px; /* 10px (margem zoom) + 30px (largura zoom) + 30px (espaço extra) */
    z-index: 1200; 
    display: flex; 
    flex-direction: column; 
    align-items: flex-end; 
}

/* Forçar controlos do MapLibre (Zoom/Bússola) para o fundo, ao lado das opções */
.maplibregl-ctrl-top-right, .maplibregl-ctrl-bottom-right {
    top: auto !important;
    bottom: 15px !important;
    right: 15px !important;
    margin: 0 !important;
}

/* Unificar estilo visual dos controlos do mapa */
.maplibregl-ctrl-group, .leaflet-bar {
    background: rgba(255,255,255,0.95) !important;
    backdrop-filter: blur(10px) !important;
    border-radius: 6px !important;
    border: 1px solid rgba(0,0,0,0.1) !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    overflow: hidden;
}

.maplibregl-ctrl-group button, .leaflet-bar a {
    width: 29px !important;
    height: 29px !important;
    line-height: 29px !important;
    color: #475569 !important;
    background: transparent !important;
    transition: all 0.2s ease !important;
}

.maplibregl-ctrl-group button:hover, .leaflet-bar a:hover {
    background: rgba(var(--primary-rgb), 0.08) !important;
    color: var(--primary) !important;
}

.leaflet-bar a {
    border-bottom: 1px solid rgba(0,0,0,0.05) !important;
}
.leaflet-bar a:last-child {
    border-bottom: none !important;
}

/* Forçar posição também para o Leaflet */
.leaflet-bottom.leaflet-right {
    bottom: 15px !important;
    right: 15px !important;
}
.leaflet-control-zoom {
    margin: 0 !important;
}

.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;
    display: flex;
    flex-direction: column-reverse; /* Inverte a ordem: header no fundo, content no topo */
}
.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;
    flex-shrink: 0;
}
.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; transform: rotate(180deg); /* Começa a apontar para cima */ }
.map-options-content { 
    padding: 10px 15px 18px 15px; 
    border-bottom: 1px solid rgba(0,0,0,0.05); /* Border agora fica por baixo do conteúdo */
    opacity: 0; 
    visibility: hidden; 
    transition: opacity 0.2s; 
}
/* Alinhamento refinado para os switches dentro das opções */
.map-options-content .form-check {
    padding-left: 0 !important;
    margin-left: 0 !important;
}
.map-options-content .form-check-input {
    margin-left: 0 !important;
    margin-right: 10px !important;
    float: none;
}
.map-options-wrapper.active .map-options-content { opacity: 1; visibility: visible; }
.map-options-wrapper.active .arrow-icon { transform: rotate(0deg); /* Aponta para baixo quando aberto */ }
.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: auto; 
    min-width: 320px;
    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: 320px; 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; }

/* Catálogo de Patologias */
.pathology-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 15px;
    width: 100%;
}
.pathology-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 2px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-width: 0;
}
.pathology-item i {
    font-size: 1rem;
    margin-bottom: 4px;
    color: #64748b;
}
.pathology-item span {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.1;
    color: #475569;
}
.pathology-item:hover {
    background: white;
    border-color: var(--primary);
    transform: translateY(-1px);
}
.pathology-item.active {
    background: rgba(var(--primary-rgb), 0.08);
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}
.pathology-item.active i {
    color: var(--primary);
}
.pathology-item.active span {
    color: var(--primary);
}
.pathology-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* 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: 150px;
}
.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)); 
    justify-content: center;
    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); }

/* Cartões Bloqueados (Sincronização Ativa) */
.subarea-card.locked-card {
    opacity: 0.7;
    cursor: not-allowed !important;
    background: #f1f5f9;
    border-style: dashed;
    position: relative;
    overflow: hidden;
}
.subarea-card.locked-card .silhouette-container {
    filter: grayscale(1) blur(1px);
    opacity: 0.3;
}
.subarea-card.locked-card h3 {
    opacity: 0.5;
}
.lock-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary);
    color: white;
    padding: 0 16px 0 6px;
    height: 32px;
    border-radius: 16px;
    font-size: 12px; /* Valor inteiro para evitar sub-pixels */
    font-weight: 700;
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid rgba(255,255,255,0.2);
}

.lock-indicator .icon-wrapper {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.lock-indicator i {
    font-size: 14px; /* Forçar 14px exatos (par) em vez de 13.6px */
    width: 14px;
    height: 14px;
    display: block;
    line-height: 14px;
    text-align: center;
    transform-origin: center center;
}

.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) !important;
    border-color: var(--primary) !important;
}

.form-check-input:focus {
    border-color: var(--primary) !important;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25) !important;
}

/* Forçar a cor do check (ícone interno) para branco quando selecionado */
.form-check-input:checked[type=checkbox] {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e") !important;
}

.form-check-input:checked[type=radio] {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='2' fill='%23fff'/%3e%3c/svg%3e") !important;
}

.form-check {
    padding-left: 1.75em; /* Aumentar ligeiramente para dar espaço à sombra */
}

.form-check-input {
    margin-left: -1.75em;
    cursor: pointer;
}

/* 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; 
    background-color: transparent !important;
}
.btn-outline-primary:hover, 
.btn-check:checked + .btn-outline-primary { 
    background-color: var(--primary) !important; 
    color: white !important; 
    border-color: var(--primary) !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; }

/* Standardized Item Card Mini (Sync with Teams) */
.item-card-mini {
    padding: 8px 12px;
    border-radius: 10px;
    background: white;
    border: 1px solid #f1f5f9;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}
.item-card-mini:hover {
    border-color: var(--primary);
    transform: translateX(4px);
}
.item-card-mini.active {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb), 0.05);
}

.icon-badge {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    background: #f1f5f9;
    color: #64748b;
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.active .icon-badge {
    background: var(--primary) !important;
    color: white !important;
}

.item-card-mini .detail-text {
    font-size: 0.65rem;
    color: #64748b;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-card-mini .action-icons {
    display: flex;
    gap: 8px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s;
}
.item-card-mini:hover .action-icons { opacity: 1; }

.action-icon-mini {
    font-size: 0.85rem;
    color: #cbd5e1;
    cursor: pointer;
    transition: color 0.2s;
}
.action-icon-mini:hover { color: var(--primary); }
.action-icon-mini.delete:hover { color: #ef4444; }

.drag-handle-mini {
    color: #e2e8f0;
    cursor: grab;
    font-size: 0.75rem;
}
.drag-handle-mini:hover { color: #94a3b8; }

#evalProgressBar .progress-bar {
    border-right: 1px solid rgba(255,255,255,0.2);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
#evalProgressBar .progress-bar:last-child { border-right: none; }

#evalStatusLegend span {
    color: #64748b;
    font-size: 0.6rem;
    white-space: nowrap;
}

.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; }

/* Garantir que modais e backdrop ficam acima de todos os overlays (road-detail: 1500, selection: 3000) */
.modal { z-index: 3200 !important; }
.modal-backdrop { z-index: 3100 !important; }
#discardOccModal { z-index: 3300 !important; }

/* 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 {
    /* Gerido pelo template _version_footer.html */
}

.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 */
/* Global Overrides para Primary Color em Interações */
:focus { outline-color: var(--primary) !important; }
.form-control:focus { 
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25) !important; 
}
.btn-primary { background-color: var(--primary) !important; border-color: var(--primary) !important; }
.btn-primary:hover, .btn-primary:active, .btn-primary:focus { 
    background-color: rgba(var(--primary-rgb), 0.9) !important; 
    border-color: rgba(var(--primary-rgb), 0.9) !important;
    box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25) !important;
}
.btn-outline-primary { color: var(--primary) !important; border-color: var(--primary) !important; }
.btn-outline-primary:hover, .btn-outline-primary:active { 
    background-color: var(--primary) !important; 
    color: white !important; 
}

/* Sidebar Item Hover */
.street-item:hover {
    background: rgba(var(--primary-rgb), 0.05);
    border-left: 3px solid var(--primary);
}
.street-item.active {
    background: rgba(var(--primary-rgb), 0.1);
    border-left: 3px solid var(--primary);
}

/* Pill de rota: no desktop fica no overlay-stack, em mobile fica fixo no fundo */
@media (max-width: 768px) {
    #routePill { position: fixed !important; bottom: 72px; left: 50%; transform: translateX(-50%); z-index: 1150; }
}

@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: 7000; /* Prioridade máxima para o botão hambúrguer estar sempre clicável */
    }
    .btn-zoom-mobile { display: flex; }
    .nav-sidebar {
        position: fixed;
        left: -60px;
        top: 56px;
        transition: left 0.3s ease;
        padding-top: 15px;
        height: calc(100vh - 56px);
        z-index: 6100;
        padding-bottom: 100px !important;
        width: 45px !important;
        overflow: hidden !important;
    }
    body.mobile-menu-open .nav-sidebar {
        left: 0;
    }
    /* Flyouts no mobile: abre ao click (via classe .flyout-open adicionada por JS) */
    .nav-flyout {
        position: fixed;
        left: 53px;
        top: auto;
        bottom: auto;
        transform: translateX(-6px);
    }
    .nav-flyout-up { top: auto !important; }
    .nav-item.flyout-open .nav-flyout {
        opacity: 1;
        visibility: visible;
        transform: translateX(0);
        pointer-events: auto;
    }
    
    /* Esconder o footer da versão quando o menu está aberto para não tapar botões */
    body.mobile-menu-open .app-version {
        background: transparent !important;
        border: none !important;
    }
    /* ─── Sidebar → Bottom Sheet em mobile ─── */
    .sidebar {
        position: fixed !important;
        bottom: -110% !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 72vh !important;
        border-radius: 20px 20px 0 0 !important;
        border-top: 1px solid #e2e8f0 !important;
        box-shadow: 0 -8px 32px rgba(0,0,0,0.15) !important;
        transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
        padding-top: 4px !important;
        overflow: hidden !important;
        z-index: 6050;
    }
    /* Handle bar no topo do bottom sheet */
    .sidebar::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 8px auto 12px;
        flex-shrink: 0;
    }
    .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; }
    /* Street list sheet — abre via handle dedicado, não via hamburger */
    body.street-sheet-open .sidebar { bottom: 0 !important; }
    body.street-sheet-open { overflow: hidden !important; }
    body.street-sheet-open .menu-backdrop { display: block; z-index: 1999; }

    /* Handle persistente no fundo do ecrã para abrir a lista de ruas */
    .mobile-street-handle {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1100;
        background: white;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -4px 16px rgba(0,0,0,0.10);
        border-radius: 16px 16px 0 0;
        padding: 0 16px 12px;
        cursor: pointer;
        transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
    /* Ocultar handle quando uma card de avaliação / ponto / rota está visível */
    body:has(#evalCard[style*="block"]) .mobile-street-handle,
    body:has(#pointCard[style*="block"]) .mobile-street-handle,
    body:has(#routeSummaryCard[style*="block"]) .mobile-street-handle {
        display: none !important;
    }
    /* Ocultar handle quando a sheet de ruas está aberta */
    body.street-sheet-open .mobile-street-handle {
        display: none !important;
    }
    .mobile-street-handle-bar {
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 8px auto 10px;
    }
    .mobile-street-handle-content {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .mobile-street-handle-label {
        font-size: 0.82rem;
        font-weight: 600;
        color: #374151;
    }
    .mobile-street-handle-progress {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--primary);
    }
    .mobile-street-handle-chevron {
        font-size: 0.75rem;
        color: #9ca3af;
    }
    body.street-sheet-open .mobile-street-handle-chevron {
        transform: rotate(180deg);
    }

    /* EXCEÇÃO: No ecrã de seleção (selection-mode), a barra lateral de pesquisa não deve aparecer */
    body.mobile-menu-open.selection-mode .sidebar { left: -100%; }
    
    /* Garantir que o conteúdo da sidebar (tab-map) não aparece mesmo que a sidebar fosse visível por engano */
    body.selection-mode .sidebar .brand,
    body.selection-mode .sidebar #tab-map,
    body.selection-mode .sidebar #tab-route {
        display: none !important;
    }
    
    body.mobile-menu-open .menu-backdrop { display: block; z-index: 5900; }
    
    .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: 2500; /* Abaixo do cabeçalho e menu */
        padding-top: 56px; /* Começar abaixo do cabeçalho fixo */
    }
    .selection-wrapper {
        padding: 40px 15px 180px 15px !important; /* Aumentado padding-bottom para permitir scroll acima do botão fixo */
    }
    .selection-spacer {
        flex: 0 0 20px !important;
        min-height: 20px !important;
    }
    .selection-main {
        padding: 0 5px !important;
    }
    .selection-grid { 
        gap: 10px;
    }
    #closeSelectionBtn { top: 15px !important; right: 15px !important; font-size: 1.2rem !important; z-index: 3100; }
    .selection-grid { 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: 45px !important;
        left: 50% !important;
        padding: 12px 30px !important; 
        font-size: 0.9rem !important;
    }
    
    .selection-footer {
        padding: 0 !important;
        min-height: 40px !important; /* Espaço extra para não encavalitar */
        flex: 0 0 auto !important; 
    }

    .street-list {
        padding-bottom: 80px !important; /* Espaço para não ficar colado ao fundo no mobile */
    }

    /* ─── Overlay stack: irrelevante pois os cards são position:fixed ─── */
    .overlay-stack { top: 0; left: 0; width: 0; pointer-events: none; }

    /* ─── Overlay Cards → Bottom Sheets ─── */
    .eval-card, .point-card, #groupManagementCard {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 62vh;
        overflow-y: auto;
        border-radius: 20px 20px 0 0 !important;
        border: none !important;
        border-top: 1px solid #e2e8f0 !important;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.12) !important;
        z-index: 1200;
        padding: 0 16px 28px !important;
    }
    /* Resumo de rota — mais compacto para deixar o mapa visível */
    #routeSummaryCard {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 58vh;
        overflow-y: auto;
        border-radius: 20px 20px 0 0 !important;
        border: none !important;
        border-top: 1px solid #e2e8f0 !important;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.12) !important;
        z-index: 1200;
        padding: 0 16px 28px !important;
    }
    /* Handle bar no topo de cada card */
    .eval-card::before, .point-card::before,
    #routeSummaryCard::before, #groupManagementCard::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 12px auto 16px;
        flex-shrink: 0;
    }

    /* ─── Street View → full width, fixo no topo do mapa ─── */
    #gsv-container {
        position: fixed !important;
        top: 66px !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        height: 180px !important;
        border-radius: 12px !important;
        border-width: 2px !important;
        z-index: 1300 !important;
    }

    /* ─── Map controls → canto superior direito no mobile ─── */
    /* Controlos MapLibre (zoom/bússola) ficam no topo-direito */
    .maplibregl-ctrl-top-right, .maplibregl-ctrl-bottom-right {
        bottom: auto !important;
        top: 10px !important;
        right: 10px !important;
    }
    /* Controlos Leaflet (zoom/draw) ficam no topo-direito */
    .leaflet-bottom.leaflet-right {
        bottom: auto !important;
        top: 10px !important;
    }
    /* Painel de Opções fica à esquerda dos controlos MapLibre */
    .map-controls {
        bottom: auto !important;
        top: 20px !important;
        right: 62px !important;
        align-items: flex-end;
    }
    /* Expande para baixo em mobile (header topo → conteúdo abaixo) */
    .map-options-wrapper {
        flex-direction: column !important;
        width: 190px !important;
        min-width: unset !important;
    }
    /* Header compacto: só ícone + "Opções", sem seta */
    .map-options-header .arrow-icon { display: none !important; }
    .map-options-header {
        padding: 0 10px !important;
        gap: 0 !important;
        justify-content: flex-start !important;
    }
    .map-options-header i:first-child { margin-right: 6px !important; }
    /* Quando aberto, o conteúdo não ultrapassa o ecrã à direita */
    .map-options-wrapper.active {
        z-index: 9999;
        position: relative;
        overflow: hidden !important;
    }
    .map-options-wrapper.active .map-options-content {
        border-top: 1px solid rgba(0,0,0,0.06) !important;
        border-bottom: none !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);
    }

    /* ─── Padding inferior: conteúdo não fica tapado pelo handle ou pelo footer fixo ─── */

    /* Listas dentro do sidebar bottom sheet (72vh) */
    .street-list,
    #routePointList,
    .zoning-list,
    .pathology-content,
    .teams-content { padding-bottom: 24px; }

    /* Áreas de conteúdo principal com handle fixo no fundo (~65px) */
    .catalog-grid-view,
    .team-grid-view { padding-bottom: 90px !important; }

    /* users.html — sem handle mas com footer fixo */
    .user-grid-view { padding-bottom: 60px !important; }

    /* Sidebar da auditoria: brand/header topo + espaço para swipe no fundo */
    .sidebar .street-list { flex: 1; min-height: 0; }

    /* Modais — z-index acima do sidebar bottom sheet (6050) */
    .modal-backdrop { z-index: 6900 !important; }
    .modal { z-index: 7000 !important; }

    /* Modais como bottom sheets */
    .modal-dialog,
    .modal-dialog.modal-dialog-centered,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-dialog-centered.modal-lg {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        align-items: flex-end !important;
        min-height: unset !important;
    }
    .modal.fade .modal-dialog {
        transform: translateY(100%) !important;
        transition: transform 0.3s ease !important;
    }
    .modal.show .modal-dialog {
        transform: translateY(0) !important;
    }
    .modal-content {
        border-radius: 20px 20px 0 0 !important;
        max-height: 82vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    .modal-body {
        overflow-y: auto;
        padding: 12px 16px !important;
        flex: 1;
        min-height: 0;
    }
    .modal-header {
        padding: 16px 16px 8px !important;
        flex-shrink: 0;
    }
    .modal-footer {
        padding: 8px 16px 20px !important;
        flex-shrink: 0;
    }
    /* Handle visual no topo do modal */
    .modal-header::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #dee2e6;
        border-radius: 2px;
        margin: 0 auto 12px;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
    }
    .modal-header { position: relative; padding-top: 24px !important; }
    /* Formulários compactos dentro de modal */
    .modal-body .form-label { font-size: 0.75rem; margin-bottom: 4px; }
    .modal-body .form-control { font-size: 0.875rem; padding: 7px 10px; }
    .modal-body .form-control-color { height: 38px; }
    .modal-body textarea.form-control { rows: 2; }
    .modal-body h5.modal-title, .modal-title { font-size: 1rem; }
    /* Ícone picker — 3 colunas */
    .icon-grid-picker { grid-template-columns: repeat(6, 1fr) !important; gap: 6px !important; }
    .icon-opt { padding: 6px !important; font-size: 1rem !important; }
    /* Checklists lado a lado -> empilhadas */
    .modal-body .row.g-3 > .col-md-6 { width: 100% !important; flex: none; }
    /* Bloquear scroll de fundo quando modal aberto */
    body.modal-open { overflow: hidden !important; touch-action: none; }
    body.modal-open .modal { overflow-y: auto !important; touch-action: pan-y; }
}
