/**
 * Map View Page Styles
 * Extracted from components/map-view.html
 * Phase 2C - CSS Refactor
 * Updated: v4 palette migration (coral/teal/cream)
 */

/* ===== BASE ===== */
body {
    margin: 0;
    padding: 0;
    padding-top: 56px;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
}

/* ===== MAP CONTAINER ===== */
.map-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
}

/* ===== MAP TOOLBAR ===== */
.map-toolbar {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-accent));
    padding: 12px 24px;
    border-bottom: 2px solid var(--primary-orange);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.map-toolbar-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.map-toolbar-title h1 {
    font-size: 1.25rem;
    margin: 0;
    color: var(--primary-orange);
    font-weight: 800;
    font-family: var(--font-heading);
    text-align: center;
}

.map-toolbar-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ===== BUTTONS ===== */
.btn {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    box-shadow: 0 2px 8px rgba(232, 112, 78, 0.25);
    font-family: var(--font-body);
}

.btn:hover {
    background: linear-gradient(135deg, var(--primary-orange-dark), var(--primary-orange));
    box-shadow: 0 4px 16px rgba(232, 112, 78, 0.4);
}

.btn:active {
    transform: translateY(1px);
}

.btn.secondary {
    background: var(--bg-secondary);
    color: var(--primary-orange);
    border: 2px solid var(--bg-accent);
}

.btn.secondary:hover {
    background: var(--primary-orange);
    color: white;
    border-color: var(--primary-orange);
}

/* ===== MAIN CONTENT ===== */
.map-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== MAP ===== */
#map {
    flex: 1;
    height: 100%;
    z-index: 1;
    position: relative;
    background: white;
}

.mapboxgl-canvas-container {
    opacity: 0.95;
}

/* ===== SIDEBAR ===== */
.map-sidebar {
    width: 350px;
    background: var(--bg-secondary);
    border-left: 2px solid var(--bg-accent);
    overflow-y: auto;
    z-index: 2;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.04);
}

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid var(--bg-accent);
}

.sidebar-section h3 {
    margin: 0 0 16px 0;
    color: var(--primary-orange);
    font-size: 1.05rem;
    font-weight: 700;
    font-family: var(--font-heading);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-section h3 i,
.sidebar-section h3 [data-lucide] {
    color: var(--primary-orange);
}

/* ===== FILTERS ===== */
.filter-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 6px 12px;
    border: 2px solid var(--bg-accent);
    background: white;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    font-family: var(--font-body);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.filter-btn:hover {
    background: var(--primary-orange);
    border-color: var(--primary-orange);
    color: white;
}

.filter-btn.active {
    border-color: var(--accent-teal);
    background: var(--accent-teal);
    color: white;
    box-shadow: 0 2px 8px rgba(53, 133, 133, 0.25);
}

/* ===== OCCASION DROPDOWN ===== */
.occasion-select {
    width: 100%;
    background: white;
    border: 2px solid var(--bg-accent);
    border-radius: var(--radius-md);
    padding: 10px 15px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.occasion-select:hover {
    border-color: var(--primary-orange);
}

.occasion-select:focus {
    outline: none;
    border-color: var(--primary-orange);
    box-shadow: 0 0 0 3px rgba(232, 112, 78, 0.1);
}

/* ===== STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    background: white;
    border: 2px solid var(--bg-accent);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: center;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    border-color: var(--primary-orange);
    box-shadow: var(--shadow-md);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-orange);
    margin-bottom: 4px;
    font-family: var(--font-heading);
}

/* Alternate teal for every other stat */
.stat-card:nth-child(2) .stat-value,
.stat-card:nth-child(4) .stat-value {
    color: var(--accent-teal);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ===== LOCATION LIST ===== */
.location-list {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 8px;
}

.location-item {
    padding: 12px;
    background: white;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid var(--bg-accent);
}

.location-item:hover {
    background: var(--bg-secondary);
    transform: translateX(4px);
    border-color: var(--primary-orange);
    box-shadow: var(--shadow-sm);
}

.location-name {
    color: var(--text-primary);
    font-weight: 600;
}

.location-count {
    background: var(--primary-orange);
    color: white;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 700;
}

/* ===== MAPBOX POPUP ===== */
.mapboxgl-popup-content {
    background: white !important;
    color: var(--text-primary);
    border-radius: 16px !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12) !important;
    border: 2px solid var(--bg-accent);
    padding: 0 !important;
    min-width: 260px;
    max-width: 320px;
}

.mapboxgl-popup-tip {
    border-top-color: white !important;
}

.mapboxgl-popup-close-button {
    color: var(--text-secondary) !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    width: 28px !important;
    height: 28px !important;
    line-height: 24px !important;
    text-align: center !important;
    padding: 0 !important;
    top: 8px !important;
    right: 8px !important;
    background: var(--bg-secondary) !important;
    border-radius: 50% !important;
    border: 2px solid var(--bg-accent) !important;
    transition: all 0.2s ease !important;
    z-index: 10;
}

.mapboxgl-popup-close-button:hover {
    background: var(--primary-orange) !important;
    color: white !important;
    border-color: var(--primary-orange) !important;
}

.popup-content {
    text-align: center;
}

.popup-photo {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 12px;
    border: 2px solid var(--bg-accent);
}

.popup-name {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary-orange);
}

.popup-location {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 12px;
    font-weight: 600;
}

.popup-link {
    display: inline-block;
    background: var(--gradient-primary);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 700;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(232, 112, 78, 0.25);
}

.popup-link:hover {
    box-shadow: 0 4px 16px rgba(232, 112, 78, 0.4);
}

/* ===== SCROLLBAR STYLING ===== */
.map-sidebar::-webkit-scrollbar,
.location-list::-webkit-scrollbar {
    width: 6px;
}

.map-sidebar::-webkit-scrollbar-track,
.location-list::-webkit-scrollbar-track {
    background: transparent;
}

.map-sidebar::-webkit-scrollbar-thumb,
.location-list::-webkit-scrollbar-thumb {
    background: var(--bg-accent);
    border-radius: 3px;
}

.map-sidebar::-webkit-scrollbar-thumb:hover,
.location-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-orange-light);
}

