/* ─── Reset & Base ─── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #0a0a14;
    color: #fff;
}

/* ─── Layout 80/20 (mapa + ads) ─── */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#map-container {
    flex: 0 0 80vh;
    position: relative;
}

/* Footer legal */
#legal-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(10, 10, 20, 0.92);
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px 16px;
    text-align: center;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
}

#legal-footer a {
    color: #4fc3f7;
    text-decoration: underline;
}

#legal-footer a:hover {
    color: #80deea;
}

#map {
    width: 100%;
    height: 100%;
}

.visit-counter {
    position: fixed;
    bottom: 20vh;
    left: 8px;
    z-index: 5;
    opacity: 0.5;
}

.visit-counter:hover {
    opacity: 1;
}

.visit-counter img {
    width: 60px;
    height: auto;
}

#ad-zone {
    flex: 0 0 20vh;
    background: #0a0a14;
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.legal-bar {
    background: #000;
    color: #fff;
    font-size: 11px;
    text-align: center;
    padding: 6px 12px;
    flex-shrink: 0;
}

.legal-bar a {
    color: #4fc3f7;
    text-decoration: none;
}

.legal-bar a:hover {
    text-decoration: underline;
}

.ad-banner {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    min-height: 60px;
    width: 100%;
    max-width: 728px;
    height: 90px;
}

/* ─── Controles flotantes (50% opaco, visible al hover) ─── */
.map-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.map-controls:hover {
    opacity: 1;
}

.map-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(18, 18, 30, 0.9);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.15s;
}

.map-btn:hover {
    background: rgba(41, 98, 255, 0.8);
    transform: scale(1.05);
}

.map-btn:active {
    transform: scale(0.95);
}

/* ─── Indicador de nivel de zoom (mismo formato que .map-btn) ─── */
.zoom-level-indicator {
    position: absolute;
    top: 12px;
    right: 20px;
    z-index: 10;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(18, 18, 30, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    opacity: 0.5;
    transition: opacity 0.2s;
    pointer-events: none;
    user-select: none;
}

.zoom-level-indicator:hover {
    opacity: 1;
}

.gps-btn {
    position: absolute;
    bottom: 70px;
    right: 20px;
    z-index: 10;
}

/* ─── Tooltip hover con miniatura (clickeable) ─── */
.map-tooltip {
    position: absolute;
    z-index: 100;
    background: rgba(10, 10, 20, 0.94);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 0;
    font-size: 12px;
    color: #fff;
    pointer-events: auto;
    display: none;
    width: 140px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    cursor: pointer;
}

.map-tooltip.visible {
    display: block;
}

.map-tooltip .tt-img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
    background: #111;
}

.map-tooltip .tt-body {
    padding: 8px 10px;
}

.map-tooltip .tt-title {
    font-weight: 600;
    margin-bottom: 2px;
    font-size: 13px;
}

.map-tooltip .tt-date {
    font-size: 11px;
    opacity: 0.6;
}

/* ─── Filtro de tiempo (timeline de rectángulos) ─── */
.time-filter {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.time-filter-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #4fc3f7;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Contenedor de etiquetas + ticks */
.time-labels-container {
    position: relative;
    height: 28px;
    margin-bottom: 2px;
}

.time-label-tick {
    position: absolute;
    bottom: 0;
    left: 0;
    transform: translateX(-50%);
    text-align: center;
}

.time-label-tick .tick-line {
    display: block;
    width: 1px;
    height: 8px;
    background: #888;
    margin: 0 auto;
}

.time-label-tick .label-text {
    display: block;
    font-size: 12px;
    color: #aaa;
    font-weight: 500;
    letter-spacing: 0.2px;
    white-space: nowrap;
    margin-bottom: 2px;
}

/* Barra de rectángulos */
.time-rects-row {
    display: flex;
    border: 1.5px solid #888;
    border-radius: 5px;
    overflow: hidden;
    height: 22px;
}

.time-rect-btn {
    flex: 1;
    border: none;
    border-right: 1px solid #888;
    cursor: pointer;
    transition: background 0.15s ease;
    padding: 0;
    outline: none;
}

.time-rect-btn:last-child {
    border-right: none;
}

.time-rect-btn.active {
    background: #4CAF50;
}

.time-rect-btn.inactive {
    background: #444;
}

.time-rect-btn:hover {
    filter: brightness(1.15);
}

/* ─── Botones de filtro flotantes (esquina superior izquierda) ─── */
.filter-buttons {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(18, 18, 30, 0.9);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.15s;
    opacity: 0.5;
}

.filter-btn:hover {
    background: rgba(41, 98, 255, 0.8);
    transform: scale(1.05);
    opacity: 1;
}

.filter-btn:active {
    transform: scale(0.95);
}

/* ─── Paneles de filtro (comparten estilo) ─── */
.filter-panel {
    position: absolute;
    top: 12px;
    left: 68px;
    z-index: 10;
    background: rgba(18, 18, 30, 0.94);
    backdrop-filter: blur(16px);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 14px;
    min-width: 480px;
    max-width: 624px;
    font-size: 13px;
    display: none;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    opacity: 0.4;
    transition: opacity 0.2s;
}

.filter-panel.visible {
    display: block;
}

.filter-panel:hover {
    opacity: 1;
}

.filter-panel::-webkit-scrollbar {
    width: 4px;
}

.filter-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.filter-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #4fc3f7;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.filter-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    margin-bottom: 10px;
}

