/* ═══ Reset & Base ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    color-scheme: dark;
    --bg: #0f1923;
    --bg-card: #1a2a36;
    --bg-hover: #243544;
    --text: #e0e9f0;
    --text-muted: #8899aa;
    --accent: #d4a545;
    --accent-dim: #a07830;
    --border: #2a3f50;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --radius: 8px;
    --topbar-h: 52px;
}

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

/* ═══ Top Bar ═══ */
#topbar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
    background: var(--bg-card); border-bottom: 1px solid var(--border);
    z-index: 1000; display: flex; align-items: center;
}
.topbar-inner {
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px; width: 100%; height: 100%;
}
.logo { display: flex; align-items: center; gap: 6px; text-decoration: none; flex-shrink: 0; }
.logo-icon { font-size: 22px; }
.logo-text {
    font-size: 18px; font-weight: 700; color: var(--accent);
    letter-spacing: -0.5px;
}

.search-wrap {
    flex: 1; position: relative; max-width: 360px;
}
#search-input {
    width: 100%; padding: 8px 14px; border-radius: 20px;
    border: 1px solid var(--border); background: var(--bg);
    color: var(--text); font-size: 14px; outline: none;
}
#search-input:focus { border-color: var(--accent); }
.search-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); max-height: 300px; overflow-y: auto;
    box-shadow: var(--shadow); z-index: 1001;
}
.search-dropdown .sr-item {
    padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.search-dropdown .sr-item:last-child { border: none; }
.search-dropdown .sr-item:hover { background: var(--bg-hover); }
.sr-item .sr-name { font-weight: 600; font-size: 14px; }
.sr-item .sr-country { font-size: 12px; color: var(--text-muted); }
.sr-item .sr-flag { font-size: 16px; }
.hidden { display: none !important; }

.topbar-stats { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.btn-icon {
    background: none; border: 1px solid var(--border); color: var(--text);
    padding: 6px 10px; border-radius: var(--radius); cursor: pointer;
    font-size: 16px; line-height: 1;
}
.btn-icon:hover { background: var(--bg-hover); border-color: var(--accent-dim); }

/* ═══ Filter Panel ═══ */
#filter-panel {
    position: fixed; top: var(--topbar-h); right: 0; width: 300px;
    max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    background: var(--bg-card); border-left: 1px solid var(--border);
    z-index: 999; box-shadow: var(--shadow);
}
.filter-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.filter-header h3 { font-size: 15px; }
#country-list { padding: 8px 0; }
.country-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; cursor: pointer; font-size: 14px;
}
.country-item:hover { background: var(--bg-hover); }
.country-item.active { color: var(--accent); }
.country-item .ci-count { color: var(--text-muted); font-size: 12px; }
.country-item .ci-clear { color: var(--accent); font-weight: 600; cursor: pointer; padding: 20px 16px; }

/* ═══ Map ═══ */
#main {
    position: fixed; top: var(--topbar-h); left: 0; right: 0;
    bottom: 90px; /* space for footer ad */
    display: flex;
}
#map { flex: 1; }
.leaflet-container { background: #0d1b28; }
.leaflet-popup-content-wrapper { background: var(--bg-card); color: var(--text); border-radius: var(--radius); }
.leaflet-popup-tip { background: var(--bg-card); }
.leaflet-control-zoom a { background: var(--bg-card) !important; color: var(--text) !important; border-color: var(--border) !important; }
.marker-cluster-small { background-color: rgba(212, 165, 69, 0.3) !important; }
.marker-cluster-small div { background-color: rgba(212, 165, 69, 0.6) !important; color: #fff !important; }
.marker-cluster-medium { background-color: rgba(160, 120, 48, 0.3) !important; }
.marker-cluster-medium div { background-color: rgba(160, 120, 48, 0.6) !important; color: #fff !important; }
.marker-cluster-large { background-color: rgba(100, 70, 20, 0.3) !important; }
.marker-cluster-large div { background-color: rgba(100, 70, 20, 0.6) !important; color: #fff !important; }

/* ═══ Info Panel ═══ */
#info-panel {
    width: 380px; overflow-y: auto; background: var(--bg-card);
    border-left: 1px solid var(--border); padding: 0;
}
#info-content {
    padding: 0;
}
.cave-detail {
    padding: 0;
}
.cave-detail-img {
    width: 100%; height: 200px; object-fit: cover;
    display: block; background: var(--bg);
}
.cave-detail-body { padding: 16px; }
.cave-detail h2 { font-size: 20px; margin-bottom: 4px; }
.cave-detail .cd-country { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.cave-detail .cd-desc {
    font-size: 14px; line-height: 1.6; margin-bottom: 16px;
    color: var(--text); max-height: 120px; overflow-y: auto;
}
.cave-detail .cd-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.cd-meta-item { font-size: 13px; }
.cd-meta-item .cdm-label { color: var(--text-muted); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.cave-detail .cd-links { display: flex; gap: 10px; flex-wrap: wrap; }
.cd-link {
    background: var(--bg); padding: 8px 16px; border-radius: 20px;
    text-decoration: none; color: var(--accent); font-size: 13px;
    border: 1px solid var(--border);
}
.cd-link:hover { border-color: var(--accent); background: var(--bg-hover); }
.cd-close-btn {
    position: sticky; top: 8px; float: right; margin: 8px;
    background: rgba(0,0,0,0.5); border: none; color: #fff;
    width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
    font-size: 14px;
}

/* ═══ Footer Ad (desktop only) ═══ */
#footer-ad {
    position: fixed; bottom: 0; left: 0; right: 0; height: 90px;
    background: var(--bg-card); border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
}
.footer-ad-inner { display: flex; justify-content: center; align-items: center; }

/* ═══ Mobile sticky ad strip ═══ */
#mobile-ad-strip {
    display: none;
}
@media (max-width: 768px) {
    #mobile-ad-strip {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 50px;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        z-index: 999;
        overflow: hidden;
    }
}

/* ═══ Info panel ad (shown when cave detail is open) ═══ */
.info-panel-ad {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: center; align-items: center;
    min-height: 60px;
}

/* ═══ Mobile Responsive ═══ */
@media (max-width: 768px) {
    #main { flex-direction: column; }
    #info-panel {
        position: fixed; bottom: 50px; left: 0; right: 0;
        max-height: 50vh; width: 100%; border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        transform: translateY(0);
        transition: transform 0.3s ease;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    }
    #info-panel.hidden {
        transform: translateY(100%);
    }
    #info-panel .cd-close-btn { display: block; }
    .search-wrap { max-width: none; }
    /* Hide footer ad on mobile — replaced by 50px strip */
    #footer-ad { display: none; }
    #main { bottom: 50px !important; }
    .topbar-stats { display: none; }
    .cave-detail-img { height: 160px; }
}

