/* Map Page Styles */

/* Theme Variables */
:root {
    --ui-bg: rgba(255, 255, 255, 0.95);
    --ui-border: rgba(0, 0, 0, 0.08);
    --ui-text: #1a1a2e;
    --ui-text-muted: #666;
    --ui-hover: #f5f5f5;
    --ui-shadow: rgba(0, 0, 0, 0.15);
    --page-bg: #f5f5f5;
    --ui-glass: rgba(255, 255, 255, 0.75);
    --ui-glass-border: rgba(0, 0, 0, 0.06);
    --popup-bg: rgba(30, 30, 40, 0.92);
    --popup-border: rgba(88, 166, 255, 0.2);
}

body.theme-dark {
    --ui-bg: rgba(22, 27, 34, 0.95);
    --ui-border: rgba(255, 255, 255, 0.1);
    --ui-text: #f0f6fc;
    --ui-text-muted: #9BA4AE;
    --ui-hover: #30363d;
    --ui-shadow: rgba(0, 0, 0, 0.4);
    --page-bg: #0d1117;
    --ui-glass: rgba(13, 17, 23, 0.6);
    --ui-glass-border: rgba(255, 255, 255, 0.06);
    --popup-bg: rgba(13, 17, 23, 0.92);
    --popup-border: rgba(88, 166, 255, 0.2);
}

body {
    background: var(--page-bg);
    transition: background 0.3s ease;
}

#map-container {
    width: 100%;
    height: 100vh;
}

#globe-container {
    width: 100%;
    height: 100vh;
    display: none;
    background: #0D1117;
}

#globe-container.active {
    display: block;
}

#map-container.hidden {
    display: none;
}

/* View Toggle Button */
.view-toggle {
    display: flex;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.view-toggle-btn {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    color: var(--ui-text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.view-toggle-btn:hover {
    color: var(--ui-text);
}

.view-toggle-btn.active {
    background: var(--accent-blue);
    color: white;
}

.view-toggle-btn:first-child {
    border-right: 1px solid var(--ui-border);
}

.view-toggle-btn.active:first-child {
    border-right: 1px solid var(--accent-blue);
}

.view-toggle-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.4);
}

/* Header */
.map-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--ui-glass);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid var(--ui-glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
    z-index: 100;
    transition: all 0.3s ease;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--ui-text);
    text-decoration: none;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 600;
    font-size: 1.125rem;
}

.header-logo i {
    color: var(--accent-blue);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Style Selector */
.style-selector {
    position: relative;
}

.style-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-sm);
    color: var(--ui-text);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.style-btn:hover {
    border-color: var(--accent-blue);
}

.style-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.4);
}

.style-dropdown {
    position: absolute;
    top: calc(100% + var(--space-xs));
    right: 0;
    min-width: 180px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px var(--ui-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    overflow: hidden;
}

.style-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.style-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    color: var(--ui-text);
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background var(--transition-fast);
}

.style-option:hover {
    background: var(--ui-hover);
}

.style-option.active {
    color: var(--accent-blue);
}

.style-option i {
    width: 16px;
    text-align: center;
    color: var(--ui-text-muted);
}

.style-option.active i {
    color: var(--accent-blue);
}

/* Control Button */
.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-sm);
    color: var(--ui-text);
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 1;
}

.control-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.control-btn.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Floating Stats Bar Pill */
.stats-bar {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ui-glass);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border: 1px solid var(--ui-glass-border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 24px;
    z-index: 98;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    animation: slideUpStats 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.5s both;
    max-width: 90vw;
    transition: background 0.3s ease, border-color 0.3s ease;
}

@keyframes slideUpStats {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Country Flags Row */
.stats-bar-flags {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--ui-glass-border);
    width: 100%;
}

.flags-label {
    font-size: 0.65rem;
    color: var(--ui-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
    margin-right: 8px;
}

.country-flags-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.country-flag-sm.flag-hidden {
    display: none;
}

.country-flags-bar.expanded .country-flag-sm.flag-hidden {
    display: inline-block;
}

.flags-overflow-badge {
    flex-shrink: 0;
    font-size: 0.65rem;
    color: var(--ui-text-muted);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--ui-glass-border);
    border-radius: 12px;
    padding: 2px 8px;
    margin-left: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.25s ease;
}

.flags-overflow-badge:hover {
    color: var(--ui-text);
    background: rgba(255, 255, 255, 0.15);
}

