:root {
    --bg-dark: #020617;
    --surface: rgba(30, 41, 59, 0.7);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --accent: #ef4444;
    --accent-glow: rgba(239, 68, 68, 0.3);
    --text-primary: #f8fafc;
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
    --danger: #f43f5e;
    --success: #10b981;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Outfit', sans-serif; }

html, body {
    height: 100vh;
    height: -webkit-fill-available;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    background-image: linear-gradient(rgba(2, 6, 23, 0.85), rgba(2, 6, 23, 0.95)), url('https://images.unsplash.com/photo-1513635269975-59663e0ac1ad?q=80&w=2070&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-primary);
    font-size: 1.05rem;
}

/* SPA View Logic */
.view-container {
    display: none;
    height: 100vh;
    height: -webkit-fill-available;
    width: 100%;
    position: relative;
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
#view-map {
    overflow: hidden;
}
.view-container.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

header { padding: 3rem 1rem 1rem; text-align: center; }
header h1 {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -2px;
    background: linear-gradient(to bottom, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
header p {
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 4px;
    font-weight: 600;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.container { max-width: 650px; margin: 0 auto; padding: 0 1.5rem 5rem; }

/* Components: Search, Cards, Buttons, etc. (Merged from modules) */
.glass-panel, .planner-card, .station-card, .search-section {
    background: var(--surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 1100;
}

/* Dynamically elevate z-index of the entire view when suggestions are visible to overlap other page content, but stay under bottom-nav */
.view-container:has(.suggestions[style*="display: block"]) {
    z-index: 5000;
}

.input-group, .search-container { position: relative; margin-bottom: 1rem; }
.input-group input, input#main-search, .search-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1rem 1rem 1rem 3rem;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: 0.3s;
}
.input-group i, .search-icon { position: absolute; left: 1.25rem; top: 50%; transform: translateY(-50%); color: var(--accent); }

.suggestions {
    position: absolute; top: 100%; left: 0; right: 0;
    background: #1e293b;
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    margin-top: 0.5rem;
    max-height: 500px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}
.suggestion-item { padding: 1rem 1.25rem; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.05); }
.suggestion-item:hover { background: var(--accent-glow); }
.route-chip-interactive:hover { background: var(--accent) !important; color: var(--bg-dark) !important; transform: scale(1.05); }

.mode-selector { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.mode-btn {
    width: 3.2rem; height: 3.5rem;
    background: var(--surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 0.8rem;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.3s;
    color: var(--text-secondary); font-size: 1.1rem;
}
.mode-btn.active { background: var(--mode-color, var(--accent)); color: white; box-shadow: 0 10px 20px var(--mode-glow, var(--accent-glow)); }

/* Map UI */
#map { height: 100vh; width: 100%; z-index: 1; }
.hud-container {
    position: absolute; top: 0; left: 1rem; right: 1rem;
    z-index: 1001; pointer-events: none;
    max-width: 500px; margin: 0 auto;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.hud-container.collapsed {
    transform: translateY(calc(-100% + 2rem)) !important;
}
.hud-handle {
    position: absolute; 
    bottom: -1.8rem; 
    left: 50%; 
    transform: translateX(-50%); 
    width: 4rem; 
    height: 1.8rem; 
    background: var(--bg-dark); 
    border: 1px solid var(--accent); 
    border-top: none;
    border-radius: 0 0 1.2rem 1.2rem; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    color: var(--accent); 
    box-shadow: 0 5px 15px rgba(0,0,0,0.5), 0 0 10px var(--accent-glow); 
    z-index: 1001;
    backdrop-filter: blur(5px);
}
.map-tools { 
    position: absolute; 
    bottom: 6rem; 
    right: 1.2rem; 
    z-index: 10000; 
    display: flex; 
    flex-direction: column; 
    gap: 0.8rem; 
}
.map-tools-left { 
    position: absolute; 
    bottom: 6rem; 
    left: 1.2rem; 
    z-index: 10000; 
    display: flex; 
    flex-direction: column; 
    gap: 0.8rem; 
    pointer-events: none; 
}
.map-tools-left .tool-group, .map-tools .tool-group {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    pointer-events: auto;
}
.tool-btn {
    width: 3.8rem; height: 3.8rem;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.2rem;
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; cursor: pointer; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.tool-btn:hover { background: var(--accent); color: var(--bg-dark); transform: scale(1.05); border-color: var(--accent); }
.tool-btn.gps-searching {
    background: rgba(56, 189, 248, 0.15) !important;
    border-color: #38bdf8 !important;
    color: #38bdf8 !important;
    animation: gpsBtnPulse 1s ease-in-out infinite;
}
@keyframes gpsBtnPulse {
    0%, 100% { box-shadow: 0 5px 15px rgba(0,0,0,0.3), 0 0 0 0 rgba(56, 189, 248, 0.5); }
    50% { box-shadow: 0 5px 15px rgba(0,0,0,0.3), 0 0 0 8px rgba(56, 189, 248, 0); }
}
/* Nearby mode filter chips */
.nearby-mode-chip { opacity: 1; transition: opacity 0.2s, filter 0.2s; }
.nearby-mode-chip:not(.active) { opacity: 0.22; filter: grayscale(0.6); }

/* Radius Circle Pulse */
@keyframes nearbyCirclePulse {
    0% { stroke-opacity: 0.8; fill-opacity: 0.1; }
    50% { stroke-opacity: 0.4; fill-opacity: 0.2; }
    100% { stroke-opacity: 0.8; fill-opacity: 0.1; }
}
.nearby-search-circle-pulse {
    animation: nearbyCirclePulse 3s ease-in-out infinite;
}
@keyframes gpsToastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes gpsToastOut {
    from { opacity: 1; transform: translateX(-50%) translateY(0); }
    to   { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

.skeleton-pulse {
    animation: skeletonPulse 1.5s ease-in-out infinite;
}
@keyframes skeletonPulse {
    0% { opacity: 0.05; }
    50% { opacity: 0.15; }
    100% { opacity: 0.05; }
}

/* --- Public Display Responsive Engine --- */
@media screen and (max-width: 768px) {
    #view-display > div {
        padding: 1rem !important;
    }
    #view-display h1 {
        font-size: 1.5rem !important;
    }
    #display-clock {
        font-size: 1.8rem !important;
    }
    #display-arrivals-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        overflow-y: auto !important; /* Allow scroll on mobile portrait if multiple stations */
    }
    .display-row {
        grid-template-columns: 25px 60px 1fr 65px !important; /* Index, Line, Dest, Exp */
        gap: 0.4rem !important;
    }
    .display-platform, .display-time {
        display: none !important;
    }
}

#view-display::-webkit-scrollbar { width: 0px; }

.chip {
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    padding: 0.3rem 0.6rem; border-radius: 1rem; font-size: 0.7rem;
    cursor: pointer; transition: 0.2s; color: var(--text-secondary);
}
.chip.active { background: var(--accent); color: var(--bg-dark); font-weight: 800; border-color: var(--accent); }

.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 4.8rem; background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px); border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex; align-items: stretch; z-index: 10000;
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.3rem; color: var(--text-secondary); text-decoration: none; font-size: 0.75rem;
    font-weight: 700; cursor: pointer; transition: 0.3s;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
}
.nav-item:last-child { border-right: none; }
.nav-item.active { color: var(--accent); background: rgba(56, 189, 248, 0.03); }
.nav-item.active::after {
    content: ''; position: absolute; top: 0; left: 20%; right: 20%; height: 3px;
    background: var(--accent); border-radius: 0 0 4px 4px; box-shadow: 0 0 10px var(--accent-glow);
}
.nav-item i { font-size: 1.1rem; transition: 0.3s; }
.nav-item.active i { transform: translateY(-2px); }

/* Logo */
.logo-container { display: flex; align-items: center; justify-content: center; gap: 0.8rem; margin-bottom: 0.5rem; }
.roundel-o {
    width: 2rem; height: 2rem; border: 5px solid #dc241f; border-radius: 50%;
    position: relative; display: flex; align-items: center; justify-content: center;
}
.roundel-o::after { content: ''; position: absolute; width: 140%; height: 6px; background: #dc241f; z-index: 1; }
.logo-text { font-size: 1.8rem; font-weight: 900; color: var(--text-main); line-height: 1; }

/* Header Controls */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    width: 100%;
}
.corner-btn {
    width: 2.8rem; height: 2.8rem;
    background: var(--surface); backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border); border-radius: 0.8rem;
    color: var(--accent); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.3s; z-index: 10;
}
.corner-btn:hover { background: var(--accent); color: white; box-shadow: 0 0 20px var(--accent-glow); }

/* Enhanced Search Bar */
.search-input-wrapper { display: flex; gap: 0.5rem; position: relative; }
.search-action-btn {
    width: 3.5rem; height: 3.5rem;
    background: var(--accent); color: var(--bg-dark);
    border: none; border-radius: 1rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; cursor: pointer; transition: 0.3s;
}
.search-action-btn:hover { transform: scale(1.05); filter: brightness(1.1); box-shadow: 0 0 20px var(--accent-glow); }

/* Station Card Enhancements */
.station-card { padding: 1.2rem; }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.station-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.btn-delete { color: var(--danger); opacity: 0.5; cursor: pointer; transition: 0.3s; font-size: 0.9rem; margin-top: 0.2rem; }
.btn-delete:hover { opacity: 1; transform: scale(1.2); }

.line-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 0.8rem; }
.line-chip {
    padding: 0.2rem 0.6rem; border-radius: 0.4rem; font-size: 0.65rem; font-weight: 800;
    background: rgba(255,255,255,0.1); color: var(--text-secondary); cursor: pointer; transition: 0.2s;
    border: 1px solid transparent;
}
.line-chip.active { background: var(--accent); color: var(--bg-dark); }
.line-chip.all { background: var(--accent); color: var(--bg-dark); }

.arrival-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.8rem 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.arrival-row:last-child { border-bottom: none; }
.arrival-info { display: flex; align-items: center; gap: 0.8rem; flex: 1; }
.line-badge {
    min-width: 2.2rem; height: 1.6rem; display: flex; align-items: center; justify-content: center;
    border-radius: 0.3rem; font-size: 0.8rem; font-weight: 900; color: white;
}
.arrival-details { display: flex; flex-direction: column; }
.arrival-dest { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); }
.arrival-meta { font-size: 0.7rem; color: var(--text-secondary); }
.arrival-time-box { text-align: right; min-width: 4.5rem; }
.arrival-due { font-size: 1rem; font-weight: 800; color: var(--accent); display: block; }
.arrival-clock { font-size: 0.7rem; color: var(--text-secondary); }

/* Animation */
.user-location-pulse {
    width: 14px; height: 14px; background: #38bdf8; border: 3px solid #fff; border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

.scanner-circle {
    width: 4rem;
    height: 4rem;
    border: 2px solid var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.scanner-circle::after {
    content: '';
    position: absolute;
    top: -5px; left: -5px; right: -5px; bottom: -5px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    animation: scanPulse 1.5s ease-out infinite;
    opacity: 0;
}
@keyframes scanPulse {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.8); opacity: 0; }
}

/* ============================================================
   LIVE NAVIGATION OVERLAY — Compact Map-First Layout
   ============================================================ */
.nav-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9000;
    flex-direction: column;
    animation: slideUpFade 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: #020617;
}
.nav-overlay.active {
    display: flex;
}
@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Compact top information strip */
.nav-compact-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: rgba(2, 6, 23, 0.97);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
    min-height: 4.5rem;
    padding-top: env(safe-area-inset-top, 0.6rem);
}
.nav-compact-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    overflow: hidden;
    min-width: 0;
}
.nav-compact-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
    flex-shrink: 0;
}
.nav-leg-badge {
    font-size: 0.6rem;
    font-weight: 900;
    letter-spacing: 2px;
    opacity: 0.45;
    text-transform: uppercase;
}
.nav-step-inline {
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-step-inline .nav-step-title {
    font-weight: 800;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-step-inline .nav-step-meta {
    font-size: 0.7rem;
    opacity: 0.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-step-inline .nav-step-next {
    font-size: 0.65rem;
    color: var(--accent);
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Alert pill (inline, not full-width banner) */
.nav-alert-pill {
    font-size: 0.65rem;
    font-weight: 800;
    padding: 0.2rem 0.6rem;
    border-radius: 2rem;
    text-align: center;
    max-width: 9rem;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}
.nav-alert-board { background:rgba(56,189,248,0.15); border:1px solid var(--accent); color:var(--accent); }
.nav-alert-alight { background:rgba(16,185,129,0.15); border:1px solid var(--success); color:var(--success); }

.nav-stop-btn {
    background: rgba(220, 36, 31, 0.2);
    border: 1px solid #dc241f;
    color: #ff6b6b;
    border-radius: 0.6rem;
    padding: 0.4rem 0.9rem;
    font-weight: 900;
    font-size: 0.75rem;
    cursor: pointer;
    letter-spacing: 1px;
    transition: 0.2s;
    white-space: nowrap;
}
.nav-stop-btn:hover { background: #dc241f; color: #fff; }

.map-layer-stack {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    pointer-events: auto;
}

.layer-btn {
    width: 3.8rem;
    height: 3.8rem;
    border-radius: 1.2rem;
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.layer-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: scale(1.05);
}

.layer-btn.active {
    background: var(--accent);
    color: var(--bg-dark);
    box-shadow: 0 0 20px var(--accent-glow);
    border-color: var(--accent);
}

@keyframes pulse-red {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(220, 36, 31, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(220, 36, 31, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(220, 36, 31, 0); }
}

.pulse-marker-icon {
    background: #dc241f;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    box-shadow: 0 0 0 rgba(220, 36, 31, 0.4);
    animation: pulse-red 2s infinite;
    border: 2px solid white;
}

.tool-btn.active {
    background: var(--accent) !important;
    color: var(--bg-dark) !important;
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Desktop Scaling Adjustments - 10% UI Reduction */
@media (min-width: 1024px) {
    html {
        font-size: 90%;
    }
}
