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

body {
    font-family: 'Figtree', system-ui, -apple-system, sans-serif;
    overflow: hidden;
    background: #0f172a;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

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

/* === Loading Overlay === */
#loadingOverlay {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: #0f172a; z-index: 9999;
    color: #94a3b8; font-size: 0.95rem; gap: 1rem;
    transition: opacity 0.5s;
}
#loadingOverlay.hidden { opacity: 0; pointer-events: none; }
.loader {
    width: 40px; height: 40px;
    border: 4px solid #1e293b;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Error Banner === */
#errorBanner {
    position: fixed; top: 1rem; left: 50%; transform: translateX(-50%);
    background: #7f1d1d; color: #fca5a5;
    padding: 1rem 2rem; border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
    z-index: 9998; text-align: center;
    border: 1px solid #991b1b;
}
#errorBanner code {
    background: #450a0a; padding: 0.1rem 0.4rem; border-radius: 0.25rem;
    font-size: 0.8rem;
}
#errorBanner button {
    margin-top: 0.5rem; padding: 0.4rem 1rem;
    background: #dc2626; color: #fff;
    border: none; border-radius: 0.5rem; cursor: pointer;
    font-weight: 600; font-size: 0.85rem;
}
#errorBanner button:hover { background: #b91c1c; }
.hidden { display: none !important; }

/* === Route Panel === */
#routePanel {
    position: absolute; left: 1rem; top: 1rem; z-index: 1000;
    width: 20rem; max-width: calc(100vw - 2rem);
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(8px);
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    transition: transform 0.2s, opacity 0.2s;
}
#routePanel.collapsed #routePanelBody {
    display: none;
}
#routePanel.collapsed .btn-toggle { transform: rotate(180deg); }

.route-header {
    display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.route-header label {
    font-size: 0.85rem; font-weight: 700; color: #1e293b;
    white-space: nowrap;
}
.btn-toggle {
    background: none; border: 1px solid #cbd5e1; border-radius: 0.375rem;
    width: 1.75rem; height: 1.75rem;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1.1rem; color: #64748b;
    transition: transform 0.2s;
}
.btn-toggle:hover { background: #f1f5f9; }

#routeSelect {
    width: 100%; padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1; border-radius: 0.5rem;
    font-size: 0.85rem; font-family: inherit;
    background: #fff; color: #1e293b;
    cursor: pointer;
}
#routeSelect:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }

#routeMeta {
    font-size: 0.75rem; color: #64748b; margin-top: 0.375rem;
}

/* === Leaflet Customizations === */
.leaflet-popup-content-wrapper {
    border-radius: 0.75rem; box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    padding: 0;
}
.leaflet-popup-content { margin: 1rem; min-width: 280px; max-width: 360px; }
.leaflet-popup-close-button { top: 0.5rem !important; right: 0.5rem !important; }

.popup-content h5 {
    font-size: 1rem; font-weight: 700; color: #0f172a;
    margin-bottom: 0.25rem;
}
.popup-content .address {
    font-size: 0.75rem; color: #64748b; margin-bottom: 0.5rem;
}
.popup-content .coords {
    font-size: 0.7rem; color: #94a3b8; margin-bottom: 0.5rem;
    font-family: monospace;
}
.popup-content .coverage {
    display: flex; gap: 0.5rem; flex-wrap: wrap;
    margin-bottom: 0.5rem;
}
.popup-content .coverage span {
    font-size: 0.7rem; background: #f1f5f9; padding: 0.15rem 0.4rem;
    border-radius: 0.25rem; color: #475569;
}
.popup-content .video-wrapper {
    margin-top: 0.5rem; border-radius: 0.5rem; overflow: hidden;
    background: #000;
}
.popup-content video, .popup-content iframe {
    width: 100%; height: 160px;
    display: block; border: 0;
    background: #000; object-fit: cover;
}
.popup-content .no-stream {
    margin-top: 0.5rem; padding: 1rem;
    background: #f8fafc; border-radius: 0.5rem;
    text-align: center; color: #94a3b8; font-size: 0.8rem;
}

/* === Custom Marker === */
.custom-pin-wrapper { background: none !important; border: none !important; }
.custom-pin {
    width: 30px; height: 30px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 36" fill="%233b82f6"><path d="M12 0C5.4 0 0 5.4 0 12c0 9 12 24 12 24s12-15 12-24C24 5.4 18.6 0 12 0z"/><circle cx="12" cy="12" r="5" fill="%23ffffff"/></svg>') no-repeat center;
    background-size: contain;
}
.custom-pin.kab-green {
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 36" fill="%2322c55e"><path d="M12 0C5.4 0 0 5.4 0 12c0 9 12 24 12 24s12-15 12-24C24 5.4 18.6 0 12 0z"/><circle cx="12" cy="12" r="5" fill="%23ffffff"/></svg>') no-repeat center;
    background-size: contain;
}
.custom-pin.kab-red {
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 36" fill="%23ef4444"><path d="M12 0C5.4 0 0 5.4 0 12c0 9 12 24 12 24s12-15 12-24C24 5.4 18.6 0 12 0z"/><circle cx="12" cy="12" r="5" fill="%23ffffff"/></svg>') no-repeat center;
    background-size: contain;
}
.custom-pin.offline { filter: grayscale(1) opacity(0.5); }

