/**
 * PWA Animations & Styles - IntGest Transparência PNTP
 * 
 * Estilos específicos para funcionalidades PWA:
 * - Animações de loading
 * - Indicadores de status
 * - Transições suaves
 * - Estados offline
 * 
 * @version 2.0.0
 */

/* ========================================
   ANIMAÇÕES BASE
   ======================================== */

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes ping {
    75%, 100% {
        transform: scale(2);
        opacity: 0;
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(-5%);
        animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
    }
    50% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
    }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

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

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

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes progress {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

@keyframes scan {
    0%, 100% { top: 0; }
    50% { top: calc(100% - 2px); }
}

/* ========================================
   CLASSES DE ANIMAÇÃO
   ======================================== */

.animate-spin {
    animation: spin 1s linear infinite;
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-ping {
    animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.animate-bounce {
    animation: bounce 1s infinite;
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

.animate-shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

.animate-slide-in {
    animation: slideIn 0.3s ease-out forwards;
}

.animate-slide-out {
    animation: slideOut 0.3s ease-in forwards;
}

.animate-slide-up {
    animation: slideUp 0.3s ease-out forwards;
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

.animate-fade-out {
    animation: fadeOut 0.3s ease-in forwards;
}

.animate-scale-in {
    animation: scaleIn 0.2s ease-out forwards;
}

.animate-scan {
    animation: scan 2s ease-in-out infinite;
}

/* ========================================
   ESTADOS DE LOADING
   ======================================== */

.pwa-loading {
    position: relative;
    pointer-events: none;
}

.pwa-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.pwa-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #e2e8f0;
    border-top-color: #1e40af;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 11;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-title {
    height: 1.5em;
    width: 60%;
    margin-bottom: 1em;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-card {
    height: 120px;
    border-radius: 12px;
}

/* ========================================
   INDICADORES DE STATUS PWA
   ======================================== */

/* Indicador de conexão */
.connectivity-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.connectivity-indicator.online {
    background: #dcfce7;
    color: #166534;
}

.connectivity-indicator.offline {
    background: #fef2f2;
    color: #991b1b;
}

.connectivity-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background 0.3s;
}

.connectivity-indicator.online::before {
    background: #22c55e;
}

.connectivity-indicator.offline::before {
    background: #ef4444;
    animation: pulse 1.5s infinite;
}

/* Banner offline */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(90deg, #fbbf24, #f59e0b);
    color: #78350f;
    padding: 8px 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-banner.visible,
body.pwa-offline .offline-banner {
    transform: translateY(0);
}

/* Indicador de sincronização */
.sync-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    font-size: 13px;
    color: #1e40af;
}

.sync-indicator.syncing .sync-icon {
    animation: spin 1s linear infinite;
}

.sync-indicator.synced {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

.sync-indicator.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

/* ========================================
   TOASTS E NOTIFICAÇÕES
   ======================================== */

.toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease-out;
}

.toast.exiting {
    animation: slideOut 0.3s ease-in forwards;
}

.toast-success {
    background: #22c55e;
    color: white;
}

.toast-error {
    background: #ef4444;
    color: white;
}

.toast-warning {
    background: #f59e0b;
    color: white;
}

.toast-info {
    background: #3b82f6;
    color: white;
}

/* ========================================
   BOTÕES PWA
   ======================================== */

.pwa-install-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    color: white;
    border: none;
    border-radius: 9999px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(30, 64, 175, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
    animation: bounce 2s infinite;
}

.pwa-install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(30, 64, 175, 0.5);
}

.pwa-install-btn.hidden {
    display: none;
}

/* Botão de atualização */
.pwa-update-btn {
    padding: 8px 16px;
    background: white;
    color: #1e40af;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pwa-update-btn:hover {
    background: #eff6ff;
}

/* ========================================
   ESTADOS OFFLINE
   ======================================== */

body.pwa-offline {
    /* Indicação visual global quando offline */
    --offline-overlay: rgba(250, 250, 250, 0.95);
}

body.pwa-offline .requires-online {
    opacity: 0.5;
    pointer-events: none;
    position: relative;
}

body.pwa-offline .requires-online::after {
    content: 'Indisponível offline';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    color: #64748b;
    border-radius: inherit;
}

.offline-available {
    position: relative;
}

.offline-available::after {
    content: '✓ Offline';
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 2px 6px;
    background: #22c55e;
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
}

/* Data from cache indicator */
.from-cache {
    border-left: 3px solid #f59e0b;
}

.from-cache::before {
    content: '📦 Dados em cache';
    display: block;
    padding: 4px 8px;
    background: #fef3c7;
    color: #92400e;
    font-size: 11px;
    margin-bottom: 8px;
    border-radius: 4px;
}

/* ========================================
   MODAIS E OVERLAYS PWA
   ======================================== */

.pwa-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 9999;
    animation: fadeIn 0.2s ease-out;
}

.pwa-modal {
    background: white;
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: scaleIn 0.3s ease-out;
}

.pwa-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pwa-modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: 60vh;
}

.pwa-modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ========================================
   CHECKLIST OFFLINE STYLES
   ======================================== */

.checklist-item {
    transition: all 0.2s ease;
}

.checklist-item[data-synced="false"] {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
}

.checklist-item[data-synced="true"] {
    border-left: 3px solid #22c55e;
}

.checklist-status-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
}

