/* ====================================================
   CORREÇÃO DE EMERGÊNCIA PARA AGENDA MOBILE - 2025
   Solução definitiva para problemas de visualização
==================================================== */

/* RESET AGRESSIVO PARA MOBILE - REMOVE TODOS OS CONFLITOS */
@media screen and (max-width: 768px) {
    
    /* ===== FORÇAR EXIBIÇÃO DA AGENDA ===== */
    #agenda.active {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        z-index: 1 !important;
        background: transparent !important;
        padding: 20px 10px !important;
        margin: 0 !important;
    }
    
    /* ===== LAYOUT PRINCIPAL - VERTICAL NO MOBILE ===== */
    #agenda.active .agenda-modern-layout {
        display: flex !important;
        flex-direction: column !important;
        gap: 30px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 0 !important;
        align-items: center !important;
        justify-content: flex-start !important;
        /* REMOVE GRID DO DESKTOP */
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        grid-gap: unset !important;
    }
    
    /* ===== RESET TOTAL DO CALENDÁRIO ===== */
    #agenda.active .modern-calendar-container {
        /* RESET COMPLETO */
        all: unset !important;
        
        /* ESTRUTURA BÁSICA */
        display: block !important;
        position: relative !important;
        box-sizing: border-box !important;
        
        /* DIMENSÕES */
        width: 100% !important;
        max-width: 360px !important;
        min-width: 300px !important;
        height: auto !important;
        
        /* ESPAÇAMENTO */
        margin: 0 auto 30px auto !important;
        padding: 25px !important;
        
        /* VISUAL */
        background: #ffffff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 16px !important;
        box-shadow: 0 10px 35px rgba(0,0,0,0.1) !important;
        
        /* TIPOGRAFIA */
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
        color: #1f2937 !important;
        
        /* COMPORTAMENTO */
        overflow: visible !important;
        z-index: 2 !important;
    }
    
    /* ===== CABEÇALHO DO CALENDÁRIO ===== */
    #agenda.active .calendar-header-modern {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
        margin: 0 0 25px 0 !important;
        padding: 0 !important;
        gap: 15px !important;
    }
    
    /* ===== TÍTULO DO MÊS ===== */
    #agenda.active #currentMonth,
    #agenda.active .calendar-month-title {
        font-size: 22px !important;
        font-weight: 700 !important;
        color: #1e40af !important;
        margin: 0 !important;
        padding: 0 !important;
        text-align: center !important;
        flex: 1 !important;
        line-height: 1.2 !important;
    }
    
    /* ===== BOTÕES DE NAVEGAÇÃO ===== */
    #agenda.active .calendar-nav-modern,
    #agenda.active #prevMonth,
    #agenda.active #nextMonth {
        width: 45px !important;
        height: 45px !important;
        min-width: 45px !important;
        min-height: 45px !important;
        
        background: linear-gradient(135deg, #3b82f6, #1e40af) !important;
        color: #ffffff !important;
        border: none !important;
        border-radius: 12px !important;
        
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        
        font-size: 18px !important;
        font-weight: 600 !important;
        
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3) !important;
        
        /* GARANTIR POSICIONAMENTO */
        position: relative !important;
        z-index: 3 !important;
        flex-shrink: 0 !important;
    }
    
    #agenda.active .calendar-nav-modern:hover,
    #agenda.active #prevMonth:hover,
    #agenda.active #nextMonth:hover {
        transform: translateY(-2px) scale(1.05) !important;
        box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5) !important;
        background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
    }
    
    /* ===== DIAS DA SEMANA ===== */
    #agenda.active .calendar-weekdays-modern {
        display: grid !important;
        grid-template-columns: repeat(7, 1fr) !important;
        gap: 3px !important;
        width: 100% !important;
        margin: 0 0 15px 0 !important;
        padding: 0 !important;
    }
    
    #agenda.active .weekday-modern {
        text-align: center !important;
        font-size: 12px !important;
        font-weight: 700 !important;
        color: #6b7280 !important;
        padding: 12px 4px !important;
        background: #f8fafc !important;
        border-radius: 10px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.8px !important;
        border: 1px solid #e5e7eb !important;
    }
    
    /* ===== GRID PRINCIPAL DOS DIAS ===== */
    #agenda.active .calendar-days-modern,
    #agenda.active #calendarDays {
        display: grid !important;
        grid-template-columns: repeat(7, 1fr) !important;
        grid-template-rows: repeat(6, 55px) !important;
        gap: 4px !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        
        /* GARANTIR ESTRUTURA */
        position: relative !important;
        box-sizing: border-box !important;
    }
    
    /* ===== CÉLULAS INDIVIDUAIS DOS DIAS ===== */
    #agenda.active .calendar-day-modern {
        /* RESET */
        all: unset !important;
        
        /* ESTRUTURA */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
        position: relative !important;
        
        /* DIMENSÕES */
        width: 100% !important;
        height: 55px !important;
        min-width: 40px !important;
        min-height: 55px !important;
        
        /* TIPOGRAFIA */
        font-family: 'Inter', sans-serif !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        color: #374151 !important;
        text-align: center !important;
        line-height: 1 !important;
        
        /* VISUAL */
        background: #ffffff !important;
        border: 2px solid #e5e7eb !important;
        border-radius: 12px !important;
        
        /* COMPORTAMENTO */
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        
        /* SOMBRA */
        box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
        
        /* GARANTIR VISIBILIDADE */
        opacity: 1 !important;
        visibility: visible !important;
        z-index: 1 !important;
        
        /* ANTI-ALIASING */
        text-rendering: optimizeLegibility !important;
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
    }
    
    /* ===== HOVER DOS DIAS ===== */
    #agenda.active .calendar-day-modern:not(.inactive):hover {
        background: #f3f4f6 !important;
        border-color: #3b82f6 !important;
        transform: translateY(-2px) scale(1.03) !important;
        box-shadow: 0 4px 15px rgba(59, 130, 246, 0.2) !important;
        z-index: 2 !important;
    }
    
    /* ===== DIA ATUAL ===== */
    #agenda.active .calendar-day-modern.current {
        background: linear-gradient(135deg, #3b82f6, #1e40af) !important;
        color: #ffffff !important;
        font-weight: 800 !important;
        font-size: 16px !important;
        border: 3px solid #1e40af !important;
        box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4) !important;
        transform: scale(1.05) !important;
        z-index: 3 !important;
        text-shadow: 0 1px 3px rgba(0,0,0,0.2) !important;
    }
    
    /* ===== DIAS COM EVENTOS ===== */
    #agenda.active .calendar-day-modern.event {
        background: linear-gradient(135deg, #10b981, #059669) !important;
        color: #ffffff !important;
        font-weight: 800 !important;
        font-size: 15px !important;
        border: 3px solid #059669 !important;
        box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4) !important;
        z-index: 2 !important;
        text-shadow: 0 1px 3px rgba(0,0,0,0.2) !important;
    }
    
    /* ===== DIAS INATIVOS ===== */
    #agenda.active .calendar-day-modern.inactive {
        background: #f9fafb !important;
        color: #9ca3af !important;
        border-color: #f3f4f6 !important;
        cursor: default !important;
        opacity: 0.6 !important;
        font-weight: 400 !important;
    }
    
    #agenda.active .calendar-day-modern.inactive:hover {
        transform: none !important;
        background: #f9fafb !important;
        border-color: #f3f4f6 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
    }
    
    /* ===== TELAS MUITO PEQUENAS ===== */
    @media screen and (max-width: 380px) {
        #agenda.active .modern-calendar-container {
            max-width: 100% !important;
            margin: 0 5px 25px 5px !important;
            padding: 20px !important;
        }
        
        #agenda.active .calendar-days-modern,
        #agenda.active #calendarDays {
            grid-template-rows: repeat(6, 50px) !important;
            gap: 3px !important;
        }
        
        #agenda.active .calendar-day-modern {
            height: 50px !important;
            min-height: 50px !important;
            font-size: 14px !important;
        }
        
        #agenda.active .weekday-modern {
            font-size: 11px !important;
            padding: 10px 3px !important;
        }
        
        #agenda.active #currentMonth,
        #agenda.active .calendar-month-title {
            font-size: 20px !important;
        }
        
        #agenda.active .calendar-nav-modern,
        #agenda.active #prevMonth,
        #agenda.active #nextMonth {
            width: 40px !important;
            height: 40px !important;
            min-width: 40px !important;
            min-height: 40px !important;
            font-size: 16px !important;
        }
    }
    
    /* ===== GARANTIR QUE LISTA DE EVENTOS TAMBÉM FUNCIONE ===== */
    #agenda.active .events-list-modern {
        width: 100% !important;
        max-width: 360px !important;
        margin: 0 auto !important;
        padding: 25px !important;
        background: #ffffff !important;
        border-radius: 16px !important;
        border: 1px solid #e5e7eb !important;
        box-shadow: 0 10px 35px rgba(0,0,0,0.1) !important;
    }
    
    #agenda.active .event-item-modern {
        padding: 15px !important;
        margin-bottom: 10px !important;
        background: #f8fafc !important;
        border-radius: 12px !important;
        border-left: 4px solid #3b82f6 !important;
    }
}

/* ===== DESKTOP - NÃO AFETAR ===== */
@media screen and (min-width: 769px) {
    /* Manter desktop intacto */
}

/* ===== FORÇAR PRIORIDADE MÁXIMA ===== */
#agenda.active .modern-calendar-container,
#agenda.active .calendar-day-modern,
#agenda.active .calendar-header-modern,
#agenda.active .calendar-days-modern {
    z-index: auto !important;
}