/* styles.css - Polished Version */
:root {
    --primary-blue: #0057a3;
    --primary-dark: #1a237e;
    --primary-light: #4f7cac;
    --accent-red: #e53935;
    --accent-green: #43a047;
    --accent-orange: #ff9800;
    --text-dark: #2c3e50;
    --text-medium: #546e7a;
    --text-light: #78909c;
    --background-light: #f8f9fa;
    --background-medium: #eef2f6;
    --background-dark: #e8eaf6;
    --border-light: #e0e0e0;
    --border-medium: #b0bec5;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-heavy: 0 8px 24px rgba(0, 0, 0, 0.16);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition: all 0.25s ease;
}

* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text-dark);
    background-color: var(--background-light);
    line-height: 1.5;
}

#map {
    height: 100vh;
    width: 100%;
}

/* Top search container */
.top-search-container {
    position: fixed;
    top: 20px;
    right: 80px;
    z-index: 999;
    width: 340px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-heavy);
    padding: 14px;
    transition: var(--transition);
}

.search-controls {
    display: flex;
    gap: 10px;
}

#top-station-search {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-sizing: border-box;
    transition: var(--transition);
    background: var(--background-light);
}

#top-station-search:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 87, 163, 0.1);
}

#line-filter {
    padding: 12px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: white;
    cursor: pointer;
    min-width: 110px;
    transition: var(--transition);
    background: var(--background-light);
}

#line-filter:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 87, 163, 0.1);
}

#top-search-results {
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-top: 10px;
    display: none;
    position: absolute;
    width: calc(100% - 28px);
    background: white;
    z-index: 1000;
    box-shadow: var(--shadow-medium);
}

/* Modern, accessible popup styling */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-heavy);
}

.leaflet-popup-content {
    margin: 20px;
    font-size: 15px;
    line-height: 1.6;
    min-width: 240px;
}

.station-header {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary-blue);
    margin-bottom: 15px;
    display: block;
    border-bottom: 2px solid var(--border-light);
    padding-bottom: 12px;
}

.train-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--background-medium);
    transition: var(--transition);
}

.train-line:hover {
    background-color: var(--background-light);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin: 4px -12px;
}

.train-line:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.destination {
    font-weight: 600;
    color: var(--text-dark);
    flex-grow: 1;
    padding-right: 10px;
}

.arrival-time {
    font-weight: 700;
    color: var(--accent-red);
    font-feature-settings: "tnum";
    background: var(--background-light);
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 13px;
}

.loading-text {
    color: var(--text-light);
    font-style: italic;
    text-align: center;
    padding: 16px;
}

/* --- Sidebar Styles --- */
#sidebar {
    position: fixed;
    top: 0;
    right: 0;
    left: auto;
    height: 100%;
    width: 340px;
    background: #fff;
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#sidebar.active {
    transform: translateX(0);
}

.sidebar-content {
    padding: 20px;
    flex: 1;
}

.sidebar-content h3 {
    color: var(--primary-blue);
    margin-top: 0;
    border-bottom: 2px solid var(--border-light);
    padding-bottom: 14px;
    font-size: 20px;
}

/* --- Menu Toggle Button --- */
.menu-toggle-button {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-heavy);
    transition: var(--transition);
}

.menu-toggle-button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

/* Search result items */
.search-result-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--background-medium);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-result-item:before {
    content: "•";
    color: var(--primary-blue);
    font-size: 18px;
}

.search-result-item:hover {
    background-color: var(--background-dark);
}

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

/* Custom marker styling */
.custom-line-icon {
    background: transparent !important;
    border: none !important;
}

/* Location button styles */
.locate-button {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 1000;
    background-color: white;
    border: none;
    border-radius: 50%;
    width: 54px;
    height: 54px;
    box-shadow: var(--shadow-heavy);
    cursor: pointer;
    font-size: 20px;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.locate-button:hover {
    background-color: var(--background-light);
    transform: translateY(-2px);
    color: var(--primary-blue);
}

/* Nearest stations list */
.nearest-stations {
    margin-top: 20px;
    padding: 0;
}

.nearest-station-item {
    padding: 14px;
    margin: 8px 0;
    background-color: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-light);
    border-left: 4px solid var(--primary-blue);
    transition: var(--transition);
}

.nearest-station-item:hover {
    background-color: var(--background-dark);
    transform: translateX(-4px);
    box-shadow: var(--shadow-medium);
}

.distance-badge {
    background-color: var(--primary-blue);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 600;
}

