/* Common styles for all map applications */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

header {
    background: #2c3e50;
    color: white;
    padding: 0rem 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filter-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: auto;
    display: none;
    transition: opacity 0.3s ease;
    line-height: 1;
}

.filter-toggle:hover {
    opacity: 0.8;
}

.filter-toggle.expanded .toggle-icon {
    opacity: 0.6;
}

.filters-panel {
    background: #34495e;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.filters-panel .header-filter {
    padding: 0.5rem 0.5rem;
}

/* Desktop: horizontal layout with slider and dropdowns in one row */
@media (min-width: 769px) {
    .filter-toggle {
        display: block;
    }
    
    .filters-panel {
        max-height: 500px;
        display: flex !important;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        column-gap: 0rem;
        row-gap: 0rem;
        justify-content: flex-end;
    }
    
    .filters-panel .header-filter {
        flex: 0 0 auto;
        width: 500px;
        padding: 0.5rem 0.5rem;
    }
    
    .filters-panel .subheader {
        flex: 0 0 auto;
        background: transparent;
        padding: 0.5rem 0.75rem;
        justify-content: flex-end;
        flex-direction: row;
        gap: 1rem;
    }
}

.header-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 1;
    min-width: 0;
}

.home-link {
    color: white;
    text-decoration: none;
    font-size: 1.4rem;
    opacity: 0.85;
    transition: opacity 0.2s, transform 0.2s;
    flex-shrink: 0;
    line-height: 1;
}

.home-link:hover {
    opacity: 1;
    transform: scale(1.1);
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subheader {
    background: #34495e;
    color: white;
    padding: 0.5rem 0.75rem;
    display: flex;
    gap: 2rem;
    align-items: center;
    justify-content: flex-end;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.875rem;
    white-space: nowrap;
}

.filter-group select {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 0.875rem;
    min-width: 150px;
}

.header-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
    width: 500px;
    margin-left: auto;
}

.filter-label {
    font-size: 0.875rem;
    white-space: nowrap;
    color: white;
}

.range-slider-container {
    flex: 1;
    display: block;
    position: relative;
}

#rangeCanvas {
    width: 100%;
    height: 24px;
    cursor: pointer;
    display: block;
}

#map {
    flex: 1;
    width: 100%;
    position: relative;
}

.item-count {
    position: absolute;
    top: 5px;
    right: 10px;
    z-index: 1000;
    font-size: 0.875rem;
    font-weight: 600;
    color: #2c3e50;
    background: rgba(255, 255, 255, 0.85);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
}

.data-source {
    position: absolute;
    bottom: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.8);
    padding: 0 5px;
    z-index: 1000;
    font-size: 12px;
    line-height: 1.5;
    box-sizing: border-box;
}

.data-source a {
    color: #3498db;
    text-decoration: none;
}

.data-source a:hover {
    text-decoration: underline;
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 2000;
    text-align: center;
}

.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    header {
        flex-direction: row;
        align-items: center;
        padding: 0rem 1rem;
        gap: 0.75rem;
    }
    
    .header-title-group {
        flex: 1;
        min-width: 0;
    }
    
    h1 {
        font-size: 1.25rem;
    }
    
    .filter-toggle {
        display: block;
    }
    
    .filters-panel {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        display: block;
        flex-direction: column;
    }
    
    .filters-panel.expanded {
        max-height: 500px;
    }
    
    .filters-panel .subheader {
        padding: 0.5rem 0.75rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .filters-panel .header-filter {
        padding: 0.5rem 0.5rem;
    }
    
    .item-count {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }
    
    .header-filter {
        width: 100%;
        max-width: none;
        margin-left: 0;
    }
    
    .filter-label {
        font-size: 0.75rem;
    }
    
    #rangeCanvas {
        height: 24px;
    }
    
    /* Subheader filters - stack vertically on mobile */
    .subheader {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }
    
    .filter-group {
        width: 100%;
        justify-content: flex-end;
    }
    
    .filter-group label {
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    .filter-group select {
        flex: 1;
        min-width: 0;
        max-width: 65%;
        font-size: 0.8rem;
    }
}

/* Cluster marker styles */
.cluster-marker {
    background: none !important;
    border: none !important;
}

.cluster-pin {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #3498db;
    border: 3px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.cluster-count {
    color: white;
    font-weight: bold;
    font-size: 16px;
    line-height: 1;
}


/* Popup width control - apply to all popups */
.leaflet-popup-content-wrapper {
    min-width: 300px;
}

.leaflet-popup-content {
    min-width: 300px;
}

/* Multi-incident popup - remove default padding so scrollbar goes to edge */
.multi-popup .leaflet-popup-content {
    margin: 0;
    padding: 0 !important;
}

.multi-popup .leaflet-popup-content > div {
    padding: 13px 15px;
}


/* Popup styles (unified for both single and cluster popups) */
.popup-title-link {
    color: #2c3e50;
    text-decoration: none;
    border-bottom: 1px solid #3498db;
}

/* Cluster popup styles */
.popup-content-wrapper {
    max-width: 100%;
    padding: 0;
}

.popup-header {
    margin: 0 0 0.5rem 0;
    color: #2c3e50;
    font-size: 1rem;
}

.popup-scroll {
    max-height: 400px;
    overflow-y: auto;
    margin: 0 -15px 0 -13px;
    padding: 0 15px 0 13px;
}

.popup-item {
    padding: 0;
    max-width: 100%;
    overflow: hidden;
}

.popup-separator {
    border: none;
    border-top: 1px solid #f0f0f0;
    margin: 0.5rem 0;
}

.popup-item-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 1rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.popup-field {
    font-size: 0.875rem;
    color: #666;
    margin: 0 0 2px 0;
}

.popup-field-details {
    font-size: 1.1rem;
    margin: 0.4em 0 0.2em 0;
}

.popup-field-labeled {
    color: #666;
    margin-left: 0px;
}
