/* --- DESIGN TOKENS --- */
:root {
    --primary: #2563EB;
    --primary-dark: #1E40AF;
    --accent: #F59E0B;
    --bg-body: #F3F4F6;
    --bg-surface: #FFFFFF;
    --bg-muted: #F9FAFB;
    --bg-soft: #F3F4F6;
    --bg-elevated: #FFFFFF;
    --text-main: #111827;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --input-border: #E5E7EB;
    --input-bg: transparent;
    --hover-bg: #F3F4F6;
    --action-bg: #111827;
    --action-bg-hover: #000000;
    --action-text: #FFFFFF;
    --badge-bg: #111827;
    --badge-text: #FFFFFF;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --font-main: 'Plus Jakarta Sans', sans-serif;
    --font-logo: 'Varela Round', sans-serif; /* New Font for Logo */
}

[data-theme="dark"] {
    --primary: #60A5FA;
    --primary-dark: #3B82F6;
    --accent: #FBBF24;
    --bg-body: #0B1220;
    --bg-surface: #111827;
    --bg-muted: #1F2937;
    --bg-soft: #1F2937;
    --bg-elevated: #0F172A;
    --text-main: #F3F4F6;
    --text-secondary: #9CA3AF;
    --border: #374151;
    --input-border: #4B5563;
    --input-bg: transparent;
    --hover-bg: #1F2937;
    --action-bg: #2563EB;
    --action-bg-hover: #1D4ED8;
    --action-text: #FFFFFF;
    --badge-bg: #1D4ED8;
    --badge-text: #FFFFFF;
    --shadow-color: rgba(0, 0, 0, 0.4);
}

/* --- GLOBAL RESET --- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body, html { margin: 0; padding: 0; height: 100%; width: 100%; font-family: var(--font-main); background: var(--bg-body); color: var(--text-main); overflow: hidden; }

/* --- LAYOUT --- */
.app-layout { display: flex; height: 100vh; width: 100vw; position: relative; }

