/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* Use stable viewport height */
    height: 100vh; /* Fixed height for mobile stability */
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    flex-wrap: nowrap; /* This is the key to prevent wrapping */
    gap: 1rem; /* Add a gap to ensure spacing */
}

.app-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    flex-wrap: nowrap; /* This is the key to prevent wrapping */
    gap: 1rem; /* Add a gap to ensure spacing */
}

.app-header h2 i {
    margin-right: 0.5rem;
    color: #ffd700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-radius {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    color: white;
}

.search-radius select {
    padding: 0.25rem 0.5rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 0.9rem;
}

.location-status {
    display: flex;
    align-items: center;
    font-size: 0.75rem; /* Smaller font */
    background: rgba(255,255,255,0.2);
    padding: 0.3rem 0.6rem; /* Reduced padding */
    border-radius: 12px; /* Smaller border radius */
    backdrop-filter: blur(10px);
    max-width: fit-content; /* Only take up as much space as needed */
    margin-left: auto; /* Push to the right side */
}

.location-status i {
    margin-right: 0.5rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1; /* Take remaining space after header */
    max-height: calc(100vh - 60px); /* Use stable viewport height */
    overflow: hidden; /* Prevent expansion beyond viewport */
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
    background: #e0e0e0;
    min-height: 0; /* Allow flexbox to work properly */
    max-height: 100%; /* Prevent expansion beyond parent */
}

.map {
    width: 100%;
    height: 100%;
    min-height: 200px; /* Ensure minimum height for proper rendering */
}

/* Map Controls */
.map-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}

.control-btn {
    width: 40px;
    height: 40px;
    background: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #667eea;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

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

/* Stops Panel */
.stops-panel {
    width: 350px;
    background: white;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 1.2rem;
    color: #333;
    display: flex;
    align-items: center;
}

.panel-header h2 i {
    margin-right: 0.5rem;
    color: #667eea;
}


/* Stops List */
.stops-list {
    flex: 1;
    overflow-y: auto; /* Restore scrolling to contain stops within panel */
    padding: 1rem;
    max-height: 100%; /* Ensure it doesn't exceed parent height */
}

.loading-message {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #666;
    font-style: italic;
}

.loading-message i {
    margin-right: 0.5rem;
    color: #667eea;
}

.stop-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    cursor: pointer;
}

