/* PWA Styles - Native App Experience */

/* Install Button */
#install-button {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    animation: slideInUp 0.5s ease-out;
}

#install-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#install-button:active {
    transform: translateY(0);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Offline Mode Indicator */
body.offline-mode::before {
    content: 'Offline-Modus';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ffc107;
    color: #000;
    text-align: center;
    padding: 8px;
    font-size: 12px;
    font-weight: 600;
    z-index: 10000;
    animation: slideDown 0.3s ease-out;
}

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

/* Loading spinner for offline content */
.offline-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #0d6efd;
    animation: spin 1s ease-in-out infinite;
}

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

/* Update notification */
.update-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: #333;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 16px;
    animation: slideInUp 0.3s ease-out;
}

.update-notification button {
    background: #0d6efd;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.update-notification button:hover {
    background: #0b5ed7;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #install-button {
        bottom: 80px;
        right: 16px;
        padding: 10px 20px;
        font-size: 13px;
    }
}

/* Mobile: Top-Bar immer fixed (auch ohne PWA) */
@media (max-width: 991px) {
    .top-bar {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
    }

    /* Fixede Leiste nimmt keinen Platz im Flex-Layout ein — oberen Abstand reservieren.
       Explizite Klasse (base.html), kein :has() — besserer Support in älteren WebViews. */
    .main-content.app-main-has-topbar {
        padding-top: var(--topbar-height);
        box-sizing: border-box;
    }
}

/* ============================================
   NATIVE APP MODE - STANDALONE/FULLSCREEN
   ============================================ */

/* iOS Safe Area Insets */
@supports (padding: env(safe-area-inset-top)) {
    @media (display-mode: standalone), (display-mode: fullscreen) {
        body {
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
        }
        
        /* Top Bar muss sticky sein und direkt unter der Statusleiste */
        .top-bar {
            position: sticky;
            top: 0;
            z-index: 1000;
            margin-top: 0;
        }
        
        /* Sidebar Padding für Safe Area */
        .sidebar {
            padding-top: env(safe-area-inset-top);
        }
        
        /* Main Content Padding für Safe Area */
        .main-content {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* Standalone App Mode (PWA installed) */
@media (display-mode: standalone), (display-mode: fullscreen) {
    body {
        background: var(--bs-body-bg);
        overscroll-behavior-y: contain; /* Prevent pull-to-refresh */
    }
    
    /* Full viewport height */
    .app-wrapper,
    .main-wrapper {
        min-height: 100vh;
        height: 100vh;
    }
    
    /* Hide any browser UI elements */
    .browser-ui,
    .address-bar,
    .navigation-bar {
        display: none !important;
    }
    
    /* Native app scrolling */
    * {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Better touch feedback */
    button, a, .btn, .clickable {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }
    
    /* Disable text selection for UI elements only */
    button, .sidebar, .navbar, .topbar, .top-bar {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Keep text selectable in content areas */
    input, textarea, [contenteditable], .card-body, .main-content {
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* Custom scrollbars */
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }
    
    ::-webkit-scrollbar-track {
        background: transparent;
    }
    
    ::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.3);
    }
    
    /* Edge-to-edge content */
    .container-fluid {
        padding-left: 0;
        padding-right: 0;
        max-width: 100%;
    }
}

/* Window Controls Overlay support (Windows 11) */
@media (display-mode: window-controls-overlay) {
    .app-header, .top-bar {
        -webkit-app-region: drag;
        padding-left: env(titlebar-area-x, 0);
        padding-top: env(titlebar-area-height, 0);
    }
    
    .app-header button,
    .app-header a,
    .app-header input,
    .top-bar button,
    .top-bar a,
    .top-bar input {
        -webkit-app-region: no-drag;
    }
}
