body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

#map {
    height: 100vh;
    width: 100%;
    z-index: 1;
}

/* --- Desktop Sidebar (Default) --- */
#sidebar {
    position: absolute;
    top: 60px;
    right: 10px;
    left: auto;
    bottom: auto;
    width: 300px;
    height: calc(100vh - 80px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
}

#sidebar.collapsed {
    transform: translateX(calc(100% + 20px));
}

/* --- Toggle Button --- */
.toggle-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    /* Tighter to the corner for Desktop */
    z-index: 2000;
    background: #fff;
    border: 2px solid rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
    color: #333;
    padding: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}

.toggle-btn:hover {
    background: #f4f4f4;
}

/* --- Last Updated Badge --- */
#last-updated {
    font-size: 0.8rem;
    font-weight: normal;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    color: white;
}

/* --- Mobile Layout (Bottom Sheet) --- */
@media (max-width: 768px) {
    #sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 45vh;
        /* Takes up bottom 45% of screen */
        border-radius: 16px 16px 0 0;
        /* Rounded top corners only */
        max-width: none;
        transform: translateY(0);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }

    #sidebar.collapsed {
        transform: translateY(100%);
        /* Slide completely down */
    }

    .toggle-btn {
        top: 10px;
        bottom: auto;
        right: 10px;
        /* Top right on mobile too */
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    }
}

/* --- Sidebar Content --- */
.sidebar-header {
    padding: 15px;
    background: #005eb8;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* --- Train Items --- */
.train-item {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid #ccc;
}

.train-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.train-item.active {
    border-left-color: #28a745;
}

.train-item.delayed {
    border-left-color: #dc3545;
}

.train-headcode {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.train-route {
    font-size: 0.9em;
    color: #666;
    margin-top: 4px;
}

.train-status {
    font-size: 0.85em;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    background: #e9ecef;
    color: #495057;
}

.status-badge.on-time {
    background: #d4edda;
    color: #155724;
}

/* --- Popup Styling --- */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important;
}

.popup-header {
    background: #005eb8;
    color: white;
    padding: 10px 15px;
}

.popup-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.popup-body {
    padding: 15px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    font-weight: 600;
    color: #555;
}

.popup-value {
    color: #333;
    text-align: right;
}

.toggle-btn:hover {
    background: #f4f4f4;
}

/* --- Last Updated Badge --- */
#last-updated {
    font-size: 0.8rem;
    font-weight: normal;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    color: white;
}

/* --- Mobile Layout (Bottom Sheet) --- */
@media (max-width: 768px) {
    #sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 45vh;
        /* Takes up bottom 45% of screen */
        border-radius: 16px 16px 0 0;
        /* Rounded top corners only */
        max-width: none;
        transform: translateY(0);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }

    #sidebar.collapsed {
        transform: translateY(100%);
        /* Slide completely down */
    }

    .toggle-btn {
        top: 10px;
        bottom: auto;
        right: 10px;
        /* Top right on mobile too */
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    }
}

/* --- Sidebar Content --- */
.sidebar-header {
    padding: 15px;
    background: #005eb8;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* --- Train Items --- */
.train-item {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid #ccc;
}

.train-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.train-item.active {
    border-left-color: #28a745;
}

.train-item.delayed {
    border-left-color: #dc3545;
}

.train-headcode {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.train-route {
    font-size: 0.9em;
    color: #666;
    margin-top: 4px;
}

.train-status {
    font-size: 0.85em;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    background: #e9ecef;
    color: #495057;
}

.status-badge.on-time {
    background: #d4edda;
    color: #155724;
}

/* --- Popup Styling --- */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important;
}

.popup-header {
    background: #005eb8;
    color: white;
    padding: 10px 15px;
}

.popup-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.popup-body {
    padding: 15px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    font-weight: 600;
    color: #555;
}

.popup-value {
    color: #333;
    text-align: right;
}

.follow-btn {
    display: block;
    width: 100%;
    padding: 8px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    margin-top: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.follow-btn:hover {
    background: #218838;
}


.popup-value {
    color: #333;
    text-align: right;
}

.toggle-btn:hover {
    background: #f4f4f4;
}

/* --- Last Updated Badge --- */
#last-updated {
    font-size: 0.8rem;
    font-weight: normal;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    color: white;
}

/* --- Mobile Layout (Bottom Sheet) --- */
@media (max-width: 768px) {
    #sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 45vh;
        /* Takes up bottom 45% of screen */
        border-radius: 16px 16px 0 0;
        /* Rounded top corners only */
        max-width: none;
        transform: translateY(0);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }

    #sidebar.collapsed {
        transform: translateY(100%);
        /* Slide completely down */
    }

    .toggle-btn {
        top: 10px;
        bottom: auto;
        right: 10px;
        /* Top right on mobile too */
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    }
}