.stop-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.stop-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.stop-name {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.stop-distance {
    background: #667eea;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.stop-routes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.stop-meta {
    display: none; /* Hidden by default */
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.route-badge {
    display: inline-flex;
    align-items: center;
    background: #099741;
    color: white;
    padding: 0.2rem 0.5rem;
    margin: 0.1rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    gap: 0.4rem;
}

.route-code {
    font-weight: bold;
}


.route-eta {
    font-size: 0.7rem;
    color: #e0e0e0;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.1rem 0.3rem;
    border-radius: 8px;
    white-space: nowrap;
}

.route-eta.loading {
    animation: pulse 1.5s infinite ease-in-out;
}

.route-eta.updating {
    animation: subtle-pulse 2s infinite ease-in-out;
}

@keyframes subtle-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.stop-coordinates {
    font-size: 0.8rem;
    color: #999;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.loading-content i {
    font-size: 2rem;
    color: #667eea;
    margin-bottom: 1rem;
}

.loading-content p {
    font-size: 1.1rem;
    color: #333;
}

/* Error States */
.error-message {
    background: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem;
    text-align: center;
}

.no-stops-message {
    text-align: center;
    padding: 2rem;
    color: #666;
}

.no-stops-message i {
    font-size: 3rem;
    color: #ddd;
    margin-bottom: 1rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        max-height: calc(100vh - 60px); /* Use stable viewport height */
    }
    
    .stops-panel {
        width: 100%;
        height: 60vh; /* Fixed CSS height - no JS needed */
        border-left: none;
        border-top: 1px solid #e0e0e0;
        position: relative; /* Needed for resizer positioning */
        transition: height 0.4s ease; /* Smooth transition */
        flex-shrink: 0; /* Prevent panel from shrinking */
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Ensure scrolling stays within panel */
    }

    .map-container {
        transition: height 0.4s ease; /* Smooth transition */
        height: 40vh; /* Fixed CSS height - no JS needed */
        flex-shrink: 0; /* Prevent map from shrinking */
    }

    .panel-resizer {
        position: absolute;
        top: -10px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 20px;
        background: #f8f9fa;
        border: 1px solid #e0e0e0;
        border-radius: 10px 10px 0 0;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #667eea;
        z-index: 10;
    }

    .panel-resizer i {
        transition: transform 0.4s ease;
    }

    /* Collapsed state */
    .main-content.map-collapsed .map-container {
        height: 25vh; /* Fixed CSS height for collapsed state */
    }

    .main-content.map-collapsed .stops-panel {
        height: 75vh; /* Fixed CSS height for collapsed state */
    }

    .main-content.map-collapsed .panel-resizer i {
        transform: rotate(180deg);
    }
    
    
    .app-header {
        padding: 0.75rem;
        font-size: 1.0rem;
    }
    
    .app-header h1 {
        font-size: 1.2rem;
    }
    
    
    .panel-header {
        padding: 0.75rem;
    }
    
    .stops-list {
        padding: 0.75rem;
    }
}

/* --- Styles for Stop Items and Route Badges (GLOBAL) --- */

/* General item styling and highlighting */
.stop-item.highlighted {
    border-color: #667eea !important;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2) !important;
    background: #f8f9ff !important;
}
.stop-item.expanded {
    background-color: #f8f9ff;
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Header within a stop item */
.expand-indicator {
    color: #667eea;
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

/* Meta info (distance, walking time) - shown when expanded */
.stop-item.expanded .stop-meta {
    display: flex;
}

/* This rule is no longer needed as coordinates are inside stop-meta */
.walking-time {
    font-size: 0.8rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* --- Forceful Styles for Stop Item Expansion --- */

/* By default, the expanded list is ALWAYS hidden. */
.routes-expanded {
    display: none !important;
}

/* By default, the collapsed list is ALWAYS visible. */
.routes-collapsed {
    display: block !important;
}

/* When the parent .stop-item is expanded... */
.stop-item.expanded .routes-collapsed {
    /* ...FORCE the collapsed list to hide. */
    display: none !important;
}

.stop-item.expanded .routes-expanded {
    /* ...and FORCE the expanded list to appear as a flex container. */
    display: flex !important;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #e0e0e0;
}

/* Individual route badge styling */
.no-routes {
    color: #999;
    font-style: italic;
    font-size: 0.8rem;
}
.routes-collapsed .route-badge {
    cursor: default;
}

/* Expanded route item details */
.route-detail-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.route-destination {
    font-size: 0.8rem;
    color: #555;
}

/* --- Modal Styles --- */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal-overlay:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
}

.modal-header .route-direction {
    font-size: 0.9rem;
    color: #4b5563;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.modal-header .route-direction[style*="cursor: pointer"]:hover {
    background-color: #f3f4f6;
}

.modal-header .route-direction i {
    margin-left: 0.5rem;
    color: #667eea;
}

.modal-close {
    border: none;
    background: none;
    font-size: 1.75rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    color: #6b7280;
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
}

.modal-body ol {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.modal-body li {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
}

.modal-body li:last-child {
    border-bottom: none;
}

.modal-body li .stop-seq {
    font-size: 0.8rem;
    font-weight: bold;
    color: #667eea;
    background: #eef2ff;
    border-radius: 50%;
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.modal-body li.current-stop {
    background: #eef2ff;
    font-weight: bold;
    color: #4338ca;
    border-radius: 4px;
}

.modal-body .loading-spinner {
    text-align: center;
    padding: 2rem;
    font-size: 1.5rem;
    color: #667eea;
}

/* --- Search Container Styles --- */
.search-container {
    position: absolute;
    top: -60px;
    left: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: top 0.3s ease-in-out;
    overflow: visible;
}
.search-container:not(.hidden) { top: 1rem; }
#addressSearch { flex-grow: 1; padding: 0.75rem; border: none; background: transparent; font-size: 1rem; outline: none; }
.search-container #searchBtn { border-radius: 0 8px 8px 0; width: 50px; height: auto; box-shadow: none; }
.search-results { position: absolute; top: 100%; left: 0; right: 0; background: white; border-radius: 0 0 8px 8px; box-shadow: 0 8px 10px rgba(0,0,0,0.15); max-height: 300px; overflow-y: auto; z-index: -1; }
.search-result-item { padding: 0.75rem; border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f8f9ff; }

/* --- ETA Breathing Animation --- */
@keyframes breathing {
  0% { background-color: rgba(0, 0, 0, 0.2); }
  50% { background-color: rgba(255, 165, 0, 0.6); }
  100% { background-color: rgba(0, 0, 0, 0.2); }
}

.eta-breathing {
  animation: breathing 2s infinite ease-in-out;
}

.operating-hours {
	font-size: 0.8rem;
	color: #ccc; 
	margin-top: 0.25rem; 
	display: flex; 
	align-items: center; 
	gap: 0.4rem; 
}