/* Jasiri PWA Enhancements */

/* === PWA STANDALONE MODE STYLES === */
@media (display-mode: standalone) {
    /* Remove any browser-specific styling when in PWA mode */
    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Allow text selection in specific areas */
    input, textarea, [contenteditable] {
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
    
    /* Enhanced navigation for PWA */
    .navbar {
        padding-top: calc(1rem + env(safe-area-inset-top));
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }
    
    /* Full-height content in PWA */
    .main-content {
        min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* PWA-specific button styles */
    .btn-pwa {
        background: #54e6b6;
        color: #000;
        border: none;
        padding: 12px 24px;
        border-radius: 12px;
        font-weight: 600;
        font-size: 16px;
        cursor: pointer;
        transition: all 0.2s ease;
        box-shadow: 0 4px 12px rgba(84, 230, 182, 0.3);
    }
    
    .btn-pwa:active {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(84, 230, 182, 0.4);
    }
}

/* === PWA WINDOW CONTROLS OVERLAY === */
@media (display-mode: window-controls-overlay) {
    .navbar {
        app-region: drag;
        padding-left: env(titlebar-area-x, 0);
        padding-top: env(titlebar-area-y, 0);
        padding-right: calc(100vw - env(titlebar-area-x, 0) - env(titlebar-area-width, 100vw));
        padding-bottom: calc(env(titlebar-area-height, 33px) - env(titlebar-area-y, 0));
    }
    
    .navbar * {
        app-region: no-drag;
    }
}

/* === PULL-TO-REFRESH ENHANCEMENT === */
.pull-to-refresh-container {
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

.pull-to-refresh-indicator {
    position: absolute;
    top: -80px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    background: #54e6b6;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    font-size: 24px;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    opacity: 0;
    z-index: 1000;
}

.pull-to-refresh-container.pulling .pull-to-refresh-indicator {
    opacity: 1;
    top: 20px;
}

.pull-to-refresh-container.refreshing .pull-to-refresh-indicator {
    animation: spin 1s linear infinite;
}

/* === PWA INSTALLATION STYLES === */
.pwa-install-banner {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    animation: slideUpBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border: 1px solid #e5e7eb;
    max-width: 400px;
    margin: 0 auto;
}

/* Floating Install Button */
.pwa-install-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #54e6b6 0%, #45d9a8 100%);
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 16px rgba(84, 230, 182, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: pulseInstall 2s infinite;
    transition: all 0.3s ease;
}

.pwa-install-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(84, 230, 182, 0.5);
}

.pwa-install-fab:active {
    transform: scale(0.95);
}

.pwa-install-fab svg {
    width: 24px;
    height: 24px;
    color: #000;
}

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

@keyframes slideUpBounce {
    0% {
        transform: translateY(100%) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translateY(-10%) scale(1.05);
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.pwa-install-content {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 12px;
}

.pwa-install-icon img {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pwa-install-text {
    flex: 1;
}

.pwa-install-title {
    font-weight: 600;
    color: #111827;
    font-size: 14px;
    margin-bottom: 2px;
}

.pwa-install-subtitle {
    color: #6b7280;
    font-size: 12px;
}

.pwa-install-btn {
    background: linear-gradient(135deg, #54e6b6 0%, #45d9a8 100%);
    color: #000;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(84, 230, 182, 0.3);
}

.pwa-install-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(84, 230, 182, 0.4);
}

.pwa-install-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(84, 230, 182, 0.3);
}

.pwa-install-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    margin-left: 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.pwa-install-close:hover {
    background: #f3f4f6;
    color: #6b7280;
}

/* === OFFLINE INDICATOR === */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    text-align: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10001;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.show {
    transform: translateY(0);
}

.offline-indicator::before {
    content: "📡";
    margin-right: 8px;
}

/* === PWA NAVIGATION ENHANCEMENTS === */
@media (display-mode: standalone) {
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(229, 231, 235, 0.8);
        padding: calc(8px + env(safe-area-inset-bottom)) 0 env(safe-area-inset-bottom);
        z-index: 1000;
    }
    
    .bottom-nav-items {
        display: flex;
        justify-content: space-around;
        align-items: center;
        max-width: 500px;
        margin: 0 auto;
        padding: 0 16px;
    }
    
    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 12px;
        color: #6b7280;
        text-decoration: none;
        font-size: 12px;
        font-weight: 500;
        transition: all 0.2s ease;
        border-radius: 12px;
        min-width: 60px;
    }
    
    .bottom-nav-item:hover,
    .bottom-nav-item.active {
        color: #54e6b6;
        background: rgba(84, 230, 182, 0.1);
    }
    
    .bottom-nav-item svg {
        width: 24px;
        height: 24px;
        margin-bottom: 4px;
        transition: transform 0.2s ease;
    }
    
    .bottom-nav-item:active svg {
        transform: scale(0.9);
    }
    
    /* Adjust main content for bottom nav */
    .main-content {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
}

/* === HAPTIC FEEDBACK SIMULATION === */
@media (display-mode: standalone) {
    .haptic-light:active {
        animation: hapticLight 0.1s ease;
    }
    
    .haptic-medium:active {
        animation: hapticMedium 0.15s ease;
    }
    
    .haptic-heavy:active {
        animation: hapticHeavy 0.2s ease;
    }
    
    @keyframes hapticLight {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(0.98); }
    }
    
    @keyframes hapticMedium {
        0%, 100% { transform: scale(1); }
        25% { transform: scale(0.95); }
        75% { transform: scale(1.02); }
    }
    
    @keyframes hapticHeavy {
        0%, 100% { transform: scale(1); }
        20% { transform: scale(0.92); }
        40% { transform: scale(1.05); }
        60% { transform: scale(0.98); }
        80% { transform: scale(1.02); }
    }
}

/* === RESPONSIVE PWA OPTIMIZATIONS === */
@media (max-width: 640px) and (display-mode: standalone) {
    .pwa-install-banner {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }
    
    .container {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* === DARK MODE PWA ENHANCEMENTS === */
@media (prefers-color-scheme: dark) and (display-mode: standalone) {
    .navbar {
        background: rgba(17, 24, 39, 0.95);
        border-bottom-color: rgba(55, 65, 81, 0.8);
    }
    
    .bottom-nav {
        background: rgba(17, 24, 39, 0.95);
        border-top-color: rgba(55, 65, 81, 0.8);
    }
    
    .pwa-install-banner {
        background: #1f2937;
        border-color: #374151;
    }
    
    .pwa-install-title {
        color: #f9fafb;
    }
    
    .pwa-install-subtitle {
        color: #9ca3af;
    }
}

/* === ACCESSIBILITY ENHANCEMENTS === */
@media (prefers-reduced-motion: reduce) {
    .pwa-install-banner {
        animation: none;
    }
    
    .pull-to-refresh-indicator {
        transition: none;
    }
    
    .haptic-light, .haptic-medium, .haptic-heavy {
        animation: none !important;
    }
}

@media (prefers-contrast: high) {
    .pwa-install-btn {
        border: 2px solid #000;
    }
    
    .bottom-nav-item.active {
        border: 2px solid #54e6b6;
    }
}
