/* ============================================
   MOBILE OPTIMIZATION - Fokuz App
   Centralização e correção de sobreposições
   ============================================ */

/* Força textos e títulos pretos no modo claro */
:root:not([data-theme="dark"]) h1,
:root:not([data-theme="dark"]) h2,
:root:not([data-theme="dark"]) h3,
:root:not([data-theme="dark"]) h4,
:root:not([data-theme="dark"]) h5,
:root:not([data-theme="dark"]) h6,
:root:not([data-theme="dark"]) p,
:root:not([data-theme="dark"]) span:not(.premium-badge):not(.premium-badge-small),
:root:not([data-theme="dark"]) label {
    color: #000000 !important;
}

/* Garantir que todas as páginas usem box-sizing correto */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Prevenir scroll horizontal em todas as telas */
html,
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* ============================================
   MOBILE GERAL - Tablets e dispositivos pequenos
   ============================================ */
@media (max-width: 768px) {
    /* Navegação mobile */
    nav ul {
        padding: 1rem !important;
        gap: 0.5rem !important;
        justify-content: center !important;
    }

    nav li {
        flex: 0 1 auto;
        min-width: 0;
    }

    nav a {
        padding: 0.6rem 1rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap;
    }

    /* Headers centralizados */
    header {
        text-align: center;
        padding: 1.5rem 1rem !important;
        margin: 1rem auto !important;
        max-width: 100%;
    }

    header h1 {
        font-size: 1.8rem !important;
        word-wrap: break-word;
    }

    header p {
        font-size: 1rem !important;
    }

    /* Containers principais */
    main,
    section,
    .container {
        padding: 1rem !important;
        margin: 1rem auto !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Cards e conteúdo */
    .card,
    .profile-card,
    .plan-card,
    .premium-container,
    .profile-container {
        margin: 1rem 0.5rem !important;
        padding: 1.5rem 1rem !important;
        max-width: 100% !important;
    }

    /* Botões responsivos */
    button,
    .btn,
    .btn-primary,
    .btn-subscribe {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1rem !important;
        font-size: 1rem !important;
        margin: 0.5rem 0 !important;
    }

    /* Inputs e forms */
    input,
    textarea,
    select {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px !important; /* Prevenir zoom no iOS */
    }

    /* Tabelas responsivas */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Imagens responsivas */
    img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Modals centralizados */
    .modal,
    .payment-modal {
        padding: 1rem !important;
    }

    .modal-content,
    .payment-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 1.5rem 1rem !important;
        margin: auto !important;
    }

    /* Grids para mobile */
    .grid,
    .plans-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
}

/* ============================================
   MOBILE EXTRA SMALL - Smartphones
   ============================================ */
@media (max-width: 480px) {
    /* Navegação compacta */
    nav ul {
        padding: 0.75rem 0.5rem !important;
        gap: 0.35rem !important;
    }

    nav a {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.75rem !important;
    }

    /* Headers menores */
    header h1 {
        font-size: 1.5rem !important;
    }

    header p {
        font-size: 0.9rem !important;
    }

    /* Containers ultra compactos */
    main,
    section,
    .container {
        padding: 0.75rem !important;
        margin: 0.5rem auto !important;
    }

    /* Cards compactos */
    .card,
    .profile-card,
    .plan-card {
        padding: 1rem 0.75rem !important;
        margin: 0.75rem 0.25rem !important;
    }

    /* Textos menores */
    body {
        font-size: 0.9rem !important;
    }

    h2 {
        font-size: 1.3rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    /* Botões compactos */
    button,
    .btn {
        padding: 0.85rem !important;
        font-size: 0.9rem !important;
    }

    /* Badge premium móvel - movido para o rodapé */
    #premiumBadge {
        position: fixed !important;
        bottom: 20px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: auto !important;
        right: auto !important;
        font-size: 0.75rem !important;
        padding: 0.5rem 1rem !important;
        border-radius: 20px !important;
        box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4) !important;
        min-width: auto !important;
        height: auto !important;
        line-height: 1.2 !important;
        z-index: 9999 !important;
    }
}

/* ============================================
   CORREÇÃO DE SOBREPOSIÇÕES ESPECÍFICAS
   ============================================ */

