/* ============================================================
   iREDHUB — Mobile & PWA CSS  v1.1
   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: 56px;
}

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

@media (max-width: 991px) {
    .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 var(--ired-border, 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;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
    }

    .ired-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        gap: 3px;
        color: var(--ired-muted, #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;
        min-height: 44px;
    }
    .ired-bottom-nav a i {
        font-size: 18px;
        line-height: 1;
    }
    .ired-bottom-nav a.active,
    .ired-bottom-nav a:active {
        color: var(--ired-red, #ff2325);
    }
    .ired-bottom-nav a.active i {
        filter: drop-shadow(0 0 6px rgba(255,35,37,0.5));
    }

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

    /* Footer: garantir que nao fique escondido pela bottom nav */
    .footer-premium {
        margin-bottom: var(--bnav-h);
    }

    /* 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;
    }

    /* Cards: evitar que estourem o viewport */
    .ired-main-area .card,
    .ired-main-area .panel-card {
        max-width: 100%;
        overflow: hidden;
    }

    /* Tabelas DataTables: forcar scroll horizontal */
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Select2: nao ultrapassar largura da tela */
    .select2-container {
        max-width: 100% !important;
    }

    /* Paginacao DataTables: scroll se muitas paginas */
    .dataTables_paginate {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 4px;
    }
}

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

@media (max-width: 768px) {
    .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;
    }
    .hide-mobile {
        display: none !important;
    }
}

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

    .card {
        margin-bottom: 12px !important;
    }

    .col-md-6, .col-md-4, .col-md-3, .col-md-8 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    .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;
    }

    label {
        margin-top: 8px !important;
        display: block !important;
    }

    .btn {
        min-height: 44px !important;
        padding: 10px 16px !important;
    }

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

/* ── 6. PANEL DE SERVIDORES ── */
@media (max-width: 768px) {
    .panel-grid-2 {
        grid-template-columns: 1fr !important;
    }

    #logTable-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .server-control-btns {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

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

    .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;
    }

    .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 ── */
@media (max-width: 768px) {
    #kt_datatable_zero_config_wrapper,
    #rankTable_wrapper {
        overflow-x: auto !important;
    }

    .profile-stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    .workshop-viewport {
        height: 50vh !important;
    }

    /* Painel de notificacoes: nao vazar em telas < 375px */
    #ired-notif-panel {
        width: calc(100vw - 24px) !important;
        right: 12px !important;
        left: 12px !important;
    }

    /* Tabela de armas do perfil: largura minima para colunas */
    .ip-weapon-header,
    .ip-weapon-row {
        min-width: 440px;
    }
}

/* ── 8. TOPBAR MELHORIAS MOBILE ── */
@media (max-width: 991px) {
    /* User dropdown: impedir que force o body mais largo que viewport */
    .user-profile-dropdown .dropdown-menu {
        right: 0 !important;
        left: auto !important;
        max-width: calc(100vw - 24px) !important;
        transform: none !important;
    }

    /* Topbar touch targets minimos */
    .sidebarCollapse,
    .ired-search-btn,
    .ired-lang-btn {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* Lang switcher dropdown */
    .ired-lang-dropdown {
        right: 0 !important;
        left: auto !important;
    }
}

@media (max-width: 480px) {
    .srv-chips {
        display: none !important;
    }

    .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: var(--ired-radius, 12px) !important;
    }

    .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. OVERFLOW GLOBAL ── */
/* Previne scroll horizontal. NAO usar max-width: 100vw — conflita
   com regras legadas do theme e colapsa o layout em mobile. */
html, body {
    overflow-x: hidden !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;
}

/* ── 12. TOUCH & ACESSIBILIDADE ── */

/* Cursores customizados: nao aplicar em touch (economiza repaint) */
@media (hover: none) and (pointer: coarse) {
    html, body,
    a, button, .btn, [role="button"] {
        cursor: auto !important;
    }
}

/* Touch targets minimos (WCAG 2.5.5) */
@media (max-width: 767px) {
    .control-btn,
    .btn,
    .action-btn,
    .nav-link {
        min-height: 44px;
    }

    /* Toast: largura total em mobile */
    .toast-bar {
        right: 8px;
        left: 8px;
    }
    .toast-msg {
        min-width: unset;
        width: 100%;
    }
}

/* iOS fixed-position fix */
@supports (-webkit-overflow-scrolling: touch) {
    .ired-left-nav {
        -webkit-overflow-scrolling: touch;
    }
}
