/* Base Variables & Theming */
:root {
    --bg-color: #050505;
    --panel-bg: rgba(20, 20, 20, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --radius-l: 35px;
    --radius-m: 20px;
    --radius-s: 12px;

    --text-main: #f0f0f0;
    --text-muted: #888888;

    --accent-orange: #ff4500;
    --accent-red: #ff003c;
    --accent-hover: #ff5c1f;

    --font-family: 'Outfit', sans-serif;
}

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

body,
html {
    width: 100%;
    height: 100%;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    /* Prevent scrolling, UI is absolute fixed */
}

/* Map Container */
#map-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

/* UI Layer covering Map */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
    /* Let map clicks through where there's no UI */
    display: flex;
    justify-content: space-between;
    padding: 20px;
}

/* Generic Panel Styling (Sportstech / Glassmorphism) */
.panel {
    pointer-events: auto;
    /* Re-enable pointer events for panels */
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-l);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.left-panel {
    width: 380px;
}

.right-panel {
    width: 320px;
}

header {
    padding: 25px 25px 15px 25px;
    border-bottom: 1px solid var(--panel-border);
}

header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 15px;
    letter-spacing: 0.5px;
}

.panel-content {
    padding: 25px;
    overflow-y: auto;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Scrollbar Styling for Panels */
.panel-content::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.divider {
    border: 0;
    height: 1px;
    background: var(--panel-border);
    margin: 10px 0;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
}

.tab {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
    padding: 8px 15px;
    border-radius: var(--radius-m);
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: 500;
    transition: all 0.3s ease;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.tab.active {
    background: var(--accent-orange);
    border-color: var(--accent-orange);
    color: #fff;
    box-shadow: 0 0 15px rgba(255, 69, 0, 0.4);
}

/* Buttons */
.btn {
    width: 100%;
    padding: 12px 20px;
    border-radius: var(--radius-m);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-orange), var(--accent-red));
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 0, 60, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover), #ff1a53);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 0, 60, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

/* Forms & Inputs */
.styled-select {
    width: 100%;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-s);
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    margin-top: 8px;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFFFFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 15px top 50%;
    background-size: 10px auto;
}

.styled-select option {
    background: #111;
    color: #fff;
}

/* Info Elements */
.empty-state {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 20px 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-s);
    border: 1px dashed var(--panel-border);
}

.stat-box {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: var(--radius-m);
    border: 1px solid var(--panel-border);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.highlight-orange {
    color: var(--accent-orange);
}

.highlight-red {
    color: var(--accent-red);
}

/* Vehicle Items */
h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.vehicle-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vehicle-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-s);
    padding: 15px;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vehicle-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-orange);
}

.vehicle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.vehicle-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.vehicle-price {
    color: var(--accent-orange);
    font-weight: 700;
}

.vehicle-details {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

.vehicle-tags {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 5px;
}

.tag-badge {
    background: rgba(255, 69, 0, 0.15);
    color: var(--accent-orange);
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: lowercase;
}

.btn-buy {
    margin-top: 10px;
    padding: 8px;
    font-size: 0.9rem;
}

/* Tile Layer Filters (Dark Mode Map) */
.leaflet-layer,
.leaflet-control-zoom-in,
.leaflet-control-zoom-out,
.leaflet-control-attribution {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

/* Map Cursor States */
#map-container.mode-create-bus,
#map-container.mode-create-tram {
    cursor: crosshair;
}

/* Line List Items */
.line-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    border-left: 4px solid var(--accent-orange);
    border-radius: var(--radius-s);
    padding: 10px 15px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.line-item-tram {
    border-left-color: #4a90e2;
    /* Different color for tram */
}

.line-info strong {
    display: block;
    margin-bottom: 3px;
}

.line-info span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Hide Leaflet Routing Machine UI (we just want the logic/lines on map) */
.leaflet-routing-container {
    display: none !important;
}

/* Custom Map Tooltips for Stations */
.station-tooltip {
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    font-family: var(--font-family);
    border-radius: var(--radius-s);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    font-size: 0.85rem;
}

.station-tooltip b {
    color: var(--accent-orange);
}

.mode-create-tram .station-tooltip b {
    color: #4a90e2;
    /* Tram color counterpart */
}

/* =========================================
   Real-Time Route Panel (Phase 11)
   ========================================= */
.live-stops-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 5px;
}

