/* ====================================================
   RESPONSIVIDADE MOBILE - MeControlei
   Complementa user.css e admin.css
   ==================================================== */

/* ============================================================
   LAYOUT PRINCIPAL - Sidebar + Main
   ============================================================ */

/* Garante que o body não tenha overflow horizontal */
html {
    overflow-x: hidden;
}
body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ============================================================
   NAVBAR FIXA NO TOPO
   overflow-x:hidden quebra position:sticky — usamos fixed direto
   ============================================================ */
#mainNavbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 1030 !important;
}

/* Empurra o conteúdo para baixo da navbar fixa (48px de altura) */
body {
    padding-top: 48px;
}

/* Sidebar começa logo abaixo da navbar */
.sidebar {
    top: 48px !important;
    height: calc(100vh - 48px) !important;
}

/* Desktop: container principal sem quebra de linha (sidebar + main lado a lado) */
@media (min-width: 768px) {
    .container-fluid > .row {
        flex-wrap: nowrap;
    }
    main.col-md-9,
    main.col-md-10,
    main[class*="col-md"] {
        min-width: 0;
    }
}

/* ============================================================
   OVERLAY para fechar sidebar no mobile
   ============================================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
}

/* ============================================================
   NAVBAR MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
    #mainNavbar {
        padding: 0 8px !important;
        min-height: 52px;
    }

    .navbar-brand {
        font-size: 0.85rem !important;
        padding: 8px 10px !important;
        white-space: nowrap;
    }

    .navbar-brand img {
        width: 30px !important;
        height: 30px !important;
    }

    /* Esconde banner WhatsApp no mobile */
    .whatsapp-bot-banner {
        display: none !important;
    }

    /* Dropdown usuário no mobile */
    #userDropdown span {
        display: none;
    }

    #userDropdown .fa-chevron-down {
        display: none;
    }

    #userDropdownMenu {
        right: 0 !important;
        min-width: 160px !important;
    }
}

/* ============================================================
   SIDEBAR MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
    .sidebar {
        position: fixed !important;
        top: 48px !important;
        left: -100% !important;
        width: 260px !important;
        height: calc(100vh - 48px) !important;
        z-index: 100 !important;
        overflow-y: auto !important;
        background: #f8f9fa !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 15px rgba(0,0,0,0.15) !important;
        padding: 0 !important;
    }

    .sidebar.show {
        left: 0 !important;
    }

    .sidebar .position-sticky {
        position: relative !important;
        top: 0 !important;
        padding-top: 1rem !important;
        height: auto !important;
    }

    /* Links do sidebar maiores no mobile (melhor toque) */
    .sidebar .nav-link {
        padding: 14px 20px !important;
        font-size: 1rem !important;
    }

    /* Conteúdo principal sem padding lateral excessivo */
    main.col-md-9,
    main.col-md-10,
    main[class*="col-md"] {
        margin-left: 0 !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
}

/* ============================================================
   TIPOGRAFIA E ESPAÇAMENTO MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
    h1.h2 {
        font-size: 1.3rem !important;
    }

    h1, h2, h3 {
        font-size: clamp(1.1rem, 4vw, 1.5rem);
    }

    /* Cabeçalho de página (título + botões) */
    .d-flex.justify-content-between.flex-wrap {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .btn-toolbar {
        width: 100%;
    }

    .btn-toolbar .btn-group {
        display: flex;
        width: 100%;
    }

    .btn-toolbar .btn-group .btn {
        flex: 1;
    }
}

/* ============================================================
   CARDS DE RESUMO / ESTATÍSTICAS
   ============================================================ */
@media (max-width: 767.98px) {
    /* Cards lado a lado no mobile (2 por linha) */
    .col-xl-3.col-md-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
        padding-left: 6px !important;
        padding-right: 6px !important;
        margin-bottom: 12px !important;
    }

    .card-body {
        padding: 0.75rem !important;
    }

    .card-body .h5 {
        font-size: 1rem !important;
    }

    .card-body .text-xs {
        font-size: 0.65rem !important;
    }

    /* Ícone dos cards menor */
    .card-body .fa-2x {
        font-size: 1.4em !important;
    }

    /* Desativa hover transform em mobile (evita layout shift) */
    .card:hover {
        transform: none !important;
    }
}

