:root {
    --rr-nav-offset: 140px;
    --route-accent: #b91c1c;
    --route-accent-dark: #991b1b;
    --route-accent-soft: #fef2f2;
    --route-accent-border: #fca5a5;
    --route-accent-btn-bg: #b91c1c;
    --route-accent-btn-text: #ffffff;
    --route-polyline: #c81e1e;
}

.rr-page {
    padding-top: var(--rr-nav-offset, 140px);
    background-color: #ffffff;
}

.rr-schedule-card {
    border: 1px solid #e2e8f0;
    border-top: 4px solid var(--route-accent);
    border-radius: 0.75rem;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 10px 24px -18px rgba(15, 23, 42, 0.35);
    scroll-margin-top: calc(var(--rr-nav-offset, 140px) + 16px);
}

.rr-schedule-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.85rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.rr-schedule-actions {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.rr-jump-next-btn {
    background-color: var(--route-accent-btn-bg);
    color: var(--route-accent-btn-text);
    border: 1px solid var(--route-accent-btn-bg);
    font-weight: 600;
}

.rr-jump-next-btn:hover,
.rr-jump-next-btn:focus-visible {
    background-color: var(--route-accent-dark);
    border-color: var(--route-accent-dark);
    color: var(--route-accent-btn-text);
}

.rr-jump-next-btn:disabled {
    opacity: 0.55;
    background-color: var(--route-accent-btn-bg);
    border-color: var(--route-accent-btn-bg);
    color: var(--route-accent-btn-text);
}

.rr-schedule-scroll {
    max-height: 68vh;
    max-height: 68dvh;
    overflow: auto;
    border-radius: 0.5rem;
}

.rr-schedule-scroll:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.rr-schedule-scroll .table-responsive,
.rr-schedule-scroll .table-responsive-sm {
    overflow: visible;
}

.rr-schedule-scroll table thead th {
    position: sticky;
    top: 0;
    inset-block-start: 0;
    z-index: 2;
}

.rr-schedule-scroll table th a[data-bs-toggle="modal"] {
    cursor: pointer;
}

tr.rr-next-trip > td {
    background-color: var(--route-accent-soft) !important;
    box-shadow: inset 0 2px 0 var(--route-accent), inset 0 -2px 0 var(--route-accent);
    font-weight: 700;
}

.rr-next-badge {
    background-color: var(--route-accent-btn-bg);
    color: var(--route-accent-btn-text);
    font-weight: 700;
}

.rr-ctrl-btn:focus-visible,
.rr-style-btn:focus-visible,
.rr-dir-btn:focus-visible,
.rr-stop-item:focus-visible,
.rr-hud-bus-pill:focus-visible,
.rr-refresh-btn:focus-visible,
.rr-jump-next-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Interactive Map + Stop Explorer Edge-to-Edge Workbench */
.rr-map-shell {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    background: #ffffff;
    border-radius: 0;
    overflow: hidden;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
}

@media (min-width: 992px) {
    .rr-map-shell {
        grid-template-columns: minmax(0, 1fr) 360px;
    }
}

.rr-map-shell.rr-map-maximized,
.rr-map-shell:fullscreen {
    position: fixed;
    inset: 0;
    z-index: 10050;
    border-radius: 0;
    border: 0;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    width: 100dvw;
}

.rr-map-stage {
    position: relative;
    min-height: 400px;
    height: 400px;
    background: #e2e8f0;
}

.rr-map-shell.rr-map-maximized .rr-map-stage,
.rr-map-shell:fullscreen .rr-map-stage {
    height: 100vh;
    height: 100dvh;
}

#map {
    width: 100%;
    height: 100%;
}

/* Map Top Overlays */
.rr-map-hud {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 800;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 0.9rem;
    padding: 0.6rem 0.85rem;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.14);
    max-width: calc(100% - 24px);
}

@media (min-width: 768px) {
    .rr-map-hud {
        max-width: 340px;
    }
}

.rr-map-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 800;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: calc(100% - 24px);
}

