/* ===== BULGARIA ROAD NETWORK MAP STYLES ===== */
/* Clean, organized CSS for interactive speed monitoring zones map */
/* COLLAPSIBLE LEGENDS ON MAP VERSION - DEFAULT COLLAPSED */

/* ===== BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
}

/* ===== HEADER SECTION ===== */
.header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-text h1 {
    font-size: 1.8rem;
    font-weight: 600;
    margin: 0;
}

.header-text p {
    opacity: 0.9;
    font-size: 0.95rem;
    margin: 0.5rem 0 0 0;
}

.about-button {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.about-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* ===== MODAL STYLES ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
}

.modal-content {
    background-color: white !important;
    margin: 5% auto !important;
    border-radius: 12px !important;
    width: 90% !important;
    max-width: 600px !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3) !important;
    animation: modalSlideIn 0.3s ease-out !important;
    position: relative !important;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem 1rem 2rem;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.4rem;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #e74c3c;
}

.modal-body {
    padding: 1rem 2rem 2rem 2rem;
    color: #333;
    line-height: 1.6;
}

.modal-body h3 {
    color: #2c3e50;
    margin: 1.5rem 0 0.8rem 0;
    font-size: 1.1rem;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin-bottom: 1rem;
}

.modal-body ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.modal-body li {
    margin-bottom: 0.4rem;
}

.modal-body a {
    color: #3498db;
    text-decoration: none;
}

.modal-body a:hover {
    text-decoration: underline;
}

/* ===== MAP CONTAINER ===== */
.map-container {
    position: relative;
    height: calc(100vh - 120px);
    margin: 0;
}

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

.loading-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    font-size: 1rem;
    color: #2c3e50;
}

/* ===== COLLAPSIBLE CONTROLS PANEL ===== */
.controls {
    position: absolute;
    top: 20px;
    right: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    min-width: 200px;
    max-height: 70vh;
    overflow: hidden;
    transition: all 0.3s ease;
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: #2c3e50;
    color: white;
    cursor: pointer;
    user-select: none;
}

.controls-header:hover {
    background: #34495e;
}

.controls-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.controls-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: white;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: transform 0.3s ease;
}

.controls-toggle.expanded {
    transform: rotate(180deg);
}

/* Default collapsed state - content hidden by default */
.controls-content {
    padding: 0 1rem;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Expanded state - only when .expanded class is present */
.controls.expanded .controls-content {
    padding: 1rem;
    max-height: 60vh;
    overflow-y: auto;
}

.control-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.6rem;
    padding: 0.3rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.control-item:hover {
    background-color: #f8f9fa;
}

.control-item input[type="checkbox"] {
    margin-right: 0.6rem;
    transform: scale(1.1);
}

.control-item label {
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
}

.control-item input[type="checkbox"]:disabled+label {
    color: #999;
    cursor: not-allowed;
}

/* ===== COLLAPSIBLE LEGEND PANEL ===== */
.legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    overflow: hidden;
    transition: all 0.3s ease;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: #27ae60;
    color: white;
    cursor: pointer;
    user-select: none;
}

.legend-header:hover {
    background: #229954;
}

.legend-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.legend-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: white;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: transform 0.3s ease;
}

.legend-toggle.expanded {
    transform: rotate(180deg);
}

/* Default collapsed state - content hidden by default */
.legend-content {
    padding: 0 1rem;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Expanded state - only when .expanded class is present */
.legend.expanded .legend-content {
    padding: 1rem;
    max-height: none;
}

.legend-stats {
    margin: 0;
    padding: 0;
    border: none;
}

.legend-stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: #2c3e50;
}

.legend-stat-label {
    font-weight: 500;
}

.legend-stat-value {
    font-weight: 600;
    color: #27ae60;
}

.legend-color {
    width: 20px;
    height: 4px;
    margin-right: 0.6rem;
    border-radius: 2px;
}

.legend-icon {
    width: 20px;
    height: 20px;
    margin-right: 0.6rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: white;
}

/* ===== POPUP STYLES ===== */
/* Leaflet popup container overrides */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: none;
    min-width: 280px;
    max-width: 350px;
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    padding: 0;
    width: auto !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.leaflet-popup-tip {
    background: linear-gradient(135deg, #2c3e50, #34495e);
}

.leaflet-popup {
    animation: popupSlideIn 0.3s ease-out;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Point popup container */
.point-popup {
    width: 100%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
}

.popup-header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
    padding: 1rem;
    text-align: center;
}

.popup-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.3;
}

.popup-body {
    padding: 1rem;
}