@media (max-width: 400px) {
    /* Telas muito pequenas: cards empilhados */
    .col-xl-3.col-md-6 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* ============================================================
   TABELAS RESPONSIVAS
   ============================================================ */

/* Garante scroll horizontal em todas as tabelas */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    border: none;
}

/* Adiciona wrapper responsivo automaticamente onde não existe */
.card-body > table,
.card-body > .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
    .table {
        font-size: 0.78rem !important;
        min-width: 500px; /* força scroll em vez de quebrar */
    }

    .table th,
    .table td {
        padding: 0.5rem 0.6rem !important;
        white-space: nowrap;
    }

    /* Botões de ação menores */
    .table .btn-sm {
        padding: 0.2rem 0.45rem !important;
        font-size: 0.7rem !important;
    }

    /* Desativa hover scale em linhas da tabela */
    .table tbody tr:hover {
        transform: none !important;
    }

    /* Badges menores */
    .badge {
        font-size: 0.65rem !important;
        padding: 0.25em 0.5em !important;
    }
}

/* ============================================================
   FORMULÁRIOS E FILTROS
   ============================================================ */
@media (max-width: 767.98px) {
    /* Filtros em coluna única */
    .row.g-3 > [class*="col-md"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Inputs maiores para toque */
    .form-control,
    .form-select {
        font-size: 1rem !important;
        padding: 0.6rem 0.9rem !important;
        min-height: 44px; /* mínimo para área de toque acessível */
    }

    /* Desativa transform no focus (evita zoom indesejado) */
    .form-control:focus,
    .form-select:focus {
        transform: none !important;
    }

    /* Labels mais legíveis */
    .form-label {
        font-size: 0.875rem;
        font-weight: 600;
        margin-bottom: 0.3rem;
    }

    /* Botões maiores em mobile */
    .btn {
        min-height: 42px;
        font-size: 0.875rem !important;
    }

    /* Botões de ação de linha não transformam no hover mobile */
    .btn:hover {
        transform: none !important;
        box-shadow: none !important;
    }

    /* Botão de submit full width */
    .btn-primary[type="submit"] {
        width: 100%;
    }

    /* Textarea */
    textarea.form-control {
        min-height: 80px;
    }
}

/* ============================================================
   MODAIS RESPONSIVOS
   ============================================================ */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100vw - 1rem) !important;
    }

    .modal-content {
        border-radius: 0.75rem !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    .modal-header,
    .modal-footer {
        padding: 0.75rem 1rem !important;
    }

    .modal-title {
        font-size: 1rem !important;
    }

    /* Botões do modal full width */
    .modal-footer .btn {
        flex: 1;
    }
}

/* ============================================================
   ALERTAS
   ============================================================ */
@media (max-width: 767.98px) {
    .alert {
        font-size: 0.82rem !important;
        padding: 0.65rem 0.9rem !important;
    }

    .alert .btn-close {
        padding: 0.5rem !important;
    }
}

/* ============================================================
   CARDS DE CONTEÚDO (seções de listas, relatórios)
   ============================================================ */
@media (max-width: 767.98px) {
    .card-header {
        padding: 0.65rem 1rem !important;
        font-size: 0.875rem !important;
    }

    /* Elimina margem lateral excessiva */
    .row.mb-4 {
        margin-left: -6px !important;
        margin-right: -6px !important;
    }

    /* Colunas de conteúdo em 100% */
    .col-md-8, .col-md-6, .col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Progress bars */
    .progress {
        height: 18px !important;
    }
}

/* ============================================================
   NAVEGAÇÃO DE MÊS (setas de período)
   ============================================================ */
@media (max-width: 767.98px) {
    /* Mantém navegação de mês compacta */
    .btn-group .btn-sm {
        padding: 0.3rem 0.6rem !important;
        font-size: 0.8rem !important;
        min-height: 36px;
    }

    .btn-group .btn:disabled {
        min-width: 110px;
        font-size: 0.78rem !important;
    }
}

/* ============================================================
   PÁGINA DE LOGIN (index.php)
   ============================================================ */