/* Prevenir overflow em cards */
@media (max-width: 768px) {
    /* Flashcards */
    .flashcards-container,
    .deck-list {
        padding: 0.5rem !important;
    }

    .study-card {
        width: 95% !important;
        max-width: 95% !important;
        margin: 1rem auto !important;
    }

    /* Notebook */
    .notebook-container {
        flex-direction: column !important;
    }

    .sidebar,
    .notes-list {
        width: 100% !important;
        max-width: 100% !important;
        border-right: none !important;
        border-bottom: 2px solid var(--border-color) !important;
    }

    .editor-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Task Manager */
    .task-input-group {
        flex-direction: column !important;
    }

    .task-input-group input,
    .task-input-group button {
        width: 100% !important;
        margin: 0.25rem 0 !important;
    }

    /* Pomodoro */
    .timer-display {
        font-size: 3rem !important;
    }

    .pomodoro-controls {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }

    /* Calendar */
    .calendar-grid {
        font-size: 0.8rem !important;
    }

    .calendar-day {
        min-height: 60px !important;
        padding: 0.25rem !important;
    }

    /* Profile */
    .profile-header {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }

    .profile-avatar {
        margin-bottom: 1rem !important;
    }

    .profile-info {
        width: 100% !important;
    }

    .profile-info h2 {
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.5rem !important;
    }
}

/* ============================================
   LANDSCAPE MODE (Mobile deitado)
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    nav ul {
        padding: 0.5rem 1rem !important;
    }

    nav a {
        padding: 0.4rem 0.8rem !important;
        font-size: 0.8rem !important;
    }

    header {
        padding: 1rem !important;
        margin: 0.5rem auto !important;
    }

    header h1 {
        font-size: 1.5rem !important;
    }

    main {
        padding: 0.5rem !important;
    }
}

/* ============================================
   FIX ESPECÍFICOS POR DISPOSITIVO
   ============================================ */

/* iPhone SE e similares */
@media (max-width: 375px) {
    nav a {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.7rem !important;
    }

    .plan-price {
        font-size: 2rem !important;
    }

    .payment-content {
        padding: 1rem 0.5rem !important;
    }

    .qr-code img {
        max-width: 200px !important;
    }
}

/* Garantir que footer não sobreponha conteúdo */
@media (max-width: 768px) {
    footer {
        position: relative !important;
        margin-top: 3rem !important;
        padding: 1.5rem 1rem !important;
    }

    footer > div {
        flex-direction: column !important;
        gap: 1rem !important;
    }
}

/* ============================================
   TOUCH TARGETS (Áreas tocáveis mínimas)
   ============================================ */
@media (max-width: 768px) {
    /* Mínimo 44x44px para touch (recomendação Apple/Google) */
    button,
    a,
    input[type="checkbox"],
    input[type="radio"],
    .clickable {
        min-height: 44px !important;
        min-width: 44px !important;
    }

    /* Aumentar espaçamento entre elementos clicáveis */
    nav li {
        margin: 0.25rem !important;
    }
}

/* ============================================
   PREVENÇÃO DE ZOOM INDESEJADO (iOS)
   ============================================ */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* Prevenir zoom automático no iOS */
    }
}

/* ============================================
   CENTRALIZAÇÃO FORÇADA
   ============================================ */
@media (max-width: 768px) {
    body {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    body > * {
        width: 100%;
        max-width: 100vw;
    }

    /* Centralizar texto em elementos principais */
    .premium-container,
    .profile-container,
    .auth-container {
        text-align: center;
    }

    .premium-container h1,
    .profile-container h1 {
        text-align: center !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    .plans-grid,
    .profile-card {
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* ============================================
   AJUSTES ESPECÍFICOS PARA EVITAR SOBREPOSIÇÃO
   ============================================ */
@media (max-width: 768px) {
    /* Ocultar botões de toggle no mobile */
    .theme-toggle,
    .focus-mode-toggle {
        display: none !important;
    }
    
    #premiumBadge {
        position: fixed !important;
        bottom: 20px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: auto !important;
        right: auto !important;
        font-size: 0.8rem !important;
        padding: 0.6rem 1.2rem !important;
        border-radius: 25px !important;
        box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4) !important;
        z-index: 9999 !important;
    }
    
    /* Ajustar navegação para não conflitar */
    nav {
        margin-top: 0 !important;
        padding-top: 1rem !important;
    }
    
    /* Dar espaço para os botões laterais */
    body {
        padding-left: 0 !important;
    }
    
    main,
    header,
    section {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

@media (max-width: 375px) {
    #premiumBadge {
        bottom: 15px !important;
        font-size: 0.7rem !important;
        padding: 0.45rem 0.9rem !important;
        border-radius: 18px !important;
    }
}