.country-flag-sm {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--ui-glass-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    object-fit: cover;
    margin-left: -6px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.country-flag-sm:first-child {
    margin-left: 0;
}

.country-flag-sm:hover {
    transform: scale(1.3) translateY(-2px);
    z-index: 10;
    position: relative;
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Stats Row */
.stats-bar-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xl);
}

.stats-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stats-bar-value {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ui-text);
    font-variant-numeric: tabular-nums;
    transition: color 0.3s ease;
    white-space: nowrap;
}

.stats-bar-label {
    font-size: 0.6rem;
    color: var(--ui-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
    transition: color 0.3s ease;
    white-space: nowrap;
}

.stats-bar-divider {
    width: 1px;
    height: 28px;
    background: var(--ui-glass-border);
    transition: background 0.3s ease;
}

.stats-bar-more {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid rgba(88, 166, 255, 0.2);
    border-radius: 50px;
    color: #58A6FF;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.stats-bar-more:hover {
    background: rgba(88, 166, 255, 0.2);
    border-color: rgba(88, 166, 255, 0.4);
    transform: translateY(-1px);
}

.stats-bar-more:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.4);
}

/* Stats Panel (Slide-out) */
.stats-panel {
    position: fixed;
    top: 56px;
    right: -360px;
    width: 360px;
    height: calc(100vh - 56px - 80px);
    background: var(--ui-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--ui-border);
    box-shadow: -4px 0 20px var(--ui-shadow);
    padding: var(--space-lg);
    transition: right var(--transition-normal), background 0.3s ease;
    z-index: 99;
    overflow-y: auto;
    border-radius: 12px 0 0 12px;
}

.stats-panel.open {
    right: 0;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--ui-border);
}

.stats-title {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--ui-text);
}

.stats-close {
    background: none;
    border: none;
    color: var(--ui-text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: var(--space-xs);
}

.stats-close:hover {
    color: var(--ui-text);
}

.stats-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.4);
    border-radius: var(--radius-sm);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--ui-border);
}

.stat-label {
    color: var(--ui-text-muted);
    font-size: 0.875rem;
}

.stat-value {
    color: var(--ui-text);
    font-size: 1rem;
    font-weight: 600;
}


/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    z-index: 98;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Mapbox GL JS controls positioning */
.mapboxgl-ctrl-top-right {
    top: 64px !important;
}

/* Premium Popup Styling */
.mapboxgl-popup {
    z-index: 50;
}

.mapboxgl-popup-content {
    background: rgba(13, 17, 23, 0.55);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    color: #F0F6FC;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid rgba(88, 166, 255, 0.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    font-size: 0.75rem;
    line-height: 1.3;
    min-width: 60px;
}

.mapboxgl-popup-content strong {
    color: #58A6FF;
    font-size: 0.825rem;
    letter-spacing: 0.3px;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
    border-top-color: rgba(13, 17, 23, 0.55);
}

.mapboxgl-popup-anchor-top .mapboxgl-popup-tip {
    border-bottom-color: rgba(13, 17, 23, 0.55);
}

.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
    border-right-color: rgba(13, 17, 23, 0.55);
}

.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
    border-left-color: rgba(13, 17, 23, 0.55);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .country-flag-sm:hover {
        transform: none;
    }
}

/* Responsive */
@media (max-width: 768px) {
    /* Raise stats bar above Ko-fi widget */
    .stats-bar {
        bottom: 80px;
        padding: 10px 16px;
        max-width: 95vw;
    }

    /* Scale down Ko-fi widget on mobile */
    .floatingchat-container-wrap,
    .floatingchat-container-wrap-mobi {
        transform: scale(0.85);
        transform-origin: bottom left;
    }

    .stats-bar-flags {
        margin-bottom: 8px;
        padding-bottom: 8px;
    }

    .stats-bar-row {
        gap: var(--space-md);
    }

    .stats-bar-item {
        min-width: 50px;
    }

    .stats-bar-value {
        font-size: 1rem;
    }

    .stats-bar-label {
        font-size: 0.55rem;
    }

    .country-flag-sm {
        width: 22px;
        height: 22px;
        margin-left: -5px;
    }

    .flags-label {
        display: none;
    }

    .stats-panel {
        width: 100%;
        right: -100%;
        border-radius: 0;
    }
}