@media (max-width: 480px) {
    #info-panel { max-height: 60vh; }
}

/* ═══ Loading / Empty states ═══ */
.loading-spinner { padding: 40px; text-align: center; color: var(--text-muted); }
.map-placeholder { text-align: center; padding: 40px; color: var(--text-muted); font-size: 14px; }

/* ═══ Custom marker colors ═══ */
.cave-marker {
    background: var(--accent);
    border: 2px solid #fff;
    border-radius: 50%;
    width: 12px; height: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.cave-marker.featured {
    background: #e8491d;
    width: 14px; height: 14px;
}

/* ═══ Scrollbar ═══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══ Page Content (About, etc.) ═══ */
.page-content {
    max-width: 720px;
    margin: 0 auto;
    padding: 80px 24px 40px;
    line-height: 1.7;
}
.page-content h1 {
    font-size: 28px;
    margin-bottom: 16px;
    color: var(--accent);
}
.page-content h2 {
    font-size: 20px;
    margin: 32px 0 12px;
    color: var(--text);
}
.page-content p { margin-bottom: 14px; }
.page-content ul, .page-content ol {
    margin: 12px 0 16px 24px;
}
.page-content li { margin-bottom: 6px; }
.page-content a { color: var(--accent); text-decoration: none; }
.page-content a:hover { text-decoration: underline; }
.page-content strong { color: var(--text); }

.stats-list { list-style: disc; }

.btn-primary {
    display: inline-block;
    background: var(--accent);
    color: var(--bg);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    margin-top: 16px;
}
.btn-primary:hover { background: var(--accent-dim); text-decoration: none; }

/* ═══ SEO Content (visually hidden but crawlable) ═══ */
.seo-content {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}
.seo-content h1, .seo-content h2 {
    font-size: 1px;
    color: transparent;
}
.seo-content a {
    color: transparent;
    text-decoration: none;
}

/* ═══ Country cave list ═══ */
.country-cave-list {
    list-style: none;
    padding: 0;
    margin: 16px 0;
}
.country-cave-list li {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.country-cave-list li:last-child { border-bottom: none; }
.country-cave-list a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}
.country-cave-list a:hover { color: var(--accent); }

/* ═══ Cave detail ═══ */
.cave-detail {
    max-width: 800px;
    margin: 0 auto;
    padding: 72px 24px 40px;
}
.cave-detail h1 {
    font-size: 26px;
    color: var(--accent);
    margin-bottom: 8px;
}
.cave-detail .cave-meta {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 16px;
}
.cave-detail .cave-meta a { color: var(--accent); text-decoration: none; }
.cave-detail .cave-meta a:hover { text-decoration: underline; }
.cave-detail .cave-image {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.cave-detail .data-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    margin: 16px 0;
    font-size: 14px;
}
.cave-detail .data-grid .label {
    color: var(--text-muted);
    font-weight: 500;
}
.cave-detail .cave-description {
    line-height: 1.7;
    margin: 12px 0;
}

/* ── Info Panel Page Link ── */
.cd-page-link {
    background: var(--accent) !important;
    color: var(--bg) !important;
    font-weight: 600 !important;
}
.cd-page-link:hover {
    background: var(--accent-dim) !important;
    border-color: var(--accent) !important;
}