/**
 * FGC Maps Integration - Leaflet/OpenStreetMap Styling
 * Comprehensive map styles with FGC branding, dark mode, and mobile optimization
 */

/* ============================================================================
   MAP BUTTON & MODAL OVERLAY
   ============================================================================ */

.map-btn {
    background: linear-gradient(135deg, #0066B3 0%, #004D87 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 102, 179, 0.2);
    font-family: 'Montserrat', sans-serif;
}

.map-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 102, 179, 0.3);
    background: linear-gradient(135deg, #0077CC 0%, #005599 100%);
}

.map-btn:active {
    transform: translateY(0);
}

.map-btn .icon {
    font-size: 18px;
}

/* Map Modal Overlay */
.map-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.map-modal-overlay.active {
    display: flex;
    opacity: 1;
}

.map-modal-overlay.closing {
    opacity: 0;
}

/* ============================================================================
   MAP CONTAINER
   ============================================================================ */

.map-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    background: #FFFFFF;
    overflow: hidden;
}

#fgcMap {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ============================================================================
   MAP CONTROLS & TOOLBAR
   ============================================================================ */

.map-toolbar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 12px 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 90%;
}

.map-toolbar h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #1A1A1A;
    font-family: 'Montserrat', sans-serif;
}

.map-close-btn {
    background: #E31937;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Montserrat', sans-serif;
}

.map-close-btn:hover {
    background: #C01530;
    transform: scale(1.05);
}

/* Map Action Buttons */
.map-actions {
    position: absolute;
    bottom: 30px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.map-action-btn {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: 12px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    font-size: 20px;
}

.map-action-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.map-action-btn:active {
    transform: scale(0.95);
}

.map-action-btn.active {
    background: #88BB0B;
    color: white;
}

/* ============================================================================
   CUSTOM MARKERS
   ============================================================================ */

.fgc-marker {
    background: transparent;
    border: none;
}

.fgc-marker-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    border: 3px solid white;
    position: relative;
    transition: all 0.2s ease;
}

.fgc-marker-icon:hover {
    transform: scale(1.2);
    z-index: 999;
}

/* Current station marker pulse animation */
.fgc-marker-current .fgc-marker-icon {
    width: 40px;
    height: 40px;
    font-size: 14px;
    animation: pulse 2s infinite;
    border-width: 4px;
    box-shadow: 0 0 0 0 rgba(136, 187, 11, 0.7);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(136, 187, 11, 0.7);
    }
    50% {
        box-shadow: 0 0 0 15px rgba(136, 187, 11, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(136, 187, 11, 0);
    }
}

