html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Evita barras de rolagem na página inteira, mas não afeta modais */
}

/* Permite que modais Bootstrap funcionem corretamente */
body.modal-open {
    overflow: hidden !important;
    padding-right: 0 !important; /* Remove padding que Bootstrap adiciona */
}

.main-content {
    flex-grow: 1;
    display: flex;
    overflow: hidden;
}

#sidebar {
    width: 350px;
    min-width: 350px;
    background-color: #f8f9fa;
    padding: 1.5rem;
    overflow-y: auto; /* Permite rolagem apenas na sidebar */
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
}

#map-container {
    flex-grow: 1;
    height: 100%;
    position: relative;
}

#map {
    height: 100%;
    width: 100%;
}

/* Cursor customizado quando em modo de adição de vértice */
body[data-adding-vertex="true"] #map {
    cursor: crosshair !important;
}

/* Força o cursor crosshair em todos os elementos do Leaflet quando em modo de adição */
body[data-adding-vertex="true"] .leaflet-container,
body[data-adding-vertex="true"] .leaflet-grab,
body[data-adding-vertex="true"] .leaflet-dragging {
    cursor: crosshair !important;
}

/* Adiciona um indicador visual no map container */
#map-container.adding-vertex-mode::before {
    content: "✚ Clique no mapa para adicionar vértice";
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(25, 135, 84, 0.95);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: pulse 2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateX(-50%) scale(1.05);
        opacity: 0.9;
    }
}

.info-section {
    flex-grow: 1;
}

.leaflet-popup-content {
    margin: 13px 20px 13px 13px;
}

.form-label {
    font-weight: 500;
}

.table-sm th, .table-sm td {
    padding: 0.4rem;
}

/* --- Estilos para marcadores de mapa personalizados --- */

.custom-map-marker > div {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    transform-origin: center center;
}

.marker-hover {
    /* Aumenta a escala e eleva o z-index no hover */
    transform: scale(1.8);
    z-index: 1000;
}


/* --- Estilos para o modo de adição de vértice --- */

/* Muda o cursor do mapa quando em modo de adição */
body[data-adding-vertex="true"] #map-container {
    cursor: crosshair;
}

/* Exibe o texto de ajuda */
body[data-adding-vertex="true"] #addVertexHelp {
    display: block !important; /* Usa !important para sobrescrever a classe d-none do Bootstrap */
}

/* Muda a cor do botão de adicionar */
body[data-adding-vertex="true"] #btnAddVertex,
#btnAddVertex.btn-success {
    background: linear-gradient(135deg, #198754 0%, #146c43 100%) !important;
    border-color: #146c43 !important;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.5) !important;
    color: white !important;
    font-weight: bold !important;
}

#btnAddVertex.btn-success:hover {
    background: linear-gradient(135deg, #146c43 0%, #0f5132 100%) !important;
    transform: scale(1.02);
}

/* --- Estilos para o modal de gerenciamento de valuesets --- */

#managementModal .list-group-item {
    transition: background-color 0.2s ease;
}

#managementModal .list-group-item:hover {
    background-color: #f8f9fa;
}

#managementModal .btn-group {
    gap: 0.25rem;
}

.tab-content {
    min-height: 300px;
}

.add-new-type-btn {
    margin-bottom: 1rem;
}

/* Estilo para indicar item em uso que não pode ser deletado */
.valueset-item-in-use {
    background-color: #fff3cd;
    border-left: 4px solid #ffc107;
}

/* --- Animações e estilos modernos do mapa --- */

@keyframes pulse-animation {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.4), 0 0 16px rgba(255, 193, 7, 0.6);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 193, 7, 0.2), 0 0 24px rgba(255, 193, 7, 0.4);
    }
}

.custom-map-marker {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-map-marker:hover {
    filter: brightness(1.2);
}

/* Estilo para as linhas de tubulação */
.pipe-line {
    transition: all 0.3s ease;
}

/* Controle de coordenadas customizado */
.leaflet-control-coordinates {
    user-select: text;
    cursor: text;
    transition: all 0.3s ease;
}

.leaflet-control-coordinates:hover {
    background: rgba(255, 255, 255, 1) !important;
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

/* Estilo do painel de informações moderno */
#info-panel .card {
    border-width: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#info-panel .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#info-panel .card-header {
    font-weight: 600;
    border-bottom: 2px solid;
}

#info-panel .badge {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
    font-weight: 500;
}

/* Melhorias na sidebar */
#sidebar {
    background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
}

#sidebar h5 {
    color: #0d6efd;
    font-weight: 600;
    border-bottom: 2px solid #0d6efd;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

/* Botões com efeito hover melhorado */
.btn {
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

/* Estilo da navbar */
.navbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Controles do leaflet com estilo moderno */
.leaflet-control-zoom a,
.leaflet-control-layers-toggle {
    border-radius: 4px !important;
    border: 2px solid #0d6efd !important;
}

.leaflet-control-zoom a:hover {
    background-color: #0d6efd !important;
    color: white !important;
}

/* Estilo para o modo de adição de vértice */
#map-container.adding-vertex-mode {
    cursor: crosshair !important;
}

#map-container.adding-vertex-mode * {
    cursor: crosshair !important;
}

/* Badges personalizados para tipos de elementos */
.badge.bg-info {
    background-color: #0dcaf0 !important;
}

/* Cards dos modais */
.modal-content {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    border-bottom: 2px solid #dee2e6;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-header .btn-close {
    filter: brightness(0) invert(1);
}

/* Filtros com visual moderno */
.form-check-input:checked {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.form-select:focus,
.form-control:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Scrollbar customizada para a sidebar */
#sidebar::-webkit-scrollbar {
    width: 8px;
}

#sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

#sidebar::-webkit-scrollbar-thumb {
    background: #0d6efd;
    border-radius: 10px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: #0a58ca;
}

/* ========================================= */
/* === CORREÇÃO PARA MODAIS BOOTSTRAP === */
/* ========================================= */

/* IMPORTANTE: Garante que os modais Bootstrap apareçam corretamente */

/* Modal backdrop (fundo escuro) */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040 !important;
    width: 100vw;
    height: 100vh;
    background-color: #000;
}

.modal-backdrop.show {
    opacity: 0.5;
}

/* Modal principal */
.modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 1055 !important;
    width: 100% !important;
    height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    outline: 0 !important;
    display: none;
}

/* Modal quando está sendo exibido */
.modal.show {
    display: block !important;
}

/* Diálogo do modal (conteúdo centralizado) */
.modal-dialog {
    position: relative;
    width: auto;
    margin: 1.75rem auto;
    pointer-events: none;
}

.modal.show .modal-dialog {
    pointer-events: auto;
}

/* Conteúdo do modal */
.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 0.3rem;
    outline: 0;
}

/* Previne conflito com overflow do body */
body.modal-open {
    overflow: hidden !important;
    padding-right: 0 !important;
}