/* GoApex Route 1 Live Map */

:root {
    --ga-blue: #337E9D;
    --ga-blue-dark: #205F7A;
    --panel-bg: #ffffff;
    --text: #2c3e50;
    --muted: #7f8c8d;
    --green: #27ae60;
    --yellow: #f39c12;
    --red: #e74c3c;
    --purple: #8e44ad;
    --gray: #95a5a6;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
}

body {
    padding-top: var(--appbar-height, 60px);
    overflow: hidden;
}

#map {
    position: fixed;
    top: var(--appbar-height, 60px);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    background: #dde7ec;
}

/* ============ Panel (sliding sidebar) ============ */

.panel {
    position: fixed;
    top: var(--appbar-height, 60px);
    left: 0;
    bottom: 0;
    width: min(330px, 85vw);
    background: var(--panel-bg);
    border-right: 1px solid #e2e8ec;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.10);
    z-index: 850;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel.open { transform: translateX(0); }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 840;
    background: rgba(17, 24, 39, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    user-select: none;
    border-bottom: 1px solid #ecf0f1;
    background: #fafbfc;
    flex-shrink: 0;
}

.panel-summary {
    flex: 1;
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.freshness-pill {
    flex: none;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.freshness-live { background: #e8f8ef; color: var(--green); }
.freshness-stale { background: #f0f3f4; color: var(--muted); }

.panel-close {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.panel-close:hover {
    background: #eef2f4;
    color: var(--text);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
}

.panel-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 8px;
}

/* ============ Status badge ============ */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 3px 10px 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.status-live        { background: #e8f8ef; color: var(--green); }
.status-live .status-dot { animation: pulse 2s infinite; }
.status-stale       { background: #fef5e7; color: var(--yellow); }
.status-none        { background: #f0f3f4; color: var(--gray); }
.status-unavailable { background: #fdedec; color: var(--red); }
.status-fixture     { background: #f4ecf7; color: var(--purple); }
.status-loading     { background: #f0f3f4; color: var(--gray); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.status-detail {
    font-size: 0.82rem;
    background: #fef5e7;
    border-left: 3px solid var(--yellow);
    padding: 8px 10px;
    border-radius: 4px;
    margin-bottom: 12px;
}

.status-detail.severe {
    background: #fdedec;
    border-left-color: var(--red);
}

/* ============ Bus list ============ */

.bus-list {
    list-style: none;
    margin-bottom: 14px;
}

.bus-list li {
    padding: 8px 10px;
    border: 1px solid #ecf0f1;
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.bus-list li:hover { background: #f4f9fb; }

.bus-list .bus-list-empty {
    cursor: default;
    color: var(--muted);
    font-size: 0.85rem;
    border-style: dashed;
}
.bus-list .bus-list-empty:hover { background: none; }

.bus-row-top {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 0.92rem;
}

.bus-number {
    font-weight: 700;
    color: var(--ga-blue);
}

.bus-dest { flex: 1; }

.bus-row-sub {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 2px;
    display: flex;
    gap: 10px;
}

.bus-age-stale { color: var(--yellow); font-weight: 600; }
.bus-age-old   { color: var(--red); font-weight: 600; }

/* ============ Nearest stop card ============ */

.nearest-stop {
    background: #eef6f9;
    border: 1px solid #d3e7ef;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
    cursor: pointer;
    font-size: 0.85rem;
}

.nearest-stop:hover { background: #e3f0f5; }

.nearest-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ga-blue);
    font-weight: 700;
    margin-bottom: 2px;
}

.nearest-name { font-weight: 600; }

.nearest-walk {
    color: var(--muted);
    font-size: 0.78rem;
    margin-bottom: 6px;
}

.nearest-depart { padding: 1px 0; }
.nearest-depart b { color: var(--ga-blue); }
.nearest-depart.tight b { color: var(--yellow); }

/* Multiple stops (nearest + favorites) stack inside the same card */
.stopcard-entry { padding: 4px 0; }
.stopcard-entry + .stopcard-entry {
    border-top: 1px solid #d3e7ef;
    margin-top: 8px;
    padding-top: 8px;
}
.stopcard-entry .nearest-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

/* Heart / favorite toggle — same design language as cipmap's vote buttons:
   a FontAwesome heart, outline (far) when not favorited, filled (fas) when it
   is, with a soft red tint behind the active state. */
.heart-btn.vote-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}
.heart-btn.vote-btn:hover {
    background: rgba(231, 76, 60, 0.1);
    color: var(--red);
}
.heart-btn.vote-btn.active {
    color: var(--red);
    background: rgba(231, 76, 60, 0.1);
}
.heart-btn.vote-btn.active i { font-weight: 900; }

.stop-popup h3 .heart-btn { float: right; margin: -2px -2px 0 4px; }

/* ============ Delay chips (GTFS-RT schedule deviation) ============ */

.delay-chip {
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
    white-space: nowrap;
}

.delay-ontime { background: #e8f8ef; color: var(--green); }
.delay-late   { background: #fdedec; color: var(--red); }
.delay-early  { background: #fef5e7; color: var(--yellow); }

/* ============ Legend & service summary ============ */

.legend { margin-bottom: 14px; }

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    margin-bottom: 5px;
    color: var(--text);
}

.legend-line {
    width: 26px;
    height: 0;
    border-top: 4px solid var(--ga-blue);
    border-radius: 2px;
    flex: none;
}

.legend-line-east {
    border-top-style: dashed;
    border-top-color: var(--ga-blue-dark);
}

.legend-stop {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--ga-blue);
    flex: none;
    margin-left: 7px;
    margin-right: 7px;
}

.service-summary {
    font-size: 0.82rem;
    color: var(--text);
    background: #eef6f9;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 14px;
}

/* ============ Timetable ============ */

.timetable {
    border-top: 1px solid #ecf0f1;
    padding-top: 10px;
    margin-bottom: 14px;
}

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

.timetable-close {
    border: none;
    background: none;
    font-size: 1.3rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    padding: 0 4px;
}

.timetable-direction {
    font-size: 0.82rem;
    font-weight: 600;
    margin: 8px 0 4px;
}

.timetable-times {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.timetable-times span {
    font-size: 0.78rem;
    background: #f0f3f4;
    border-radius: 4px;
    padding: 2px 6px;
    font-variant-numeric: tabular-nums;
}

.timetable-times span.past { color: #b2bec3; }
.timetable-times span.next {
    background: var(--ga-blue);
    color: #fff;
    font-weight: 600;
}

/* ============ Footer (pinned About) ============ */

.panel-links {
    border-top: 1px solid #ecf0f1;
    padding-top: 10px;
    margin-top: 4px;
}

.panel-links a {
    font-size: 0.85rem;
    color: var(--ga-blue);
    text-decoration: none;
    font-weight: 600;
}

.panel-links a:hover { text-decoration: underline; }

.panel-footer {
    flex-shrink: 0;
    border-top: 1px solid #ecf0f1;
    padding: 0.6rem;
    background: #fafbfc;
}

.panel-footer a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.6rem;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.panel-footer a:hover {
    background: #eef6f9;
    color: var(--ga-blue);
}

.panel-footer a i {
    font-size: 1.1rem;
    width: 1.4rem;
    text-align: center;
    color: var(--muted);
    transition: color 0.15s;
}

.panel-footer a:hover i { color: var(--ga-blue); }

/* ============ Map markers ============ */

.bus-marker { position: relative; }

.bus-marker-arrow {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--dir-color, var(--ga-blue));
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

.bus-marker-arrow svg {
    width: 20px;
    height: 20px;
    display: block;
}

.bus-marker-label {
    position: absolute;
    top: 36px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid var(--dir-color, var(--ga-blue));
    color: var(--text);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 4px;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.bus-marker.stale .bus-marker-arrow { opacity: 0.55; }

/* Leaflet popup content */

.stop-popup { font-size: 0.85rem; min-width: 200px; }
.stop-popup h3 { font-size: 0.9rem; margin-bottom: 2px; }
.stop-popup .stop-code { color: var(--muted); font-size: 0.75rem; margin-bottom: 8px; }

.depart-direction { font-weight: 600; margin-top: 6px; }

.depart-times { margin: 2px 0 4px; }

.depart-times .depart-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 1px 0;
}

.depart-min { font-weight: 700; color: var(--ga-blue); white-space: nowrap; }
.depart-clock { color: var(--muted); font-variant-numeric: tabular-nums; }

.stop-popup .popup-loading, .stop-popup .popup-empty { color: var(--muted); }

.stop-popup .popup-timetable-link {
    display: inline-block;
    margin-top: 6px;
    color: var(--ga-blue);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}

.bus-popup { font-size: 0.85rem; }
.bus-popup h3 { font-size: 0.92rem; margin-bottom: 4px; }
.bus-popup .bus-popup-row { color: var(--text); padding: 1px 0; }
.bus-popup .bus-popup-row b { font-weight: 600; }

/* ============ Locate control + user dot ============ */

.locate-btn {
    width: 34px;
    height: 34px;
    background: #fff;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    padding: 0;
}

.locate-btn:hover { background: #f4f4f4; }
.locate-btn.active { color: #4285F4; }
.locate-btn.denied { color: var(--red); cursor: not-allowed; }

.user-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4285F4;
    border: 2.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(66, 133, 244, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3);
    animation: user-pulse 2.5s ease-out infinite;
}

@keyframes user-pulse {
    0% { box-shadow: 0 0 0 1px rgba(66, 133, 244, 0.5), 0 0 0 0 rgba(66, 133, 244, 0.35); }
    70% { box-shadow: 0 0 0 1px rgba(66, 133, 244, 0.5), 0 0 0 12px rgba(66, 133, 244, 0); }
    100% { box-shadow: 0 0 0 1px rgba(66, 133, 244, 0.5), 0 0 0 0 rgba(66, 133, 244, 0); }
}

/* ============ Mobile ============ */

@media (max-width: 768px) {
    .panel {
        width: min(330px, 88vw);
    }
}

/* Desktop: sidebar coexists with the map, no dimming overlay */
@media (min-width: 769px) {
    .sidebar-overlay { display: none; }
}
