/**
 * Coatequitl — Mapa Unificado CSS
 * @version 4.1.0 — 2026-02-17
 * @author  Lic. Joel Salazar Ramírez <joel@edugame.digital>
 * @copyright (C) 2026 Edugame Digital
 */

/* ─── Contenedor principal ─────────────────────────────────────────────────── */
#ctq-unified-map {
    position: relative;
    width: 100%;
    height: calc(100vh - 120px);
    min-height: 480px;
    background: #0d1117;
    border-radius: 0.5rem;
    overflow: hidden;
}

/* ─── Toolbar superior ─────────────────────────────────────────────────────── */
.ctq-map-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 100;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.ctq-map-toolbar .btn {
    backdrop-filter: blur(8px);
    background: rgba(13, 17, 23, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #e6edf3;
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.2s, border-color 0.2s;
}

.ctq-map-toolbar .btn:hover,
.ctq-map-toolbar .btn.active {
    background: rgba(21, 101, 192, 0.7);
    border-color: rgba(21, 101, 192, 0.8);
    color: #fff;
}

.ctq-map-toolbar .btn i {
    font-size: 0.85rem;
}

/* Badge de sync pendiente */
#ctq-sync-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #c62828;
    color: #fff;
    font-size: 0.65rem;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    font-weight: 700;
}

/* ─── Paneles laterales ────────────────────────────────────────────────────── */
.ctq-side-panel {
    position: absolute;
    top: 0;
    right: -340px;
    width: 320px;
    height: 100%;
    background: rgba(13, 17, 23, 0.95);
    backdrop-filter: blur(12px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.ctq-side-panel.ctq-panel--open {
    right: 0;
}

.ctq-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(21, 101, 192, 0.2);
    flex-shrink: 0;
}

.ctq-panel-header h6 {
    margin: 0;
    color: #e6edf3;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.ctq-panel-close {
    background: none;
    border: none;
    color: #8b949e;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.ctq-panel-close:hover {
    color: #e6edf3;
}

.ctq-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.ctq-panel-body::-webkit-scrollbar {
    width: 4px;
}

.ctq-panel-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

/* ─── Panel de capas ───────────────────────────────────────────────────────── */
.ctq-layer-group-title {
    color: #8b949e;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 8px;
}

.ctq-layer-item {
    border-radius: 6px;
    transition: background 0.15s;
}

.ctq-layer-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.ctq-layer-item .form-check-label {
    color: #c9d1d9;
    cursor: pointer;
    font-size: 0.85rem;
}

.ctq-layer-item .form-check-input {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
}

.ctq-layer-item .form-check-input:checked {
    background-color: #1565c0;
    border-color: #1565c0;
}

/* ─── Panel de análisis ────────────────────────────────────────────────────── */
.ctq-analysis-section {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.ctq-analysis-section:last-child {
    border-bottom: none;
}

.ctq-analysis-section h6 {
    color: #8b949e;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.ctq-analysis-section .form-control,
.ctq-analysis-section .form-select {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.15);
    color: #e6edf3;
    font-size: 0.85rem;
}

.ctq-analysis-section .form-control:focus,
.ctq-analysis-section .form-select:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(21, 101, 192, 0.6);
    box-shadow: 0 0 0 0.2rem rgba(21, 101, 192, 0.25);
    color: #e6edf3;
}

.ctq-analysis-section .form-control::placeholder {
    color: #6e7681;
}

#ctq-analysis-result {
    background: rgba(21, 101, 192, 0.15);
    border: 1px solid rgba(21, 101, 192, 0.3);
    border-radius: 6px;
    padding: 10px 12px;
    color: #c9d1d9;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* ─── Panel de reportes ────────────────────────────────────────────────────── */
.ctq-report-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.ctq-report-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(21, 101, 192, 0.4);
}

