/* ===== PWA STYLES - ADVANCED ===== */

/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #1fb8cd 0%, #159fa8 100%);
    color: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(31, 184, 205, 0.3);
    padding: 16px 20px;
    max-width: 320px;
    width: calc(100% - 40px);
    z-index: 9999; /* Lower than overlays but higher than content */
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.pwa-install-banner.show {
    bottom: calc(var(--banner-bottom, 20px) + var(--safe-area-inset-bottom, 0px));
    animation: slideUpBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Adjust banner position when bottom navigation is present */
body:has(.bottom-nav) .pwa-install-banner.show {
    bottom: calc(100px + var(--safe-area-inset-bottom, 0px));
}

/* Specific positioning adjustments for PWA mode */
body.pwa-installed .pwa-install-banner.show {
    bottom: calc(20px + var(--safe-area-inset-bottom, 0px));
}

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

.install-icon img {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.install-text {
    flex: 1;
}

.install-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
}

.install-text p {
    margin: 2px 0 0 0;
    font-size: 13px;
    opacity: 0.9;
    line-height: 1.3;
}

.install-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-install {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.btn-install:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.btn-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.btn-close:hover {
    opacity: 1;
}

/* PWA Update Banner */
.pwa-update-banner {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #2c3347 0%, #3a4356 100%);
    color: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(44, 51, 71, 0.4);
    padding: 16px 20px;
    max-width: 320px;
    width: calc(100% - 40px);
    z-index: 9998; /* Lower to avoid overlapping with header elements */
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.pwa-update-banner.show {
    top: calc(var(--update-banner-top, 80px) + var(--safe-area-inset-top, 0px)); /* Position below header */
    animation: slideDownBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Adjust for PWA standalone mode */
body.pwa-installed .pwa-update-banner.show {
    top: calc(var(--update-banner-top, 60px) + var(--safe-area-inset-top, 0px));
}

.update-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.update-text {
    flex: 1;
}

.update-text h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    color: #1fb8cd;
}

.update-text p {
    margin: 2px 0 0 0;
    font-size: 13px;
    opacity: 0.8;
    line-height: 1.3;
}

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

.btn-update {
    background: #1fb8cd;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-update:hover {
    background: #159fa8;
    transform: translateY(-1px);
}

.btn-dismiss {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* Offline Indicator */
.offline-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    padding: 12px 20px;
    border-radius: 0 0 12px 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 9997; /* Lower z-index to avoid header conflicts */
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.3);
    max-width: 280px;
    width: calc(100% - 40px);
}

.offline-indicator.show {
    top: var(--safe-area-inset-top, 0px);
}

/* PWA standalone mode adjustment */
body.pwa-installed .offline-indicator.show {
    top: var(--safe-area-inset-top, 0px);
}

.offline-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.offline-icon {
    font-size: 16px;
}

/* PWA Toast Notifications */
.pwa-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10003;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 280px;
    text-align: center;
    backdrop-filter: blur(10px);
}

.pwa-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.pwa-toast-success {
    background: linear-gradient(135deg, #00d2d3 0%, #54a0ff 100%);
    color: white;
    box-shadow: 0 8px 32px rgba(0, 210, 211, 0.3);
}

.pwa-toast-info {
    background: linear-gradient(135deg, #1fb8cd 0%, #159fa8 100%);
    color: white;
    box-shadow: 0 8px 32px rgba(31, 184, 205, 0.3);
}

.pwa-toast-warning {
    background: linear-gradient(135deg, #feca57 0%, #ff9ff3 100%);
    color: #2c3347;
    box-shadow: 0 8px 32px rgba(254, 202, 87, 0.3);
}

.pwa-toast-error {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    box-shadow: 0 8px 32px rgba(255, 107, 107, 0.3);
}

/* PWA App Experience Enhancements */
body.pwa-installed {
    /* Remove any browser UI elements when installed */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    
    /* Remove default padding that causes footer shift */
    padding: 0 !important;
    margin: 0 !important;
}

/* Prevent overscroll behavior for app-like feel */
body.pwa-installed {
    overscroll-behavior: none;
    /* Don't use position fixed as it causes layout issues */
    width: 100%;
    min-height: var(--app-height, 100vh);
}

body.pwa-installed #app {
    min-height: var(--app-height, 100vh);
    height: var(--app-height, 100vh);
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Fix footer positioning in PWA mode */
body.pwa-installed .bottom-nav,
body.pwa-installed .app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* Base height without safe area - safe area padding added in @supports */
    height: 70px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 1000;
}

/* Ensure main content doesn't get hidden behind fixed footer */
body.pwa-installed main,
body.pwa-installed .main-content,
body.pwa-installed .page-container {
    /* Base padding without safe area - will be overridden in @supports */
    padding-bottom: 70px;
}

/* Safe area handling for notched devices */
@supports (padding-top: env(safe-area-inset-top)) {
    /* iPhone PWA: Critical fix - top-bar should ONLY have safe-area padding, no extra height */
    body.pwa-installed .top-bar {
        /* Total height should be 64px + safe-area, not double */
        height: 64px;
        padding-top: env(safe-area-inset-top, 0px);
        /* Remove any margin that might be added */
        margin-top: 0 !important;
    }
    
    /* Fix page-container to account for top-bar height properly */
    body.pwa-installed .page-container {
        /* Top offset = 64px top-bar + safe-area (already in top-bar padding) + 20px spacing */
        margin-top: calc(64px + 20px) !important;
        /* Remove the safe-area-inset-top from here as it's already in top-bar */
        padding-top: 0 !important;
    }
    
    /* Don't add extra margin to page content */
    body.pwa-installed .page-content > :first-child {
        margin-top: 0;
        padding-top: 0;
    }
    
    body.pwa-installed .balance-summary {
        margin-top: 0;
        padding-top: 0;
    }
    
    body.pwa-installed .page-header {
        margin-top: 0;
        padding-top: 0;
    }
    
    /* Bottom navigation: Only add minimal padding for home indicator */
    body.pwa-installed .app-footer,
    body.pwa-installed .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0.5rem);
        /* Ensure fixed positioning */
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    /* Adjust main content bottom padding to account for bottom nav + safe area */
    body.pwa-installed main,
    body.pwa-installed .main-content {
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    }
}

/* Additional PWA header spacing fixes */
body.pwa-installed {
    /* Ensure the entire app respects safe areas */
    --header-safe-padding: 0; /* Remove extra padding as top-bar handles it */
    --status-bar-height: 0px; /* Don't add status bar height - top-bar already has it */
}

/* PWA: Fix top-bar content visibility and layout */
body.pwa-installed .top-bar {
    /* Ensure top-bar content is properly displayed */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

body.pwa-installed .top-bar-content {
    /* Ensure full width and proper alignment */
    width: 100% !important;
    max-width: 1200px !important;
    padding: 0 1rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    height: 64px; /* Fixed height for content */
}

body.pwa-installed .page-title {
    /* Ensure title is visible and properly sized */
    font-size: clamp(1.125rem, 4vw, 1.5rem) !important;
    font-weight: 700 !important;
    color: var(--text-primary) !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.2 !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
    /* Ensure it doesn't get cut off */
    max-height: none !important;
    flex: 1 !important;
}

body.pwa-installed .page-subtitle {
    font-size: clamp(0.75rem, 3vw, 0.875rem) !important;
    color: var(--text-muted) !important;
    margin: 0 !important;
    line-height: 1.3 !important;
}

body.pwa-installed .top-bar-actions {
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    flex-shrink: 0 !important;
}

/* Fallback for any top-level content */
body.pwa-installed .content-wrapper,
body.pwa-installed .page-wrapper {
    padding-top: 0; /* Top-bar already handles safe area */
}

/* PWA: Remove extra spacing from pages */
body.pwa-installed .page {
    padding-top: 0;
    margin-top: 0;
}

/* PWA: Remove extra spacing from page content */
body.pwa-installed .page-content {
    padding-top: 0;
    margin-top: 0;
}

/* iOS specific styles */
@supports (-webkit-appearance: none) {
    body.pwa-installed {
        -webkit-overflow-scrolling: touch;
    }
    
    /* iOS PWA: Ensure proper header spacing on iPhone */
    @media only screen and (max-width: 430px) {
        body.pwa-installed .top-bar {
            /* Ensure top bar doesn't have excessive height on iPhone */
            height: 64px !important;
        }
        
        body.pwa-installed .top-bar-content {
            height: 64px !important;
            padding: 0 1rem !important;
        }
        
        /* Compact title on small screens */
        body.pwa-installed .page-title {
            font-size: 1.25rem !important;
            line-height: 1.3 !important;
        }
        
        /* Ensure bottom nav doesn't have too much space */
        body.pwa-installed .bottom-nav {
            height: 70px !important;
            padding-bottom: env(safe-area-inset-bottom, 0.5rem) !important;
        }
        
        /* Adjust page container for smaller screens */
        body.pwa-installed .page-container {
            margin-top: calc(64px + 16px) !important;
        }
    }
}

/* Pull-to-refresh styles */
.pwa-pull-refresh {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(31, 184, 205, 0.1);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.pwa-pull-refresh.active {
    top: 20px;
    background: rgba(31, 184, 205, 0.2);
}

.pwa-pull-refresh svg {
    width: 20px;
    height: 20px;
    stroke: #1fb8cd;
    transition: transform 0.3s ease;
}

.pwa-pull-refresh.loading svg {
    animation: spin 1s linear infinite;
}

/* Animation keyframes */
@keyframes slideUpBounce {
    0% {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }
    60% {
        transform: translateX(-50%) translateY(-10px);
        opacity: 1;
    }
    100% {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

@keyframes slideDownBounce {
    0% {
        transform: translateX(-50%) translateY(-100px);
        opacity: 0;
    }
    60% {
        transform: translateX(-50%) translateY(10px);
        opacity: 1;
    }
    100% {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

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

/* Loading states for PWA */
.pwa-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(44, 51, 71, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10004;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.pwa-loading-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.pwa-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(31, 184, 205, 0.2);
    border-left-color: #1fb8cd;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.pwa-loading-text {
    color: white;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
}

/* Enhanced button styles for better touch targets */
.btn, button {
    min-height: 44px; /* iOS touch target minimum */
    min-width: 44px;
    touch-action: manipulation; /* Prevents zoom on double-tap */
}

/* Improve focus states for accessibility */
.btn:focus,
button:focus,
.btn-install:focus,
.btn-update:focus {
    outline: 2px solid #1fb8cd;
    outline-offset: 2px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .pwa-update-banner {
        background: linear-gradient(135deg, #1a1f2e 0%, #2c3347 100%);
        border-color: rgba(255, 255, 255, 0.15);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .pwa-install-banner,
    .pwa-update-banner,
    .pwa-toast,
    .offline-indicator {
        transition: none;
    }
    
    .pwa-loading-spinner {
        animation: none;
        border-left-color: #1fb8cd;
        border-top-color: #1fb8cd;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .pwa-install-banner,
    .pwa-update-banner {
        border-width: 2px;
        border-color: white;
    }
    
    .btn-install,
    .btn-update {
        border: 2px solid white;
    }
}

/* ===== PWA MODAL POSITIONING FIXES ===== */

/* Simplified PWA Modal Safe Area Handling */
body.pwa-installed .modal-overlay {
    /* Simple and effective safe area handling */
    padding: calc(env(safe-area-inset-top, 0px) + 1rem) 
             calc(env(safe-area-inset-right, 0px) + 1rem) 
             calc(env(safe-area-inset-bottom, 0px) + 1rem) 
             calc(env(safe-area-inset-left, 0px) + 1rem);
    
    /* Better centering */
    align-items: center;
    justify-content: center;
}

body.pwa-installed .modal {
    /* Optimal modal sizing for PWA */
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 2rem);
    max-width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 2rem);
    width: 100%;
    
    /* Ensure content is scrollable */
    overflow-y: auto;
    
    /* Better visual integration */
    border: 1px solid var(--border-light);
}

/* Mobile PWA Modal Optimizations */
@media (max-width: 768px) {
    body.pwa-installed .modal-overlay {
        /* Minimal but effective padding on mobile */
        padding: calc(env(safe-area-inset-top, 20px) + 0.75rem) 
                 calc(env(safe-area-inset-right, 0px) + 0.75rem) 
                 calc(env(safe-area-inset-bottom, 34px) + 0.75rem) 
                 calc(env(safe-area-inset-left, 0px) + 0.75rem);
    }
    
    body.pwa-installed .modal {
        /* Full width on mobile with proper constraints */
        width: 100%;
        max-width: 100%;
        
        /* Ensure buttons remain accessible */
        max-height: calc(100vh - env(safe-area-inset-top, 20px) - env(safe-area-inset-bottom, 34px) - 1.5rem);
        
        /* App-like rounded corners */
        border-radius: 1rem 1rem 0 0;
    }
    
    body.pwa-installed .modal-content {
        /* Ensure action buttons have space */
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    }
    
    body.pwa-installed .modal-footer,
    body.pwa-installed .form-actions,
    body.pwa-installed .action-buttons {
        /* Keep action buttons accessible */
        padding-bottom: 1rem;
        margin-bottom: 0;
        
        /* Ensure buttons don't get cut off */
        position: sticky;
        bottom: 0;
        background: var(--bg-modal);
        border-top: 1px solid var(--border);
        margin-top: auto;
    }
}

/* Landscape PWA Modal Adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    body.pwa-installed .modal {
        /* Better landscape sizing */
        max-width: min(90vw, 600px);
        max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 1rem);
    }
}

/* PWA Modal Close Button */
body.pwa-installed .modal-close {
    /* Ensure close button is accessible */
    min-width: 44px;
    min-height: 44px;
    
    /* Better visibility in PWA */
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    
    /* Positioning within header */
    position: relative;
    margin: 0;
}

/* PWA Modal Animation */
body.pwa-installed .modal-overlay.active .modal {
    animation: pwaModalSlideUp 0.3s ease-out;
}

@keyframes pwaModalSlideUp {
    0% {
        opacity: 0;
        transform: translateY(1rem);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* PWA-specific compact country select for modals */
body.pwa-installed .country-select.compact {
    flex: 0 0 64px;
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
}

/* Ensure modal inputs have adequate bottom padding so actions remain reachable */
body.pwa-installed .modal .mobile-input-group .mobile-number-input {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
}

/* Force modal footers to sit above safe area in PWA mode */
body.pwa-installed .modal-footer,
body.pwa-installed .members-modal-footer,
body.pwa-installed .confirm-modal .confirm-actions {
    position: sticky;
    bottom: env(safe-area-inset-bottom, 0);
    background: var(--bg-modal);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
}

/* ===== GENERAL PWA UI ALIGNMENT FIXES ===== */

/* PWA App Container Improvements */
body.pwa-installed #app {
    /* Ensure app fills viewport properly */
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 0; /* Remove any padding */
    margin: 0; /* Remove any margin */
}

/* PWA Main Content Area */
body.pwa-installed .main-content,
body.pwa-installed main {
    /* Account for safe areas in main content - only horizontal */
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    
    /* Don't add extra margin-top - page-container already handles it */
    margin-top: 0;
    margin-bottom: 4rem; /* Just account for navigation, no safe-area-inset */
}

/* PWA Page Headers - remove ALL extra spacing */
body.pwa-installed .page-header {
    /* Remove all extra spacing that creates empty space */
    margin-top: 0;
    padding-top: 0;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
}

body.pwa-installed h1,
body.pwa-installed h2.page-title {
    /* Remove extra padding that causes spacing issues */
    margin-top: 0;
    padding-top: 0;
}

/* PWA Card and Content Spacing */
body.pwa-installed .card,
body.pwa-installed .balance-card,
body.pwa-installed .group-card,
body.pwa-installed .expense-card {
    /* Don't add safe area margins for cards - parent handles horizontal spacing */
    margin-left: 0;
    margin-right: 0;
}

/* PWA Button and Form Element Positioning */
body.pwa-installed .btn,
body.pwa-installed button,
body.pwa-installed .form-group input {
    /* Don't add margins - let normal layout handle it */
    margin-left: 0;
    margin-right: 0;
}

/* PWA Bottom Navigation Fixes */
body.pwa-installed .bottom-nav {
    /* Fix positioning to properly align with PWA chrome */
    bottom: 0;
    
    /* Ensure navigation respects safe areas */
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    /* Don't add padding-bottom here - handled in @supports */
    
    /* Ensure it's above the home indicator */
    z-index: 1000;
    
    /* Improve visual integration with PWA */
    background: var(--bg-card);
    border-top: 1px solid var(--border-light);
}

/* PWA Floating Action Button */
body.pwa-installed .floating-action-button,
body.pwa-installed .add-button {
    /* Position FAB safely away from edges and home indicator */
    bottom: calc(env(safe-area-inset-bottom, 0) + 1rem);
    right: calc(env(safe-area-inset-right, 0) + 1rem);
}

/* PWA Add Button (+ button) specific fixes */
body.pwa-installed .nav-item.add-button {
    /* Reset the translateY transform that causes floating appearance */
    transform: translateY(0) !important;
}

body.pwa-installed .nav-item.add-button:hover {
    /* Keep hover effect but without the floating up */
    transform: translateY(0) !important;
}

/* PWA Toast and Notification Positioning */
body.pwa-installed .toast,
body.pwa-installed .notification {
    /* Position toasts within safe areas */
    left: calc(env(safe-area-inset-left, 0) + 1rem);
    right: calc(env(safe-area-inset-right, 0) + 1rem);
    bottom: calc(env(safe-area-inset-bottom, 0) + 6rem);
}

/* PWA Form and Input Improvements */
body.pwa-installed .form-container {
    /* Let parent handle padding - don't add extra */
    padding-left: 0;
    padding-right: 0;
}

/* PWA Landscape Mode Adjustments */
@media (orientation: landscape) {
    body.pwa-installed .main-content {
        /* In landscape, only handle horizontal safe areas */
        padding-left: calc(env(safe-area-inset-left, 0) + 1rem);
        padding-right: calc(env(safe-area-inset-right, 0) + 1rem);
        margin-top: 0; /* page-container handles vertical spacing */
    }
    
    body.pwa-installed .page-header {
        /* Remove ALL extra top spacing in landscape */
        margin-top: 0;
        padding-top: 0;
    }
    
    body.pwa-installed .page-container {
        /* Remove ALL extra top margin in landscape */
        margin-top: 0 !important;
        padding-top: 0;
    }
}

/* PWA Tablet and Large Screen Adjustments */
@media (min-width: 768px) {
    body.pwa-installed .modal {
        /* Better modal sizing on tablets in PWA mode */
        max-width: min(600px, calc(100vw - 4rem));
    }
    
    body.pwa-installed .main-content {
        /* Center content on larger screens */
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
        padding-left: calc(env(safe-area-inset-left, 0) + 2rem);
        padding-right: calc(env(safe-area-inset-right, 0) + 2rem);
        margin-top: 0; /* page-container handles vertical spacing */
    }
    
    body.pwa-installed .page-container {
        /* Remove ALL extra top margin on tablets */
        margin-top: 0 !important;
        padding-top: 0;
    }
}

/* PWA Status Bar and System UI Integration */
body.pwa-installed {
    /* Match status bar color in PWA mode */
    --status-bar-color: var(--bg-primary, #2c3347);
}

/* PWA Scroll Behavior Improvements */
body.pwa-installed {
    /* Prevent rubber band scrolling */
    overscroll-behavior: none;
    
    /* Smooth scrolling */
    scroll-behavior: smooth;
}

/* PWA Dark Mode System Integration */
@media (prefers-color-scheme: dark) {
    body.pwa-installed {
        /* Ensure PWA integrates well with system dark mode */
        color-scheme: dark;
    }
}

/* PWA Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    body.pwa-installed * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