/* Small phone responsive */
@media (max-width: 480px) {
    /* Header: compact controls */
    .map-header {
        padding: 0 var(--space-sm);
    }

    .header-logo span {
        display: none;
    }

    .header-controls {
        gap: 4px;
    }

    .view-toggle-btn {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.75rem;
    }

    .style-btn {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.75rem;
    }

    .style-btn #currentStyle {
        display: none;
    }

    .control-btn {
        width: 32px;
        height: 32px;
    }

    /* Stats bar: horizontal scroll */
    .stats-bar {
        max-width: 100vw;
        width: calc(100% - 16px);
        bottom: 52px;
        padding: 8px 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .stats-bar-row {
        gap: var(--space-sm);
        flex-wrap: nowrap;
        min-width: max-content;
    }

    .stats-bar-item {
        min-width: 45px;
    }

    .stats-bar-value {
        font-size: 0.875rem;
    }

    .stats-bar-label {
        font-size: 0.5rem;
    }

    .stats-bar-more {
        font-size: 0.65rem;
        padding: 4px 8px;
        white-space: nowrap;
    }

    .country-flag-sm {
        width: 18px;
        height: 18px;
        margin-left: -6px;
    }
}

/* Warnings Banner */
.warnings-banner {
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    background: rgba(240, 136, 62, 0.12);
    border: 1px solid rgba(240, 136, 62, 0.3);
    border-radius: var(--radius-md, 8px);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    max-width: 520px;
    width: calc(100% - 32px);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.warnings-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
}

.warnings-icon {
    color: #F0883E;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.warnings-text {
    color: #F0883E;
    font-size: 0.8rem;
    font-weight: 500;
}

.warnings-details-btn {
    background: rgba(240, 136, 62, 0.15);
    border: 1px solid rgba(240, 136, 62, 0.25);
    border-radius: 4px;
    color: #F0883E;
    font-size: 0.7rem;
    padding: 2px 8px;
    cursor: pointer;
    margin-left: auto;
    transition: background 0.2s;
}

.warnings-details-btn:hover {
    background: rgba(240, 136, 62, 0.25);
}

.warnings-close {
    background: none;
    border: none;
    color: #F0883E;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.warnings-close:hover {
    opacity: 1;
}

.warnings-detail-list {
    display: none;
    padding: 0 12px 10px;
    max-height: 150px;
    overflow-y: auto;
}

.warnings-detail-list.active {
    display: block;
}

.warnings-detail-item {
    font-size: 0.75rem;
    color: var(--ui-text-muted);
    padding: 3px 0;
    border-top: 1px solid rgba(240, 136, 62, 0.1);
}

@media (max-width: 480px) {
    .warnings-banner {
        max-width: calc(100% - 16px);
        width: calc(100% - 16px);
    }

    .warnings-text {
        font-size: 0.7rem;
    }

    .warnings-detail-list {
        max-height: 100px;
    }

    .warnings-detail-item {
        font-size: 0.65rem;
    }
}

/* ─── Share Card Download ───────────────────────────────────────── */

/* Download selector (wraps button + dropdown) */
.download-selector {
    position: relative;
}

.download-dropdown {
    position: absolute;
    top: calc(100% + var(--space-xs));
    right: 0;
    min-width: 170px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px var(--ui-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    overflow: hidden;
    z-index: 1000;
}

.download-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.download-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    color: var(--ui-text);
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background var(--transition-fast);
}

.download-option:hover {
    background: var(--ui-hover);
}

.download-option i {
    width: 16px;
    text-align: center;
    color: var(--ui-text-muted);
}

/* Hide dropdown on mobile — direct download instead */
@media (max-width: 768px) {
    .download-dropdown {
        display: none !important;
    }
}

/* ─── Share Card Loading Overlay ────────────────────────────────── */

.sharecard-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--page-bg, #0d1117);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.sharecard-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sharecard-loading-plane {
    font-size: 2rem;
    color: var(--accent-blue, #58A6FF);
    animation: sharecardFly 1.8s ease-in-out infinite;
}

.sharecard-loading-text {
    margin-top: var(--space-md, 12px);
    color: var(--ui-text-muted, #9BA4AE);
    font-size: 0.95rem;
}

.sharecard-loading-dots::after {
    content: '';
    animation: sharecardDots 1.5s steps(4, end) infinite;
}

@keyframes sharecardFly {
    0% { transform: translateX(-30px) translateY(4px); opacity: 0.4; }
    50% { transform: translateX(30px) translateY(-4px); opacity: 1; }
    100% { transform: translateX(-30px) translateY(4px); opacity: 0.4; }
}

@keyframes sharecardDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

@media (prefers-reduced-motion: reduce) {
    .sharecard-loading-plane { animation: none; opacity: 1; }
}
