:root {
    --nmbs-white: #FFFFFF;
    --nmbs-blue: #003399;
    --nmbs-blue-light: #0055BB;
    --nmbs-yellow: #FFCC00;
    --bg-main: #F8FAFC;
    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --border-light: #E2E8F0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --nav-height: 60px;
}

body.no-scroll {
    overflow: hidden !important;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Base Layout */
#map {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    width: 100%;
    height: calc(100vh - var(--nav-height));
    z-index: 1;
}

body.view-trips {
    overflow-y: auto !important;
}

body.view-trips #map {
    display: none;
}

body.view-trips #trips-view {
    display: block;
}

#trips-view {
    display: none;
    padding: 2.5rem;
    padding-top: calc(var(--nav-height) + 3rem);
    background: white;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
}

/* Top Navbar (trainlog.me style) */
.navbar {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    min-height: var(--nav-height);
    background: var(--nmbs-white);
    border-bottom: 1px solid var(--border-light);
    z-index: 2000;
    padding: 0 1rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--nmbs-blue);
    text-decoration: none;
    margin-right: 3rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover,
.nav-link.active {
    color: var(--nmbs-blue);
}

/* Sidebar Search Panel */
.command-panel {
    position: fixed;
    top: calc(var(--nav-height) + 1.5rem);
    left: 1.5rem;
    width: 340px;
    background: var(--nmbs-white);
    border: 1px solid var(--border-light);
    border-radius: 1rem;
    z-index: 1000;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    max-height: calc(100vh - var(--nav-height) - 4rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (max-width: 992px) {
    .command-panel {
        position: relative;
        top: 0;
        left: 0;
        width: 100%;
        max-height: none;
        margin-top: var(--nav-height);
        border-radius: 0;
        box-shadow: none;
        border: none;
        border-bottom: 1px solid var(--border-light);
        padding: 1.5rem;
    }

    #map {
        position: relative;
        height: 50vh;
        top: 0;
    }

    #composition-sheet {
        height: 85vh;
        /* Taller on mobile */
        border-radius: 1.5rem 1.5rem 0 0;
        /* Rounded top corners */
        padding: 1.5rem;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    /* Drag Handle Indicator */
    #composition-sheet::before {
        content: '';
        display: block;
        width: 40px;
        height: 5px;
        background: #E2E8F0;
        border-radius: 10px;
        margin: -0.5rem auto 1rem auto;
    }

    #composition-sheet select,
    #composition-sheet input {
        font-size: 16px !important;
        /* Prevent iOS zoom */
        padding: 0.75rem !important;
        border-radius: 0.75rem !important;
        background-color: #F8FAFC;
        border: 1px solid #E2E8F0;
    }

    #btn-log {
        width: 100%;
        padding: 1rem;
        font-size: 1.1rem;
        margin-top: 1rem;
        border-radius: 1rem;
    }

    .navbar-collapse {
        background: white;
        margin: 0 -1rem;
        padding: 1rem;
        border-bottom: 1px solid var(--border-light);
    }
}

/* Prevent iOS Auto-Zoom on inputs by enforcing 16px font size */
@media screen and (max-width: 768px) {

    input,
    select,
    textarea,
    .search-input {
        font-size: 16px !important;
    }
}



.nav-link {
    padding: 0.8rem 0 !important;
    border-bottom: 1px solid #f1f5f9;
}

.nav-link:last-child {
    border-bottom: none;
}

#results-target {
    overflow-y: auto !important;
    flex-grow: 1;
    min-height: 0;
}

.search-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem 0.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: 0.2s;
}

.tab-btn.active {
    color: var(--nmbs-blue);
    border-bottom-color: var(--nmbs-blue);
}

