/* PWA-Specific Styles */

/* Detect when running as installed PWA (standalone mode) */
@media (display-mode: standalone) {
    body {
        /* Add extra padding at top for better mobile experience */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Hide any "install app" prompts when already installed */
    .pwa-install-prompt {
        display: none !important;
    }

    /* Adjust header for PWA mode */
    .navbar {
        position: sticky;
        top: env(safe-area-inset-top);
        z-index: 1000;
    }
}

/* Enhanced mobile experience for PWA */
@media (display-mode: standalone) and (max-width: 768px) {
    /* Make buttons more touch-friendly */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }

    /* Improve tap targets */
    a, button, input, select, textarea {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Better card spacing on mobile */
    .card {
        margin-bottom: 16px;
    }

    /* Optimize form inputs for touch */
    input, select, textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
    }

    /* Full-width tables on mobile */
    .table-responsive {
        border-radius: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* PWA splash screen colors (iOS) */
@media (prefers-color-scheme: dark) {
    :root {
        --pwa-theme-color: #1a1a1a;
    }
}

@media (prefers-color-scheme: light) {
    :root {
        --pwa-theme-color: #ffffff;
    }
}

/* Install prompt styling */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1050;
    animation: slideUp 0.3s ease-out;
}

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

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

.pwa-install-icon {
    font-size: 32px;
}

.pwa-install-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.pwa-install-text p {
    margin: 0;
    font-size: 14px;
    opacity: 0.9;
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
}

.pwa-install-btn {
    background: white;
    color: #667eea;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pwa-install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.pwa-dismiss-btn {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pwa-dismiss-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Mobile-optimized navigation for PWA */
@media (display-mode: standalone) and (max-width: 576px) {
    /* Bottom navigation bar for better mobile UX */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bs-body-bg);
        border-top: 1px solid var(--bs-border-color);
        display: flex;
        justify-content: space-around;
        padding: 8px 0;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        z-index: 1000;
    }

    .mobile-bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: var(--bs-body-color);
        padding: 8px 16px;
        border-radius: 8px;
        transition: all 0.2s ease;
        min-width: 64px;
    }

    .mobile-bottom-nav-item:hover,
    .mobile-bottom-nav-item.active {
        background: var(--bs-primary);
        color: white;
    }

    .mobile-bottom-nav-item i {
        font-size: 20px;
        margin-bottom: 4px;
    }

    .mobile-bottom-nav-item span {
        font-size: 11px;
        font-weight: 500;
    }

    /* Add padding to content to avoid overlap with bottom nav */
    .container, .container-fluid {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
}

/* Pull-to-refresh indicator */
.pwa-refresh-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: var(--bs-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
    z-index: 2000;
}

.pwa-refresh-indicator.show {
    transform: translateX(-50%) translateY(0);
}

/* Offline indicator */
.pwa-offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #dc3545;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 14px;
    z-index: 2000;
    animation: slideDown 0.3s ease-out;
}

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

/* Better scrolling on iOS PWA */
@media (display-mode: standalone) {
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent bounce effect */
    body {
        overscroll-behavior-y: contain;
    }
}

/* Loading state for PWA */
.pwa-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    z-index: 2001;
    animation: loadingBar 1.5s ease-in-out infinite;
}

@keyframes loadingBar {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Update available notification */
.pwa-update-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    color: #333;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1050;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(120%);
    }
    to {
        transform: translateX(0);
    }
}

.pwa-update-notification button {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

/* Dark mode adjustments for PWA elements */
.dark-mode .pwa-update-notification {
    background: #2a2a2a;
    color: #e5e5e5;
}

.dark-mode .mobile-bottom-nav {
    background: #1a1a1a;
    border-top-color: #404040;
}

.dark-mode .pwa-offline-indicator {
    background: #8b0000;
}

/* Print styles for PWA */
@media print {
    .pwa-install-banner,
    .mobile-bottom-nav,
    .pwa-update-notification,
    .pwa-offline-indicator {
        display: none !important;
    }
}
