/**
 * PWA Standalone Mode Styles
 * Optimierungen für installierte PWA (Vollbild-Modus)
 */

/* Nur im Standalone-Modus (installierte App) anwenden */
@media all and (display-mode: standalone) {
    
    /* Body-Anpassungen */
    body {
        /* Zusätzlicher Padding oben für Status-Bar auf Mobilgeräten */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    /* Top Brand Bar - optimiert für Standalone */
    .top-brand-bar {
        /* Berücksichtige Notch/Status-Bar auf iOS */
        padding-top: calc(0.5rem + env(safe-area-inset-top));
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Navigation Bar - Standalone Optimierung */
    .navbar {
        /* Verhindere dass die Navbar unter die Notch rutscht */
        padding-top: env(safe-area-inset-top);
    }
    
    /* Footer - Standalone Optimierung */
    footer {
        /* Verhindere dass der Footer durch Home-Indicator verdeckt wird */
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
    
    /* Container - Maximale Ausnutzung des verfügbaren Platzes */
    .container-fluid {
        /* Verhindere horizontales Scrollen auf Notch-Geräten */
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
    
    /* Links - Native App Feel */
    a {
        /* Verhindere Standard-Browser-Highlight */
        -webkit-tap-highlight-color: transparent;
        tap-highlight-color: transparent;
    }
    
    /* Disable Pull-to-Refresh auf einigen Browsern */
    body {
        overscroll-behavior-y: contain;
    }
    
    /* Buttons - besseres Touch-Feedback */
    .btn {
        -webkit-tap-highlight-color: transparent;
        tap-highlight-color: transparent;
        cursor: pointer;
    }
    
    /* Scrollbars verstecken für mehr nativen Look (optional) */
    /* Entkommentieren falls gewünscht:
    ::-webkit-scrollbar {
        display: none;
    }
    
    * {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    */
}

/* iOS Safari spezifische Anpassungen */
@supports (-webkit-touch-callout: none) {
    @media all and (display-mode: standalone) {
        
        /* Verhindere Zoom bei Double-Tap */
        * {
            touch-action: manipulation;
        }
        
        /* Status Bar Styling für iOS */
        body {
            -webkit-user-select: none;
            user-select: none;
        }
        
        /* Erlaube Text-Selektion in Textfeldern */
        input, textarea {
            -webkit-user-select: text;
            user-select: text;
        }
    }
}

/* Android Chrome spezifische Anpassungen */
@media all and (display-mode: standalone) and (max-width: 768px) {
    
    /* Optimiere für kleinere Bildschirme im Standalone-Modus */
    .top-brand-bar {
        font-size: 0.95rem;
    }
    
    .navbar-brand {
        font-size: 1.1rem;
    }
}

/* Landscape-Modus im Standalone */
@media all and (display-mode: standalone) and (orientation: landscape) {
    
    /* Kompaktere Navigation im Landscape */
    .top-brand-bar {
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }
    
    .navbar {
        min-height: 48px;
    }
}

/* PWA Install Button - verstecken wenn bereits installiert */
@media all and (display-mode: standalone) {
    #pwa-install-btn,
    #pwa-install-toast {
        display: none !important;
    }
}

/* Splash Screen Simulation (während des Ladens) */
.pwa-splash {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.pwa-splash.hidden {
    opacity: 0;
    pointer-events: none;
}

.pwa-splash img {
    width: 128px;
    height: 128px;
    margin-bottom: 2rem;
}

.pwa-splash h1 {
    color: #333;
    font-size: 1.5rem;
    margin: 0;
}

/* Loading Animation */
.pwa-splash .spinner {
    width: 40px;
    height: 40px;
    margin-top: 2rem;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0d6efd;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Pull-to-Refresh Indicator (optional, für zukünftige Implementation) */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform 0.3s ease-out;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.pull-to-refresh.visible {
    transform: translateY(0);
}

.pull-to-refresh .icon {
    font-size: 24px;
    color: #0d6efd;
    animation: spin 1s linear infinite;
}

/* Optimiere Form-Elemente für Touch */
@media all and (display-mode: standalone) {
    
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        /* Größerer Touch-Target */
        min-height: 44px;
        font-size: 16px; /* Verhindert Zoom auf iOS */
    }
    
    /* Buttons größer für bessere Touch-Bedienung */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1.5rem;
    }
    
    .btn-sm {
        min-height: 38px;
        padding: 0.5rem 1rem;
    }
}

/* Dark Mode Support (falls gewünscht) */
@media (prefers-color-scheme: dark) and (display-mode: standalone) {
    /* Hier könnten Dark Mode Styles hinzugefügt werden */
    /* Beispiel:
    body {
        background-color: #1a1a1a;
        color: #ffffff;
    }
    
    .card {
        background-color: #2a2a2a;
    }
    */
}

/* Accessibility - Focus Indicators im Standalone-Modus */
@media all and (display-mode: standalone) {
    
    *:focus {
        outline: 2px solid #0d6efd;
        outline-offset: 2px;
    }
    
    /* Entferne Outline für Maus-User (nur für Touch) */
    *:focus:not(:focus-visible) {
        outline: none;
    }
}

/* Performance-Optimierung - Hardware-Beschleunigung */
@media all and (display-mode: standalone) {
    
    .navbar,
    .top-brand-bar,
    footer,
    .card {
        /* Nutze GPU für smoother Scrolling */
        transform: translateZ(0);
        will-change: transform;
    }
}

/* Network Status Indicator (optional) */
.network-status {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    background: #ffc107;
    color: #000;
    border-radius: 25px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 9998;
    display: none;
    animation: slideUp 0.3s ease-out;
}

.network-status.offline {
    background: #dc3545;
    color: #fff;
    display: block;
}

.network-status.online {
    background: #28a745;
    color: #fff;
    display: block;
}

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