.search-container {
    background: #F1F5F9;
    border-radius: 0.5rem;
    padding: 0.6rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.search-input {
    background: none;
    border: none;
    width: 100%;
    outline: none;
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Train Cards in Sidebar */
.train-card {
    padding: 1rem;
    background: #ffffff;
    border: 1px solid transparent;
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.train-card:hover {
    background: #F8FAFC;
    border-color: var(--nmbs-blue-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 51, 153, 0.08);
}

.train-card:last-child {
    border-bottom: none;
}

/* Premium Buttons */
.btn-premium {
    background: var(--nmbs-blue);
    color: white;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    white-space: nowrap;
}

.btn-premium:hover {
    background: var(--nmbs-blue-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 51, 153, 0.15);
}

.btn-premium:active {
    transform: translateY(0);
}

/* Table View (Trips) */
.trips-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.trips-table th {
    text-align: left;
    padding: 1rem;
    background: #F8FAFC;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    border-bottom: 1px solid var(--border-light);
}

.trips-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
}

.trips-table tr:hover {
    background: #F8FAFC;
}

/* Bottom Sheet */
.bottom-sheet {
    position: fixed;
    bottom: -100%;
    left: calc(340px + 3rem);
    right: 2rem;
    background: white;
    border-radius: 1.25rem;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    transition: bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-light);
    padding: 2.5rem;
}

@media (max-width: 992px) {
    .bottom-sheet {
        left: 1.5rem;
        width: calc(100% - 3rem);
    }
}

.bottom-sheet.open {
    bottom: 1.5rem;
}

.composition-track {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding: 1.5rem 0.5rem;
    margin-bottom: 2rem;
}

.unit-card {
    flex: 0 0 160px;
    background: #F8FAFC;
    border: 2px solid transparent;
    border-radius: 1rem;
    padding: 1.25rem 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.unit-card:hover {
    background: #F1F5F9;
    transform: translateY(-4px);
}

.unit-card.active {
    background: #ffffff;
    border-color: var(--nmbs-blue);
    box-shadow: 0 10px 25px rgba(0, 51, 153, 0.12);
}

/* Responsive Unit Cards */
/* Responsive Unit Cards */
@media (max-width: 768px) {
    .unit-card {
        flex: 0 0 100px;
        /* More compact flex basis */
        padding: 0.5rem 0.25rem;
    }

    .unit-card img {
        /* Handled by container max-height on mobile */
        max-height: 100%;
    }

    .unit-img-container {
        height: 48px;
        /* Reduced height for mobile */
    }

    .composition-track {
        gap: 0.5rem;
        padding: 0.75rem 0.25rem;
    }

    .unit-card .small {
        font-size: 0.7rem !important;
        /* Smaller text */
    }
}

/* Unit Image Alignment & Container */
.unit-img-container {
    height: 64px;
    width: 100%;
    display: flex;
    align-items: flex-end;
    /* Bottom align */
    justify-content: center;
    margin: 0.5rem 0;
}

.unit-card img {
    height: auto;
    max-height: 100%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

/* Trips Table Overhaul */
.trips-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.75rem;
    margin-top: 1.5rem;
}

.trips-table th {
    background: var(--nmbs-blue);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 1.25rem 1rem;
}

.trips-table th:first-child {
    border-radius: 0.75rem 0 0 0.75rem;
}

.trips-table th:last-child {
    border-radius: 0 0.75rem 0.75rem 0;
}

.trips-table td {
    background: white;
    padding: 1.25rem 1rem;
    vertical-align: middle;
    border-top: 1px solid #F1F5F9;
    border-bottom: 1px solid #F1F5F9;
}

.trips-table tr td:first-child {
    border-left: 1px solid #F1F5F9;
    border-radius: 0.75rem 0 0 0.75rem;
}

.trips-table tr td:last-child {
    border-right: 1px solid #F1F5F9;
    border-radius: 0 0.75rem 0.75rem 0;
}

/* Badge & Icons */
.badge-blue {
    background: #E0E7FF;
    color: var(--nmbs-blue);
    padding: 0.35rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 700;
}

.bi-train-front {
    font-size: 1.25rem;
    color: var(--nmbs-blue);
}

.route-timeline-container {
    position: relative;
}

.route-popover {
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 300px;
    overflow-y: auto;
}

.x-small {
    font-size: 0.7rem;
}

/* Responsive Extra */
@media (max-width: 768px) {
    #trips-view {
        padding: 1rem;
        padding-top: calc(var(--nav-height) + 1.5rem);
    }
}