:root {
    --primary-color: #4facfe;
    --secondary-color: #00f2fe;
    --accent-color: #ff5e62;
    --text-color: #ffffff;
    --text-muted: #a0a0b0;
    --bg-glass: rgba(16, 18, 27, 0.85);
    --border-glass: rgba(255, 255, 255, 0.1);
    --shadow-soft: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --font-family: 'Outfit', sans-serif;
    --sidebar-width: 350px;
    --transition-speed: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    color: var(--text-color);
    overflow: hidden;
    /* Prevent scrolling, map handles it */
    background-color: #0f0f13;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
}

/* Map */
#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

.map-locked {
    cursor: default;
}

/* Sidebar */
.sidebar {
    position: absolute;
    top: 20px;
    left: 20px;
    bottom: 20px;
    width: var(--sidebar-width);
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-soft);
    padding: 24px;
    padding-bottom: 90px;
    /* Space for Floating Controls */
    transition: transform var(--transition-speed) ease;
}

.floating-controls {
    position: absolute;
    left: 44px;
    /* 20px sidebar margin + 24px padding */
    bottom: 44px;
    /* 20px Sidebar Margin + 24px padding */
    width: 302px;
    /* 350px - 48px padding */
    z-index: 1002;
    display: flex;
    flex-direction: column;
    /* On desktop it sits "inside" the sidebar visually */
}

.sidebar-header {
    margin-bottom: 16px;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo i {
    font-size: 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-muted);
}

.journey-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-glass);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    padding: 12px;
    border-radius: 12px;
}

.stat-label {
    font-size: 10px;
    /* Reduced to fit 3 columns better or keep 12px? I'll stick to previous or slightly smaller if needed. Previous was 12px. Let's keep 10px for safety in 3 col */
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 18px;
    font-weight: 600;
    margin-top: 4px;
    color: var(--secondary-color);
}

.controls-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    width: auto;
}

/* Stops List */
.stops-container {
    flex: 1;
    overflow-y: auto;
    margin-right: -8px;
    /* Offset for custom scrollbar */
    padding-right: 8px;
}

.stops-container::-webkit-scrollbar {
    width: 6px;
}

.stops-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.stops-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0;
    /* Changed to 0 to handle spacing via components */
    padding-left: 10px;
    /* Space for the timeline line */
    position: relative;
    padding-bottom: 10px;
}

/* Timeline Line */
.stops-list::before {
    content: '';
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 4px;
    width: 2px;
    background: linear-gradient(to bottom, var(--primary-color), rgba(255, 255, 255, 0.05));
    border-radius: 1px;
    z-index: 0;
}

.stops-list.reordering::before {
    display: none;
    /* Hide timeline during reorder as it looks weird */
}

.stops-list .empty-state::before {
    display: none;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.empty-state i {
    font-size: 32px;
    opacity: 0.3;
}

.stop-item {
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    animation: slideIn 0.3s ease-out forwards;
    z-index: 1;
    margin-bottom: 0px;
    /* Reduced to connect to transit */
    /* Space after stop item */
}

/* Reduce margin if transit component follows? No, transit component will handle its own spacing */

.stops-list.reordering .stop-item {
    cursor: grab;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    margin-bottom: 16px;
}

.sortable-ghost {
    opacity: 0.4;
    background: rgba(255, 255, 255, 0.1);
}

.stop-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Timeline Dot */
.stop-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 40px;
    /* Adjusted to align with header/top */
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    background: var(--bg-glass);
    border: 2px solid var(--secondary-color);
    border-radius: 50%;
    z-index: 2;
    box-shadow: 0 0 10px var(--secondary-color);
}

.stops-list.reordering .stop-item::before {
    display: none;
}

/* New Stop Card Layout */
.stop-card-header {
    margin-bottom: 12px;
}

/* Updated: Name Input at Top */
.stop-name-input {
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 16px;
    display: block;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    /* Make it slightly visible */
    border: 1px solid transparent;
    color: var(--text-color);
    padding: 8px 10px;
    border-radius: 8px;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.stop-name-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    outline: none;
    box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.2);
}

