/**
 * AYIO Jobs - Map Styles
 * Leaflet map containers, popups, view toggles, Browse by Location
 */

/* ==================== Map Containers ==================== */
.map-container {
    width: 100%;
    border-radius: var(--radius-lg, 12px);
    overflow: hidden;
    box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,0.1));
    background: var(--gray-100, #f1f3f5);
    position: relative;
    z-index: 1;
}

.map-container--home {
    height: 400px;
    max-height: 400px;
    margin-bottom: 1.5rem;
}

.map-container--detail {
    height: 300px;
    max-height: 300px;
    margin-top: 1rem;
}

.map-container--jobs {
    height: 450px;
    max-height: 450px;
    margin-bottom: 1.5rem;
}

.map-container--split {
    height: 450px;
    max-height: 450px;
    border-radius: 0 var(--radius-lg, 12px) var(--radius-lg, 12px) 0;
}

/* ==================== View Toggle ==================== */
.map-view-toggle {
    display: inline-flex;
    background: var(--gray-100, #f1f3f5);
    border-radius: var(--radius, 8px);
    padding: 3px;
    gap: 2px;
}

.map-view-toggle .toggle-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--gray-600, #4b5563);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: auto;
}

.map-view-toggle .toggle-btn:hover {
    color: var(--navy, #0f1f3d);
    background: var(--gray-200, #e4e6eb);
}

.map-view-toggle .toggle-btn.active {
    background: var(--white, #fff);
    color: var(--navy, #0f1f3d);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ==================== Split View Layout ==================== */
.jobs-view-container.split-view {
    display: flex;
    gap: 20px;
    height: calc(100vh - 300px);
    min-height: 500px;
}

.jobs-view-container.split-view .jobs-list-panel {
    flex: 1;
    max-width: 50%;
    min-width: 0;
    overflow-y: auto;
    max-height: 100%;
    padding-right: 8px;
}

.jobs-view-container.split-view .map-panel {
    flex: 1;
    max-width: 50%;
    min-width: 0;
    position: sticky;
    top: 20px;
    height: 100%;
}

/* ==================== Custom Popups ==================== */
#map .leaflet-popup-content-wrapper,
.map-container .leaflet-popup-content-wrapper {
    border-radius: var(--radius, 8px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 0;
}

#map .leaflet-popup-content,
.map-container .leaflet-popup-content {
    margin: 0;
    min-width: 240px;
    max-width: 300px;
}

.map-popup {
    padding: 14px 16px;
    font-family: inherit;
}

.map-popup__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--navy, #0f1f3d);
    margin: 0 0 4px 0;
    line-height: 1.3;
}

.map-popup__title a {
    color: inherit;
    text-decoration: none;
}

.map-popup__title a:hover {
    color: var(--primary-teal, #0d9488);
}

.map-popup__company {
    font-size: 0.8125rem;
    color: var(--gray-500, #6b7280);
    margin-bottom: 8px;
}

.map-popup__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.map-popup__tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.map-popup__tag--salary {
    background: var(--success-bg, #d1fae5);
    color: var(--success-text, #065f46);
}

.map-popup__tag--type {
    background: var(--info-bg, #dbeafe);
    color: var(--info, #3b82f6);
}

.map-popup__tag--license {
    background: #e0f2f1;
    color: var(--teal-dark, #0f766e);
}

.map-popup__tag--featured {
    background: var(--warning-bg, #fef3c7);
    color: var(--warning-text, #92400e);
}

.map-popup__link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--primary-teal, #0d9488);
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
}

.map-popup__link:hover {
    text-decoration: underline;
}

/* ==================== Custom Markers ==================== */
.map-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-marker--featured {
    filter: drop-shadow(0 2px 4px rgba(247, 195, 46, 0.5));
}

/* State count markers */
.state-marker {
    background: var(--navy, #0f1f3d);
    color: var(--white, #fff);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    border: 3px solid var(--gold, #f0a500);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ==================== Cluster Overrides ==================== */
#map .marker-cluster-small,
.map-container .marker-cluster-small {
    background-color: rgba(0, 137, 123, 0.3);
}

#map .marker-cluster-small div,
.map-container .marker-cluster-small div {
    background-color: var(--primary-teal, #0d9488);
    color: var(--white, #fff);
    font-weight: 600;
}

#map .marker-cluster-medium,
.map-container .marker-cluster-medium {
    background-color: rgba(26, 43, 74, 0.3);
}

#map .marker-cluster-medium div,
.map-container .marker-cluster-medium div {
    background-color: var(--navy, #0f1f3d);
    color: var(--white, #fff);
    font-weight: 600;
}

#map .marker-cluster-large,
.map-container .marker-cluster-large {
    background-color: rgba(247, 195, 46, 0.3);
}

#map .marker-cluster-large div,
.map-container .marker-cluster-large div {
    background-color: var(--gold-dark, #c8880a);
    color: var(--navy, #0f1f3d);
    font-weight: 700;
}

/* ==================== Location Circle ==================== */
.leaflet-interactive.location-circle {
    fill-opacity: 0.1;
    stroke-opacity: 0.4;
}

/* ==================== Browse by Location ==================== */
.browse-locations {
    padding: 3rem 0;
    background: var(--gray-50, #f8f9fa);
}

.state-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.state-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem 1rem;
    background: var(--white, #fff);
    border-radius: var(--radius, 8px);
    border: 2px solid var(--gray-200, #e4e6eb);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.state-card:hover {
    border-color: var(--primary-teal, #0d9488);
    box-shadow: 0 4px 12px rgba(0, 137, 123, 0.15);
    transform: translateY(-2px);
}

.state-card__name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--navy, #0f1f3d);
    margin-bottom: 4px;
}

.state-card__count {
    font-size: 0.875rem;
    color: var(--gray-500, #6b7280);
    font-weight: 500;
}

/* ==================== Job Detail Map Section ==================== */
.jd-map-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200, #e4e6eb);
}

.jd-map-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--navy, #0f1f3d);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==================== Map Loading State ==================== */
.map-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-500, #6b7280);
    font-size: 0.875rem;
}

.map-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300, #d0d3d8);
    border-top-color: var(--primary-teal, #0d9488);
    border-radius: 50%;
    animation: map-spin 0.8s linear infinite;
    margin-right: 8px;
}

@keyframes map-spin {
    to { transform: rotate(360deg); }
}

/* ==================== Dark Mode ==================== */
[data-theme="dark"] .map-container {
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

[data-theme="dark"] #map .leaflet-popup-content-wrapper,
[data-theme="dark"] .map-container .leaflet-popup-content-wrapper {
    background: var(--gray-800, #1f2937);
    color: var(--gray-100, #f1f3f5);
}

[data-theme="dark"] #map .leaflet-popup-tip,
[data-theme="dark"] .map-container .leaflet-popup-tip {
    background: var(--gray-800, #1f2937);
}

[data-theme="dark"] .map-popup__title {
    color: var(--gray-100, #f1f3f5);
}

[data-theme="dark"] .map-popup__company {
    color: var(--gray-400, #9ca3af);
}

[data-theme="dark"] .state-card {
    background: var(--gray-800, #1f2937);
    border-color: var(--gray-700, #374151);
}

[data-theme="dark"] .state-card:hover {
    border-color: var(--primary-teal, #0d9488);
}

[data-theme="dark"] .state-card__name {
    color: var(--gray-100, #f1f3f5);
}

[data-theme="dark"] .state-card__count {
    color: var(--gray-400, #9ca3af);
}

[data-theme="dark"] .browse-locations {
    background: var(--gray-900, #111827);
}

[data-theme="dark"] .map-view-toggle {
    background: var(--gray-800, #1f2937);
}

[data-theme="dark"] .map-view-toggle .toggle-btn {
    color: var(--gray-400, #9ca3af);
}

[data-theme="dark"] .map-view-toggle .toggle-btn:hover {
    color: var(--gray-200, #e4e6eb);
    background: var(--gray-700, #374151);
}

[data-theme="dark"] .map-view-toggle .toggle-btn.active {
    background: var(--gray-700, #374151);
    color: var(--gray-100, #f1f3f5);
}

/* Invert map tiles slightly for dark mode */
[data-theme="dark"] .leaflet-tile-pane {
    filter: brightness(0.7) contrast(1.1) saturate(0.8);
}

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
    .jobs-view-container.split-view {
        flex-direction: column;
    }

    .jobs-view-container.split-view .jobs-list-panel,
    .jobs-view-container.split-view .map-panel {
        max-width: 100%;
        max-height: none;
    }

    .jobs-view-container.split-view .jobs-list-panel {
        padding-right: 0;
    }

    .jobs-view-container.split-view .map-panel {
        position: relative;
        top: auto;
        height: auto;
    }

    .map-container--jobs {
        height: 400px;
        max-height: 400px;
    }

    .map-container--split {
        height: 400px;
        max-height: 400px;
        border-radius: var(--radius-lg, 12px);
    }
}

@media (max-width: 768px) {
    .state-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .map-container--home {
        height: 300px;
        max-height: 300px;
    }

    .map-container--jobs {
        height: 350px;
        max-height: 350px;
    }

    .map-container--detail {
        height: 250px;
        max-height: 250px;
    }

    .map-container--split {
        height: 350px;
        max-height: 350px;
    }

    .map-view-toggle .toggle-btn {
        padding: 8px 14px;
        font-size: 0.8125rem;
        min-height: 44px;
    }

    /* Hide split view on mobile */
    .map-view-toggle .toggle-btn[data-view="split"] {
        display: none;
    }

    .map-popup {
        padding: 10px 12px;
    }

    .map-popup__title {
        font-size: 0.875rem;
    }

    .map-popup__company {
        font-size: 0.75rem;
    }

    .map-popup__tag {
        font-size: 0.6875rem;
    }

    #map .leaflet-popup-content,
    .map-container .leaflet-popup-content {
        min-width: 200px;
        max-width: 260px;
    }
}

@media (max-width: 480px) {
    .state-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .state-card {
        padding: 0.875rem 0.625rem;
    }

    .state-card__name {
        font-size: 0.95rem;
    }

    .state-card__count {
        font-size: 0.8125rem;
    }

    .map-container--home {
        height: 250px;
        max-height: 250px;
    }

    .map-container--detail {
        height: 220px;
        max-height: 220px;
    }

    #map .leaflet-popup-content,
    .map-container .leaflet-popup-content {
        min-width: 180px;
        max-width: 240px;
    }
}

/* ==================== Leaflet Attribution ==================== */
#map .leaflet-control-attribution,
.map-container .leaflet-control-attribution {
    font-size: 0.625rem;
    opacity: 0.7;
}

#map .leaflet-control-attribution a,
.map-container .leaflet-control-attribution a {
    color: var(--primary-teal, #0d9488);
}