/* --- SIDEBAR --- */
.sidebar {
    width: 420px;
    flex: 0 0 420px;
    min-width: 0;
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    z-index: 20;
    box-shadow: 4px 0 24px var(--shadow-color);
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- SIDEBAR DRAG HANDLE / TOGGLE --- */
.sidebar-handle {
    position: absolute;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    background: var(--bg-surface);
    transition: background 0.2s, color 0.2s;
}

/* Desktop: Side Tab */
@media (min-width: 769px) {
    .sidebar {
        overflow: visible;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), flex-basis 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar-handle {
        top: 50%;
        left: 100%;
        right: auto;
        width: 24px;
        height: 60px;
        border-radius: 0 8px 8px 0;
        border: 1px solid var(--border);
        border-left: none;
        box-shadow: 4px 0 6px rgba(0,0,0,0.05);
        transform: translateY(-50%);
    }
    .sidebar-handle:hover { background: var(--hover-bg); color: var(--primary); }
    
    .sidebar.collapsed {
        width: 0;
        flex-basis: 0;
    }
    .sidebar.collapsed .sidebar-content,
    .sidebar.collapsed .sidebar-header,
    .sidebar.collapsed .bottom-nav {
        opacity: 0;
        pointer-events: none;
    }
    .sidebar.collapsed .sidebar-handle i { transform: rotate(180deg); }
}

/* Mobile: Top Drag Bar */
@media (max-width: 768px) {
    .sidebar-handle {
        top: 0; left: 0; right: 0;
        height: 24px;
        background: transparent;
        width: 100%;
    }
    .sidebar-handle::after {
        content: '';
        width: 40px; height: 5px;
        background: #D1D5DB;
        border-radius: 10px;
        margin-top: 8px;
    }
    
    .sidebar.collapsed {
        transform: translateY(calc(100% - 80px)); /* Peek mode */
    }
}

/* Header */
.sidebar-header {
    padding: 24px 32px 16px;
    border-bottom: 1px solid transparent;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Brand Icon Wrapper */
.brand-icon {
    width: 80px; /* Increased size for better visibility */
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Logo Image Placeholder Style */
.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Dark mode: invert logo so light parts stay visible on dark background */
[data-theme="dark"] .logo-img {
    filter: invert(1);
}

.brand h1 {
    font-family: var(--font-logo); /* Applied Varela Round */
    font-size: 26px;
    font-weight: 400; /* Rounded fonts look better with regular weight usually, or bold */
    margin: 0;
    line-height: 1;
    color: var(--text-main);
    text-transform: uppercase; /* Uppercase to match design */
    letter-spacing: 0.5px;
}

.brand p {
    font-family: var(--font-logo); /* Applied Varela Round */
    margin: 4px 0 0 0;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px; /* Spacing for the subtitle */
}

/* --- MAIN CONTENT AREA (Scrollable) --- */
.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: #D1D5DB transparent;
}

.view-section {
    display: none;
    padding: 0 32px 32px;
    animation: fadeIn 0.3s ease;
}

.view-section.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- HOME VIEW STYLES --- */
.search-container {
    margin-top: 10px;
    position: relative;
    z-index: 30;
}

.journey-inputs {
    position: relative;
    background: var(--bg-muted);
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.journey-line {
    position: absolute;
    left: 36px;
    top: 45px;
    bottom: 45px;
    width: 2px;
    background: #D1D5DB;
    z-index: 1;
}

.input-group {
    position: relative;
    margin-bottom: 24px; /* Increased spacing to prevent overlap */
    z-index: 2;
}

.input-group:focus-within {
    z-index: 50; /* Brings the active input/dropdown to the front */
}

.input-group:last-child { margin-bottom: 0; }

.input-wrapper { display: flex; align-items: center; gap: 16px; }

.input-icon {
    width: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
    font-size: 12px;
}

.dot-icon { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--text-main); background: white; }
.pin-icon { color: var(--primary); }

.field-container { flex-grow: 1; position: relative; }

input[type="text"] {
    width: 100%;
    padding: 12px 0;
    font-size: 16px;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-main);
    background: var(--input-bg);
    border: none;
    border-bottom: 1px solid var(--input-border);
    border-radius: 0;
    transition: border-color 0.2s;
}

input[type="text"]:focus { outline: none; border-bottom-color: var(--primary); }
input::placeholder { color: #9CA3AF; font-weight: 400; }

/* Keep browser autofill readable */
input[type="text"]:-webkit-autofill,
input[type="text"]:-webkit-autofill:hover,
input[type="text"]:-webkit-autofill:focus,
input[type="text"]:-webkit-autofill:active {
    -webkit-text-fill-color: var(--text-main);
    transition: background-color 9999s ease-in-out 0s;
    box-shadow: 0 0 0 1000px var(--bg-muted) inset;
    border-bottom: 1px solid var(--input-border);
}

/* Dark mode: autofill text as soft gray (not white) for readability */
[data-theme="dark"] input[type="text"]:-webkit-autofill,
[data-theme="dark"] input[type="text"]:-webkit-autofill:hover,
[data-theme="dark"] input[type="text"]:-webkit-autofill:focus,
[data-theme="dark"] input[type="text"]:-webkit-autofill:active {
    -webkit-text-fill-color: #B4BAC4;
    box-shadow: 0 0 0 1000px var(--bg-muted) inset;
}

.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    margin-top: 4px;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.1s;
    color: var(--text-main);
}
.suggestion-item:hover { background: var(--hover-bg); }

.error-msg { font-size: 12px; color: #EF4444; margin-top: 4px; display: none; padding-left: 48px; }

.btn-search {
    width: 100%;
    margin-top: 20px;
    padding: 16px;
    background: var(--action-bg);
    color: var(--action-text);
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.btn-search:hover { background: var(--action-bg-hover); transform: translateY(-1px); }
.btn-search:active { transform: translateY(0); }

.section-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 24px 0 16px;
    display: block;
}

/* Result Cards */
.route-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.route-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.route-card.active { 
    border-color: var(--primary); 
    box-shadow: var(--shadow-lg); 
    background: rgba(37, 99, 235, 0.1);
}

.route-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.jeep-badge { background: var(--badge-bg); color: var(--badge-text); font-weight: 700; font-size: 18px; padding: 4px 12px; border-radius: 8px; }

.trip-type { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 4px 10px; border-radius: 20px; }
.trip-type.direct { background: #DCFCE7; color: #166534; }
.trip-type.transfer { background: #FEF3C7; color: #B45309; }

.signboard { font-size: 15px; font-weight: 500; color: var(--text-main); margin-bottom: 16px; display: flex; align-items: center; gap: 6px; }
.instructions { background: var(--bg-muted); padding: 12px; border-radius: 8px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; border-left: 3px solid #D1D5DB; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.empty-state i { opacity: 0.5; margin-bottom: 12px; }

/* --- FARE VIEW --- */
.fare-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 16px;
}
.fare-header {
    background: var(--bg-muted);
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}
.fare-row {
    display: flex;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.fare-row:last-child { border-bottom: none; }
.fare-type { color: var(--text-secondary); font-size: 14px; }
.fare-price { font-weight: 600; color: var(--text-main); font-size: 14px; }
.fare-note {
    font-size: 12px;
    color: var(--text-secondary);
    background: #FEF3C7;
    color: #B45309;
    padding: 8px 12px;
    border-radius: 8px;
    margin-top: 12px;
    line-height: 1.4;
}

/* --- RECOMMENDATIONS VIEW --- */
.place-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 16px;
    margin-bottom: 16px;
    display: flex;
    gap: 16px;
    align-items: center;
}
.place-icon {
    width: 50px;
    height: 50px;
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.place-info { flex-grow: 1; }
.place-name { font-weight: 700; font-size: 15px; margin-bottom: 4px; display: block; }
.place-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; line-height: 1.3; }
.btn-go {
    background: transparent;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-go:hover { background: var(--primary); color: white; border-color: var(--primary); }

/* --- ABOUT VIEW --- */
.about-text { font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 16px; }
.about-text strong { color: var(--text-main); }
.social-links { display: flex; gap: 12px; margin-top: 20px; }
.social-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    transition: background 0.2s;
    cursor: pointer;
}
.social-btn:hover { background: var(--hover-bg); }

/* --- DEVELOPER TEAM --- */
.dev-team-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.dev-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.dev-card {
    background: var(--bg-muted);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: transform 0.2s;
}
.dev-card:hover { transform: translateY(-2px); background: var(--hover-bg); }

.dev-avatar {
    width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
    margin-bottom: 12px; border: 2px solid white; box-shadow: var(--shadow-sm);
}
.dev-name { font-size: 14px; font-weight: 700; color: var(--text-main); margin-bottom: 2px; }
.dev-role { font-size: 11px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; }

/* --- BOTTOM NAV BAR --- */
.bottom-nav {
    flex-shrink: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: #9CA3AF;
    transition: color 0.2s;
    flex: 1;
}

.nav-item span { font-size: 10px; font-weight: 600; letter-spacing: 0.02em; }
.nav-item.active { color: var(--primary); }
.nav-item.active svg { stroke-width: 2.5px; }

/* --- MAP --- */
.map-wrapper { flex-grow: 1; position: relative; height: 100%; z-index: 10; }
#map { width: 100%; height: 100%; background: #e5e7eb; }

/* Dark mode: dark background everywhere so no white boxes or grid show (loading/failed tiles or gaps) */
[data-theme="dark"] #map,
[data-theme="dark"] .map-wrapper,
[data-theme="dark"] .leaflet-map-pane,
[data-theme="dark"] .leaflet-tile-pane,
[data-theme="dark"] .leaflet-tile {
    background: #242424 !important;
}

/* Hide tile grid lines: no borders, and in dark mode match gap color so seams don’t show */
.leaflet-tile {
    outline: none;
    border: none;
}
.leaflet-tile-pane img {
    outline: none;
    border: none;
}
[data-theme="dark"] .leaflet-tile {
    margin: -1px;
}

/* Theme Toggle (minimal switch) */
.theme-toggle {
    flex-shrink: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.theme-toggle-track {
    display: block;
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: var(--border);
    position: relative;
    transition: background 0.2s;
}

.theme-toggle:hover .theme-toggle-track {
    background: var(--text-secondary);
}

.theme-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease;
}

[data-theme="dark"] .theme-toggle-knob {
    transform: translateX(18px);
}

/* Recenter Button (Google Maps Style) */
.recenter-btn {
    position: absolute;
    bottom: 24px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: var(--bg-surface);
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.recenter-btn:hover {
    background: var(--hover-bg);
    color: #4285F4;
    transform: scale(1.05);
}

.recenter-btn:active {
    transform: scale(0.95);
}

/* Mobile positioning */
@media (max-width: 768px) {
    .recenter-btn {
        bottom: 24px;
        right: 16px;
        width: 44px;
        height: 44px;
    }
}

/* --- USER LOCATION MARKER (Google Maps Style) --- */
.user-location-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}

.location-dot-wrapper {
    position: relative;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pulsing outer ring */
.location-dot-wrapper::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    background: rgba(66, 133, 244, 0.3);
    border-radius: 50%;
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Main blue dot */
.location-dot {
    width: 16px;
    height: 16px;
    background: #4285F4;
    border: 3px solid #FFFFFF;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 2;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.5);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 60vh; /* Taller on mobile for content */
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
        transform: translateY(0);
    }
    .sidebar-header { padding: 20px 24px 10px; }
    .view-section { padding: 0 24px 20px; }
    .map-wrapper { height: 100%; width: 100%; }
}