/* ==================== MOBILE-FIRST STYLES ==================== */
/* Mobile container - hidden on desktop */
.mobile-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: transparent;
    overflow: hidden;
    z-index: 9999;
}

/* Show mobile container only on mobile */
@media (max-width: 768px) and (orientation: portrait) {
    .mobile-container {
        display: flex;
        flex-direction: column;
        background: rgba(0, 0, 0, 0.3); /* Semi-transparent overlay */
    }
    
    /* Hide desktop container on mobile */
    .app-container {
        display: none !important;
    }
}


/* Updated Mobile KPI Section - FIXED TEXT OVERFLOW */
.mobile-kpi-section {
    height: 14vh;
    min-height: 80px;
    max-height: 100px;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.8rem 1rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.mobile-kpi-grid {
    display: flex;
    gap: 0.75rem;
    height: 100%;
    align-items: center;
    width: 100%;
}

.mobile-kpi-card {
    flex: 1;
    background: rgba(22, 27, 34, 0.9);
    border-radius: 12px;
    padding: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 100%;
    min-height: 60px;
    transition: transform 0.2s ease;
    overflow: hidden;
    min-width: 0; /* CRITICAL FIX: Allows child to shrink */
}

.mobile-kpi-card:active {
    transform: scale(0.98);
}

.mobile-kpi-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    color: #fbbf24;
    width: 30px;
    text-align: center;
}

.mobile-kpi-content {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    overflow: hidden;
    flex: 1;
    min-width: 0; /* CRITICAL FIX: Allows text to truncate */
}

.mobile-kpi-value {
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.5px;
}

