/* ============================================
   MOBILE RESPONSIVE 
   Mobile-first approach with progressive enhancement
   ============================================ */

/* ============================================
   VARIÁVEIS MOBILE
   ============================================ */
:root {
    --mobile-header-height: 60px;
    --mobile-bottom-nav-height: 70px;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================
   BREAKPOINT: Tablets (768px - 1023px)
   ============================================ */
@media (max-width: 1023px) {
    .app-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .preview-container {
        position: relative;
        top: 0;
    }

    .preview-paper {
        min-height: 600px;
        padding: 40px;
    }
}

/* ============================================
   BREAKPOINT: Mobile (< 768px)
   ============================================ */
@media (max-width: 767px) {

    /* Container */
    .container {
        padding: 0;
        max-width: 100%;
    }

    /* Header compacto */
    .app-header {
        padding: 15px;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 50;
        box-shadow: var(--shadow-sm);
    }

    .app-title {
        font-size: 1.5rem;
    }

    .app-subtitle {
        font-size: 0.9rem;
        display: none;
        /* Oculto no mobile, mostra apenas no desktop */
    }

    .app-header.has-mobile-tabs .app-subtitle {
        display: none;
    }

    /* Layout mobile: uma coluna */
    .app-layout {
        grid-template-columns: 1fr;
        gap: 0;
        margin-top: 0;
    }

    /* Editor mobile */
    .editor {
        border-radius: 0;
        box-shadow: none;
        padding: 20px 15px;
        min-height: calc(100vh - var(--mobile-header-height) - var(--mobile-bottom-nav-height));
    }

    .editor.hidden-mobile {
        display: none;
    }

    /* Preview mobile */
    .preview-container {
        position: fixed;
        top: var(--mobile-header-height);
        left: 0;
        right: 0;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--safe-area-inset-bottom));
        z-index: 50;
        display: none;
        background: var(--bg);
    }

    .preview-container.active-mobile {
        display: block;
        z-index: 60;
    }

    .preview-container.active-mobile .preview-header {
        position: sticky;
        top: 0;
        z-index: 61;
        background: var(--card);
    }

    .preview-container.fullscreen-mobile {
        bottom: 0;
        z-index: 200;
    }

    .preview-header {
        flex-wrap: wrap;
        padding: 12px;
        gap: 5px;
        position: sticky;
        top: 0;
    }

    .preview-label {
        font-size: 0.9rem;
        width: 100%;
        /* Quebra linha se necessário */
        margin-bottom: 5px;
    }

    .preview-actions {
        width: 100%;
        justify-content: space-between;
    }

    .preview-paper {
        border-radius: 0;
        min-height: calc(100vh - var(--mobile-header-height) - 60px);
        padding: 30px 20px;
        overflow-y: auto;
    }

    /* Navegação inferior (Tabs) */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--mobile-bottom-nav-height) + var(--safe-area-inset-bottom));
        background: var(--card);
        border-top: 1px solid var(--border);
        z-index: 100;
        padding-bottom: var(--safe-area-inset-bottom);
    }

    .mobile-nav.hidden {
        display: none;
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        background: none;
        border: none;
        color: var(--text-light);
        font-size: 0.75rem;
        font-weight: 500;
        cursor: pointer;
        transition: var(--transition);
        padding: 8px;
    }

    .mobile-nav-item.active {
        color: var(--primary);
    }

    .mobile-nav-item svg {
        width: 24px;
        height: 24px;
    }

    /* Botão fullscreen */
    .btn-fullscreen {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    /* Formulário mobile otimizado */
    .form-group {
        margin-bottom: 24px;
    }

    label {
        font-size: 0.95rem;
        margin-bottom: 10px;
        font-weight: 600;
    }

    input,
    textarea,
    select {
        padding: 14px 16px;
        font-size: 16px;
        /* Previne zoom no iOS */
        border-radius: var(--radius);
        min-height: 48px;
        /* Touch target mínimo */
    }

    textarea {
        min-height: 120px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    /* Botões maiores para touch */
    .btn {
        padding: 16px 24px;
        min-height: 48px;
        font-size: 1rem;
    }

    .btn-sm {
        flex: 1;
        min-height: 44px;
        /* Touch target adequado */
        font-size: 0.85rem;
    }

    /* Lista dinâmica mobile */
    .list-item {
        padding: 20px 15px;
        margin-bottom: 15px;
    }

    .remove-btn {
        width: 36px;
        height: 36px;
        font-size: 1.5rem;
    }

    /* Painel de personalização mobile */
    .customization-panel {
        margin: -20px -15px 20px -15px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding: 20px 15px;
    }

    /* Toast mobile */
    .toast {
        left: 15px;
        right: 15px;
        bottom: calc(var(--mobile-bottom-nav-height) + 15px);
        text-align: center;
    }

    /* CV em mobile: ajustes de legibilidade */
    .theme-minimal .cv-name,
    .theme-modern .cv-name,
    .theme-creative .cv-name {
        font-size: 1.8rem;
    }

    .cv-header {
        padding: 20px 0;
    }

    .cv-contact {
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }

    .cv-paper {
        padding: 30px 20px;
    }

    :root {
        --mobile-header-height: 65px;
    }

    /* Esconde texto "Fullscreen" no mobile pequeno, mostra só ícone */
    @media (max-width: 380px) {
        .btn-fullscreen span {
            display: none;
        }
    }
}

/* ============================================
   BREAKPOINT: Mobile pequeno (< 375px)
   ============================================ */
@media (max-width: 374px) {
    .app-title {
        font-size: 1.3rem;
    }

    .section-title {
        font-size: 1rem;
    }

    .cv-name {
        font-size: 1.5rem !important;
    }
}

/* ============================================
   ORIENTAÇÃO: Landscape mobile
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
    .mobile-nav {
        display: none;
    }

    .app-layout {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
        padding: 15px;
    }

    .editor,
    .preview-container {
        position: relative;
        top: 0;
        bottom: auto;
        display: block !important;
        height: calc(100vh - var(--mobile-header-height) - 30px);
        overflow-y: auto;
    }

    .preview-paper {
        min-height: auto;
    }
}

/* ============================================
   DESKTOP: Esconde elementos mobile
   ============================================ */
@media (min-width: 768px) {
    .mobile-nav {
        display: none;
    }

    .btn-fullscreen {
        display: none;
    }

    .app-subtitle {
        display: block;
    }
}

/* ============================================
   UTILITÁRIOS MOBILE
   ============================================ */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Animação de transição entre abas */
.tab-transition {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Touch feedback */
@media (hover: none) and (pointer: coarse) {
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .mobile-nav-item:active {
        background: var(--bg);
    }
}