/* ===== MOBILE UNIVERSAL CSS ===== */
/* CSS universal para resolver problemas mobile em todas as páginas */

/* Reset e base mobile */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: linear-gradient(135deg, #FF0000 0%, #ff3333 100%);
    color: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(255, 0, 0, 0.3);
    z-index: 10000;
    animation: slideUp 0.5s ease-out;
}

.pwa-banner-content {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    gap: 15px;
}

.pwa-banner-content span {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.pwa-install-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.pwa-install-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.pwa-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.pwa-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Update Banner */
.update-banner {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.3);
    z-index: 10001;
    animation: slideDown 0.5s ease-out;
}

.update-banner-content {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    gap: 15px;
}

.update-banner-content span {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.update-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.update-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.update-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.update-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Offline Banner */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #ffc107 0%, #ff8f00 100%);
    color: #333;
    z-index: 10002;
    animation: slideDown 0.5s ease-out;
}

.offline-banner-content {
    padding: 12px 20px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Auto-hide header styles */
@media (max-width: 768px) {
    header, .header {
        transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out, background 0.3s ease;
    }

    header.hidden, .header.hidden {
        transform: translateY(-100%);
        opacity: 0.8;
    }

    header.visible, .header.visible {
        transform: translateY(0);
        opacity: 1;
    }

    header.scrolled, .header.scrolled {
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    }
}

/* Viewport height fix */
.full-height,
body,
html {
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
}

/* Input optimizations */
input,
textarea,
select {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
    -webkit-border-radius: 0;
}

/* Prevent zoom on iOS */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
        -webkit-border-radius: 8px;
    }

    /* Better touch targets */
    button,
    .btn,
    .login-btn,
    .register-btn,
    .tab,
    a,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }

    /* Improve scrolling */
    body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Container adjustments */
    .container,
    .login-container {
        width: 100%;
        max-width: 100%;
        padding-left: 15px;
        padding-right: 15px;
        box-sizing: border-box;
    }

    /* Modal adjustments */
    .modal,
    [id$="-modal"] {
        padding: 10px;
    }

    .modal > div,
    [id$="-modal"] > div {
        width: 95% !important;
        max-width: none !important;
        margin: 10px auto !important;
        max-height: 85vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Form improvements */
    .form-group {
        margin-bottom: 20px;
    }

    .form-group label {
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
    }

    /* Radio button groups */
    .radio-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    /* Tab improvements */
    .tab-group {
        display: flex;
        width: 100%;
        border-radius: 8px;
        overflow: hidden;
    }

    .tab {
        flex: 1;
        text-align: center;
        padding: 12px 8px;
        font-size: 14px;
        border: none;
        background: rgba(255, 0, 0, 0.1);
        color: #FF0000;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .tab.active {
        background: #FF0000;
        color: white;
    }

    /* Loading overlay */
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        z-index: 9999;
        background: linear-gradient(135deg, #FF0000 0%, #ff3333 100%);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Particles container */
    .particles {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        pointer-events: none;
        z-index: -1;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }

    input,
    textarea,
    select {
        background-clip: padding-box;
    }
}

/* Android specific fixes */
@media screen and (max-width: 768px) and (-webkit-min-device-pixel-ratio: 1) {
    input,
    textarea,
    select {
        background-color: white;
        background-clip: padding-box;
    }
}

/* High DPI screens */
@media screen and (max-width: 768px) and (min-resolution: 2dppx) {
    .login-container,
    .container {
        transform: translateZ(0);
        will-change: transform;
    }
}

/* Orientation changes */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .login-container {
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    body {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }
}

/* Performance optimizations */
.mobile-optimized * {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.mobile-optimized .animate-on-scroll,
.mobile-optimized .particle,
.mobile-optimized [class*="animation"] {
    will-change: transform, opacity;
}

/* Prevent text selection on mobile except inputs */
.mobile-optimized {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.mobile-optimized input,
.mobile-optimized textarea,
.mobile-optimized [contenteditable] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Touch feedback */
.mobile-optimized button:active,
.mobile-optimized .btn:active,
.mobile-optimized .tab:active,
.mobile-optimized a:active {
    transform: scale(0.98);
    opacity: 0.8;
}

/* Improve click delay */
.mobile-optimized a,
.mobile-optimized button,
.mobile-optimized input,
.mobile-optimized textarea,
.mobile-optimized select {
    touch-action: manipulation;
}

/* Safe area for devices with notches */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .login-container,
    .container {
        padding-left: max(15px, env(safe-area-inset-left) + 15px);
        padding-right: max(15px, env(safe-area-inset-right) + 15px);
    }
}

/* ===== UNIVERSAL HEADER MOBILE FIXES ===== */
/* Correção universal para problemas do menu superior mobile em todas as páginas */
@media (max-width: 768px) {
    /* Header container optimization */
    header, .header {
        padding: 0.5rem 0 !important;
        min-height: 60px;
    }

    .header-content {
        padding: 0 10px !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
    }

    /* Logo optimization */
    .logo {
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .logo img, .logo-icon {
        width: 35px !important;
        height: 35px !important;
    }

    .logo h1, .logo-text {
        display: none !important;
    }

    /* Nav links container optimization - VERSÃO SIMPLIFICADA */
    .nav-links {
        display: flex !important;
        gap: 8px !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
    }

    /* MOBILE SIMPLE: Ocultar elementos desnecessários */
    .user-info,
    .logout-btn,
    .mobile-menu-toggle,
    #demo-indicator {
        display: none !important;
    }

    /* Button optimization - APENAS FLASHCARD E VOLTAR */
    .nav-links .flashcard-btn,
    .nav-links .back-btn,
    .nav-links .btn-secondary {
        padding: 8px 16px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        margin: 0 4px !important;
        min-width: auto !important;
        flex-shrink: 0 !important;
        border-radius: 20px !important;
        font-weight: 600 !important;
    }

    /* Ordem dos botões */
    .flashcard-btn {
        order: 1 !important;
    }

    .back-btn, .btn-secondary {
        order: 2 !important;
    }

    /* Specific button type optimizations */
    .flashcard-btn {
        background: linear-gradient(135deg, #FF0000, #ff3333) !important;
        color: white !important;
    }

    .back-btn, .btn-secondary {
        background: linear-gradient(135deg, #6c757d, #495057) !important;
        color: white !important;
    }

    /* Title hide for mobile */
    .page-title h1,
    .site-title,
    .brand-text {
        display: none !important;
    }

    /* Ensure header stays compact */
    .container {
        max-width: 100% !important;
    }
}