.mobile-kpi-label {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Responsive font sizes for very small screens */
@media (max-width: 360px) {
    .mobile-kpi-value {
        font-size: 1.2rem;
    }
    
    .mobile-kpi-label {
        font-size: 0.7rem;
    }
}

@media (max-height: 600px) {
    .mobile-kpi-value {
        font-size: 1.1rem;
    }
}

/* Mobile Segmented Control - 8-9% of screen height */
.mobile-segmented-control {
    height: 8vh;
    min-height: 50px;
    max-height: 60px;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    padding: 0.4rem 1rem;
    gap: 0.5rem;
    flex-shrink: 0;
    align-items: center;
}

.mobile-segment {
    flex: 1;
    height: 100%;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(22, 27, 34, 0.9);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    transition: all 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
}

.mobile-segment:active {
    transform: scale(0.95);
}

.mobile-segment.active {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
}

.segment-icon {
    font-size: 1rem;
}

.segment-label {
    font-size: 0.7rem;
    letter-spacing: 0.3px;
}

/* Mobile Search Section - 8-10% of screen height - UPDATED FOR Z-INDEX */
.mobile-search-section {
    height: 9vh;
    min-height: 60px;
    max-height: 70px;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.8rem 1rem;
    flex-shrink: 0;
    position: relative;
    /* Ensure this container doesn't clip children */
    overflow: visible !important;
    z-index: 10002; /* Higher than container */
}

.mobile-search-container {
    display: flex;
    gap: 0.5rem;
    height: 100%;
    position: relative;
    z-index: 10003;
}

.mobile-search-input {
    flex: 1;
    background: rgba(22, 27, 34, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 0 1rem;
    color: #ffffff;
    font-size: 0.9rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-appearance: none;
    appearance: none;
    z-index: 10004;
}

.mobile-search-input:focus {
    outline: none;
    border-color: #dc2626;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2);
}

.mobile-search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.mobile-search-btn {
    width: 44px;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10004;
}

.mobile-search-btn:active {
    transform: scale(0.95);
}

/* UPDATED: Search Results - HIGHEST Z-INDEX */
.mobile-search-results {
    position: absolute;
    top: 100% !important;
    left: 0;
    right: 0;
    background: rgba(22, 27, 34, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 10050 !important; /* HIGHEST Z-INDEX - ABOVE EVERYTHING */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
    display: none;
    margin-top: 1px;
}

.mobile-search-result {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: background 0.2s ease;
}

.mobile-search-result:last-child {
    border-bottom: none;
}

.mobile-search-result:hover,
.mobile-search-result:active {
    background: rgba(255, 255, 255, 0.05);
}

.mobile-search-result .route-name {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.15rem;
    font-size: 0.85rem;
}

.mobile-search-result .route-delay {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
}

/* Mobile Map Section - Remaining space */
.mobile-map-section {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: transparent;
    /* Ensure map stays below search results */
    z-index: 1;
}

.mobile-map {
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: pan-x pan-y;
}

.mobile-map:active {
    cursor: grabbing;
}

/* Mobile route lines - thinner for mobile */
.mobile-route-line {
    stroke-width: 3 !important;
}



/* Mobile About Content */
.mobile-about-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 17, 23, 0.95);
    backdrop-filter: blur(20px);
    overflow-y: auto;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
}

.mobile-about-content.active {
    transform: translateX(0);
}

.mobile-about-inner {
    padding: 1rem;
    padding-top: 0;
}

.mobile-about-back {
    position: sticky;
    top: 0;
    background: rgba(22, 27, 34, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    z-index: 10;
}

.mobile-about-back-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #ffffff;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mobile-about-back-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

.mobile-about-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    flex: 1;
}

.mobile-about-section {
    background: rgba(22, 27, 34, 0.7);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-about-section h2 {
    font-size: 1rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 0.75rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mobile-about-section p {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.5;
    margin: 0 0 0.5rem 0;
}

.mobile-about-section p:last-child {
    margin-bottom: 0;
}

.mobile-about-section ul {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.mobile-about-section li {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.5;
    margin-bottom: 0.25rem;
}

.mobile-about-section a {
    color: #fbbf24;
    text-decoration: none;
    font-weight: 500;
}

.mobile-about-section a:hover,
.mobile-about-section a:active {
    text-decoration: underline;
}

.support-section {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.1), rgba(251, 191, 36, 0.1));
    border-color: rgba(220, 38, 38, 0.3);
}

.mobile-coffee-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.85rem;
    text-decoration: none;
    margin-top: 0.75rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mobile-coffee-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}



/* Loading and Error States */
.mobile-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.mobile-loading-content {
    text-align: center;
}

.mobile-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #dc2626;
    border-radius: 50%;
    animation: mobile-spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.mobile-error-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.mobile-error-content {
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    max-width: 300px;
}

.mobile-error-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.mobile-error-message {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Responsive Adjustments */
@media (max-width: 360px) {
    .mobile-kpi-value {
        font-size: 1.2rem;
    }
    
    .mobile-kpi-label {
        font-size: 0.7rem;
    }
}

@media (max-height: 600px) {
    .mobile-kpi-value {
        font-size: 1.1rem;
    }
}

/* iOS Safe Areas */
@supports (padding: max(0px)) {
    .mobile-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .mobile-kpi-section,
    .mobile-segmented-control,
    .mobile-search-section {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .mobile-about-back {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .mobile-legend-toggle {
        left: max(1rem, env(safe-area-inset-left));
        bottom: max(1.5rem, env(safe-area-inset-bottom) + 0.5rem);
    }
}

/* Prevent text selection on mobile */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    input, textarea {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .mobile-container *,
    .mobile-container *::before,
    .mobile-container *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Custom scrollbar for mobile */
.mobile-legend-content::-webkit-scrollbar,
.mobile-about-content::-webkit-scrollbar {
    width: 4px;
}

.mobile-legend-content::-webkit-scrollbar-track,
.mobile-about-content::-webkit-scrollbar-track {
    background: transparent;
}

.mobile-legend-content::-webkit-scrollbar-thumb,
.mobile-about-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Mobile Popup Styling - Ensure these are in mobile.css */
.mobile-route-popup {
    max-width: 280px !important;
    background: rgba(22, 27, 34, 0.95) !important;
    backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 12px !important;
    padding: 0.8rem !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4) !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

.mobile-route-popup .leaflet-popup-content-wrapper {
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
}

.mobile-route-popup .leaflet-popup-content {
    margin: 0 !important;
    line-height: 1.4 !important;
    font-size: 0.9rem !important;
}

.mobile-route-popup .mobile-popup-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.mobile-route-popup .mobile-popup-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    flex: 1;
    line-height: 1.2;
}

.mobile-route-popup .mobile-popup-content {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.mobile-route-popup .mobile-popup-actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.mobile-route-popup .mobile-popup-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #ffffff;
    padding: 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.mobile-route-popup .mobile-popup-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

.mobile-about-content.active {
    z-index: 90050 !important;
}