.rr-style-group {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 0.65rem;
    padding: 2px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.rr-style-btn,
.rr-ctrl-btn {
    border: none;
    background: transparent;
    color: #1e293b;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.38rem 0.62rem;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.rr-ctrl-btn {
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 0.65rem;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.rr-style-btn.active {
    background: var(--route-accent-btn-bg);
    color: var(--route-accent-btn-text);
}

.rr-ctrl-btn:hover,
.rr-style-btn:not(.active):hover {
    background: #f1f5f9;
}

.rr-refresh-btn {
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #334155;
    border-radius: 0.45rem;
    padding: 0.15rem 0.4rem;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.rr-refresh-btn.is-spinning .material-icons {
    animation: rrSpin 0.9s linear infinite;
}

@keyframes rrSpin {
    to { transform: rotate(360deg); }
}

.rr-hud-bus-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.rr-hud-bus-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.74rem;
    font-weight: 700;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #0f172a;
    border-radius: 9999px;
    padding: 0.15rem 0.55rem;
    cursor: pointer;
}

.rr-hud-bus-pill:hover {
    background: var(--route-accent-soft);
    border-color: var(--route-accent-border);
}

.rr-hud-bus-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

/* Map Legend */
.rr-map-legend {
    position: absolute;
    bottom: 12px;
    left: 12px;
    z-index: 800;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 0.65rem;
    padding: 0.35rem 0.7rem;
    font-size: 0.74rem;
    color: #334155;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}

.rr-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.rr-legend-line {
    width: 16px;
    height: 4px;
    background: var(--route-polyline);
    border-radius: 2px;
    display: inline-block;
}

.rr-legend-stop {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffffff;
    border: 2.5px solid var(--route-accent);
    display: inline-block;
}

.rr-legend-hub {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fbbf24;
    border: 2.5px solid var(--route-accent-dark);
    display: inline-block;
}

/* Stop Explorer Sidebar */
.rr-stop-explorer {
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    height: 360px;
}

@media (min-width: 992px) {
    .rr-stop-explorer {
        border-top: none;
        border-left: 1px solid #e2e8f0;
        height: 400px;
    }
}

.rr-map-shell.rr-map-maximized .rr-stop-explorer,
.rr-map-shell:fullscreen .rr-stop-explorer {
    height: 100vh;
    height: 100dvh;
}

.rr-explorer-header {
    padding: 0.75rem 1rem 0.65rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.rr-dir-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-top: 0.5rem;
}

.rr-dir-btn {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.32rem 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
}

.rr-dir-btn.active {
    background: var(--route-accent-btn-bg);
    border-color: var(--route-accent-btn-bg);
    color: var(--route-accent-btn-text);
}

.rr-nearest-active {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.65rem;
}

.rr-stop-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.rr-stop-item {
    text-align: left;
    width: 100%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.7rem;
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.12s ease;
}

.rr-stop-item:hover {
    border-color: var(--route-accent-border);
    background: #fffafa;
    transform: translateY(-1px);
}

.rr-stop-item.is-selected {
    border-color: var(--route-accent);
    background: var(--route-accent-soft);
    box-shadow: 0 0 0 1px var(--route-accent);
}

.rr-stop-item-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.rr-stop-name {
    font-weight: 700;
    font-size: 0.86rem;
    color: #0f172a;
    line-height: 1.25;
}

.rr-stop-eta {
    font-size: 0.74rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 9999px;
    background: #dcfce7;
    color: #166534;
    white-space: nowrap;
    flex-shrink: 0;
}

.rr-stop-eta.is-empty {
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
}

.rr-stop-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 0.3rem;
    font-size: 0.74rem;
}

/* Leaflet Custom Markers */
.rr-stop-marker-wrap,
.rr-vehicle-marker-wrap,
.rr-user-marker-wrap {
    background: transparent;
    border: none;
}

.rr-stop-marker {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid var(--route-accent);
    box-shadow: 0 2px 5px rgba(15, 23, 42, 0.35);
}

.rr-stop-marker.is-hub {
    background: #fbbf24;
    border: 3px solid var(--route-accent-dark);
    box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35), 0 3px 8px rgba(15, 23, 42, 0.4);
}

.rr-stop-marker.is-selected {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35);
}

.rr-vehicle-pin {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rr-vehicle-pulse {
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    border: 2px solid var(--rr-status-color, #16a34a);
    opacity: 0.65;
    animation: rrBusPulse 2s ease-out infinite;
}

@keyframes rrBusPulse {
    0% { transform: scale(0.85); opacity: 0.8; }
    100% { transform: scale(1.35); opacity: 0; }
}

.rr-vehicle-badge {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #16a34a;
    padding: 3px;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.rr-vehicle-badge img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.rr-vehicle-dir-tag {
    position: absolute;
    bottom: -2px;
    right: -2px;
    z-index: 3;
    color: #ffffff;
    font-size: 0.62rem;
    font-weight: 800;
    padding: 0 4px;
    border-radius: 9999px;
    border: 1.5px solid #ffffff;
    line-height: 1.3;
}

.rr-user-dot {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2563eb;
    border: 3px solid #ffffff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.3);
}

.rr-popup { min-width: 210px; font-size: 0.84rem; }
.rr-popup-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.rr-popup-title { font-weight: 700; color: #0f172a; }
.rr-popup-route { border-top: 1px solid #e2e8f0; padding-top: 6px; margin-top: 6px; }
.rr-popup-route-label { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.rr-eta-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.rr-eta-chip {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.74rem;
}

@media (max-width: 767.98px) {
    .rr-map-hud {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rr-vehicle-pulse,
    .rr-refresh-btn.is-spinning .material-icons {
        animation: none !important;
    }

    .rr-stop-item {
        transition: none !important;
    }

    .rr-stop-item:hover {
        transform: none !important;
    }
}

@media print {
    .rr-page {
        padding-top: 0 !important;
        background: #ffffff !important;
    }

    .rr-map-shell,
    .rr-schedule-actions,
    #rrJumpNextOut,
    #rrJumpNextIn {
        display: none !important;
    }

    .rr-schedule-card {
        border-top-width: 2px;
        box-shadow: none !important;
    }

    .rr-schedule-scroll {
        max-height: none !important;
        overflow: visible !important;
    }
}