.stop-name-input:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Controls Logic */
.stop-controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stop-main-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nights-counter {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    padding: 2px 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.nights-input {
    background: transparent;
    border: none;
    color: var(--text-color);
    width: 30px;
    text-align: center;
    font-weight: 600;
    font-family: var(--font-family);
    font-size: 12px;
    appearance: textfield;
    /* Remove arrows */
}

.nights-input::-webkit-outer-spin-button,
.nights-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.nights-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 2px;
    padding-right: 4px;
    text-transform: uppercase;
}

.night-adjust-btns {
    display: flex;
    gap: 2px;
    margin-left: 4px;
}

.night-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-color);
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.night-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-plus {
    color: #2ecc71;
}

.btn-minus {
    color: #ff5e62;
}

.stop-type-badge {
    text-transform: uppercase;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.type-start {
    background: rgba(79, 172, 254, 0.2);
    color: #4facfe;
}

.type-transit {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.type-stop {
    background: rgba(255, 215, 0, 0.2);
    color: #ffd700;
}

.type-end {
    background: rgba(255, 94, 98, 0.2);
    color: #ff5e62;
}

.drag-handle {
    color: var(--text-muted);
    cursor: grab;
    padding: 4px;
    margin-right: 4px;
    /* display: none; Handled by reorder class logic */
    display: none;
}

.stops-list.reordering .drag-handle {
    display: inline-block;
}

/* Controls */
.delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    font-size: 14px;
    transition: color 0.2s;
    border-radius: 4px;
}

.delete-btn:hover {
    color: var(--accent-color);
    background: rgba(255, 255, 255, 0.05);
}

.stop-coords {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
    margin-top: 4px;
}

/* Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 24px;
}

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-family: var(--font-family);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #000;
}

/* Mobile Toggle */
/* Mobile Toggle */
.sidebar-toggle {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    color: var(--text-color);
    font-size: 18px;
    cursor: pointer;
    z-index: 1001;
    display: none;
    /* Hidden on Desktop */
    align-items: center;
    justify-content: center;
}

/* Transit Component - Separate Panel */
.transit-item {
    padding-left: 10px;
    position: relative;
    z-index: 0;
    margin-bottom: 0;
}

.transit-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--bg-glass);
    border: 1px solid var(--text-muted);
    border-radius: 50%;
    z-index: 2;
}

.transit-container {
    position: relative;
    margin: 8px 0;
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: fadeScale 0.3s ease-out forwards;
}

.transit-container.separate-transit {
    border: 1px dashed rgba(79, 172, 254, 0.3);
    background: rgba(16, 18, 27, 0.6);
}

.transit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.transit-time {
    color: var(--secondary-color);
    font-weight: 600;
}

.transit-options {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.transit-option-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.transit-option-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
}

.transit-option-btn.active {
    /* Fallback/Common active style */
    background: rgba(255, 255, 255, 0.1);
}

.transit-option-btn.btn-car.active {
    background: rgba(0, 242, 254, 0.1);
    border-color: rgba(0, 242, 254, 0.3);
    color: #00f2fe;
}

.transit-option-btn.btn-train.active {
    background: rgba(255, 159, 67, 0.1);
    border-color: rgba(255, 159, 67, 0.3);
    color: #ff9f43;
}

.transit-option-btn.btn-bus.active {
    background: rgba(241, 196, 15, 0.1);
    border-color: rgba(241, 196, 15, 0.3);
    color: #f1c40f;
}

.transit-option-btn.btn-walk.active {
    background: rgba(46, 204, 113, 0.1);
    border-color: rgba(46, 204, 113, 0.3);
    color: #2ecc71;
}

.transit-option-btn.btn-plane.active {
    background: rgba(155, 89, 182, 0.1);
    border-color: rgba(155, 89, 182, 0.3);
    color: #9b59b6;
}

.stops-list.reordering .transit-item {
    display: none;
}

@keyframes fadeScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Playback Dock - Default Desktop Behavior */
.playback-dock {
    display: flex;
    flex: 3;
    gap: 6px;
}

