:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --accent: #10b981;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --input-bg: #f1f5f9;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-light: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
}


* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}


/* --- Hero Section (Landing Page) --- */
.hero {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 25px 20px 80px;
    /* Extra bottom padding for overlap */
    color: white;
    text-align: center;
    border-radius: 0 0 30px 30px;
}

.hero h1 {
    font-size: 2rem;
    font-weight: 800;
    margin: 0 0 10px;
    letter-spacing: -0.5px;
}

.hero p {
    font-size: 1rem;
    opacity: 0.9;
    margin: 0;
    font-weight: 500;
}

/* --- Search Widget (Landing Page) --- */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 20px;
}

.search-card {
    background: var(--card-bg);
    border-radius: 24px;
    padding: 25px;
    box-shadow: var(--shadow-lg);
    margin-top: -50px;
    /* Overlap Hero */
    position: relative;
    z-index: 10;
}

.form-group {
    margin-bottom: 20px;
    position: relative;
    /* For icon */
    z-index: 1;
    /* Default */
}

.form-group:focus-within {
    z-index: 50;
    /* Bring to front when typing */

}

.form-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 15px;
    color: var(--primary);
    font-size: 1.1rem;
}

.form-input {
    width: 100%;
    padding: 14px 14px 14px 45px;
    /* Space for icon */
    border: 2px solid var(--input-bg);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
    appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--card-bg);
}


.form-row {
    display: flex;
    gap: 15px;
}

.form-row .form-group {
    flex: 1;
}

.btn-search {
    width: 100%;
    padding: 16px;
    background: var(--primary);
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

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

/* --- Autocomplete --- */
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 100;
    max-height: 250px;
    overflow-y: auto;
    margin-top: 5px;
    border: 1px solid var(--border);
}

.autocomplete-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

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

.autocomplete-item:hover {
    background: var(--input-bg);
}

.autocomplete-item strong {
    color: var(--primary-dark);
}


/* --- Results --- */
.results-area {
    margin-top: 30px;
    padding-bottom: 50px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 15px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bus-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
}

.bus-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    background: var(--primary);
}

.bus-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.bus-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}

.bus-type {
    font-size: 0.75rem;
    background: var(--input-bg);
    color: var(--text-light);
    padding: 4px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    font-weight: 600;
}

.bus-route-text {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 2px;
}

.time-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--input-bg);
    padding: 12px;
    border-radius: 12px;
}

.time-group {
    text-align: center;
}

.time-val {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-main);
}

.time-label {
    font-size: 0.7rem;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
}

.duration-arrow {
    color: var(--text-light);
    font-size: 0.9rem;
}

.card-actions {
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stop-count {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.btn-track {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none !important;
    /* Force remove underscore */
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
}

.btn-track:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(59, 130, 246, 0.5);
}

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

/* Swap Button */
.swap-btn {
    position: absolute;
    bottom: -20px;
    right: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--card-bg);
    /* Dynamic */
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    color: var(--primary);
    z-index: 10;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.3s;
}

[data-theme="dark"] .swap-btn {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}