.user-location-marker {
    background-color: var(--primary-dark);
    border: 3px solid white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    box-shadow: var(--shadow-heavy);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Chatbot Styles */
.chatbot-container {
    position: fixed;
    bottom: 90px;
    right: 25px;
    z-index: 1000;
    width: 380px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-heavy);
    display: none;
    flex-direction: column;
    max-height: 460px;
    overflow: hidden;
    transition: var(--transition);
}

.chatbot-container.active {
    display: flex;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.chatbot-header {
    background: var(--primary-blue);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
}

.chatbot-title {
    font-weight: 600;
    font-size: 16px;
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
    opacity: 0.8;
    transition: var(--transition);
    padding: 4px;
    border-radius: 50%;
}

.chatbot-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    max-height: 340px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--background-light);
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    box-shadow: var(--shadow-light);
}

.message.user {
    align-self: flex-end;
    background: var(--primary-blue);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.bot {
    align-self: flex-start;
    background: white;
    color: var(--text-dark);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--border-light);
}

.chatbot-input {
    display: flex;
    padding: 16px 20px;
    border-top: 1px solid var(--border-light);
    background: white;
}

.chatbot-input input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-light);
    border-radius: 24px;
    outline: none;
    font-size: 14px;
    transition: var(--transition);
}

.chatbot-input input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 87, 163, 0.1);
}

.chatbot-input button {
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    margin-left: 10px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-input button:hover {
    background: var(--primary-dark);
    transform: rotate(15deg);
}

.chatbot-toggle {
    position: fixed;
    bottom: 150px;
    right: 25px;
    z-index: 1000;
    background-color: var(--primary-blue);
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    box-shadow: var(--shadow-heavy);
    cursor: pointer;
    font-size: 22px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.chatbot-toggle:hover {
    background-color: var(--primary-dark);
    transform: translateY(-4px);
}

.route-suggestion {
    background: #e8f4ff;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 8px;
    border-left: 4px solid var(--primary-blue);
}

.route-step {
    margin: 8px 0;
    display: flex;
    align-items: flex-start;
}

.route-icon {
    margin-right: 10px;
    min-width: 20px;
    color: var(--primary-blue);
    font-size: 16px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Mobile responsiveness improvements */
@media (max-width: 768px) {
    .top-search-container {
        width: calc(100% - 30px);
        left: 15px;
        right: 15px;
        top: 15px;
        padding: 12px;
    }
    
    .search-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    #top-station-search, #line-filter {
        width: 100%;
        padding: 12px;
        font-size: 16px;
    }
    
    #sidebar {
        width: 85%;
    }
    
    .menu-toggle-button {
        top: 15px;
        right: 15px;
        padding: 10px 12px;
    }
    
    /* Adjust location button for mobile */
    .locate-button {
        bottom: 80px;
        right: 20px;
        width: 50px;
        height: 50px;
    }
    
    /* Improve popup for mobile */
    .leaflet-popup-content {
        margin: 16px;
        font-size: 14px;
        min-width: 200px;
    }
    
    .station-header {
        font-size: 17px;
    }
    
    /* Chatbot adjustments for mobile */
    .chatbot-container {
        width: 90%;
        right: 15px;
        bottom: 85px;
        max-height: 55vh;
    }
    
    .chatbot-toggle {
        bottom: 150px;
        right: 20px;
    }
}

@media (max-width: 480px) {
    .top-search-container {
        width: calc(100% - 20px);
        left: 10px;
        right: 10px;
    }
    
    .locate-button {
        bottom: 75px;
        right: 15px;
    }
    
    /* Improve touch targets for mobile */
    .search-result-item, .nearest-station-item {
        padding: 14px;
        min-height: 24px;
    }
    
    /* Better spacing for mobile sidebar */
    .sidebar-content {
        padding: 16px;
    }
}

/* Special fix for very small screens */
@media (max-width: 360px) {
    .top-search-container {
        width: calc(100% - 16px);
        left: 8px;
        right: 8px;
    }
    
    #top-station-search, #line-filter {
        font-size: 14px;
        padding: 10px;
    }
    
    .locate-button {
        width: 46px;
        height: 46px;
        font-size: 18px;
    }
}

/* Prevent zoom on input focus for iOS */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* Animation for loading states */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.train-line, .search-result-item, .nearest-station-item {
    animation: fadeIn 0.3s ease;
}

/* Focus states for accessibility */
button:focus, input:focus, select:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}