/**
 * Mobile App-Like Experience
 * Somente mobile - zero impacto no desktop.
 * Carregado com media="(max-width: 768px)" no header.php
 * v1.0
 */

/* ============================================================
   A. BOTTOM NAVIGATION BAR
   ============================================================ */

/* Esconder no desktop (safety net) */
@media (min-width: 769px) {
    .mobile-bottom-nav {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: #ffffff;
        box-shadow: 0 -1px 10px rgba(0, 0, 0, 0.08);
        z-index: 1040;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom, 0);
        border-top: 1px solid #eee;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
    }

    .mobile-bottom-nav::-webkit-scrollbar {
        display: none;
    }

    .mobile-bottom-nav .bottom-nav-item {
        flex: 0 0 auto;
        min-width: 68px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: #8b95a2;
        font-size: 0.62rem;
        font-weight: 500;
        padding: 6px 14px;
        gap: 3px;
        position: relative;
        transition: color 0.2s ease;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.04);
        scroll-snap-align: start;
        white-space: nowrap;
    }

    .mobile-bottom-nav .bottom-nav-item i {
        font-size: 1.35rem;
        line-height: 1;
    }

    .mobile-bottom-nav .bottom-nav-item span {
        line-height: 1;
        letter-spacing: 0.01em;
    }

    .mobile-bottom-nav .bottom-nav-item.active {
        color: #22c55e;
    }

    .mobile-bottom-nav .bottom-nav-item.active i {
        font-weight: 900;
    }

    .mobile-bottom-nav .bottom-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 28px;
        height: 3px;
        background: #22c55e;
        border-radius: 0 0 3px 3px;
    }

    /* Dot badge para notificações */
    .mobile-bottom-nav .bottom-nav-dot {
        position: absolute;
        top: 5px;
        right: 8px;
        width: 7px;
        height: 7px;
        background: #f59e0b;
        border-radius: 50%;
        border: 1.5px solid #fff;
    }

    /* Sair: leve destaque visual */
    .mobile-bottom-nav .bottom-nav-logout {
        color: #cbd5e1;
        border-left: 1px solid #f1f5f9;
        padding-left: 12px;
        margin-left: 4px;
    }

    /* Body padding para compensar bottom nav */
    .main-content {
        padding-bottom: 72px !important;
    }
}

/* ============================================================
   B. SAVE BAR - FIXO E ANIMADO
   ============================================================ */

@media (max-width: 768px) {
    /* Save bar — ID selector para máxima especificidade */
    #saveBar {
        position: fixed !important;
        bottom: 56px !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0.75rem 1rem !important;
        z-index: 1039 !important;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.3s ease;
        transform: translateY(0);
        opacity: 1;
    }

    /* Quando escondido (d-none) — animar em vez de display:none */
    #saveBar.d-none {
        display: block !important;
        transform: translateY(100%) !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* Container interno — forçar coluna */
    #saveBar > div {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: center !important;
        gap: 0.5rem !important;
        flex-wrap: nowrap !important;
    }

    /* Texto */
    #saveBar > div > span {
        font-size: 0.8rem;
        text-align: center;
    }

    /* Botões container */
    #saveBar > div > div {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        gap: 0.5rem !important;
    }

    /* Cada botão */
    #saveBar > div > div > button,
    #saveBar > div > div > .btn {
        flex: 1 !important;
        min-height: 42px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Padding extra no form para último campo não ficar escondido */
    #formPerfil {
        padding-bottom: 90px;
    }
}

/* ============================================================
   C. PERFIL CARD COMPACTO (coluna esquerda avatar)
   ============================================================ */

@media (max-width: 991.98px) {
    /* Layout horizontal: avatar + nome lado a lado */
    .col-lg-3 > .card > .card-body.text-center {
        display: flex !important;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.75rem;
        padding: 0.875rem 1rem !important;
        text-align: left !important;
    }

    /* Avatar menor */
    .col-lg-3 .avatar-container {
        width: 52px !important;
        height: 52px !important;
        margin: 0 !important;
        flex-shrink: 0;
    }

    .col-lg-3 .avatar-large {
        width: 52px !important;
        height: 52px !important;
        font-size: 1rem !important;
    }

    .col-lg-3 .avatar-overlay {
        width: 22px !important;
        height: 22px !important;
        font-size: 0.55rem !important;
    }

    /* Nome e email ao lado do avatar */
    .col-lg-3 .card-body > h6.fw-bold {
        margin: 0 !important;
        font-size: 0.95rem;
        order: 0;
    }

    .col-lg-3 .card-body > small.text-muted {
        margin-top: -0.5rem;
        font-size: 0.75rem;
        order: 1;
    }

    /* Badge ativo */
    .col-lg-3 .card-body > .mt-2 {
        margin: 0 !important;
        order: 2;
    }

    /* Esconder info-list no mobile (dados já estão no form) */
    .col-lg-3 .info-list {
        display: none !important;
    }

    /* Esconder separadores */
    .col-lg-3 .card-body > hr {
        display: none !important;
    }

    /* Esconder botão remover foto (manter apenas o overlay da câmera) */
    .col-lg-3 .card-body > form:has([name="acao"][value="remover_foto_perfil"]) {
        display: none !important;
    }

    /* Botão Alterar Senha compacto */
    .col-lg-3 .card-body > .btn-outline-primary {
        width: auto !important;
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
        min-height: 34px;
        order: 10;
        margin-left: auto;
    }

    /* Reduzir margem da coluna esquerda */
    .col-lg-3.mb-4 {
        margin-bottom: 0.75rem !important;
    }
}

/* ============================================================
   D. SECOES COLAPSIVEIS
   ============================================================ */