/* Road image section */
.road-image {
    margin-bottom: 1rem;
    text-align: center;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.1);
    background: #f8f9fa;
}

.road-image img {
    width: 100%;
    max-width: 280px;
    height: 160px;
    object-fit: cover;
    object-position: center;
    display: block;
    border: none;
    border-radius: 8px;
}

/* Road information section */
.road-info-section {
    margin-bottom: 1rem;
    padding: 0.8rem;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #3498db;
}

.road-info-section p {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #333;
}

.road-info-section p:last-child {
    margin-bottom: 0;
}

.road-info-section strong {
    color: #2c3e50;
    font-weight: 600;
}

/* Coordinates section */
.coordinates {
    font-size: 0.9rem;
    color: #34495e;
    text-align: center;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
}

/* Speed limit styling */
.speed-limit {
    font-weight: bold;
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* ===== MOBILE RESPONSIVENESS - UPDATED WITH BETTER POPUP HANDLING ===== */
@media (max-width: 768px) {

    /* Header adjustments */
    .header {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .header-text h1 {
        font-size: 1.5rem;
    }

    /* Modal adjustments */
    .modal-content {
        margin: 10% auto;
        width: 95%;
        max-height: 75vh;
    }

    .modal-header,
    .modal-body {
        padding: 1rem;
    }

    .modal-header h2 {
        font-size: 1.2rem;
    }

    /* Make controls more mobile-friendly but keep them positioned */
    .controls {
        top: 15px;
        right: 15px;
        min-width: 250px;
        max-width: calc(100vw - 30px);
    }

    .controls-header {
        padding: 0.8rem;
    }

    .controls-header h3 {
        font-size: 0.9rem;
    }

    .controls.expanded .controls-content {
        max-height: 50vh;
        padding: 0.8rem;
    }

    .control-item {
        margin-bottom: 0.5rem;
        padding: 0.4rem;
    }

    .control-item input[type="checkbox"] {
        transform: scale(1.3);
    }

    .control-item label {
        font-size: 0.85rem;
        line-height: 1.3;
    }

    /* Make legend more mobile-friendly but keep it positioned - AVOID ZOOM CONTROLS */
    .legend {
        bottom: 15px;
        left: 15px;
        right: 70px;
        /* Leave space for zoom controls */
        max-width: none;
    }

    .legend-header {
        padding: 0.8rem;
    }

    .legend-header h3 {
        font-size: 0.9rem;
    }

    .legend.expanded .legend-content {
        padding: 0.8rem;
    }

    .legend-stat {
        font-size: 0.8rem;
        margin-bottom: 0.3rem;
    }

    /* Map container stays full height */
    .map-container {
        height: calc(100vh - 140px);
    }

    /* IMPROVED POPUP ADJUSTMENTS */
    .leaflet-popup-content-wrapper {
        min-width: 260px !important;
        max-width: 300px !important;
        /* Crucial: Ensure popup doesn't exceed screen width */
        max-width: calc(100vw - 40px) !important;
    }

    /* Make popup body scrollable if too tall */
    .popup-body {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }

    .popup-header {
        padding: 0.8rem;
    }

    .popup-header h3 {
        font-size: 1rem;
    }

    .road-image {
        margin-bottom: 0.8rem;
        background: #f8f9fa;
    }

    .road-image img {
        width: 100% !important;
        max-width: none !important;
        height: 135px;
        border-radius: 6px;
    }

    .coordinates {
        font-size: 0.85rem;
    }

    /* Better close button for mobile */
    .leaflet-popup-close-button {
        width: 28px !important;
        height: 28px !important;
        font-size: 20px !important;
        line-height: 26px !important;
        top: 8px !important;
        right: 8px !important;
    }
}

/* Very small phones - ULTRA COMPACT POPUPS */
@media (max-width: 480px) {
    .header {
        padding: 0.8rem;
    }

    .header-text h1 {
        font-size: 1.3rem;
    }

    .header-text p {
        font-size: 0.85rem;
    }

    .about-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .map-container {
        height: calc(100vh - 130px);
    }

    /* Ultra-compact controls - AVOID ZOOM CONTROLS */
    .controls {
        top: 5px;
        right: 5px;
        left: 60px;
        /* Leave space for zoom controls on the left */
        min-width: auto;
        max-width: none;
    }

    .controls-header {
        padding: 0.6rem;
    }

    .controls-header h3 {
        font-size: 0.85rem;
    }

    .controls.expanded .controls-content {
        max-height: 40vh;
        padding: 0.6rem;
    }

    .control-item {
        margin-bottom: 0.4rem;
        padding: 0.3rem;
    }

    .control-item label {
        font-size: 0.8rem;
    }

    /* Ultra-compact legend - half screen width */
    .legend {
        bottom: 5px;
        left: 5px;
        width: 50%;
        /* Half screen width */
    }

    .legend-header {
        padding: 0.6rem;
    }

    .legend-header h3 {
        font-size: 0.85rem;
    }

    .legend.expanded .legend-content {
        padding: 0.6rem;
    }

    .legend-stat {
        font-size: 0.75rem;
        margin-bottom: 0.2rem;
    }

    /* ULTRA COMPACT POPUPS FOR SMALL PHONES */
    .leaflet-popup-content-wrapper {
        min-width: 240px !important;
        max-width: 280px !important;
        /* Leave more margin on small screens */
        max-width: calc(100vw - 60px) !important;
    }

    .popup-header {
        padding: 0.6rem;
    }

    .popup-header h3 {
        font-size: 0.9rem;
        line-height: 1.2;
    }

    .popup-body {
        padding: 0.6rem;
        max-height: calc(100vh - 180px);
        overflow-y: auto;
    }

    .road-image {
        margin-bottom: 0.6rem;
        background: #f8f9fa;
    }

    .road-image img {
        width: 100% !important;
        max-width: none !important;
        height: 120px;
        border-radius: 6px;
    }

    .road-info-section {
        padding: 0.5rem;
        margin-bottom: 0.6rem;
    }

    .road-info-section p {
        font-size: 0.8rem;
        margin-bottom: 0.3rem;
        line-height: 1.3;
    }

    .coordinates {
        font-size: 0.8rem;
        padding: 0.3rem;
    }

    .speed-limit {
        font-size: 0.75rem;
        padding: 1px 6px;
    }
}

/* Landscape phones - MINIMAL POPUPS FOR LANDSCAPE */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 0.5rem 1rem;
    }

    .header-content {
        flex-direction: row;
        gap: 1rem;
    }

    .header-text h1 {
        font-size: 1.2rem;
    }

    .header-text p {
        margin: 0.2rem 0 0 0;
        font-size: 0.8rem;
    }

    .map-container {
        height: calc(100vh - 80px);
    }

    /* Minimal controls for landscape */
    .controls {
        top: 5px;
        right: 5px;
        width: 180px;
        max-width: 180px;
        min-width: 180px;
    }

    .controls-header {
        padding: 0.5rem;
    }

    .controls-header h3 {
        font-size: 0.8rem;
    }

    .controls.expanded .controls-content {
        max-height: 25vh;
        padding: 0.5rem;
    }

    .control-item {
        margin-bottom: 0.2rem;
        padding: 0.1rem;
    }

    .control-item label {
        font-size: 0.75rem;
        line-height: 1.1;
    }

    /* Minimal legend for landscape */
    .legend {
        bottom: 5px;
        left: 5px;
        width: 200px;
        right: auto;
    }

    .legend-header {
        padding: 0.5rem;
    }

    .legend-header h3 {
        font-size: 0.8rem;
    }

    .legend.expanded .legend-content {
        padding: 0.5rem;
    }

    .legend-stat {
        font-size: 0.65rem;
        margin-bottom: 0.1rem;
    }

    /* LANDSCAPE POPUP OPTIMIZATIONS */
    .leaflet-popup-content-wrapper {
        min-width: 220px !important;
        max-width: 260px !important;
        /* Fit in landscape with room for controls */
        max-width: calc(100vw - 220px) !important;
        max-height: calc(100vh - 120px) !important;
    }

    .popup-header {
        padding: 0.4rem;
    }

    .popup-header h3 {
        font-size: 0.85rem;
        line-height: 1.1;
    }

    .popup-body {
        padding: 0.4rem;
        max-height: calc(100vh - 160px);
        overflow-y: auto;
    }

    .road-image {
        margin-bottom: 0.4rem;
        background: #f8f9fa;
    }

    .road-image img {
        width: 100% !important;
        max-width: none !important;
        height: 100px;
        border-radius: 6px;
    }

    .road-info-section {
        padding: 0.4rem;
        margin-bottom: 0.4rem;
    }

    .road-info-section p {
        font-size: 0.75rem;
        margin-bottom: 0.2rem;
        line-height: 1.2;
    }

    .coordinates {
        font-size: 0.7rem;
        padding: 0.2rem;
    }

    .speed-limit {
        font-size: 0.7rem;
        padding: 1px 4px;
    }
}

/* High pixel density displays */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .control-item input[type="checkbox"] {
        transform: scale(1);
    }

    /* Ensure popup text is still readable on high-DPI screens */
    .popup-body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}