/* === Scrape Button === */
.panel-divider {
    border: none; border-top: 1px solid #e2e8f0;
    margin: 0.75rem 0;
}
.btn-scrape {
    width: 100%; padding: 0.6rem 0.75rem;
    background: linear-gradient(135deg, #059669, #047857);
    color: #fff; border: none;
    border-radius: 0.5rem;
    font-size: 0.8rem; font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex; align-items: center; gap: 0.5rem;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
    position: relative; overflow: hidden;
}
.btn-scrape::after {
    content: ''; position: absolute;
    inset: 0; background: rgba(255,255,255,0.1);
    opacity: 0; transition: opacity 0.25s;
}
.btn-scrape:hover::after { opacity: 1; }
.btn-scrape:hover {
    box-shadow: 0 4px 16px rgba(5, 150, 105, 0.45);
    transform: translateY(-1px);
}
.btn-scrape:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(5, 150, 105, 0.3);
}
.btn-scrape:disabled {
    background: linear-gradient(135deg, #94a3b8, #64748b);
    box-shadow: none; cursor: not-allowed;
    transform: none;
}
.btn-scrape:disabled::after { opacity: 0; }
.btn-scrape .scrape-icon {
    font-size: 1.1rem;
    display: inline-block;
    transition: transform 0.25s;
}
.btn-scrape:hover .scrape-icon { transform: rotate(-30deg); }
.btn-scrape.scraping .scrape-icon {
    animation: spin 0.8s linear infinite;
}
.btn-scrape.scraping:hover .scrape-icon { transform: none; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.scrape-status {
    margin-top: 0.5rem; font-size: 0.7rem;
    text-align: center; padding: 0.35rem 0.5rem;
    border-radius: 0.375rem;
    font-weight: 500;
    animation: fadeSlide 0.3s ease;
}
.scrape-status.ok { background: #d1fae5; color: #065f46; }
.scrape-status.err { background: #fee2e2; color: #991b1b; }
.scrape-status.hidden { display: none; }
@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Search Box — Modern === */
.search-box { position: relative; }
#searchInput {
    width: 100%; padding: 0.55rem 0.75rem 0.55rem 2rem;
    border: 1.5px solid #e2e8f0; border-radius: 0.75rem;
    font-size: 0.8rem; outline: none;
    background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath d='M8.5 3a5.5 5.5 0 0 1 4.23 9.02l4.12 4.13a.75.75 0 0 1-1.06 1.06l-4.13-4.12A5.5 5.5 0 1 1 8.5 3zm0 1.5a4 4 0 1 0 0 8 4 4 0 0 0 0-8z'/%3E%3C/svg%3E") 0.6rem 50% / 1rem no-repeat;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    box-sizing: border-box;
}
#searchInput:focus {
    border-color: #3b82f6; background: #fff;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12), 0 1px 3px rgba(0,0,0,0.06);
}
#searchInput::placeholder { color: #94a3b8; font-weight: 400; }
.search-dropdown {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    max-height: 260px; overflow-y: auto;
    background: rgba(255,255,255,0.98);
    border: 1px solid #f1f5f9; border-radius: 0.75rem;
    box-shadow: 0 12px 40px rgba(0,0,0,0.12);
    z-index: 1000; padding: 0.4rem;
    animation: dropIn 0.15s ease;
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.search-dropdown.hidden { display: none; }
.search-item { padding: 0.5rem 0.75rem; border-radius: 0.5rem; cursor: pointer; transition: background 0.15s; margin-bottom: 2px; }
.search-item:last-child { margin-bottom: 0; }
.search-item:hover { background: #eff6ff; }
.search-item:active { background: #dbeafe; }
.search-item .label { font-size: 0.8rem; font-weight: 600; color: #1e293b; }
.search-item .sub { font-size: 0.7rem; color: #94a3b8; margin-top: 0.15rem; display: flex; gap: 0.4rem; }
.search-item .sub .tag { display: inline-block; padding: 0.05rem 0.4rem; border-radius: 0.25rem; font-size: 0.65rem; font-weight: 600; }
.search-item .sub .tag-kota { background: #dbeafe; color: #1d4ed8; }
.search-item .sub .tag-kab { background: #d1fae5; color: #047857; }
.search-item .sub .tag-hls { background: #fef3c7; color: #b45309; }
.search-item .sub .tag-yt { background: #fce7f3; color: #be185d; }
.search-item .sub .tag-off { background: #f1f5f9; color: #64748b; }
#routePanelBody { overflow: visible !important; }

/* Responsive */
@media (max-width: 640px) {
    #routePanel { width: 16rem; left: 0.5rem; top: 0.5rem; padding: 0.75rem; }
    .leaflet-popup-content { min-width: 220px; max-width: 280px; }
}
