/*
==================================================
    MOBILE RESPONSIVO - Sistema de Gestão Financeira
==================================================
*/

/* ============================================
   HEADER MOBILE - FIXO
============================================ */
@media (max-width: 991px) {
    #kt_app_header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        height: 64px;
    }

    body {
        padding-top: 64px;
    }

    /* Logo menor no mobile */
    .app-header-logo img {
        max-height: 38px !important;
    }
}

@supports (padding: max(0px)) {
    @media (max-width: 991px) {
        body {
            padding-top: max(64px, env(safe-area-inset-top));
        }
    }
}

/* ============================================
   SIDEBAR / DRAWER MOBILE
============================================ */
@media (max-width: 991px) {
    #kt_app_sidebar {
        position: fixed !important;
        top: 0;
        left: -290px;
        height: 100vh;
        width: 280px;
        z-index: 1050;
        transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        padding-top: 1rem;
    }

    #kt_app_sidebar.drawer-on {
        left: 0 !important;
    }

    /* Overlay de fundo criado pelo JS */
    .fin-sidebar-overlay {
        position: fixed;
        inset: 0;
        background-color: rgba(7, 14, 25, 0.55);
        z-index: 1049;
        display: none;
    }

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

    /* Remove padding lateral do main */
    .app-main {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .app-container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* ============================================
   TABELAS RESPONSIVAS - SCROLL HORIZONTAL
   NOTA: NÃO usar display:block na table pois
   quebra o DataTables
============================================ */
@media (max-width: 991px) {
    /* Container responsivo recebe o scroll */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        display: block !important;
        width: 100% !important;
        position: relative;
    }

    /* Wrapper do DataTables também deve scrollar */
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Largura mínima para tabelas com dados */
    .table-responsive > table,
    .dataTables_wrapper table {
        min-width: 650px;
    }

    /* Células não quebram linha */
    .table th,
    .table td {
        white-space: nowrap;
    }

    /* Sombra indicando scroll à direita */
    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 28px;
        background: linear-gradient(to left, rgba(13, 27, 42, 0.08), transparent);
        pointer-events: none;
        transition: opacity 0.25s;
        border-radius: 0 6px 6px 0;
    }

    .table-responsive.scrolled-end::after {
        opacity: 0;
    }

    .table-responsive.scrolled::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 28px;
        background: linear-gradient(to right, rgba(13, 27, 42, 0.08), transparent);
        pointer-events: none;
        z-index: 1;
    }
}

/* ============================================
   DATATABLES MOBILE
============================================ */
@media (max-width: 991px) {
    .dataTables_filter input {
        width: 100% !important;
        max-width: 100%;
        margin-bottom: 0.75rem;
    }

    .dataTables_length select {
        margin-bottom: 0.75rem;
    }

    .dataTables_info,
    .dataTables_paginate {
        text-align: center;
        margin: 0.75rem 0;
    }

    .dataTables_paginate .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 2px;
    }

    .dataTables_paginate .page-link {
        padding: 0.4rem 0.65rem;
        font-size: 0.8rem;
    }
}

/* ============================================
   CARDS RESPONSIVOS
============================================ */
@media (max-width: 767px) {
    .card-body {
        padding: 1rem !important;
    }

    .card-body .fs-2x {
        font-size: 1.5rem !important;
    }

    .card-body .fs-7 {
        font-size: 0.82rem !important;
    }
}

/* ============================================
   BOTÕES E TOOLBAR RESPONSIVOS
============================================ */
@media (max-width: 767px) {
    .card-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .form-select,
    .form-control {
        width: 100% !important;
        max-width: 100% !important;
    }
}

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

    .modal-body {
        padding: 1rem;
    }

    .modal-body .form-control,
    .modal-body .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px !important; /* Previne zoom indesejado no iOS */
    }
}

/* ============================================
   BREADCRUMB MOBILE
============================================ */
@media (max-width: 767px) {
    .breadcrumb {
        font-size: 0.72rem;
        flex-wrap: wrap;
    }

    .page-heading {
        font-size: 1.1rem !important;
    }
}

/* ============================================
   GRID DE CARDS RESPONSIVO
============================================ */
@media (max-width: 767px) {
    .row.g-5,
    .row.g-xl-10 {
        --bs-gutter-x: 0.75rem;
        --bs-gutter-y: 0.75rem;
    }
}

/* ============================================
   SCROLL SUAVE
============================================ */
html {
    scroll-behavior: smooth;
}