/* --- Maps Button --- */
.btn-maps {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary-light, rgba(59, 130, 246, 0.1));
    color: var(--primary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-maps:hover {
    background: #dbeafe;
    border-color: #bfdbfe;
}

/* Marker Transition */
.smooth-marker {
    transition: transform 1s linear;
}

.leaflet-marker-icon {
    /* General smoothing if class not applied perfectly */
    transition: transform 1s linear;
}

/* --- MOBILE RESPONSIVENESS OVERRIDES --- */
@media (max-width: 767px) {

    /* Adjust Hero for smaller screens */
    .hero {
        padding: 30px 15px 70px;
        /* Reducing top/side padding, keeping bottom for overlap */
        border-radius: 0 0 20px 20px;
    }

    .hero h1 {
        font-size: 1.75rem;
        /* Slightly smaller heading */
    }

    /* Adjust Search Card overlap and spacing */
    .search-card {
        margin-top: -40px;
        padding: 20px 15px;
        /* Tighter padding on mobile */
        border-radius: 20px;
    }

    /* Adjust button sizes for touch */
    .btn-search {
        padding: 14px;
        font-size: 1rem;
    }

    .btn-track {
        padding: 10px 15px;
        width: 100%;
        justify-content: center;
    }

    .card-actions {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .card-actions .stop-count {
        width: 100%;
    }

    /* Ensure modals pickering fits */
    .picker-search-box input {
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }
}

/* --- Multi-Leg Expandable Card --- */
/* --- Multi-Leg Expandable Card --- */
/* --- Multi-Leg Expandable Card --- */
.bus-card.multi-leg {
    border-left: 5px solid #06b6d4;
    /* Cyan-500 */
    background: var(--card-bg);
    /* Match normal cards */
    position: relative;
    overflow: hidden;
}

/* Fix for double color issue: Hide the default blue ::before strip */
.bus-card.multi-leg::before {
    display: none;
}

/* Optional: Add a subtle texture or icon background */
.bus-card.multi-leg::after {
    content: '\f2f8';
    /* map-signs icon */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    right: -20px;
    top: -20px;
    font-size: 8rem;
    opacity: 0.03;
    /* Reduced opacity */
    pointer-events: none;
    z-index: 0;
    color: #06b6d4;
}

/* Specific Overrides for Connected Route Card */
.bus-card.multi-leg .text-highlight {
    color: #0891b2;
    /* Cyan-600 */
    font-weight: 800;
}

.bus-card.multi-leg .btn-track {
    /* Use standard primary button styles */
    background: #06b6d4;
    box-shadow: 0 4px 10px rgba(6, 182, 212, 0.4);
}

.bus-card.multi-leg .btn-track:hover {
    background: #0891b2;
    box-shadow: 0 6px 15px rgba(6, 182, 212, 0.5);
}

.bus-card.multi-leg .btn-toggle-details {
    color: #0891b2;
}

.bus-card.multi-leg .btn-toggle-details:hover {
    background: rgba(6, 182, 212, 0.1);
}

.multi-leg-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 15px;
    background: rgba(6, 182, 212, 0.05);
    /* Cyan tint */
    margin: 15px -20px -20px -20px;
    /* Full width stretch */
    border-top: 1px solid rgba(6, 182, 212, 0.15);
    transition: background 0.2s;
}

.multi-leg-summary:hover {
    background: rgba(6, 182, 212, 0.08);
}

.btn-toggle-details {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

.btn-toggle-details:hover {
    background: rgba(59, 130, 246, 0.1);
}

.leg-details-pane {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    opacity: 0;
    padding: 0;
    margin-top: 0;
}

.leg-details-pane.open {
    max-height: 1000px;
    opacity: 1;
    padding: 15px 0;
    margin-top: 15px;
    border-top: 1px dashed var(--border);
}

.leg-timeline {
    position: relative;
    padding-left: 30px;
}

.leg-timeline::before {
    content: '';
    position: absolute;
    left: 9px;
    /* Centered with dot (20px width / 2 - 1px) */
    top: 10px;
    bottom: 30px;
    /* Stop before last item fully */
    width: 2px;
    background: #cbd5e1;
    /* Lighter grey line */
    z-index: 0;
}

.leg-item {
    position: relative;
    margin-bottom: 20px;
}

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

.leg-dot {
    position: absolute;
    left: -29px;
    /* Adjust based on padding-left of parent (30px) */
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 3px solid #06b6d4;
    z-index: 2;
    box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.15);
    /* Ring effect */
}

.leg-dot.hub {
    border-color: #f59e0b;
}

.leg-info {
    display: flex;
    flex-direction: column;
}

.leg-bus-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #0891b2;
    margin-bottom: 4px;
}

.leg-route-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.leg-times {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 2px;
}

.layover-tag {
    background: #fffbeb;
    color: #b45309;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 15px 0;
    border: 1px dashed #fcd34d;
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.05);
    position: relative;
    z-index: 2;
}

[data-theme="dark"] .layover-tag {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.2);
}