/* ============================================
   DUAL ASIDE SYSTEM - CSS COMPLETO
   Versión 1.0
   ============================================ */

/* Reset y variables */
:root {
    --aside-primary-width: 80%;
    --aside-primary-max-width: 1920px;
    --aside-secondary-width: 70%;
    --aside-secondary-max-width: 1500px;
    --aside-tertiary-width: 60%;
    --aside-tertiary-max-width: 1200px;
    --aside-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --aside-z-primary: 9999999;   /* por encima del header de Divi (#main-header ~99999) */
    --aside-z-secondary: 10000000;
    --aside-z-tertiary: 10000001;
}

/* El aside debe quedar por encima de TODO (header/menu de Divi incluidos) */
.aside-overlay { z-index: var(--aside-z-primary); }
.aside-secondary { z-index: var(--aside-z-secondary); }
.aside-tertiary { z-index: var(--aside-z-tertiary); }

/* Los swals (validaciones/errores) y sus tooltips deben salir POR ENCIMA de los asides
   (que están a ~10 millones); si no, las modales de error quedaban detrás del panel. */
.swal2-container { z-index: 100000000 !important; }
.tippy-box, [data-tippy-root] { z-index: 100000001 !important; }

/* En el aside, los expedientes (wizard-type=exp) y módulos (list) navegan por TABS:
   ocultar los botones Previous / Next / Finish del wizard (jQuery Steps .actions). */
.aside-overlay .resize_wizard_block_v2[wizard-type="exp"] > .actions,
.aside-overlay .resize_wizard_block_v2[wizard-type="exp"] .actions,
.aside-overlay .resize_wizard_block_v2[wizard-type="list"] > .actions,
.aside-overlay .resize_wizard_block_v2[wizard-type="list"] .actions {
    display: none !important;
}

/* Prevenir scroll del body cuando un aside está abierto */
body.aside-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Asegurar que los asides tengan su propio scroll */
.aside-overlay .aside-content {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    -webkit-overflow-scrolling: touch;
    /* Evita el encadenamiento de scroll (scroll chaining) hacia el body o el aside de debajo
       cuando se llega al tope/fondo del scroll de este aside. */
    overscroll-behavior: contain;
}

/* Solo el aside TOPMOST hace scroll; los asides de debajo (abiertos pero tapados) se congelan.
   El JS marca el topmost con .aside-scroll-locked en los demás (wtkUpdateAsideScrollLock). */
.aside-overlay.aside-scroll-locked .aside-content {
    overflow-y: hidden !important;
}

/* Para el contenido dentro del aside. El ÚNICO contenedor con scroll es .aside-content;
   los internos van a overflow VISIBLE para que el dropdown del selectr (posición absoluta)
   no se recorte contra un ancestro con overflow. */
.aside-overlay .fake-post-container {
    overflow: visible;
}

.aside-overlay .resize_wizard_block_v2 {
    overflow: visible;
}

/* Idem para los wrappers internos del wizard (jQuery Steps), secciones y grids. */
.aside-overlay .resize_wizard_block_v2 > .content,
.aside-overlay .resize_wizard_block_v2 .body,
.aside-overlay section.current,
.aside-overlay .wtk-data-grid {
    overflow: visible !important;
}

/* Asegurar que el contenido del aside no afecte al body */
.aside-overlay.active {
    position: fixed;
    top: 0;
    right: -100%;
    bottom: 0;
    transition: right 0.3s ease;
}

.aside-overlay.active.active {
    right: 0;
}

/* Contenedor principal - respeta tu max-width de 1200px */
.main-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    background: #fff;
    min-height: 100vh;
}

/* ========== ASIDES OVERLAY ========== */
.aside-overlay {
    position: fixed;
    top: 0;
    right: -100%;
    height: 100vh;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transition: right var(--aside-transition);
    display: flex;
    flex-direction: column;
}

.aside-primary {
    width: var(--aside-primary-width);
    max-width: var(--aside-primary-max-width);
    z-index: var(--aside-z-primary);
}

.aside-secondary {
    width: var(--aside-secondary-width);
    max-width: var(--aside-secondary-max-width);
    z-index: var(--aside-z-secondary);
    box-shadow: -6px 0 25px rgba(0, 0, 0, 0.2);
}

.aside-tertiary {
    width: var(--aside-tertiary-width);
    max-width: var(--aside-tertiary-max-width);
    z-index: var(--aside-z-tertiary);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.25);
}

.aside-overlay.active {
    right: 0;
}

