/* 滿版地圖 */
#map {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* 底層 */
}

/* 懸浮玻璃側邊欄 */
#sidebar {
    position: fixed;
    top: 20px;
    left: 20px;
    bottom: 20px;
    width: 360px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.admin-mode {
    border: 2px solid #FFD700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4), var(--shadow-lg);
}

#sidebar.user-mode {
    border: 2px solid var(--accent-color);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4), var(--shadow-lg);
}

/* Desktop Collapsed State */
#sidebar.collapsed {
    transform: translateX(-400px);
    /* 360px width + 20px left + extra buffer */
}

/* Floating Toggle Button */
#sidebar-toggle-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 90;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.3s, transform 0.3s;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-20px);
}

#sidebar-toggle-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

/* My Location Floating Button */
#my-location-btn {
    position: fixed;
    bottom: 130px;
    /* Aligned with map controls usually */
    right: 60px;
    width: 50px;
    height: 50px;
    background: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 5;
    /* Above map */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s;
}

#my-location-btn:hover {
    background: #f8f8f8;
    color: #333;
    transform: scale(1.05);
}

#my-location-btn:active {
    background: #eee;
    transform: scale(0.95);
}

/* F235: Persistent tracking states
   - tracking-active     : following + auto-centering (blue, pulsing)
   - tracking-unfollowed : following but camera drifted off after user drag
                           (orange, static — tap to re-center)
   - tracking-paused     : screen-off power-save pause (dim, normally not visible) */
#my-location-btn.tracking-active {
    color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4), 0 0 0 0 rgba(37, 99, 235, 0.6);
    animation: locationTrackPulse 1.6s ease-out infinite;
}

#my-location-btn.tracking-unfollowed {
    color: #f59e0b;
    background: #fffbeb;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
}

#my-location-btn.tracking-paused {
    color: #9ca3af;
    background: #f3f4f6;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    opacity: 0.7;
}

@keyframes locationTrackPulse {
    0%   { box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4), 0 0 0 0 rgba(37, 99, 235, 0.55); }
    70%  { box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4), 0 0 0 14px rgba(37, 99, 235, 0); }
    100% { box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4), 0 0 0 0 rgba(37, 99, 235, 0); }
}

/* Refresh Floating Button */
#refresh-btn {
    position: fixed;
    bottom: 190px;
    right: 60px;
    width: 50px;
    height: 50px;
    background: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s;
}

#refresh-btn:hover {
    background: #f8f8f8;
    color: #2563eb;
    /* Blue on hover */
    transform: scale(1.05);
}

#refresh-btn:active {
    background: #eee;
    transform: scale(0.95) rotate(180deg);
    /* Rotate effect on click */
    transition: transform 0.2s;
}

/* Map long-press ripple feedback — starts large, shrinks to pinpoint */
.map-longpress-ripple {
    position: fixed;
    width: 120px;
    height: 120px;
    margin-left: -60px;
    margin-top: -60px;
    border-radius: 50%;
    border: 2.5px solid rgba(37, 99, 235, 0.5);
    background: rgba(37, 99, 235, 0.08);
    pointer-events: none;
    z-index: 9999;
    animation: mapRippleShrink 0.5s ease-in-out forwards;
}

@keyframes mapRippleShrink {
    0% {
        transform: scale(2);
        opacity: 0;
    }
    20% {
        opacity: 0.8;
    }
    100% {
        transform: scale(0.6);
        opacity: 1;
        border-color: rgba(37, 99, 235, 0.8);
        background: rgba(37, 99, 235, 0.12);
    }
}

/* Adjust for Mobile */
@media (max-width: 768px) {
    /* Sidebar collapsed height = 125px + safe-area-inset-bottom (sidebar.css);
       float buttons sit 25px above its top edge, plus tracking the safe-area inset
       so iPhone home-indicator zone never clips them. */
    #my-location-btn {
        bottom: calc(150px + env(safe-area-inset-bottom));
        right: 16px;
        transition: bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    }

    #refresh-btn {
        bottom: calc(210px + env(safe-area-inset-bottom));
        right: 16px;
        transition: bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    }

    /* When sidebar is fully expanded, hide floating buttons to avoid overlap */
    body.sidebar-expanded #my-location-btn,
    body.sidebar-expanded #refresh-btn {
        opacity: 0;
        pointer-events: none;
    }
}

/* Landscape mode: reduce sidebar height so map remains visible */
@media (max-height: 500px) and (orientation: landscape) {
    #sidebar {
        height: 35vh !important;
    }
    #sidebar.collapsed {
        height: calc(100px + env(safe-area-inset-bottom)) !important;
    }
}
