/* Add custom CSS to complement Tailwind classes */
#rey-cytoscape-dashboard {
    /* Override WordPress default margins in admin */
    margin: 0 -20px 0 -20px;
}

#cy {
    width: 100%;
    height: 100%;
    display: block;
    background-image:
        radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.4) 0%, transparent 80%),
        linear-gradient(rgba(15, 23, 42, 0.9) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 23, 42, 0.9) 1px, transparent 1px);
    background-size: 100% 100%, 40px 40px, 40px 40px;
    background-position: 0 0, -1px -1px, -1px -1px;
}

/* Scrollbar styling for inspector */
#rey-inspector .overflow-y-auto::-webkit-scrollbar {
    width: 6px;
}

#rey-inspector .overflow-y-auto::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.5);
    border-radius: 10px;
}

#rey-inspector .overflow-y-auto::-webkit-scrollbar-thumb {
    background: rgba(71, 85, 105, 0.8);
    border-radius: 10px;
}

#rey-inspector .overflow-y-auto::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 1);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#rey-inspector:not(.hidden) {
    animation: fadeIn 0.3s ease-out forwards;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Panel Derecho e Inspector - Modelo rey-leaflet-map)
   ========================================================================== */

/* Estado colapsado general */
#panel-right-sidebar.collapsed {
    max-height: 52px !important;
    height: 52px !important;
    overflow: hidden !important;
    border-radius: 16px;
    background: rgba(30, 41, 59, 0.75) !important;
    backdrop-filter: blur(16px);
}

#panel-right-sidebar.collapsed #panel-right-content {
    display: none !important;
}

#panel-right-sidebar.collapsed .rey-ui-header {
    border-bottom: none !important;
}

/* Tablets / Pantallas medianas (<= 1024px) */
@media (max-width: 1024px) {
    #panel-right-sidebar {
        width: 260px;
        right: 16px;
        top: 110px;
        bottom: 16px;
        max-height: calc(100% - 130px);
    }

    #rey-inspector {
        right: 290px;
        width: 300px;
        top: 110px;
        bottom: 16px;
        max-height: calc(100% - 130px);
    }
}

/* Móviles / Pantallas pequeñas (<= 768px - Bottom Sheet exacto de la guía) */
@media (max-width: 768px) {
    #panel-right-sidebar {
        position: fixed !important;
        top: auto !important;
        bottom: 12px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        max-height: 50vh !important;
        border-radius: 16px !important;
        transform-origin: bottom center;
        box-shadow: 0 -6px 25px rgba(0, 0, 0, 0.45) !important;
        z-index: 1005 !important;
    }

    #panel-right-sidebar.collapsed {
        top: auto !important;
        bottom: 12px !important;
        left: 10px !important;
        right: 10px !important;
        height: 48px !important;
        max-height: 48px !important;
        border-radius: 24px !important;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3) !important;
    }

    #rey-inspector {
        position: fixed !important;
        top: auto !important;
        bottom: 12px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        max-height: 75vh !important;
        border-radius: 16px !important;
        z-index: 1020 !important;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6) !important;
    }
}

/* ==========================================================================
   BARRA DE FILTROS POR TIPO DE ELEMENTO (Estilo rey-leaflet-map)
   ========================================================================== */

.rey-filter-bar {
    position: absolute;
    top: 78px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(71, 85, 105, 0.4);
    padding: 5px 8px;
    border-radius: 9999px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    max-width: calc(100% - 32px);
    overflow-x: auto;
    scrollbar-width: none;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
}

.rey-filter-bar::-webkit-scrollbar {
    display: none;
}