@media (max-width: 768px) {
    /* Card headers clicáveis com chevron */
    .col-lg-9 .card .card-header {
        cursor: pointer;
        position: relative;
        padding-right: 2.5rem !important;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.04);
    }

    .col-lg-9 .card .card-header::after {
        content: '\f078';
        font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free';
        font-weight: 900;
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        transition: transform 0.25s ease;
        font-size: 0.7rem;
        color: #9ca3af;
    }

    .col-lg-9 .card.section-collapsed .card-header::after {
        transform: translateY(-50%) rotate(-90deg);
    }

    .col-lg-9 .card.section-collapsed .card-body {
        max-height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        opacity: 0;
        overflow: hidden;
        border-top: none !important;
    }

    /* Cards unidos visualmente (lista contínua) */
    .col-lg-9 > form > .card {
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        margin-bottom: 0 !important;
        border-bottom: none !important;
        border-top: 1px solid #e9ecef !important;
    }

    .col-lg-9 > form > .card:first-child {
        border-top: none !important;
        border-top-left-radius: 12px !important;
        border-top-right-radius: 12px !important;
    }

    .col-lg-9 > form > .card:last-of-type {
        border-bottom-left-radius: 12px !important;
        border-bottom-right-radius: 12px !important;
        border-bottom: 1px solid #e9ecef !important;
    }

    /* Card header sem border bottom quando colapsado */
    .col-lg-9 .card.section-collapsed .card-header {
        border-bottom: none !important;
    }
}

/* ============================================================
   E. HEADER COMPACTO
   ============================================================ */

@media (max-width: 768px) {
    /* Container principal menos padding */
    .container-fluid.py-4 {
        padding-top: 0.5rem !important;
        padding-bottom: 0.25rem !important;
    }

    /* Título menor */
    .container-fluid > .row.mb-4:first-child {
        margin-bottom: 0.5rem !important;
    }

    .container-fluid > .row.mb-4:first-child .h3,
    .container-fluid > .row.mb-4:first-child h1 {
        font-size: 1.05rem !important;
        margin-bottom: 0 !important;
    }

    /* Esconder subtítulo */
    .container-fluid > .row.mb-4:first-child .text-muted.mb-0 {
        display: none;
    }
}

/* ============================================================
   F. CAMPOS LADO A LADO
   ============================================================ */

@media (max-width: 767.98px) {
    /* Experiência: Início + Fim na mesma linha */
    .exp-entry .row > .col-md-3:has(input[type="month"]) {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Endereço: CEP + UF */
    .card-body .row > .col-md-3:has(#cep) {
        flex: 0 0 60%;
        max-width: 60%;
    }

    .card-body .row > .col-md-2:has(#estado) {
        flex: 0 0 40%;
        max-width: 40%;
    }

    /* Endereço: Número + Complemento */
    .card-body .row > .col-md-2:has([name="numero"]) {
        flex: 0 0 35%;
        max-width: 35%;
    }

    .card-body .row > .col-md-4:has([name="complemento"]) {
        flex: 0 0 65%;
        max-width: 65%;
    }

    /* Experiência: checkbox "Emprego atual" full width */
    .exp-entry .row > .col-md-3:has(.form-check) {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ============================================================
   G. MODAL FULLSCREEN NO MOBILE
   ============================================================ */

@media (max-width: 576px) {
    .modal-dialog:not(.modal-lg):not(.modal-xl) {
        margin: 0 !important;
        max-width: 100% !important;
        min-height: 100vh;
        display: flex;
        align-items: stretch;
    }

    .modal-dialog:not(.modal-lg):not(.modal-xl) .modal-content {
        border-radius: 0 !important;
        min-height: 100vh;
        border: none !important;
        display: flex;
        flex-direction: column;
    }

    .modal-dialog:not(.modal-lg):not(.modal-xl) .modal-header {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 10;
        border-radius: 0;
    }

    .modal-dialog:not(.modal-lg):not(.modal-xl) .modal-body {
        flex: 1;
    }

    .modal-dialog:not(.modal-lg):not(.modal-xl) .modal-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 10;
        border-radius: 0;
        padding: 0.75rem 1rem;
    }

    .modal-dialog:not(.modal-lg):not(.modal-xl) .modal-footer .btn {
        flex: 1;
    }
}

/* ============================================================
   H. POLISH APP-LIKE
   ============================================================ */

@media (max-width: 768px) {
    /* Esconder hamburguer do topbar — bottom nav já tem o botão Menu */
    .topbar .sidebar-toggle {
        display: none !important;
    }

    /* Feedback tátil sutil */
    .mobile-bottom-nav a,
    .col-lg-9 .card .card-header {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.04);
    }

    /* Transição suave ao abrir sidebar (não sobrepor bottom nav) */
    .sidebar.active ~ .mobile-bottom-nav {
        opacity: 0.3;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    /* Alertas mais compactos no mobile */
    .container-fluid > .alert {
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
        margin-bottom: 0.5rem;
        border-radius: 8px;
    }

    .container-fluid > .alert .btn-close {
        padding: 0.625rem;
    }

    /* Currículo card: botões empilhados */
    .card-body > .d-flex.align-items-center.gap-3 {
        flex-wrap: wrap;
    }

    .card-body > .d-flex.align-items-center.gap-3 .btn {
        margin-left: 0 !important;
    }

    /* Tags input mais touch friendly */
    .tags-input-wrapper {
        min-height: 48px !important;
        padding: 0.5rem !important;
    }

    .tags-input-wrapper .tag-badge {
        font-size: 0.8rem;
        padding: 0.35rem 0.5rem;
    }

    /* Experiências: botão Adicionar mais visível */
    .card-header .btn-outline-primary.btn-sm {
        font-size: 0.75rem;
        min-height: 32px;
        z-index: 2;
        position: relative;
    }
}