/* Header del aside */
.aside-header {
    background: var(--primary-color-ligth);
    border-bottom: 1px solid var(--primary-color-ligth);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

/* Mismo estilo que .wtk-tab-title-container de los módulos/expedientes: caja con gradiente
   y bordes laterales, y el nombre en color primario. Solo el nombre (sin emoji ni nivel). */
.aside-title {
    flex: 1;
    min-width: 0;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    padding: 10px 16px;
    border-radius: 10px;
    border-left: 5px solid var(--primary-color-lightest);
    border-right: 5px solid var(--primary-color-lightest);
    border-top: 1px solid var(--primary-color-lightest);
    border-bottom: 1px solid var(--primary-color-lightest);
}

.aside-title h3 {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    color: var(--primary-color) !important;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.3 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aside-level {
    font-size: 10px;
    background: #667eea;
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
}

.aside-controls {
    display: flex;
    gap: 5px;
}

.aside-controls button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s;
    color: #6c757d;
}

.aside-controls button:hover:not(:disabled) {
    background: #e9ecef;
    color: #212529;
}

.aside-controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.close-aside {
    color: #dc3545 !important;
}

.close-aside:hover:not(:disabled) {
    background: #f8d7da !important;
    color: #c82333 !important;
}

/* Contenido */
.aside-content {
    flex: 1;
    overflow: auto;
    position: relative;
}

.iframe-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* Fake post container */
.fake-post-container {
    padding: 20px;
    overflow-y: auto;
    height: 100%;
    background: #fff;
}

/* Loading */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 15px;
    /* Alto para cubrir TODO el contenido del wizard (que tiene z-index propios) y que no asome el
       spinner interno por debajo del overlay durante la carga inicial. Antes 20 (demasiado bajo). */
    z-index: 999999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e9ecef;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay span {
    color: #666;
    font-size: 14px;
}

/* Error message */
.aside-error-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 25;
    min-width: 280px;
}

.aside-error-message i {
    font-size: 48px;
    color: #dc3545;
    margin-bottom: 15px;
}

.aside-error-message button {
    margin-top: 15px;
    padding: 8px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Botones flotantes */
.floating-buttons {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9998;
}

.float-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #667eea;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
    display: none;
    align-items: center;
    justify-content: center;
}

.float-btn:hover {
    transform: scale(1.1);
    background: #5a67d8;
}

/* Indicador */
.aside-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(102, 126, 234, 0.95);
    color: #fff;
    padding: 6px 14px;
    border-radius: 30px;
    font-size: 12px;
    z-index: 9997;
    display: flex;
    gap: 8px;
    backdrop-filter: blur(10px);
    pointer-events: none;
}

.indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #48bb78;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* Header para el contenido */
.wp-aside-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
}

.wp-aside-header h1 {
    font-size: 24px;
    margin-bottom: 10px;
}

.wp-aside-header p {
    opacity: 0.9;
    font-size: 14px;
}

.badge-container {
    display: flex;
    gap: 12px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
}

/* Grid de posts */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* Tarjetas */
.post-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    transition: all 0.2s;
    cursor: pointer;
}

.post-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
}

.post-title {
    font-size: 18px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 10px;
}

.post-url {
    font-size: 11px;
    color: #888;
    margin-bottom: 10px;
    word-break: break-all;
    font-family: monospace;
}

.post-excerpt {
    font-size: 13px;
    color: #555;
    line-height: 1.5;
}

.post-meta {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tag {
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    color: #666;
}

/* Botones */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
}

.btn-secondary {
    background: #48bb78;
    color: white;
}

.btn-secondary:hover {
    background: #38a169;
}

/* Responsive */
@media (max-width: 768px) {
    .aside-primary,
    .aside-secondary {
        width: 100%;
        max-width: 100%;
    }
    
    .float-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    .posts-grid {
        grid-template-columns: 1fr;
    }
    
    .wp-aside-header {
        padding: 20px;
    }
    
    .aside-header {
        padding: 10px 15px;
    }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    .aside-overlay {
        background: white;
    }
    
    .aside-header {
        background: var(--primary-color-ligth);
        border-bottom-color: var(--primary-color-ligth);
    }
    
    .aside-title h3 {
        color: var(--primary-color-darkest);
    }
    
    .loading-overlay {
        background: rgba(30, 30, 47, 0.95);
    }
    
    .loading-overlay span {
        color: #ccc;
    }
    
    .post-card {
        background: #2d2d3a;
        border-color: #3d3d4a;
    }
    
    .post-title {
        color: #8ab4f8;
    }
    
    .post-excerpt, .post-url {
        color: #aaa;
    }
    
    .tag {
        background: #3d3d4a;
        color: #ccc;
    }
}

/* Scrollbar personalizada */
.aside-content::-webkit-scrollbar {
    width: 8px;
}

.aside-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.aside-content::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 4px;
}

.aside-content::-webkit-scrollbar-thumb:hover {
    background: #5a67d8;
}

@media (prefers-color-scheme: dark) {
    .aside-content::-webkit-scrollbar-track {
        background: #2a2a3e;
    }
}