.checklist-status-btn:hover {
    border-color: #1e40af;
}

.checklist-status-btn.selected {
    border-color: transparent;
}

.checklist-status-btn.selected[data-status="yes"] {
    background: #22c55e;
    color: white;
}

.checklist-status-btn.selected[data-status="no"] {
    background: #ef4444;
    color: white;
}

.checklist-status-btn.selected[data-status="partial"] {
    background: #f59e0b;
    color: white;
}

.checklist-status-btn.selected[data-status="na"] {
    background: #64748b;
    color: white;
}

/* ========================================
   CAMERA & SCANNER UI
   ======================================== */

.camera-overlay {
    position: fixed;
    inset: 0;
    background: black;
    z-index: 9999;
}

.camera-viewfinder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 280px;
    height: 280px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 16px;
}

.camera-viewfinder::before,
.camera-viewfinder::after,
.camera-viewfinder .corner-tl,
.camera-viewfinder .corner-tr,
.camera-viewfinder .corner-bl,
.camera-viewfinder .corner-br {
    content: '';
    position: absolute;
    width: 32px;
    height: 32px;
    border-color: #3b82f6;
    border-style: solid;
    border-width: 0;
}

.camera-viewfinder .corner-tl {
    top: -2px;
    left: -2px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-top-left-radius: 16px;
}

.camera-viewfinder .corner-tr {
    top: -2px;
    right: -2px;
    border-top-width: 4px;
    border-right-width: 4px;
    border-top-right-radius: 16px;
}

.camera-viewfinder .corner-bl {
    bottom: -2px;
    left: -2px;
    border-bottom-width: 4px;
    border-left-width: 4px;
    border-bottom-left-radius: 16px;
}

.camera-viewfinder .corner-br {
    bottom: -2px;
    right: -2px;
    border-bottom-width: 4px;
    border-right-width: 4px;
    border-bottom-right-radius: 16px;
}

.scanner-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, #ef4444, transparent);
    animation: scan 2s ease-in-out infinite;
}

/* ========================================
   SEAL SIMULATOR GAMIFICATION
   ======================================== */

.seal-badge {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    border: 2px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
}

.seal-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.seal-name {
    font-size: 24px;
    font-weight: 700;
}

.seal-score {
    font-size: 36px;
    font-family: monospace;
    font-weight: 700;
}

.seal-diamond { color: #60a5fa; }
.seal-gold { color: #fbbf24; }
.seal-silver { color: #9ca3af; }
.seal-bronze { color: #cd7f32; }

.seal-upgrade-indicator {
    position: absolute;
    top: -8px;
    right: -8px;
    padding: 4px 8px;
    background: #22c55e;
    color: white;
    font-size: 11px;
    font-weight: 700;
    border-radius: 9999px;
    animation: bounce 1s infinite;
}

/* Progress bar with markers */
.seal-progress {
    position: relative;
    height: 16px;
    background: #e2e8f0;
    border-radius: 9999px;
    overflow: visible;
}

.seal-progress-fill {
    height: 100%;
    border-radius: 9999px;
    background: linear-gradient(90deg, #ef4444, #f59e0b, #22c55e);
    transition: width 0.5s ease;
}

.seal-progress-potential {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(34, 197, 94, 0.3);
    border-radius: 9999px;
    animation: pulse 2s infinite;
}

.seal-marker {
    position: absolute;
    top: -4px;
    width: 2px;
    height: 24px;
    background: rgba(0,0,0,0.2);
}

/* ========================================
   RESPONSIVE PWA ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    .toast-container {
        left: 16px;
        right: 16px;
        max-width: none;
    }
    
    .pwa-install-btn {
        left: 16px;
        right: 16px;
        justify-content: center;
    }
    
    .pwa-modal {
        margin: 16px;
        max-height: calc(100vh - 32px);
    }
}

/* Standalone mode adjustments */
@media (display-mode: standalone) {
    body {
        /* Ajustes para modo instalado */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .pwa-install-btn {
        display: none !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    }
    
    .pwa-modal {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .pwa-modal-header,
    .pwa-modal-footer {
        border-color: #374151;
    }
}