/* Line-specific marker colors */
.marker-L6 { background: #F7941D; }
.marker-L7 { background: #8B4513; }
.marker-L8 { background: #E31937; }
.marker-S1 { background: #88BB0B; }
.marker-S2 { background: #0066B3; }
.marker-R5 { background: #9B59B6; }
.marker-R6 { background: #E74C3C; }
.marker-R50 { background: #95A5A6; }
.marker-R53 { background: #F39C12; }
.marker-R60 { background: #16A085; }
.marker-R63 { background: #2980B9; }
.marker-S3 { background: #27AE60; }
.marker-S4 { background: #E67E22; }
.marker-S8 { background: #8E44AD; }
.marker-S9 { background: #C0392B; }
.marker-RL1 { background: #1ABC9C; }
.marker-RL2 { background: #34495E; }
.marker-MM { background: #D35400; }

/* ============================================================================
   CUSTOM POPUP STYLING
   ============================================================================ */

.leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 2px solid #E0E0E0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 280px;
    font-family: 'Montserrat', sans-serif;
}

.map-popup-header {
    background: linear-gradient(135deg, #88BB0B 0%, #6A9308 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.map-popup-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.map-popup-lines {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.map-popup-line-badge {
    background: white;
    color: #1A1A1A;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}

.map-popup-body {
    padding: 16px 20px;
}

.map-popup-departure {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #E0E0E0;
}

.map-popup-departure:last-child {
    border-bottom: none;
}

.map-popup-destination {
    font-weight: 600;
    color: #1A1A1A;
    font-size: 14px;
}

.map-popup-time {
    color: #666;
    font-size: 13px;
}

.map-popup-countdown {
    background: #88BB0B;
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 13px;
}

.map-popup-no-departures {
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 12px 0;
}

.map-popup-select-btn {
    background: #0066B3;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    width: 100%;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 12px;
    font-family: 'Montserrat', sans-serif;
}

.map-popup-select-btn:hover {
    background: #0077CC;
    transform: translateY(-1px);
}

/* ============================================================================
   LINE ROUTES
   ============================================================================ */

.fgc-line-route {
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.fgc-line-route:hover {
    opacity: 1;
    stroke-width: 6;
    z-index: 998;
}

/* ============================================================================
   LEGEND & INFO BOX
   ============================================================================ */

.map-legend {
    position: absolute;
    bottom: 30px;
    left: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    max-width: 300px;
}

.map-legend h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 700;
    color: #1A1A1A;
}

.map-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.map-legend-item:last-child {
    margin-bottom: 0;
}

.map-legend-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.map-legend-label {
    font-size: 13px;
    color: #333;
    font-weight: 500;
}

/* ============================================================================
   LOADING STATE
   ============================================================================ */

.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 30px 40px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.map-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #E0E0E0;
    border-top-color: #88BB0B;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

.map-loading-text {
    font-size: 16px;
    font-weight: 600;
    color: #1A1A1A;
}

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

/* ============================================================================
   DARK MODE
   ============================================================================ */

body.dark-mode .map-modal-content {
    background: #1A1A1A;
}

body.dark-mode .map-toolbar {
    background: rgba(42, 42, 42, 0.95);
}

body.dark-mode .map-toolbar h2 {
    color: #FFFFFF;
}

body.dark-mode .map-action-btn {
    background: rgba(42, 42, 42, 0.95);
    color: white;
}

body.dark-mode .map-legend {
    background: rgba(42, 42, 42, 0.95);
}

body.dark-mode .map-legend h4,
body.dark-mode .map-legend-label {
    color: #FFFFFF;
}

body.dark-mode .map-loading {
    background: rgba(42, 42, 42, 0.95);
}

body.dark-mode .map-loading-text {
    color: #FFFFFF;
}

body.dark-mode .leaflet-popup-content-wrapper {
    background: #2A2A2A;
    border-color: #444;
}

body.dark-mode .map-popup-body {
    background: #2A2A2A;
}

body.dark-mode .map-popup-destination {
    color: #FFFFFF;
}

body.dark-mode .map-popup-time {
    color: #AAA;
}

body.dark-mode .map-popup-departure {
    border-bottom-color: #444;
}

/* ============================================================================
   MOBILE OPTIMIZATION
   ============================================================================ */

@media (max-width: 768px) {
    .map-toolbar {
        top: 10px;
        padding: 10px 16px;
        max-width: calc(100% - 20px);
    }

    .map-toolbar h2 {
        font-size: 16px;
    }

    .map-close-btn {
        font-size: 13px;
        padding: 6px 12px;
    }

    .map-actions {
        bottom: 20px;
        right: 10px;
        gap: 8px;
    }

    .map-action-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    .map-legend {
        bottom: 20px;
        left: 10px;
        padding: 12px 16px;
        max-width: calc(100% - 90px);
    }

    .map-legend h4 {
        font-size: 13px;
        margin-bottom: 10px;
    }

    .map-legend-label {
        font-size: 12px;
    }

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

    .map-popup-header {
        padding: 12px 16px;
    }

    .map-popup-header h3 {
        font-size: 16px;
    }

    .map-popup-body {
        padding: 12px 16px;
    }

    .map-btn {
        padding: 10px 16px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .map-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .map-legend {
        max-width: calc(100% - 80px);
        font-size: 11px;
    }

    .map-legend-item {
        gap: 8px;
        margin-bottom: 6px;
    }

    .map-legend-color {
        width: 20px;
        height: 20px;
    }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

.map-btn:focus,
.map-close-btn:focus,
.map-action-btn:focus,
.map-popup-select-btn:focus {
    outline: 3px solid #88BB0B;
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .fgc-marker-icon {
        border-width: 4px;
    }

    .map-toolbar,
    .map-action-btn,
    .map-legend {
        border: 2px solid #000;
    }

    body.dark-mode .map-toolbar,
    body.dark-mode .map-action-btn,
    body.dark-mode .map-legend {
        border-color: #FFF;
    }
}

/* ============================================================================
   TOUCH GESTURES OPTIMIZATION
   ============================================================================ */

.leaflet-container {
    touch-action: pan-x pan-y;
}

.leaflet-interactive {
    touch-action: none;
}

/* Larger touch targets for mobile */
@media (hover: none) and (pointer: coarse) {
    .fgc-marker-icon {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }

    .leaflet-popup-close-button {
        width: 30px;
        height: 30px;
        font-size: 20px;
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .map-modal-overlay {
        display: none !important;
    }
}
