/**
 * Zeta Finances - PWA Styles
 * Estilos específicos para melhorar a experiência como PWA
 * Compatível com Android e iOS
 */

/* === Safe Area para dispositivos com notch (iOS) === */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
}

/* Quando rodando como PWA standalone */
@media (display-mode: standalone) {
    body {
        padding-top: var(--safe-area-top);
        padding-bottom: var(--safe-area-bottom);
        padding-left: var(--safe-area-left);
        padding-right: var(--safe-area-right);
    }
    
    /* Remove a barra de URL (já não existe no PWA) */
    header {
        padding-top: calc(1rem + var(--safe-area-top));
    }
    
    /* Ajusta footer para safe area */
    footer {
        padding-bottom: calc(1.5rem + var(--safe-area-bottom));
    }
}

/* === Previne zoom indesejado no iOS === */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="date"],
select,
textarea {
    font-size: 16px !important; /* iOS não dá zoom se for >= 16px */
}

/* === Touch feedback === */
button,
a,
.clickable {
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
    tap-highlight-color: rgba(59, 130, 246, 0.2);
}

/* === Scroll suave em iOS === */
* {
    -webkit-overflow-scrolling: touch;
}

/* === Pull to refresh customizado (opcional) === */
body {
    overscroll-behavior-y: contain;
}

/* === Splash screen enquanto carrega === */
.pwa-splash {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeOut 0.5s ease-out 1s forwards;
}

.pwa-splash img {
    width: 120px;
    height: 120px;
    margin-bottom: 20px;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        pointer-events: none;
    }
}

/* === Badge de instalação === */
#pwa-install-banner {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* === Status bar iOS (quando standalone) === */
@supports (-webkit-touch-callout: none) {
    /* Específico para iOS */
    @media (display-mode: standalone) {
        body {
            padding-top: calc(20px + var(--safe-area-top)); /* Status bar height */
        }
    }
}

/* === Orientação landscape === */
@media (orientation: landscape) and (max-height: 500px) {
    /* Reduz padding em landscape para aproveitar espaço */
    .container {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
}

/* === Previne seleção de texto em botões === */
button,
.btn,
a.button {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* === Performance: Hardware acceleration === */
.card,
.modal,
.dropdown,
.sidebar {
    transform: translateZ(0);
    will-change: transform;
}

/* === Loading indicator para PWA === */
.pwa-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9998;
}

.pwa-loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Offline indicator === */
.pwa-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f59e0b;
    color: white;
    padding: 0.75rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 9997;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

/* === iOS bounce effect fix === */
/* REMOVIDO: Estava bloqueando scroll na página principal */
/* Aplicar apenas em PWA standalone se necessário */
@media (display-mode: standalone) {
    html, body {
        /* Permite scroll normal */
        overflow: auto;
        width: 100%;
        height: 100%;
    }
}

/* === Add to home screen hint (iOS) === */
.ios-install-hint {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 1rem;
    box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
    z-index: 9996;
    animation: slideUp 0.3s ease-out;
}

.ios-install-hint.dark {
    background: #1f2937;
    color: white;
}

/* === Responsivo para tablets === */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Ajustes específicos para tablets em modo PWA */
    .sidebar {
        width: 250px;
    }
    
    .container {
        max-width: 100%;
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

/* === Android Chrome: Remove highlight === */
* {
    -webkit-tap-highlight-color: transparent;
}

/* === Print styles (quando usuário tenta imprimir) === */
@media print {
    #pwa-install-banner,
    .pwa-offline-banner,
    .ios-install-hint,
    .sidebar,
    nav,
    footer {
        display: none !important;
    }
}
