/* =============================================================
   KATEDRAL ADMIN MOBILE ADAPTER v3.6 - LOTTERY VERTICAL STACK
   ============================================================= */

/* 1. ESTADO DE SEGURANÇA GLOBAL
   Oculta os elementos mobile por padrão para evitar vazamento no Desktop ou Login. */
#mobile-admin-header, 
#admin-bottom-nav { 
    display: none !important; 
}

/* 2. REGRAS EXCLUSIVAS PARA DISPOSITIVOS MÓVEIS (ATÉ 1024PX) */
@media (max-width: 1024px) {

    /* MANIFESTAÇÃO DO HEADER MOBILE (SÓ LOGADO) */
    body.is-logged-in #mobile-admin-header {
        display: flex !important;
        position: fixed;
        top: 0; 
        left: 0; 
        width: 100%;
        background: #050506;
        border-bottom: 1px solid var(--border-color);
        z-index: 15000;
        padding: 12px 15px;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    /* MANIFESTAÇÃO DO BOTTOM NAV (SÓ LOGADO) */
    body.is-logged-in #admin-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0; 
        left: 0; 
        width: 100%;
        height: 70px;
        background: rgba(7, 7, 9, 0.98);
        border-top: 1px solid var(--border-color);
        z-index: 15000;
        justify-content: space-around;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* 3. PROTEÇÃO DO HANDSHAKE DE LOGIN
       Garante que o dashboard não cubra os botões de login antes da entrada. */
    #dashboard-view {
        display: none !important;
        pointer-events: none !important;
    }

    body.is-logged-in #dashboard-view.visible {
        display: block !important; /* Força o bloco para permitir empilhamento */
        flex-direction: column !important;
        position: relative;
        z-index: 10;
        pointer-events: auto !important;
    }

    /* 4. REESTRUTURAÇÃO DA ÁREA DE CONTEÚDO
       Ajusta o scroll e o espaçamento para os elementos fixos (Header/Nav). */
    body.is-logged-in .content-area {
        padding: 8px !important;
        padding-top: 130px !important;
        padding-bottom: 80px !important;
        width: 100% !important;
        height: 100vh !important;
        overflow-y: auto !important;
        background: #050506 !important;
        margin-left: 0 !important;
        display: block !important; /* Importante para que itens fluam para baixo */
    }

    /* 5. SIDEBAR / DRAWER MOBILE (MENU LATERAL DESLIZANTE) */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -280px !important;
        width: 260px !important;
        height: 100vh !important;
        z-index: 20000 !important;
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
        background: rgba(7, 7, 9, 0.98) !important;
        display: flex !important;
        box-shadow: 20px 0 50px rgba(0,0,0,0.8) !important;
    }

    .sidebar.drawer-open {
        transform: translateX(280px) !important;
    }

    /* 6. EXTRATO MOBILE - COMPACTAÇÃO */
    .user-snapshot-card {
        position: relative !important;
        flex-direction: row !important;
        align-items: center !important;
        padding: 10px !important;
        gap: 12px !important;
        height: auto !important;
        min-height: 80px !important;
        background: #0a0a0c !important;
        margin-bottom: 5px !important;
    }

    .avatar-wrapper {
        width: 45px !important;
        height: 45px !important;
    }

    .arconte-name { font-size: 15px !important; color: #ffffff !important;}
    .arconte-uid { font-size: 8px !important; }

    .snapshot-balances {
        flex-direction: row !important;
        width: auto !important;
        gap: 6px !important;
        margin-top: 5px !important;
    }

    .balance-pill {
        padding: 4px 6px !important;
        min-width: 90px !important;
    }

    /* 7. TABELA DE EXTRATO - DISTRIBUIÇÃO TÁTICA */
    .extract-table {
        display: table !important;
        width: 100% !important;
        table-layout: fixed !important;
        border-spacing: 0 2px !important;
    }

    .extract-table th, 
    .extract-table td {
        font-size: 9px !important;
        padding: 6px 2px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .extract-table th:nth-child(1), .extract-table td:nth-child(1) { width: 55px !important; }
    .extract-table th:nth-child(2), .extract-table td:nth-child(2) { width: 22px !important; text-align: center; }
    .extract-table th:nth-child(3), .extract-table td:nth-child(3) { width: auto !important; }
    .extract-table th:nth-child(4), .extract-table td:nth-child(4) { width: 50px !important; text-align: right; }
    .extract-table th:nth-child(5), .extract-table td:nth-child(5) { width: 65px !important; text-align: right; }

    /* 8. CORREÇÃO FINAL: LAYOUT DE LOTERIAS (DETALHES TOTALMENTE ABAIXO) */
    
    /* Força o container a ser uma coluna única de largura total */
    .admin-overview-layout {
        display: block !important; /* Muda de flex para block para garantir quebra de linha */
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Caixa de Lista (Registros em Memória) */
    #admin-lotteries-list-container {
        width: 100% !important; /* Ocupa a tela toda */
        max-width: 100% !important;
        max-height: 250px !important; /* Limita a altura para sobrar espaço para os detalhes */
        overflow-y: auto !important;
        margin-bottom: 20px !important; /* Dá um respiro antes dos detalhes */
        background: rgba(0, 0, 0, 0.3) !important;
        border: 1px solid var(--border-color) !important;
    }

    /* Caixa de Detalhes (Participantes/Stats que estavam sumindo à direita) */
    #admin-lottery-detail-view {
        display: block !important;
        width: 100% !important; /* Ocupa 100% da largura */
        max-width: 100% !important;
        min-height: 300px !important;
        margin-top: 15px !important;
        padding: 15px !important;
        background: rgba(255, 255, 255, 0.02) !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 12px !important;
        position: relative !important;
        left: 0 !important; /* Garante o alinhamento à esquerda */
    }

    /* Ajuste de Grids dentro do detalhe da loteria */
    #admin-lottery-detail-view .dashboard-grid {
        grid-template-columns: 1fr 1fr !important; /* Mantém 2 colunas para os stats */
        gap: 10px !important;
    }

    /* 9. ESTILO DOS ITENS DO BOTTOM NAV */
    .nav-item-mobile {
        display: flex; flex-direction: column; align-items: center;
        color: var(--text-muted); font-size: 9px; font-weight: 800;
        text-decoration: none; gap: 4px; transition: 0.3s;
    }

    .nav-item-mobile.active { color: var(--arconte-gold); }
    .nav-item-mobile span { font-size: 22px; }

    .content-area::-webkit-scrollbar { display: none; }
}

/* 10. PROTEÇÃO E RESET PARA DESKTOP */
@media (min-width: 1025px) {
    #mobile-admin-header, 
    #admin-bottom-nav { 
        display: none !important; 
    }

    .sidebar { 
        left: 0 !important; 
        position: relative !important; 
        transform: none !important; 
    }
}