/* PWA Styles - Mobile-first approach based on aa-neo implementation */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    /* iOS safe area support */
    height: -webkit-fill-available;
}

body {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    width: 100%;
    overflow: hidden;
    background: #f6c637; /* Antunes yellow */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Ensure full height in standalone mode */
body.standalone-mode {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* PWA Header */
#pwa-header {
    background: #f6c637; /* Antunes yellow */
    color: #fff; /* White text like aa-neo */
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
    min-height: 60px; /* Reduced height to match aa-neo */
}

#pwa-header h1 {
    font-size: 1.125rem; /* Slightly smaller to match aa-neo */
    font-weight: 600;
    margin: 0;
    color: #fff; /* White text */
}

#pwa-header .subtitle {
    font-size: 0.8rem; /* Smaller subtitle */
    opacity: 0.9;
    margin-top: 0.125rem;
    color: #fff; /* White text */
}

#pwa-header .logo {
    width: 40px;
    height: 40px;
    margin-right: 1rem;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#pwa-header .logo.loaded {
    opacity: 1;
}

#pwa-header .header-content {
    display: flex;
    align-items: center;
    flex: 1;
}

#pwa-header .header-text {
    display: flex;
    flex-direction: column;
}

#pwa-header .action-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s;
}

#pwa-header .action-button:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-1px);
}

#pwa-header .action-button:active {
    transform: translateY(0);
}

/* Widget Container */
#widget-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* Important for flex children */
    position: relative;
    /* Account for bottom safe area */
    padding-bottom: env(safe-area-inset-bottom);
    background: #ffffff;
}

#widget-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    flex: 1;
    background: #ffffff;
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

/* Initial loading (before iframe) */
#loading-overlay.initial {
    background: #f6c637;
}

/* Widget loading (after iframe loads) */
#loading-overlay.widget-loading {
    background: #ffffff;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #0066A5;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}


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

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Use visual viewport height on iOS */
    body {
        height: 100vh;
        /* Fallback for iOS < 13 */
        height: -webkit-fill-available;
    }
    
    /* In standalone mode, ensure proper height */
    @media all and (display-mode: standalone) {
        html, body {
            height: 100%;
            overflow: hidden;
        }
        
        #widget-container {
            /* Ensure container fills remaining space */
            height: 100%;
        }
    }
}

/* Fix for iOS 15+ viewport issues */
@supports (height: 100dvh) {
    body {
        height: 100dvh;
    }
}

/* Standalone mode specific styles */
@media all and (display-mode: standalone) {
    /* Status bar padding already handled in #pwa-header */
    body {
        background: #f6c637;
    }
}

/* Responsive adjustments for larger screens */
@media (min-width: 768px) {
    #pwa-header {
        padding: 0.875rem 1.5rem;
        padding-top: calc(0.875rem + env(safe-area-inset-top));
    }
    
    #pwa-header h1 {
        font-size: 1.25rem; /* Keep size moderate like aa-neo */
    }
    
    #pwa-header .subtitle {
        font-size: 0.875rem;
    }
}

/* Landscape mode optimizations */
@media (orientation: landscape) and (max-height: 500px) {
    #pwa-header {
        padding: 0.5rem 1rem;
        padding-top: calc(0.5rem + env(safe-area-inset-top));
        min-height: 50px; /* Even smaller in landscape */
    }
    
    #pwa-header h1 {
        font-size: 1rem;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    /* Keep Antunes branding consistent - no dark mode override */
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #pwa-header .action-button {
        border: 2px solid #fff;
        background: rgba(255,255,255,0.3);
        color: #fff;
    }
    
    .spinner {
        border: 4px solid rgba(255,255,255,0.3);
        border-top: 4px solid #0066A5;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
    }
    
    #pwa-header .action-button {
        transition: none;
    }
    
    #loading-overlay {
        transition: none;
    }
}