/* components/legend.css - Consolidated legend styles for maps */

/* ===== BASE LEGEND CONTAINER ===== */
/* Used for both desktop (positioned in map) and mobile (in drawer) */
.legend-container {
    background-color: var(--background-light-shade, #FDF0DC);
    border: 3px solid var(--primary-dark);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    width: auto;
}

/* Desktop: positioned absolutely in map area */
/* Shared positioning for both legends */
#legend,
#growth-legend {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
}

#legend.visible,
#growth-legend.visible {
    display: block;
}

/* Standard legend */
#legend {
    width: 240px;
    z-index: 300; /* DESKTOP_LEGEND - ZIndexManager */
    box-sizing: border-box;
}

/* Growth legend */
#growth-legend {
    background-color: var(--background-light-shade, #FDF0DC);
    border-radius: 8px;
    border: 2px solid var(--primary-dark, #004D42);
    z-index: 900;
    padding: 15px;
    width: 180px;
    box-shadow: 0 2px 4px var(--shadow-medium);
}

/* ===== LEGEND CONTENT ===== */
.legend-title {
    font-family: var(--main-font-family);
    font-style: italic;
    font-weight: 700;
    font-size: 1em;
    color: var(--primary-dark, #004D42);
    text-align: center;
    margin-bottom: 10px;
}

#growth-legend .legend-title {
    font-size: 1rem;
}

.legend-year {
    font-size: 0.8rem;
    color: var(--primary-dark);
    text-align: center;
    margin-bottom: 8px;
    font-weight: 500;
}

.legend-subtitle {
    font-weight: 400;
    font-size: 0.85em;
    display: block;
    margin-top: 4px;
    line-height: 1.2;
    font-style: italic;
    text-align: center;
    color: var(--primary-dark);
    max-width: 220px;
}

#growth-legend .legend-subtitle {
    font-size: 0.85rem;
}

.legend-content,
.legend {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 5px;
    gap: 15px;
    height: 150px;
}

.legend-gradient {
    width: 24px;
    height: 150px;
    border: 1px solid #ccc;
    border-radius: 4px;
    flex-shrink: 0;
}

.legend-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 150px;
    margin-left: 8px;
    font-family: var(--main-font-family);
    font-size: 0.8em;
    color: var(--text-dark, #333333);
}

.legend-labels div {
    text-align: left;
}

/* ===== GRADIENT STYLES BY MAP MODE ===== */
/* Growth Legend Gradient */
#growth-legend .legend-gradient {
    width: 30px;
    background: linear-gradient(to bottom, #1a9850, #91cf60, #d9ef8b, #ffffbf, #fee08b, #fc8d59, #d73027);
}

/* Heatmap Mode Gradient */
#legend.visible[data-mode="heatmap"] .legend-gradient {
    background: linear-gradient(to top, #ffffb2, #fed976, #feb24c, #fd8d3c, #fc4e2a, #e31a1c, #b10026);
}

/* Salary Heatmap Mode Gradient */
#legend.visible[data-mode="salary-heatmap"] .legend-gradient {
    background: linear-gradient(to bottom, #005a32, #238b45, #41ab5d, #74c476, #a1d99b, #e5f5e0);
}

/* Salary Heatmap Specific Adjustments */
#legend.visible[data-mode="salary-heatmap"] .legend-subtitle {
    margin-top: 10px;
}

#legend.visible[data-mode="salary-heatmap"] {
    width: auto;
    padding: 15px;
}

#legend.visible[data-mode="salary-heatmap"] .legend {
    height: 150px;
    justify-content: center;
}

/* ===== MOBILE LEGEND STYLES ===== */
/* Mobile: width <= 768px OR height <= 768px (includes mobile landscape) */
@media screen and (max-width: 768px), screen and (max-height: 768px) {
    /* Hide legend on mobile - it's in the controls drawer */
    #legend {
        display: none !important;
    }
    
    /* Center legend labels on mobile */
    .legend-labels {
        margin-left: 0;
        margin-right: 0;
    }
    
    .legend-labels div {
        text-align: center;
    }
    
    /* Mobile Drawer Legend Styles */
    .mobile-map-controls-content .legend-container,
    #mobile-legend-container .legend-container {
        display: block !important;
        position: static;
        bottom: auto;
        left: auto;
        transform: none;
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding: 12px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        box-sizing: border-box;
    }
    
    .mobile-map-controls-content .legend-container .legend-title {
        font-size: 0.85rem !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
        margin-bottom: 8px;
    }
    
    .mobile-map-controls-content .legend-container .legend-subtitle {
        font-size: 0.75rem !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100% !important;
        line-height: 1.3;
        margin-top: 4px;
    }
    
    .mobile-map-controls-content .legend-container .legend-content,
    .mobile-map-controls-content .legend-container .legend {
        gap: 10px !important;
        margin-top: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .mobile-map-controls-content .legend-container .legend-gradient {
        width: 20px !important;
        flex-shrink: 0;
    }
    
    .mobile-map-controls-content .legend-container .legend-labels {
        font-size: 0.7rem !important;
        flex: 0 1 auto;
        min-width: 0;
    }
    
    .mobile-map-controls-content .legend-container .legend-labels div {
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
        line-height: 1.2;
        text-align: center;
    }
    
    /* Specific fixes for salary-heatmap and growth legends with long subtitles */
    .mobile-map-controls-content .legend-container[data-mode="salary-heatmap"] .legend-subtitle,
    .mobile-map-controls-content .legend-container[data-mode="growth-heatmap"] .legend-subtitle,
    .mobile-map-controls-content .legend-container[data-mode="growth"] .legend-subtitle {
        font-size: 0.7rem !important;
        line-height: 1.4 !important;
        padding: 0 4px;
    }
    
    .mobile-map-controls-content .legend-container .legend-content {
        max-width: 100%;
        overflow: hidden;
    }
    
    /* Growth Legend in Mobile Drawer - Reset positioning (legacy support) */
    .mobile-map-controls-content #growth-legend {
        display: block !important;
        position: static !important;
        right: auto !important;
        top: auto !important;
        transform: none !important;
        max-width: 100%;
        width: 100% !important;
        margin: 0;
        margin-top: 20px;
        padding: 12px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        box-sizing: border-box;
    }
}