.filter-close-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.filter-group {
    margin-bottom: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.filter-group-header {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    user-select: none;
    transition: all 0.15s;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    margin-top: 2px;
}

.filter-group-header:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.7);
}

.filter-group-header.active {
    border-color: #1b8019;
    box-shadow: 0 0 0 2px #1b8019, 0 0 8px rgba(27, 128, 25, 0.4);
}

.filter-group-header {
    border: 3px solid rgba(255, 255, 255, 0.5);
}

.filter-group-header.empty {
    opacity: 0.4;
    cursor: default;
    border-color: rgba(255, 255, 255, 0.15);
}

.filter-group-header.empty:hover {
    transform: none;
}

.filter-group-header .group-count {
    display: none;
}

.filter-icons-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.filter-icon-item {
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    transition: all 0.15s;
    border: 1px solid rgba(255, 255, 255, 0.5);
    user-select: none;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
    filter: saturate(0.3) brightness(0.7);
    background-size: 240px 150px;
    background-repeat: no-repeat;
    background-position: center;
}

.filter-icon-item:hover {
    transform: scale(1.1);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
    filter: saturate(0.6) brightness(0.85);
}

.filter-icon-item.active {
    filter: saturate(1) brightness(1);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}

/* Icono sin fotos en el viewport: se ve pero desactivado, no clickeable */
.filter-icon-item.no-photos {
    filter: saturate(0.1) brightness(0.4);
    border-color: rgba(255, 255, 255, 0.15);
    cursor: default;
    opacity: 0.5;
}

.filter-icon-item.no-photos:hover {
    transform: none;
    filter: saturate(0.1) brightness(0.4);
    box-shadow: none;
}

/* ─── Botón TODOS del filtro ─── */
.reset-filter-btn {
    background: rgba(79, 195, 247, 0.15);
    border: 1px solid rgba(79, 195, 247, 0.3);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    color: #4fc3f7;
    cursor: pointer;
    transition: all 0.15s;
}

.reset-filter-btn:hover {
    background: rgba(79, 195, 247, 0.25);
}

/* ─── Loading ─── */
#loading {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 20, 0.95);
    transition: opacity 0.5s;
}

#loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #4fc3f7;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 14px;
    opacity: 0.7;
}

/* ─── Modal del visor (centrado, arrastrable) ─── */
.photo-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    cursor: pointer;
}

.photo-modal.active {
    display: flex;
}

.photo-modal .modal-card {
    cursor: default;
    position: relative;
}

.modal-card {
    background: rgba(18, 18, 30, 0.97);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    max-width: 420px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* Header arrastrable */
.modal-header {
    cursor: grab;
    user-select: none;
}

.modal-header:active {
    cursor: grabbing;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h2 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.modal-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.modal-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 0;
    position: relative;
}

.modal-body .img-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body .img-wrap img {
    width: 100%;
    height: auto;
    max-height: 75vh;
    object-fit: contain;
    display: block;
}

.modal-body .img-date-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    font-size: 13px;
    color: #fff;
    text-align: center;
}

.modal-body .img-author-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    font-size: 13px;
    color: #ccc;
    text-align: left;
}

.modal-info {
    display: none;
}

.modal-date {
    display: none;
}

.modal-title-text {
    display: none;
}

.modal-category {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    margin-top: 6px;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 12px;
}

.nav-overlay {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.4);
    border: none;
    color: #fff;
    font-size: 32px;
    width: 48px;
    height: 80px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    border-radius: 6px;
    backdrop-filter: blur(4px);
    transition: background 0.2s;
}

.nav-overlay:first-of-type {
    left: 4px;
}

.nav-overlay:last-of-type {
    right: 4px;
}

.nav-overlay:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.7);
}

.nav-overlay:disabled {
    opacity: 0.2;
    cursor: default;
}

.share-btn {
    background: #2962ff;
    border: none;
    color: #fff;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.share-btn:hover {
    background: #1a56ff;
}

/* ─── Native ad in viewer ─── */
.native-ad {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.native-ad-label {
    font-size: 10px;
    opacity: 0.4;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.native-ad-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.native-ad-content .ad-placeholder {
    flex: 1;
    height: 60px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0.5;
}

/* ─── Maplibre overrides ─── */
.maplibregl-popup-content {
    background: rgba(18, 18, 30, 0.95) !important;
    color: #fff !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 10px !important;
    padding: 12px !important;
    font-size: 13px;
}

.maplibregl-popup-tip {
    border-top-color: rgba(18, 18, 30, 0.95) !important;
}

.maplibregl-ctrl-attrib {
    background: rgba(0, 0, 0, 0.4) !important;
    font-size: 10px !important;
}

/* ─── Responsive ─── */
@media(max-width:640px) {
    #map-container {
        flex: 0 0 75vh;
    }

    #ad-zone {
        flex: 0 0 25vh;
    }

    .modal-card {
        max-width: 100%;
        width: 100%;
        border-radius: 12px 12px 0 0;
        max-height: 85vh;
        align-self: flex-end;
    }

    .photo-modal {
        align-items: flex-end;
    }
}

/* ─── Zoom Overlay ─── */
.zoom-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-in;
}

.zoom-overlay.active {
    display: flex;
}

.zoom-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    transition: transform 0.2s ease;
}

.zoom-overlay .close-zoom {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    opacity: 0.6;
}

.zoom-overlay .close-zoom:hover {
    opacity: 1;
}