/**
 * Unified Header Design - Clean and Simple
 * Single gradient container approach without z-index tricks
 * Path: /assets/css/unified-header.css
 */

/**
 * iOS Safe Area Fix (2025-09-11)
 * Uses pseudo-element approach to extend gradient into safe area
 * Restores solution from commit 50a0eda
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */
:root {
    /* Gradient colors */
    --gradient-start: #003d7a; /* Dark blue */
    --gradient-end: #00a7e1;   /* Light blue */
    
    /* Safe area variables */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    
    /* Layout dimensions */
    --header-height: auto; /* Auto height based on content */
    --search-height: 56px;
    --nav-height: 60px;
}

/* ==========================================================================
   Reset Body Styles
   ========================================================================== */
body {
    margin: 0;
    padding: 0;
    padding-bottom: var(--nav-height);
    background: #ffffff;
}

/* Remove any existing pseudo-elements from body */
body::before,
body::after {
    display: none !important;
}

/* ==========================================================================
   Unified Header Container
   ========================================================================== */
.unified-header-container {
    position: relative;
    width: 100%;
    /* Natural document flow - no fixed positioning */
}

/* ==========================================================================
   Gradient Header - ONE Container with Gradient
   ========================================================================== */
.gradient-header {
    /* Add safe area as top padding - gradient fills this naturally */
    padding-top: 0;
    
    /* Gradient background across the entire header including safe area */
    background: linear-gradient(
        180deg,
        var(--gradient-start) 0%,
        var(--gradient-start) 40%,
        var(--gradient-end) 100%
    );
    
    /* Horizontal safe area padding */
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    
    /* Height adjusts to content */
    min-height: auto;
    
    /* Ensure content is visible */
    position: relative;
    color: #ffffff !important;
    
    /* Smooth edges */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Pseudo-element to extend gradient into safe area */
.gradient-header::before {
    content: "";
    position: absolute;
    top: calc(-1 * var(--safe-top));
    left: 0;
    right: 0;
    height: var(--safe-top);
    background: linear-gradient(
        180deg,
        var(--gradient-start) 0%,
        var(--gradient-start) 100%
    );
    pointer-events: none;
    z-index: -1;
}

/* iOS 11.0-11.2 compatibility */
@supports (padding: constant(safe-area-inset-top)) {
    .gradient-header {
        padding-top: 0;
        padding-left: constant(safe-area-inset-left);
        padding-right: constant(safe-area-inset-right);
    }
    
    .gradient-header::before {
        top: calc(-1 * constant(safe-area-inset-top));
        height: constant(safe-area-inset-top);
    }
}

/* Android - use actual padding instead of pseudo-element */
.android-device .gradient-header,
html.android-device .gradient-header,
.android-webview .gradient-header,
body.android-webview .gradient-header {
    /* Use actual padding-top for Android */
    padding-top: var(--safe-top, 15px) !important;
}

/* Hide pseudo-element on Android since we use padding */
.android-device .gradient-header::before,
html.android-device .gradient-header::before,
.android-webview .gradient-header::before,
body.android-webview .gradient-header::before {
    display: none !important;
}

/* ==========================================================================
   Header Navigation Section (Back Button + Title)
   ========================================================================== */
.header-nav-section {
    /* Simple padding - safe area handled by gradient-header */
    padding: calc(var(--safe-top) + 5px) 15px 7px 15px;
    min-height: 56px;
    display: flex;
    align-items: center;
}

/* Android-specific adjustment since parent has padding */
.android-device .header-nav-section,
html.android-device .header-nav-section,
.android-webview .header-nav-section {
    padding-top: 5px !important; /* Reduced since parent handles safe area */
}

.header-nav-content {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.back-button-header {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
    text-decoration: none;
    color: #ffffff !important;
}

.back-button-header i {
    color: #ffffff !important;
    font-size: 18px;
}

.back-button-header:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
}

.page-title-header {
    flex: 1;
    font-size: 18px;
    font-weight: 600;
    color: #ffffff !important;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Platform-specific adjustments for nav header - unified */
html.android-webview-js .header-nav-section,
html.ios-webview-js .header-nav-section,
body.ios-webview .header-nav-section {
    /* Same simple padding for all platforms */
    padding: 12px 15px 16px 15px !important;
}

/* ==========================================================================
   Address Section Inside Gradient
   ========================================================================== */
.address-section {
    /* Simple padding - safe area handled by gradient-header */
    padding: 12px 15px 16px 15px;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

/* Android-specific adjustment since parent has padding */
.android-device .address-section,
html.android-device .address-section,
.android-webview .address-section {
    padding-top: 12px !important; /* No need for safe area calc, parent handles it */
}

.address-section:active {
    opacity: 0.8;
}

.address-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 100%;
}

/* Location Icon */
.location-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.location-icon i {
    color: #ffffff !important;
    font-size: 18px;
}

/* Address Details */
.address-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Force white text with maximum specificity */
.gradient-header .address-section .address-details .address-label,
.gradient-header .address-section .address-details span.address-label,
.address-details .address-label,
.address-label {
    font-size: 12px;
    color: #ffffff !important;
    font-weight: 400;
    opacity: 1 !important;
}

.gradient-header .address-section .address-details .address-text,
.gradient-header .address-section .address-details span.address-text,
.address-details .address-text,
.address-text {
    font-size: 15px;
    color: #ffffff !important;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 1 !important;
}

/* Arrow Icon */
.address-arrow {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.address-arrow i {
    color: #ffffff !important;
    font-size: 12px;
}

/* Hover effects */
.address-section:hover .location-icon,
.address-section:hover .address-arrow {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
}

/* ==========================================================================
   Search Section (Separate from Gradient)
   ========================================================================== */
.search-section {
    background: #ffffff;
    padding: 12px 20px;
    border-bottom: 1px solid #f0f0f0;
}

.search-wrapper {
    max-width: 100%;
}

.search-box {
    background: #ffffff;
    border-radius: 25px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s ease;
}

.search-box:focus-within {
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-icon {
    color: #999;
    font-size: 16px;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: #333;
}

.search-input::placeholder {
    color: #999;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Small devices */
@media (max-width: 375px) {
    /* Height adjusts to content automatically */
    
    .address-label {
        font-size: 11px;
    }
    
    .address-text {
        font-size: 14px;
    }
    
    .location-icon,
    .address-arrow {
        width: 36px;
        height: 36px;
    }
}

/* Large devices */
@media (min-width: 430px) {
    /* Height adjusts to content automatically */
    
    .address-section {
        padding: 24px;
    }
    
    .address-text {
        font-size: 16px;
    }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 480px) {
    .address-section {
        padding: 10px 20px 10px 20px;
    }
}

/* ==========================================================================
   Device-Specific Adjustments
   ========================================================================== */

/* iPhone X and newer (with notch) - simplified */
@supports (padding: env(safe-area-inset-top)) {
    @media only screen and (min-height: 812px) {
        .address-section {
            /* Standard padding - safe area handled by gradient-header */
            padding: 12px 15px 16px 15px;
        }
    }
}

/* Platform-specific WebView handling using JavaScript-injected variables */
/* Android WebView - simplified padding */
html.android-webview-js .address-section {
    padding-top: 12px !important;
}

/* iOS WebView - simplified padding */
html.ios-webview-js .address-section,
body.ios-webview .address-section {
    padding-top: 12px !important;
}

/* Fallback for non-WebView browsers - removed complex calc() */
@supports (padding: env(safe-area-inset-top)) {
    @supports not (-webkit-touch-callout: none) {
        body:not(.webview) .address-section {
            padding-top: 12px;
        }
    }
}

/* ==========================================================================
   WebView Support - Removed (now handled by platform-specific rules above)
   ========================================================================== */

/* ==========================================================================
   Dark Mode Removed - Keeping Consistent White Appearance
   ========================================================================== */

/* ==========================================================================
   Keyboard Handling - Prevent gap when keyboard opens
   ========================================================================== */

/* When keyboard is open, maintain header position */
html.keyboard-open .gradient-header {
    /* Keep header stable when keyboard opens */
    position: relative;
}

/* Ensure consistent padding when keyboard is open */
html.keyboard-open .address-section,
html.keyboard-open .header-nav-section {
    /* Maintain same padding */
    padding: 12px 15px 16px 15px;
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Reduce animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .address-section,
    .location-icon,
    .address-arrow,
    .search-box {
        transition: none;
    }
}

/* GPU acceleration for smooth gradients */
.gradient-header {
    transform: translateZ(0);
    will-change: transform;
}