/* =========================================
   📱 MOBILE & RESPONSIVE CSS OVERRIDES
   ========================================= */

/* Estilos Globais Mobile-First para UX melhor */
@media (max-width: 768px) {

    /* --- LAYOUT GERAL --- */
    body,
    html {
        overflow-x: hidden;
        overflow-y: auto !important;
        /* Garante scroll sempre (útil para login) */
        padding-bottom: 90px !important;
        /* Espaço p/ Bottom Nav */
        background-color: #f8fafc !important;
        height: auto !important;
        min-height: 100vh;
    }

    /* --- LOGIN PAGE FIX (Tentativa de cobrir containers comuns) --- */
    .login-container,
    .login-box,
    #login-wrapper,
    form {
        overflow-y: auto !important;
        max-height: 100vh !important;
    }

    /* --- MODAL COM SCROLL E ESPAÇO EXTRA --- */
    .modal-content {
        max-height: 85vh !important;
        overflow-y: auto !important;
        width: 92% !important;
        margin: auto !important;
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        border-radius: 16px !important;
        padding: 20px !important;
        /* Espaço extra no final para o botão Salvar não ficar escondido */
        padding-bottom: 100px !important;
        -webkit-overflow-scrolling: touch;
        z-index: 10001 !important;
    }

    .modal-overlay {
        position: fixed !important;
        z-index: 10000 !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
    }

    /* Esconde Sidebar Desktop */
    .sidebar {
        display: none !important;
    }

    /* Sidebar vira Off-Canvas quando ativa */
    .sidebar.active {
        display: flex !important;
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 80%;
        max-width: 300px;
        z-index: 9999;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.2);
    }

    /* Conteúdo Principal Full Width */
    .main-content,
    #main-app-container {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 15px !important;
        box-sizing: border-box !important;
    }

    /* Titles */
    h1,
    .page-title {
        font-size: 1.5rem !important;
        text-align: center;
        margin-top: 10px !important;
        color: #1e293b;
    }

    .mobile-menu-btn {
        display: none !important;
    }

    /* --- CARDS & GRIDS --- */
    .card,
    .card-kpi {
        padding: 20px !important;
        margin-bottom: 20px !important;
        border: none !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
        border-radius: 20px !important;
        background: white !important;
    }

    .grid-container,
    .row,
    .stats-grid,
    .dashboard-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }

    .stat-card,
    .card-kpi {
        width: 100% !important;
        border-left-width: 6px !important;
    }

    /* --- TABELAS --- */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tbody tr {
        margin-bottom: 20px;
        border: 1px solid #f1f5f9;
        border-radius: 16px;
        background: white;
        padding: 15px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    }

    td {
        border: none;
        border-bottom: 1px solid #f8fafc;
        position: relative;
        padding-left: 45% !important;
        padding-top: 12px !important;
        padding-bottom: 12px !important;
        text-align: right !important;
        min-height: 45px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #334155;
    }

    td:before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
        color: #94a3b8;
        font-size: 0.85rem;
        text-transform: uppercase;
    }

    /* --- FORMULÁRIOS --- */
    .form-grid,
    .row,
    .col {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
    }

    .form-grid>div,
    .form-group {
        width: 100% !important;
        margin: 0 !important;
        grid-column: span 1 !important;
    }

    label {
        display: block;
        margin-bottom: 8px !important;
        font-weight: 600;
        color: #475569;
        font-size: 0.95rem;
    }

    input:not([type="radio"]):not([type="checkbox"]),
    select,
    textarea,
    .form-control {
        width: 100% !important;
        height: 52px !important;
        padding: 0 16px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        border: 1px solid #cbd5e1 !important;
        background-color: #f8fafc;
        box-sizing: border-box !important;
        margin-bottom: 5px !important;
    }

    /* BUSCA (LUPA) */
    .form-grid>div>div[style*="display:flex"],
    .input-group-search {
        display: flex !important;
        flex-direction: row !important;
        gap: 0 !important;
        width: 100% !important;
    }

    .form-grid>div>div[style*="display:flex"] input {
        border-radius: 12px 0 0 12px !important;
        border-right: none !important;
        flex: 1 !important;
        width: auto !important;
        margin-bottom: 0 !important;
    }

    .form-grid>div>div[style*="display:flex"] button {
        border-radius: 0 12px 12px 0 !important;
        width: 56px !important;
        margin: 0 !important;
        height: 52px !important;
        flex: 0 0 56px !important;
    }

    /* --- SWITCH PF/PJ ESTILO BOTÃO --- */
    .radio-box {
        display: flex !important;
        flex-direction: row !important;
        background: #e2e8f0;
        padding: 4px !important;
        border-radius: 12px;
        gap: 5px !important;
        height: 50px !important;
    }

    .radio-label {
        flex: 1 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin: 0 !important;
        /* Sem margem para ocupar tudo */
        border-radius: 10px;
        background: transparent;
        font-weight: 800;
        color: #94a3b8;
        font-size: 0 !important;
        padding: 0 !important;
        height: 100% !important;
        position: relative;
        cursor: pointer;
    }

    .radio-label input[type="radio"] {
        appearance: none;
        -webkit-appearance: none;
        display: none !important;
    }

    .radio-label:has(input[value="PF"])::after {
        content: "PF";
        font-size: 18px !important;
        display: block;
    }

    .radio-label:has(input[value="PJ"])::after {
        content: "PJ";
        font-size: 18px !important;
        display: block;
    }

    .radio-label:has(input:checked) {
        background: white;
        color: var(--primary, #6366f1);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        transform: scale(0.98);
    }

    /* CORREÇÃO VERTICAL GROUP */
    .mobile-vertical-group {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .mobile-vertical-group button {
        width: 100% !important;
        border-radius: 12px !important;
        margin-top: 5px;
    }

    .mobile-vertical-group select {
        border-radius: 12px !important;
    }

    /* CAIXAS ESPECIAIS */
    #box-cli-conjuge,
    .venda-box {
        display: flex !important;
        flex-direction: column !important;
        padding: 20px !important;
        background: #f1f5f9 !important;
        gap: 15px !important;
        margin-top: 15px !important;
        border-radius: 16px !important;
        border: 1px solid #e2e8f0;
    }

    #box-cli-conjuge>div,
    .venda-box>div {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #box-cli-conjuge>div>div[style*="display:flex"] {
        flex-direction: row !important;
    }

    /* Mapa Mobile */
    #mapa-container-card {
        height: 50vh !important;
    }

    .mapa-zoom-controls {
        bottom: 80px !important;
    }

    /* REFORÇO DE LAYOUT ESPREMIDO */
    input[style],
    select[style],
    .form-control[style] {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        flex: none !important;
    }
}

/* --- BOTTOM NAV BAR DESKTOP (Hidden) --- */
.mobile-bottom-nav {
    display: none !important;
}

/* --- BOTTOM NAV BAR MOBILE --- */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70px;
        background: white;
        box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.08);
        z-index: 10000;
        justify-content: space-evenly;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom);
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
    }

    .nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 60px;
        color: #94a3b8;
        font-size: 0.7rem;
        font-weight: 600;
    }

    .nav-item.active {
        color: var(--primary, #6366f1);
    }

    .nav-item .nav-icon {
        font-size: 1.5rem;
        margin-bottom: 3px;
    }

    .nav-item.highlight {
        background: var(--primary, #6366f1);
        width: 56px;
        height: 56px;
        border-radius: 50%;
        position: relative;
        top: -20px;
        justify-content: center;
        color: white;
        box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
        border: 4px solid white;
    }

    .nav-item.highlight .nav-icon {
        font-size: 1.6rem;
        margin: 0;
    }

    .nav-item.highlight .nav-label {
        display: none;
    }
}

#mobile-menu-overlay {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;
}

#mobile-menu-overlay.active {
    display: block;
}