/* ==========================================================================
   ACADEMIAQR · VERSIÓN WEB COMPLETA DE RED SOCIAL ESTUDIANTIL (SOLO PC >= 1024px)
   Aislamiento 100% garantizado: cero impacto en móviles y tablets (< 1024px).
   Solo activa cuando body tiene la clase .carnet-desktop-web.
   ========================================================================== */

/* Por defecto ocultos en móvil y en vista móvil de desarrollo */
#carnetDesktopTopbar,
#superAdminMobileReturnPill {
    display: none;
}

@media (min-width: 1024px) {
    /* Píldora flotante exclusiva de SuperAdmin cuando está en Vista Móvil (Dev) */
    body.is-superadmin-dev:not(.carnet-desktop-web) #superAdminMobileReturnPill {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
        position: fixed;
        top: 14px;
        right: 16px;
        z-index: 10040;
        padding: 0.48rem 0.9rem;
        border-radius: 999px;
        border: 1.5px solid rgba(14, 165, 233, 0.45);
        background: rgba(15, 23, 42, 0.92);
        color: #ffffff;
        font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
        font-size: 0.76rem;
        font-weight: 800;
        cursor: pointer;
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.3);
        transition: transform 0.15s ease, background 0.15s ease;
    }

    body.is-superadmin-dev:not(.carnet-desktop-web) #superAdminMobileReturnPill:hover {
        background: #0284c7;
        transform: translateY(-1px);
    }

    /* ================= MODO WEB COMPLETO (3 COLUMNAS) ================= */
    body.carnet-desktop-web {
        background:
            radial-gradient(circle at 8% 12%, rgba(14, 165, 233, 0.09), transparent 36%),
            radial-gradient(circle at 92% 18%, rgba(16, 185, 129, 0.08), transparent 36%),
            #eef2f7 !important;
        min-height: 100dvh !important;
        height: auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 0 !important;
        display: block !important;
    }

    /* 1. Barra Superior Web Fija */
    body.carnet-desktop-web #carnetDesktopTopbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 62px;
        padding: 0 1.5rem;
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid #e2e8f0;
        box-shadow: 0 4px 18px rgba(15, 23, 42, 0.05);
        z-index: 9950;
        box-sizing: border-box;
    }

    body.carnet-desktop-web.is-moroso-web #carnetDesktopTopbar {
        border-bottom: 2px solid #dc2626;
        box-shadow: 0 4px 20px rgba(220, 38, 38, 0.14);
    }

    .dweb-brand {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        min-width: 0;
        cursor: pointer;
    }

    .dweb-brand-logo {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        object-fit: contain;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        padding: 3px;
    }

    .dweb-brand-title {
        font-family: 'Outfit', sans-serif;
        font-size: 0.96rem;
        font-weight: 900;
        color: #0f172a;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 240px;
    }

    .dweb-brand-sub {
        font-size: 0.68rem;
        font-weight: 700;
        color: #0284c7;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .dweb-nav-links {
        display: flex;
        align-items: center;
        gap: 0.35rem;
    }

    .dweb-nav-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.42rem;
        padding: 0.46rem 0.82rem;
        border-radius: 11px;
        border: 1px solid transparent;
        background: transparent;
        color: #475569;
        font-family: inherit;
        font-size: 0.79rem;
        font-weight: 700;
        text-decoration: none;
        cursor: pointer;
        transition: all 0.15s ease;
    }

    .dweb-nav-btn:hover {
        background: #f1f5f9;
        color: #0f172a;
    }

    .dweb-nav-btn.is-active {
        background: #eff6ff;
        color: #1d4ed8;
        border-color: #bfdbfe;
    }

    .dweb-actions {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        flex-shrink: 0;
    }

    @media (min-width: 1024px) and (max-width: 1260px) {
        body.carnet-desktop-web #carnetDesktopTopbar {
            padding: 0 0.85rem;
            gap: 0.5rem;
        }
        .dweb-brand-title {
            max-width: 155px;
            font-size: 0.86rem;
        }
        .dweb-nav-btn {
            padding: 0.38rem 0.55rem;
            font-size: 0.74rem;
            gap: 0.3rem;
        }
        .dweb-cta-post,
        .dweb-cta-story,
        .dweb-cta-qr {
            padding: 0.4rem 0.65rem;
            font-size: 0.72rem;
        }
    }

    .dweb-cta-post {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        padding: 0.48rem 0.92rem;
        border-radius: 999px;
        border: none;
        background: linear-gradient(135deg, #2563eb, #4f46e5);
        color: #ffffff;
        font-family: inherit;
        font-size: 0.78rem;
        font-weight: 800;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
    }

    .dweb-cta-story {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.46rem 0.8rem;
        border-radius: 999px;
        border: 1.5px solid #c4b5fd;
        background: #f5f3ff;
        color: #6d28d9;
        font-family: inherit;
        font-size: 0.76rem;
        font-weight: 800;
        cursor: pointer;
    }

    .dweb-cta-qr {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.46rem 0.75rem;
        border-radius: 999px;
        border: 1.5px solid #cbd5e1;
        background: #ffffff;
        color: #0f172a;
        font-family: inherit;
        font-size: 0.76rem;
        font-weight: 800;
        cursor: pointer;
    }

    .dweb-dev-switch {
        display: none;
        align-items: center;
        gap: 2px;
        padding: 3px;
        border-radius: 999px;
        border: 1.5px solid #cbd5e1;
        background: #f1f5f9;
        font-family: inherit;
    }

    .dweb-dev-switch-opt {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        padding: 0.32rem 0.65rem;
        border-radius: 999px;
        border: none;
        background: transparent;
        color: #475569;
        font-family: inherit;
        font-size: 0.71rem;
        font-weight: 800;
        cursor: pointer;
        transition: all 0.15s ease;
        white-space: nowrap;
    }

    .dweb-dev-switch-opt.is-active {
        background: #0f172a;
        color: #ffffff;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.22);
    }

    body.carnet-desktop-web.is-superadmin-dev .dweb-dev-switch {
        display: inline-flex;
    }

    /* 2. Contenedor Principal Expansivo (sin límites de teléfono) */
    body.carnet-desktop-web .mobile-viewport {
        width: 100% !important;
        max-width: 1320px !important;
        min-height: calc(100dvh - 62px) !important;
        height: auto !important;
        margin: 62px auto 0 !important;
        padding: 1.25rem 1.4rem 2.5rem !important;
        box-shadow: none !important;
        background: transparent !important;
        border-radius: 0 !important;
        overflow: visible !important;
        display: block !important;
    }

    /* Ocultar barra inferior móvil en modo Desktop Web */
    body.carnet-desktop-web .mobile-bottom-nav {
        display: none !important;
    }

    /* 3. Grid de 3 Columnas usando el mismo DOM vivo */
    body.carnet-desktop-web .carnet-flip-container {
        width: 100% !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        perspective: none !important;
        margin: 0 !important;
        overflow: visible !important;
    }

    body.carnet-desktop-web #carnetCardInner.carnet-card-inner {
        display: grid !important;
        grid-template-columns: 315px minmax(0, 1fr) 315px !important;
        column-gap: 1.25rem !important;
        row-gap: 0 !important;
        align-items: start !important;
        transform: none !important;
        transform-style: flat !important;
        height: auto !important;
        min-height: 0 !important;
        cursor: default !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    /* Desenvolver la cara frontal para distribuir Perfil (Col 1) y Muro Social (Col 2) */
    body.carnet-desktop-web .carnet-face-front,
    body.carnet-desktop-web .carnet-face-front .id-body {
        display: contents !important;
    }

    /* --- COLUMNA 1: TARJETA DE PERFIL Y CREDENCIAL ESTUDIANTIL --- */
    body.carnet-desktop-web .carnet-face-front .id-banner {
        grid-column: 1 !important;
        grid-row: 1 !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
    }

    body.carnet-desktop-web .carnet-face-front .id-profile-card {
        grid-column: 1 !important;
        grid-row: 2 !important;
        background: #ffffff !important;
        border-left: 1px solid #e2e8f0;
        border-right: 1px solid #e2e8f0;
        padding: 0.9rem 1rem !important;
    }

    body.carnet-desktop-web .carnet-face-front .id-bio {
        grid-column: 1 !important;
        grid-row: 3 !important;
        background: #ffffff !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border-left: 1px solid #e2e8f0;
        border-right: 1px solid #e2e8f0;
        border-top: 1px solid #f1f5f9;
        padding: 0.65rem 1rem !important;
    }

    body.carnet-desktop-web .carnet-face-front .id-merit-strip {
        grid-column: 1 !important;
        grid-row: 4 !important;
        background: #ffffff !important;
        margin: 0 !important;
        padding: 0.75rem 0.95rem 1rem !important;
        border-radius: 0 0 20px 20px !important;
        border: 1px solid #e2e8f0;
        border-top: 1px solid #f1f5f9;
        box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
    }

    /* --- COLUMNA 2: MURO SOCIAL & FEED COMPLETO --- */
    body.carnet-desktop-web .carnet-face-front .merit-wall-section {
        grid-column: 2 !important;
        grid-row: 1 / span 12 !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 22px !important;
        padding: 1rem 1.15rem 1.25rem !important;
        box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06) !important;
        min-height: calc(100dvh - 110px) !important;
        max-height: none !important;
        overflow: visible !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.85rem !important;
    }

    body.carnet-desktop-web #studentMeritWallFeed.merit-wall-feed {
        max-height: none !important;
        overflow: visible !important;
        gap: 0.95rem !important;
        padding: 0 !important;
    }

    body.carnet-desktop-web .merit-wall-unified-header {
        padding-bottom: 0.65rem !important;
        border-bottom: 1px solid #f1f5f9 !important;
    }

    body.carnet-desktop-web .feed-scope-btn {
        font-size: 0.8rem !important;
        padding: 0.42rem 0.85rem !important;
    }

    body.carnet-desktop-web .merit-post-card {
        border-radius: 16px !important;
        padding: 0.95rem 1.05rem !important;
        border: 1px solid #e2e8f0 !important;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04) !important;
    }

    body.carnet-desktop-web .merit-post-media img {
        max-height: 420px !important;
        object-fit: cover !important;
        border-radius: 12px !important;
    }

    /* --- COLUMNA 3: PORTAL 360° (REVERSO SIEMPRE VISIBLE EN PC) --- */
    body.carnet-desktop-web .carnet-face-back {
        grid-column: 3 !important;
        grid-row: 1 / span 12 !important;
        position: sticky !important;
        top: 78px !important;
        inset: auto !important;
        transform: none !important;
        backface-visibility: visible !important;
        -webkit-backface-visibility: visible !important;
        width: 100% !important;
        height: auto !important;
        max-height: calc(100dvh - 96px) !important;
        overflow-y: auto !important;
        border-radius: 22px !important;
        border: 1px solid #e2e8f0 !important;
        background: #ffffff !important;
        box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06) !important;
        padding: 0.95rem !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.65rem !important;
    }

    /* Ocultar el botón "Voltear al Frente" dentro del reverso en PC (ya está todo visible) */
    body.carnet-desktop-web .carnet-face-back .back-flip-return-btn,
    body.carnet-desktop-web .carnet-face-back .back-quick-flip-btn {
        display: none !important;
    }

    /* ================= EXTENSIÓN FASE 2: CARNET DOCENTE WEB (3 COLUMNAS) ================= */
    body.carnet-desktop-web.is-teacher-carnet #carnetCardInner.carnet-card-inner {
        grid-template-columns: 330px minmax(0, 1fr) 350px !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .carnet-face-front .id-name {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: unset !important;
        font-size: 0.96rem !important;
        line-height: 1.2 !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .carnet-face-front .id-metrics-pill {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .carnet-face-front .id-highlights {
        grid-column: 1 !important;
        grid-row: 4 !important;
        background: #ffffff !important;
        margin: 0 !important;
        padding: 0.7rem 0.9rem 1rem !important;
        border-radius: 0 0 20px 20px !important;
        border: 1px solid #e2e8f0;
        border-top: 1px solid #f1f5f9;
        box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
    }

    body.carnet-desktop-web.is-teacher-carnet #teacherTasksWallFeed.merit-wall-feed {
        max-height: none !important;
        overflow: visible !important;
        gap: 0.85rem !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .carnet-face-back.teacher-card-back {
        padding: 0 !important;
        height: auto !important;
        min-height: 540px !important;
        max-height: calc(100dvh - 96px) !important;
        overflow: hidden !important;
        gap: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .teacher-back-header {
        flex-shrink: 0 !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .teacher-back-body {
        flex: 1 1 auto !important;
        min-height: 440px !important;
        max-height: calc(100dvh - 166px) !important;
        overflow-y: auto !important;
        padding: 0.85rem !important;
    }

    body.carnet-desktop-web.is-teacher-carnet .dweb-brand-sub {
        color: #059669;
    }

    body.carnet-desktop-web.is-teacher-carnet .dweb-cta-post {
        background: linear-gradient(135deg, #059669, #047857);
        box-shadow: 0 4px 12px rgba(5, 150, 105, 0.28);
    }

    body.carnet-desktop-web.is-teacher-carnet .dweb-nav-btn.is-active {
        background: #ecfdf5;
        color: #047857;
        border-color: #a7f3d0;
    }
}
