﻿/* ============================================================
   iREDHUB — Mobile & PWA CSS  v1.0
   Carregado em base-layout.blade.php para todas as paginas.
   Corrige: overflow, cards empilhados, tabelas, formularios,
   bottom-nav PWA, safe-areas iOS/Android.
============================================================ */

/* ── 1. SAFE AREAS (iPhone notch / Dynamic Island / barra Android) ── */
:root {
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left, 0px);
    --safe-right:  env(safe-area-inset-right, 0px);
    --bnav-h: 64px; /* altura da bottom nav */
}

/* ── 2. BOTTOM NAVIGATION (so aparece em mobile) ── */
.ired-bottom-nav {
    display: none;
}

@media (max-width: 991px) {
    /* Mostra bottom nav */
    .ired-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--bnav-h) + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
        background: rgba(6, 8, 24, 0.97);
        border-top: 1px solid rgba(255, 35, 37, 0.25);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        z-index: 1040;
        align-items: stretch;
        justify-content: space-around;
    }

    .ired-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        gap: 4px;
        color: #888ea8;
        text-decoration: none;
        font-size: 9px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        transition: color 0.2s;
        -webkit-tap-highlight-color: transparent;
    }
    .ired-bottom-nav a i {
        font-size: 18px;
        line-height: 1;
    }
    .ired-bottom-nav a.active,
    .ired-bottom-nav a:active {
        color: #ff2325;
    }

    /* Espaco para a bottom nav nao cobrir conteudo */
    body {
        padding-bottom: calc(var(--bnav-h) + var(--safe-bottom)) !important;
    }

    /* Topbar safe-area topo */
    .ired-top-header {
        padding-top: var(--safe-top);
        height: calc(60px + var(--safe-top)) !important;
    }

    /* Overlay do sidebar cobre tudo */
    .overlay {
        position: fixed !important;
        inset: 0 !important;
        background: rgba(0, 0, 0, 0.6) !important;
        z-index: 1049 !important;
        display: none;
        backdrop-filter: blur(2px);
    }
    .overlay.show { display: block !important; }

    /* Sidebar drawer ocupa tela inteira de altura */
    .ired-left-nav {
        height: 100vh !important;
        max-height: 100vh !important;
        overflow-y: auto !important;
        padding-top: var(--safe-top) !important;
        padding-bottom: calc(var(--bnav-h) + var(--safe-bottom)) !important;
    }

    /* Conteudo principal sem padding lateral excessivo */
    .ired-main-area {
        padding: 12px 12px 0 12px !important;
    }
}

/* ── 3. TABELAS RESPONSIVAS ── */
/* Envolve qualquer tabela num container scrollavel */
.table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

@media (max-width: 768px) {
    /* Faz tabelas sem wrapper tambem scrollarem */
    .ired-main-area .table-responsive,
    .ired-main-area .dataTables_wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .ired-main-area table {
        min-width: 480px;
    }
    /* Esconde colunas menos importantes em telas muito pequenas */
    .hide-mobile {
        display: none !important;
    }
}

/* ── 4. CARDS E GRIDS ── */
@media (max-width: 768px) {
    /* Rows do Bootstrap: evita overflow */
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    .row > [class*="col-"] {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Cards: largura plena, sem margin negativa */
    .card {
        margin-bottom: 12px !important;
    }

    /* Grids de 2+ colunas colapsam para 1 */
    .col-md-6, .col-md-4, .col-md-3, .col-md-8 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    /* Botoes de acao lado a lado colapsam em coluna */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .btn-group-mobile .btn {
        width: 100%;
    }
}

/* ── 5. FORMULARIOS MOBILE ── */
@media (max-width: 768px) {
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px !important; /* evita zoom no iOS */
        height: auto !important;
        min-height: 44px !important;
    }

    /* Labels mais espaCados */
    label {
        margin-top: 8px !important;
        display: block !important;
    }

    /* Botoes: minimo 44px de altura (touch target) */
    .btn {
        min-height: 44px !important;
        padding: 10px 16px !important;
    }

    /* Select2 */
    .select2-container {
        width: 100% !important;
    }
}

/* ── 6. PANEL DE SERVIDORES (pagina mais complexa) ── */
@media (max-width: 768px) {
    /* Secoes do panel: grid de 2 colunas vira 1 */
    .panel-grid-2 {
        grid-template-columns: 1fr !important;
    }

    /* Log de acoes: tabela scrollavel */
    #logTable-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Botoes de controle de servidor lado a lado */
    .server-control-btns {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    /* Console output: nao quebra layout */
    .console-output,
    .console-box,
    pre {
        max-width: 100% !important;
        overflow-x: auto !important;
        font-size: 11px !important;
        word-break: break-all !important;
    }

    /* Plugins list: cards compactos */
    .plugin-list-item {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }
    .plugin-list-item .plugin-actions {
        width: 100% !important;
        justify-content: flex-end !important;
    }

    /* Abas (tabs) do panel scrollaveis horizontalmente */
    .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }
    .nav-tabs::-webkit-scrollbar { display: none !important; }
    .nav-tabs .nav-item { flex-shrink: 0 !important; }
}

/* ── 7. PAGINAS ESPECIFICAS ── */

/* Ranking list: tabela scrollavel */
@media (max-width: 768px) {
    #kt_datatable_zero_config_wrapper,
    #rankTable_wrapper {
        overflow-x: auto !important;
    }

    /* Profile page: stats em grid 2x2 */
    .profile-stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Workshop 3D: viewport ocupa tela toda em mobile */
    .workshop-viewport {
        height: 50vh !important;
    }
}

/* ── 8. TOPBAR MELHORIAS MOBILE ── */
@media (max-width: 480px) {
    /* Esconde chips de servidor se nao couber */
    .srv-chips {
        display: none !important;
    }

    /* Titulo da pagina mais curto */
    .ired-page-title {
        max-width: 100px !important;
        font-size: 12px !important;
    }
}

/* ── 9. MODAL RESPONSIVO ── */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }
    .modal-content {
        border-radius: 12px !important;
    }

    /* Modal de convite X1 */
    .invite-card {
        padding: 20px 16px !important;
    }
    .btn-accept, .btn-refuse, .btn-pause {
        padding: 10px 16px !important;
        font-size: 13px !important;
    }
}

/* ── 10. PAINEL FLUTUANTE DE PARTIDA (mobile) ── */
@media (max-width: 768px) {
    #activeMatchPanel {
        width: calc(100vw - 24px) !important;
        right: -110vw !important;
        bottom: calc(var(--bnav-h) + var(--safe-bottom) + 8px) !important;
        top: auto !important;
    }
    #activeMatchPanel.show {
        right: 12px !important;
    }
}

/* ── 11. NOTIFICACOES PANEL MOBILE ── */
@media (max-width: 768px) {
    #ired-notif-panel {
        width: calc(100vw - 24px) !important;
        right: 12px !important;
        left: 12px !important;
    }
}

/* ── 12. UTILS GERAIS ── */

/* Impede scroll horizontal na pagina toda */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

/* Imagens nao extrapolam o container */
img {
    max-width: 100%;
}

/* Textos muito longos quebram */
.ired-main-area p,
.ired-main-area td,
.ired-main-area th,
.ired-main-area span {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Evita que elementos com position:fixed saiam da tela em iOS */
@supports (-webkit-overflow-scrolling: touch) {
    .ired-left-nav {
        -webkit-overflow-scrolling: touch;
    }
}