.map-sidebar,
.location-list {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-accent) transparent;
}

.location-list {
    overflow-y: auto;
    overflow-x: hidden;
}

.location-list::-webkit-scrollbar-thumb {
    background: transparent;
}

.location-list:hover::-webkit-scrollbar-thumb {
    background: var(--bg-accent);
}

.location-list:hover::-webkit-scrollbar-thumb:hover {
    background: var(--primary-orange-light);
}

/* ===== LOADING STATE ===== */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 1000;
    background: white;
    padding: 40px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 2px solid var(--bg-accent);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--bg-accent);
    border-top-color: var(--primary-orange);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ===== MARKER CLUSTERS ===== */
.cluster-small {
    background: var(--primary-orange) !important;
}

.cluster-medium {
    background: var(--accent-teal) !important;
}

.cluster-large {
    background: #8b5cf6 !important;
}

/* ===== STORY MODAL ===== */
.story-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 21, 20, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.story-modal {
    background: white;
    border: 2px solid var(--bg-accent);
    border-radius: 20px;
    max-width: 480px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-2xl);
    animation: storyModalIn 0.25s ease;
}

@keyframes storyModalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.story-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border: 2px solid var(--bg-accent);
    border-radius: 50%;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    line-height: 1;
}

.story-modal-close:hover {
    background: var(--primary-orange);
    color: white;
    border-color: var(--primary-orange);
}

.story-modal-body {
    padding: 28px;
}

.story-modal-photo {
    width: 100%;
    max-height: 250px;
    object-fit: cover;
    border-radius: 16px;
    margin-bottom: 16px;
    border: 2px solid var(--bg-accent);
}

.story-modal-name {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-orange);
    text-align: center;
    margin-bottom: 4px;
    font-family: var(--font-heading);
}

.story-modal-owner {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
    margin-bottom: 16px;
}

.story-modal-text {
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.story-modal-footer {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--bg-accent);
}

@media (max-width: 768px) {
    .story-modal {
        max-width: 95vw;
        max-height: 85vh;
        border-radius: 18px;
    }
    
    .story-modal-body {
        padding: 20px;
    }
    
    .story-modal-name {
        font-size: 1.25rem;
    }
}

/* ===== RESPONSIVE - MOBILE ===== */
@media (max-width: 768px) {
    .map-sidebar {
        width: 100%;
        max-height: 50vh;
        border-left: none;
        border-top: 2px solid var(--bg-accent);
        position: relative;
        transition: max-height 0.3s ease;
    }

    /* Scroll indicator: fade gradient at bottom when more filters below */
    .map-sidebar:not(.collapsed)::after {
        content: '';
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        height: 40px;
        background: linear-gradient(to bottom, transparent, var(--bg-secondary, #FAF5F0));
        pointer-events: none;
        display: block;
        z-index: 5;
    }

    /* Hide fade when scrolled to bottom (JS adds this class) */
    .map-sidebar.scrolled-bottom::after {
        display: none;
    }

    .map-sidebar.collapsed {
        max-height: 56px;
        overflow: hidden;
    }

    .map-sidebar.collapsed .sidebar-section {
        display: none;
    }

    .map-sidebar.collapsed .sidebar-toggle-bar {
        display: flex;
    }

    .sidebar-toggle-bar {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 16px;
        cursor: pointer;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--bg-accent);
        gap: 8px;
        font-weight: 700;
        color: var(--primary-orange);
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .sidebar-toggle-bar:hover {
        background: var(--bg-accent);
    }

    .sidebar-toggle-bar .toggle-icon {
        transition: transform 0.3s ease;
    }

    .map-sidebar:not(.collapsed) .sidebar-toggle-bar .toggle-icon {
        transform: rotate(180deg);
    }

    .map-content {
        flex-direction: column-reverse;
    }

    .stats-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }

    .stat-card {
        padding: 8px 12px;
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        gap: 6px;
        border-radius: var(--radius-full);
    }

    .stat-value {
        font-size: 1.1rem;
        margin-bottom: 0;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .sidebar-section {
        padding: 12px 16px;
    }

    .sidebar-section h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    .filter-buttons {
        gap: 6px;
    }

    .filter-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .location-list {
        max-height: 150px;
    }

    .location-item {
        padding: 8px 10px;
        margin-bottom: 6px;
    }

    .map-controls {
        display: none;
    }
}

/* Hide toggle bar on desktop */
@media (min-width: 769px) {
    .sidebar-toggle-bar {
        display: none;
    }
}