.ctq-report-severity {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ctq-report-severity[data-severity="1"] {
    background: #388e3c;
}

.ctq-report-severity[data-severity="2"] {
    background: #f9a825;
}

.ctq-report-severity[data-severity="3"] {
    background: #f57c00;
}

.ctq-report-severity[data-severity="4"] {
    background: #d32f2f;
}

.ctq-report-severity[data-severity="5"] {
    background: #7b1fa2;
}

/* ─── Popup del mapa ───────────────────────────────────────────────────────── */
.maplibregl-popup-content {
    background: rgba(13, 17, 23, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 10px !important;
    padding: 14px !important;
    color: #e6edf3 !important;
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4) !important;
}

.maplibregl-popup-tip {
    border-top-color: rgba(13, 17, 23, 0.95) !important;
    border-bottom-color: rgba(13, 17, 23, 0.95) !important;
}

.maplibregl-popup-close-button {
    color: #8b949e !important;
    font-size: 1.1rem !important;
    padding: 4px 8px !important;
}

.maplibregl-popup-close-button:hover {
    color: #e6edf3 !important;
    background: rgba(255, 255, 255, 0.08) !important;
}

.ctq-popup-report .badge {
    font-size: 0.7rem;
}

/* ─── Banner offline ───────────────────────────────────────────────────────── */
.ctq-offline-banner {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    background: rgba(198, 40, 40, 0.9);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    animation: ctqSlideUp 0.3s ease;
}

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

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ─── Domain pills en toolbar ──────────────────────────────────────────────── */
.ctq-domain-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}

.ctq-domain-pill.active {
    opacity: 1;
}

.ctq-domain-pill:not(.active) {
    opacity: 0.5;
    filter: grayscale(0.5);
}

.ctq-domain-pill[data-domain="visig"] {
    background: rgba(46, 125, 50, 0.3);
    border-color: rgba(46, 125, 50, 0.5);
    color: #81c784;
}

.ctq-domain-pill[data-domain="molochrm"] {
    background: rgba(198, 40, 40, 0.3);
    border-color: rgba(198, 40, 40, 0.5);
    color: #ef9a9a;
}

.ctq-domain-pill[data-domain="kanan"] {
    background: rgba(21, 101, 192, 0.3);
    border-color: rgba(21, 101, 192, 0.5);
    color: #90caf9;
}

.ctq-domain-pill[data-domain="perivisar"] {
    background: rgba(106, 27, 154, 0.3);
    border-color: rgba(106, 27, 154, 0.5);
    color: #ce93d8;
}

.ctq-domain-pill[data-domain="metztli"] {
    background: rgba(249, 168, 37, 0.3);
    border-color: rgba(249, 168, 37, 0.5);
    color: #ffe082;
}

.ctq-domain-pill[data-domain="reporteador"] {
    background: rgba(230, 81, 0, 0.3);
    border-color: rgba(230, 81, 0, 0.5);
    color: #ffab91;
}

/* ─── Controles MapLibre override ──────────────────────────────────────────── */
.maplibregl-ctrl-group {
    background: rgba(13, 17, 23, 0.9) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    backdrop-filter: blur(8px);
}

.maplibregl-ctrl-group button {
    background: transparent !important;
    color: #c9d1d9 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

.maplibregl-ctrl-group button:hover {
    background: rgba(255, 255, 255, 0.08) !important;
}

.maplibregl-ctrl-group button:last-child {
    border-bottom: none !important;
}

.maplibregl-ctrl-attrib {
    background: rgba(13, 17, 23, 0.7) !important;
    color: #6e7681 !important;
    font-size: 0.65rem !important;
}

.maplibregl-ctrl-attrib a {
    color: #8b949e !important;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #ctq-unified-map {
        height: calc(100vh - 80px);
        border-radius: 0;
    }

    .ctq-side-panel {
        width: 100%;
        right: -100%;
        top: auto;
        bottom: -100%;
        height: 60vh;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 16px 16px 0 0;
        transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .ctq-side-panel.ctq-panel--open {
        right: 0;
        bottom: 0;
    }

    .ctq-map-toolbar {
        top: auto;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
        flex-wrap: nowrap;
        overflow-x: auto;
        max-width: calc(100% - 24px);
        padding-bottom: 4px;
    }

    .ctq-domain-pill {
        white-space: nowrap;
    }
}

/* ─── Loading state ────────────────────────────────────────────────────────── */
.ctq-map-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0d1117;
    z-index: 500;
    flex-direction: column;
    gap: 16px;
    color: #8b949e;
    font-size: 0.9rem;
}

.ctq-map-loading .spinner-border {
    color: #1565c0;
    width: 2.5rem;
    height: 2.5rem;
}

/* Ocultar loading cuando el mapa carga */
.ctq-map-loading.ctq-loaded {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

/* ─── Banner modo offline ───────────────────────────────────────────────────── */
.ctq-offline-banner {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(198, 40, 40, 0.92);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 200;
    font-size: 0.85rem;
    font-weight: 600;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 12px rgba(198, 40, 40, 0.4);
    white-space: nowrap;
    pointer-events: none;
}
