/* Mobile UX/UI Fixes for iOS and Android */

/* 1. Fix 300ms click delay on all touchable elements */
* {
    touch-action: manipulation;
}

/* 2. Better touch feedback for all interactive elements */
button,
.button,
.btn,
.nav-button,
.search-button,
.price,
.station,
.radius-option,
.results-count,
[role="button"],
[onclick] {
    -webkit-tap-highlight-color: rgba(255, 183, 0, 0.2);
    transition: transform 0.1s ease-out, background-color 0.15s ease;
}

/* Active states for touch feedback */
button:active,
.button:active,
.btn:active,
.nav-button:active,
.search-button:active,
.price:active,
.station:active,
.radius-option:active,
.results-count:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* 3. Minimum touch target sizes (44x44px iOS, 48x48dp Android) */
button,
.button,
.btn,
.nav-button {
    min-height: 44px;
    min-width: 44px;
    position: relative;
}

/* Expand click area for small buttons - handled by ::after in main CSS */
.price::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    z-index: -1;
}

/* 4. Prevent double-tap zoom on buttons */
button,
.button,
input[type="button"],
input[type="submit"],
input[type="reset"],
[role="button"] {
    touch-action: manipulation;
}

/* 5. Fix input zoom on iOS */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="tel"],
select,
textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
}

/* 6. Better scrolling performance */
.station-list,
.modal-content {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* 7. Prevent text selection on UI elements */
.nav-button,
.search-button,
.price,
.station-name,
.results-count,
.radius-option {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* 8. Modal scrolling fixes */
body.modal-open {
    position: fixed;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.modal-content {
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
}

/* 9. Safe area for iPhone X+ notch and bottom bar */
.app {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.header {
    padding-top: calc(var(--spacing-xl) + env(safe-area-inset-top));
    /* Ensure header is always at the top of scroll container */
    position: relative;
    top: 0;
    z-index: 100;         /* Increased from 10 to support dropdown z-index hierarchy */
    overflow: visible;     /* Allow dropdowns to overflow */
}

/* 10. Better mobile typography */
@media (max-width: 768px) {
    .station-name {
        font-size: 16px !important;
        line-height: 1.4;
    }

    .station-address {
        font-size: 14px !important;
    }

    .price-value {
        font-size: 20px !important;
        font-weight: 700;
    }

    .distance {
        font-size: 14px !important;
    }
}

/* 11. Fix sticky hover states on touch devices */
@media (hover: hover) and (pointer: fine) {
    .station:hover,
    .price:hover,
    .nav-button:hover,
    .search-button:hover {
        background-color: var(--surface);
    }
}

/* Remove hover effects on touch devices */
@media (hover: none) and (pointer: coarse) {
    .station:hover,
    .price:hover,
    .nav-button:hover,
    .search-button:hover {
        background-color: inherit;
    }
}

/* 12. Loading spinner for touch feedback */
.loading-touch {
    position: relative;
    pointer-events: none;
}

.loading-touch::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner 0.6s linear infinite;
}

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

/* 13. Better focus states for accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible,
.station:focus-visible,
.price:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* 14. Smooth momentum scrolling */
.station-list {
    scroll-behavior: smooth;
    overscroll-behavior-y: contain;
}

/* 15. Prevent pull-to-refresh on station list */
.station-list {
    overscroll-behavior-y: contain;
}

/* 16. Fix for Android keyboard pushing content */
.search-section {
    position: relative;
    z-index: 10;
}

/* 17. Better touch targets for navigation icons */
.nav-icon {
    padding: 8px;
    margin: -8px;
}

/* 18. Improved contrast for outdoor viewing */
@media (prefers-contrast: high) {
    .price-value {
        font-weight: 900;
    }

    .station {
        border: 2px solid var(--border);
    }
}

/* 19. Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding-top: var(--spacing-md);
        padding-bottom: var(--spacing-sm);
    }

    .station {
        padding: var(--spacing-sm);
    }
}

/* 20. Fix for iOS bounce scrolling and Chrome scroll persistence */
html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed; /* Prevent body scroll on mobile */
}

.app {
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height on modern browsers */
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    /* Ensure scroll container works properly in Chrome */
    position: relative;
    overscroll-behavior-y: contain;
    /* Force new stacking context for better scroll performance */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* 21. Long press visual feedback */
.station.long-pressed {
    background-color: var(--primary-light) !important;
    transform: scale(0.98);
    transition: all 0.2s ease;
}

/* 22. Fix small clickable areas in price buttons */
.price {
    padding: 12px !important;
    margin: -4px;
}

/* 23. Improve input field touch targets */
input[type="text"],
input[type="number"],
select {
    height: 48px !important;
    padding: 12px !important;
}

/* 24. Fix radius menu for mobile */
.radius-menu {
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.radius-option {
    min-height: 44px;
    padding: 12px 16px;
}

/* 25. Better mobile font hierarchy */
@media (max-width: 768px) {
    .header h1,
    .fuelmate-text {
        font-size: 24px !important;
    }

    .tagline {
        font-size: 14px !important;
    }

    .search-input,
    .postcode-input {
        font-size: 16px !important;
        height: 48px !important;
    }

    .search-button {
        height: 48px !important;
        font-size: 16px !important;
    }

    .fuel-select {
        height: 48px !important;
        font-size: 16px !important;
    }

    .station {
        padding: 12px !important;
    }

    .station-name {
        font-size: 16px !important;
        font-weight: 600 !important;
    }

    .nav-button {
        /* Touch target is 44x44px via ::after pseudo-element */
        /* Visual size stays compact at 32x32px */
    }
}

/* 26. Fix iOS Safari bottom bar overlap */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .station-list {
        padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    }
}

/* 27. Prevent zoom on double-tap for entire app */
.app {
    touch-action: pan-x pan-y;
}

/* 28. Better contrast for price display */
.price-value {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Dark mode price contrast */
:root[data-theme="dark"] .price-value {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 29. Mobile footer styles - kept for backwards compatibility */
@media (max-width: 768px) {
    .desktop-footer {
        display: flex !important;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 4px 8px;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        background: var(--surface, #f5f5f5);
        border-top: 1px solid var(--border, #e0e0e0);
        font-size: 12px;
        text-align: center;
        width: 100%;
        box-sizing: border-box;
    }

    .desktop-footer a {
        color: var(--primary, #FFB700);
        text-decoration: none;
        padding: 4px 6px;
        white-space: nowrap;
    }

    .footer-divider {
        color: #ccc;
        font-size: 10px;
    }
}

/* 30. Override desktop-mode layout for mobile screens */
@media (max-width: 768px) {
    /* Force mobile layout even when desktop-mode class is present */
    body.desktop-mode .desktop-main {
        flex-direction: column !important;
    }

    body.desktop-mode .desktop-sidebar {
        width: 100% !important;
        max-width: none !important;
        flex: none !important;
    }

    body.desktop-mode .desktop-map-panel {
        display: none !important;  /* Hide map panel on mobile - use Map View tab instead */
    }

    /* Show the Find Stations button in sidebar on mobile */
    body.desktop-mode .desktop-search-btn {
        display: block !important;
        width: calc(100% - 32px) !important;
        margin: 16px auto !important;
        padding: 16px !important;
        background: linear-gradient(135deg, var(--primary) 0%, #e5a500 100%) !important;
        color: #000 !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        border: none !important;
        border-radius: 12px !important;
        cursor: pointer !important;
    }
}