.mobile-reorder-btn {
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(calc(-100% - 40px));
        width: calc(100% - 40px);
        max-width: 350px;
    }

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

    /* Hide Controls when Sidebar is Open */
    .sidebar.active~.floating-controls {
        display: none;
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Move Playback Controls to Bottom on Mobile */
    .floating-controls {
        position: fixed;
        bottom: 24px;
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        max-width: 400px;
        z-index: 2000;
        background: var(--bg-glass);
        backdrop-filter: blur(16px);
        padding: 8px;
        border-radius: 12px;
        border: 1px solid var(--border-glass);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }

    /* Ensure Time Display floats above it or modifies */
    #playback-time {
        /* Included in flow now or keep absolute? */
        /* It's inside floating-controls now. standard flow is fine or margin top */
        position: static;
        width: 100% !important;
        transform: none;
        margin-top: 8px;
    }

    .sidebar {
        padding-bottom: 24px;
        /* Reset padding on mobile sidebar */
    }

    /* Hide Desktop Reorder Button in Floating Controls */
    .floating-controls #reorder-btn {
        display: none !important;
    }

    /* Show Mobile Reorder Button in Sidebar */
    .mobile-reorder-btn {
        display: flex !important;
    }

    /* Show Mobile Undo Button */
    .mobile-undo-btn {
        display: flex !important;
    }
}

/* Leaflet Overrides for Dark Theme */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--bg-glass);
    color: var(--text-color);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-glass);
}

.leaflet-popup-content {
    margin: 12px;
    font-family: var(--font-family);
}

.custom-tooltip {
    background: var(--bg-glass) !important;
    border: 1px solid var(--border-glass) !important;
    color: var(--text-color) !important;
    backdrop-filter: blur(8px);
    font-family: var(--font-family);
    padding: 6px 10px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.custom-tooltip::before {
    border-top-color: var(--border-glass) !important;
}

/* Autocomplete Dropdown */
.stop-card-header {
    position: relative;
    /* Ensure absolute children position relative to this */
}

.suggestions-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    margin-top: 4px;
    display: none;
}

.suggestions-dropdown.active {
    display: block;
}

.suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s;
    font-size: 14px;
    color: var(--text-color);
}

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

.stopover-input-container {
    position: relative;
}

.suggestion-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.suggestion-item small {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
}

/* Playback Token */
.travel-token {
    z-index: 1000 !important;
}

.token-inner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    border: 2px solid #fff;
    font-size: 14px;
    transform: translate(-3px, -3px);
    /* Center adjustment if needed */
}

/* Speed Controls */
.speed-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.speed-btn:hover {
    color: #fff;
}

#speed-val {
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
    display: inline-block;
}

/* Map Theme Toggle (Desktop) */
/* Top Right Controls Container */
.top-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1005;
    display: flex;
    gap: 12px;
    align-items: center;
    pointer-events: none;
}

.top-controls>* {
    pointer-events: auto;
}

.time-display {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    color: var(--secondary-color);
    padding: 0 16px;
    height: 44px;
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    min-width: 140px;
    font-family: var(--font-family);
}

.theme-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    color: var(--text-color);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-soft);
}

.theme-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.45);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    #theme-toggle-btn {
        display: none;
    }
}

/* Add Stop Button (Plus) */
.add-stop-item {
    display: flex;
    justify-content: center;
    padding: 10px 0;
    animation: fadeScale 0.3s ease-out forwards;
}

.btn-add-stop {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.3);
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-add-stop:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--secondary-color);
    color: var(--secondary-color);
    transform: scale(1.1);
}

/* Remove arrows from number inputs */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Journey Name Input Styling */
.journey-name-input {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 16px;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.2s;
    text-align: center;
    margin-top: 4px;
}

.journey-name-input:focus,
.journey-name-input:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    outline: none;
}

/* Desktop Footer Banner */
.desktop-footer-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-glass);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(16px);
    z-index: 900;
    font-size: 12px;
    color: var(--text-muted);
    pointer-events: auto;
    font-weight: 500;
    box-shadow: var(--shadow-soft);
}

.desktop-footer-banner a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.desktop-footer-banner a:hover {
    color: var(--primary-color);
}

/* Mobile Info Panel */
.info-panel-mobile {
    position: fixed;
    top: 74px; /* Below top controls */
    right: 20px;
    background: var(--bg-glass);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(16px);
    z-index: 2005;
    font-size: 14px;
    display: none;
    color: var(--text-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    min-width: 200px;
    text-align: center;
}

.info-panel-mobile.active {
    display: block;
    animation: fadeScale 0.2s ease-out;
}

.info-panel-mobile a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 600;
}

/* Media Query Overrides for Footer/Info */
@media (max-width: 768px) {
    .desktop-footer-banner {
        display: none;
    }

    #info-toggle-btn {
        display: flex !important;
        margin-right: 8px;
    }
}