@media (max-width: 767.98px) {
    /* Esconde o painel esquerdo de features no mobile */
    .left-side {
        display: none !important;
    }

    .main-card {
        border-radius: 16px !important;
        margin: 10px !important;
        max-width: 100% !important;
    }

    .right-side {
        padding: 30px 20px !important;
    }

    /* Tabs de login/cadastro */
    .nav-tabs .nav-link {
        padding: 8px 18px !important;
        font-size: 0.9rem !important;
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    .left-side {
        padding: 40px 25px !important;
    }

    .left-side h1 {
        font-size: 1.8rem !important;
    }

    .left-side p, .feature-list li {
        font-size: 0.9rem !important;
    }

    .right-side {
        padding: 40px 25px !important;
    }
}

/* ============================================================
   PÁGINA DE PERFIL
   ============================================================ */
@media (max-width: 767.98px) {
    /* Upload de imagem centralizado */
    .text-center .rounded-circle {
        width: 80px !important;
        height: 80px !important;
    }

    /* Seções de perfil em coluna */
    .col-md-8.offset-md-2 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
    }
}

/* ============================================================
   PÁGINA DE LICENÇA E PAGAMENTO
   ============================================================ */
@media (max-width: 767.98px) {
    /* Cards de planos */
    .col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 1rem;
    }

    /* Preços grandes */
    .display-4, .display-3 {
        font-size: 2rem !important;
    }
}

/* ============================================================
   PAINEL ADMIN - Sidebar e Layout
   ============================================================ */
@media (max-width: 767.98px) {
    /* Admin usa a mesma lógica do user */
    #adminSidebarMenu {
        position: fixed !important;
        top: 48px !important;
        left: -100% !important;
        width: 260px !important;
        height: calc(100vh - 48px) !important;
        z-index: 100 !important;
        overflow-y: auto !important;
        background: #343a40 !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 15px rgba(0,0,0,0.2) !important;
        padding: 0 !important;
    }

    #adminSidebarMenu.show {
        left: 0 !important;
    }
}

/* ============================================================
   UTILIDADES EXTRAS MOBILE
   ============================================================ */

/* Touch targets mínimos acessíveis */
@media (max-width: 767.98px) {
    a, button, .btn, .nav-link {
        -webkit-tap-highlight-color: rgba(52, 152, 219, 0.15);
    }

    /* Remove transições desnecessárias no mobile */
    * {
        transition-duration: 0.15s !important;
    }

    /* Texto não quebra em lugares ruins */
    .text-xs {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Padding da main no topo (navbar fixa) */
    main {
        padding-top: 0 !important;
    }

    /* Separador de seção */
    .border-bottom {
        margin-bottom: 1rem !important;
        padding-bottom: 0.75rem !important;
    }
}

/* ============================================================
   MELHORIAS PARA TABLETS (768px - 991px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 991px) {
    .sidebar {
        width: 180px !important;
    }

    main.col-md-9 {
        flex: 0 0 calc(100% - 180px) !important;
        max-width: calc(100% - 180px) !important;
    }

    .sidebar .nav-link {
        font-size: 0.82rem !important;
        padding: 10px 14px !important;
    }

    .sidebar .nav-link i {
        margin-right: 5px !important;
    }

    .col-xl-3.col-md-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
}

/* ============================================================
   BOTTOM NAVIGATION (opcional - estilo app mobile)
   ============================================================ */
@media (max-width: 767.98px) {
    /* Espaço no rodapé para a bottom nav */
    body {
        padding-bottom: 64px;
    }

    .bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: #fff;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
        z-index: 1000;
        border-top: 1px solid #e9ecef;
    }

    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #6c757d;
        text-decoration: none;
        font-size: 0.6rem;
        font-weight: 600;
        gap: 3px;
        transition: color 0.2s !important;
        padding: 4px 0;
    }

    .bottom-nav a i {
        font-size: 1.1rem;
    }

    .bottom-nav a.active {
        color: #3498db;
    }

    .bottom-nav a:active {
        background: #f0f7ff;
    }
}

/* Esconde bottom nav em desktop */
@media (min-width: 768px) {
    .bottom-nav {
        display: none !important;
    }
}