/* --- Sidebar Content --- */
.sidebar-header {
    padding: 15px;
    background: #005eb8;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* --- Train Items --- */
.train-item {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid #ccc;
}

.train-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.train-item.active {
    border-left-color: #28a745;
}

.train-item.delayed {
    border-left-color: #dc3545;
}

.train-headcode {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.train-route {
    font-size: 0.9em;
    color: #666;
    margin-top: 4px;
}

.train-status {
    font-size: 0.85em;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    background: #e9ecef;
    color: #495057;
}

.status-badge.on-time {
    background: #d4edda;
    color: #155724;
}

/* --- Popup Styling --- */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important;
}

.popup-header {
    background: #005eb8;
    color: white;
    padding: 10px 15px;
}

.popup-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.popup-body {
    padding: 15px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    font-weight: 600;
    color: #555;
}

.popup-value {
    color: #333;
    text-align: right;
}

.follow-btn {
    display: block;
    width: 100%;
    padding: 8px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    margin-top: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.follow-btn:hover {
    background: #218838;
}


.popup-value {
    color: #333;
    text-align: right;
}

.toggle-btn:hover {
    background: #f4f4f4;
}

/* --- Last Updated Badge --- */
#last-updated {
    font-size: 0.8rem;
    font-weight: normal;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    color: white;
}

/* --- Mobile Layout (Bottom Sheet) --- */
@media (max-width: 768px) {
    #sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 45vh;
        /* Takes up bottom 45% of screen */
        border-radius: 16px 16px 0 0;
        /* Rounded top corners only */
        max-width: none;
        transform: translateY(0);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }

    #sidebar.collapsed {
        transform: translateY(100%);
        /* Slide completely down */
    }

    .toggle-btn {
        top: 10px;
        bottom: auto;
        right: 10px;
        /* Top right on mobile too */
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    }
}

/* --- Sidebar Content --- */
.sidebar-header {
    padding: 15px;
    background: #005eb8;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* --- Train Items --- */
.train-item {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid #ccc;
}

.train-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.train-item.active {
    border-left-color: #28a745;
}

.train-item.delayed {
    border-left-color: #dc3545;
}

.train-headcode {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.train-route {
    font-size: 0.9em;
    color: #666;
    margin-top: 4px;
}

.train-status {
    font-size: 0.85em;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    background: #e9ecef;
    color: #495057;
}

.status-badge.on-time {
    background: #d4edda;
    color: #155724;
}

/* --- Popup Styling --- */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important;
}

.popup-header {
    background: #005eb8;
    color: white;
    padding: 10px 15px;
}

.popup-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.popup-body {
    padding: 15px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    font-weight: 600;
    color: #555;
}

.popup-value {
    color: #333;
    text-align: right;
}

.follow-btn {
    display: block;
    width: 100%;
    padding: 8px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    margin-top: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.follow-btn:hover {
    background: #218838;
}

.popup-value {
    color: #333;
    text-align: right;
}

.toggle-btn:hover {
    background: #f4f4f4;
}

/* --- Last Updated Badge --- */
#last-updated {
    font-size: 0.8rem;
    font-weight: normal;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    color: white;
}

/* --- Mobile Layout (Bottom Sheet) --- */
@media (max-width: 768px) {
    #sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 45vh;
        /* Takes up bottom 45% of screen */
        border-radius: 16px 16px 0 0;
        /* Rounded top corners only */
        max-width: none;
        transform: translateY(0);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }

    #sidebar.collapsed {
        transform: translateY(100%);
        /* Slide completely down */
    }

    .toggle-btn {
        top: 10px;
        bottom: auto;
        right: 10px;
        /* Top right on mobile too */
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    }
}

/* --- Sidebar Content --- */
.sidebar-header {
    padding: 15px;
    background: #005eb8;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* --- Train Items --- */
.train-item {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid #ccc;
}

.train-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.train-item.active {
    border-left-color: #28a745;
}

.train-item.delayed {
    border-left-color: #dc3545;
}

.train-headcode {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.train-route {
    font-size: 0.9em;
    color: #666;
    margin-top: 4px;
}

.train-status {
    font-size: 0.85em;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    background: #e9ecef;
    color: #495057;
}

.status-badge.on-time {
    background: #d4edda;
    color: #155724;
}

/* --- Popup Styling --- */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important;
}

.popup-header {
    background: #005eb8;
    color: white;
    padding: 10px 15px;
}

.popup-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.popup-body {
    padding: 15px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-label {
    font-weight: 600;
    color: #555;
}

.popup-value {
    color: #333;
    text-align: right;
}

.follow-btn {
    display: block;
    width: 100%;
    padding: 8px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    margin-top: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.follow-btn:hover {
    background: #218838;
}

.follow-btn.following {
    background: #dc3545;
}

/* Operator Logo in Popup */
.operator-logo {
    width: 40px;
    /* Increased size */
    height: 40px;
    object-fit: contain;
    vertical-align: middle;
    margin-right: 8px;
    border-radius: 4px;
    display: inline-block;
    background-color: #005eb8;
    /* Translink Blue */
    padding: 2px;
}