.live-stops-list::-webkit-scrollbar {
    width: 4px;
}

.live-stops-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.live-stop-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-s);
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.live-stop-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-orange);
}

.live-stop-index {
    background: var(--accent-orange);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    flex-shrink: 0;
}

.mode-create-tram .live-stop-index {
    background: #4a90e2;
}

.mode-create-tram .live-stop-item:hover {
    border-color: #4a90e2;
}

/* =========================================
   Modals (Phase 11)
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    /* Catch clicks */
}

.modal-box {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-m);
    padding: 30px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.modal-box h2 {
    margin-bottom: 10px;
    color: var(--text-main);
}

.modal-box p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.input-group input {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-s);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    outline: none;
    text-align: center;
}

.input-group input:focus {
    border-color: var(--accent-orange);
}

.modal-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

/* =========================================
   Mobile Responsiveness (Max Width: 768px)
   ========================================= */
.mobile-nav {
    display: none;
    /* Hidden on Desktop */
}

@media (max-width: 768px) {

    /* Main Layout Shifts */
    .ui-layer {
        pointer-events: none;
        /* Map receives interactions */
        padding: 0;
    }

    /* Redefine Panels as Full Screen Bottom/Top overlays */
    .panel {
        position: fixed;
        width: 100vw;
        max-width: 100vw;
        height: 80vh;
        /* Slide up 80% */
        bottom: 0;
        left: 0;
        top: auto;
        border-radius: 20px 20px 0 0;
        border: none;
        border-top: 1px solid rgba(255, 69, 0, 0.3);
        transform: translateY(110%);
        /* Hidden below screen */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        pointer-events: auto;
        z-index: 2000;
        margin: 0;
        backdrop-filter: blur(25px);
        -webkit-backdrop-filter: blur(25px);
        background: rgba(10, 10, 10, 0.9);
    }

    /* Active State for sliding up */
    .panel.mobile-active {
        transform: translateY(0);
    }

    /* Make padding slightly tighter for mobile space */
    .panel header {
        padding: 15px;
        padding-bottom: 25px;
        /* ensure headers have breathing room */
    }

    .panel-content {
        padding: 15px;
        padding-bottom: 80px;
        /* safety for scrolling above nav nav */
    }

    /* Show Mobile Navigation Bar */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100vw;
        height: 60px;
        background: rgba(5, 5, 5, 0.85);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 69, 0, 0.4);
        z-index: 3000;
        justify-content: space-around;
        align-items: center;
        padding: 0 10px;
        pointer-events: auto;
    }

    .mobile-nav-btn {
        background: transparent;
        color: var(--text-main);
        border: none;
        padding: 10px 20px;
        font-family: var(--font-family);
        font-weight: 600;
        font-size: 1rem;
        cursor: pointer;
        border-radius: var(--radius-s);
        transition: background 0.2s;
    }

    .mobile-nav-btn:hover,
    .mobile-nav-btn:active {
        background: rgba(255, 69, 0, 0.2);
    }

    /* Increase touch targets for mobile thumbs */
    .btn {
        min-height: 48px;
        font-size: 1rem;
    }

    .styled-select {
        min-height: 48px;
        font-size: 1rem;
    }

    .line-item button {
        min-height: 44px;
        /* larger edit button for thumbs */
    }

    /* Make zoom control float slightly higher on mobile to not be hidden by nav */
    .leaflet-control-zoom {
        margin-bottom: 70px !important;
    }
}