.rey-filter-chip {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(71, 85, 105, 0.4);
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.rey-filter-chip:hover {
    background: rgba(51, 65, 85, 0.9);
    color: #ffffff;
    border-color: rgba(148, 163, 184, 0.5);
    transform: translateY(-1px);
}

.rey-filter-chip.active {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #ffffff;
    border-color: rgba(96, 165, 250, 0.8);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
}

.rey-filter-chip .chip-count {
    padding: 2px 7px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.rey-filter-chip .chip-count-all {
    background: #475569;
    color: #f1f5f9;
}

.rey-filter-chip .chip-count-normal {
    background: #10b981;
    color: #ffffff;
}

.rey-filter-chip .chip-count-completed {
    background: #3b82f6;
    color: #ffffff;
}

.rey-filter-chip .chip-count-warning {
    background: #eab308;
    color: #78350f;
}

.rey-filter-chip .chip-count-maintenance {
    background: #f97316;
    color: #ffffff;
}

.rey-filter-chip .chip-count-critical {
    background: #ef4444;
    color: #ffffff;
}

@media (max-width: 768px) {
    .rey-filter-bar {
        top: 60px;
        width: 95%;
        max-width: 95%;
        justify-content: flex-start;
        padding: 4px 6px;
        gap: 6px;
    }

    .rey-filter-chip {
        padding: 4px 10px;
        font-size: 10px;
    }
}

/* ==========================================================================
   POPUP DE ELEMENTOS (Estilo compacto rey-factory-map)
   ========================================================================== */

.rfm-style-popup {
    width: 290px;
    max-width: 90vw;
    background: rgba(15, 23, 42, 0.95) !important;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(71, 85, 105, 0.5);
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.4);
    font-family: inherit;
    overflow: hidden;
    animation: rfmPopupFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom center;
}

@keyframes rfmPopupFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -90%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -100%) scale(1);
    }
}

.rfm-style-popup .rfm-popup-image-container {
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    height: 60px;
    border-radius: 0 12px 0 8px;
    overflow: hidden;
    z-index: 1;
}

.rfm-style-popup .rfm-popup-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rfm-style-popup .rfm-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(30, 41, 59, 0.7);
    border-bottom: 1px solid rgba(71, 85, 105, 0.4);
}

.rfm-style-popup .rfm-popup-title-box {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.rfm-style-popup .rfm-popup-icon-badge {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #ffffff;
    background: #3b82f6;
}

.rfm-style-popup .rfm-popup-title {
    font-size: 13px;
    font-weight: 700;
    color: #f8fafc;
    margin: 0;
    line-height: 1.2;
}

.rfm-style-popup .rfm-popup-subtitle {
    font-size: 10px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.rfm-style-popup .rfm-popup-close-btn {
    position: absolute !important;
    top: 8px !important;
    right: 8px !important;
    width: 26px !important;
    height: 26px !important;
    background: rgba(15, 23, 42, 0.85) !important;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    font-size: 18px !important;
    color: #ffffff !important;
    cursor: pointer !important;
    line-height: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 9999px !important;
    transition: all 0.2s !important;
    z-index: 50 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5) !important;
}

.rfm-style-popup .rfm-popup-close-btn:hover {
    color: #ffffff !important;
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    transform: scale(1.12) !important;
}

.rfm-style-popup .rfm-popup-body {
    padding: 10px 12px;
}

.rfm-style-popup .rfm-popup-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.rfm-style-popup .rfm-popup-desc {
    font-size: 11px;
    color: #cbd5e1;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(71, 85, 105, 0.3);
    padding: 8px;
    border-radius: 6px;
    line-height: 1.4;
    max-height: 90px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.rfm-style-popup .rfm-popup-field {
    margin-bottom: 6px;
}

.rfm-style-popup .rfm-custom-field-item {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(71, 85, 105, 0.3);
    padding: 5px 8px;
    border-radius: 6px;
    margin-bottom: 5px;
    font-size: 11px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rfm-style-popup .rfm-custom-field-item .cf-label {
    color: #94a3b8;
    font-weight: 600;
}

.rfm-style-popup .rfm-custom-field-item .cf-value {
    color: #f1f5f9;
    font-weight: 500;
}

.rfm-style-popup .rfm-popup-footer {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(71, 85, 105, 0.3);
}

.rfm-style-popup .rfm-btn-edit {
    flex: 1;
    padding: 5px 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    border: 1px solid rgba(59, 130, 246, 0.5);
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    transition: all 0.2s;
    text-align: center;
}

.rfm-style-popup .rfm-btn-edit:hover {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.rfm-style-popup .rfm-btn-delete {
    padding: 5px 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    border: 1px solid rgba(239, 68, 68, 0.5);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(185, 28, 28, 0.3) 100%);
    color: #fca5a5;
    transition: all 0.2s;
    text-align: center;
}

.rfm-style-popup .rfm-btn-delete:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.rfm-style-popup .rfm-popup-arrow {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid rgba(15, 23, 42, 0.95);
}