/* ========================================
   Mobile Deep Optimization - Enhanced Mobile Experience
   ======================================== */

/* ========================================
   1. Base Mobile Setup - Touch-Friendly
   ======================================== */

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    touch-action: manipulation;
}

body {
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
}

/* Prevent zoom on form elements */
input,
select,
textarea {
    font-size: 16px !important;
}

/* ========================================
   2. Mobile Header & Navigation
   ======================================== */

@media (max-width: 768px) {
    .site-header {
        padding: 0;
    }
    
    .header-main {
        padding: 8px 0;
    }
    
    .mobile-menu-toggle {
        width: 44px;
        height: 44px;
        padding: 10px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        cursor: pointer;
        touch-action: manipulation;
        border-radius: 8px;
        transition: background 0.2s ease;
    }
    
    .mobile-menu-toggle:active {
        background: rgba(0, 0, 0, 0.05);
    }
    
    .mobile-menu-toggle span {
        width: 24px;
        height: 2px;
        background: var(--text-primary);
        transition: all 0.3s ease;
        border-radius: 2px;
    }
    
    .mobile-menu-toggle.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    
    .mobile-menu-toggle.active span:nth-child(2) {
        opacity: 0;
    }
    
    .mobile-menu-toggle.active span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
    }
    
    /* Mobile Navigation Panel */
    .mobile-nav-panel {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: var(--bg-white);
        z-index: 1001;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }
    
    .mobile-nav-panel.open {
        left: 0;
    }
    
    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-nav-overlay.show {
        opacity: 1;
        visibility: visible;
    }
    
    /* Support for existing .mobile-nav class from header.php */
    .mobile-nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: var(--bg-white);
        z-index: 1001;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }
    
    .mobile-nav.active {
        left: 0;
    }
    
    .mobile-nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .mobile-nav-header {
        padding: 20px;
        border-bottom: 1px solid var(--border-light);
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--bg-light);
    }
    
    .mobile-nav-close {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        cursor: pointer;
        transition: background 0.2s ease;
    }
    
    .mobile-nav-close:active {
        background: rgba(0, 0, 0, 0.05);
    }
    
    .mobile-nav-menu {
        padding: 16px 0;
    }
    
    .mobile-nav-menu a {
        display: flex;
        align-items: center;
        padding: 16px 24px;
        color: var(--text-primary);
        font-size: 16px;
        font-weight: 500;
        text-decoration: none;
        transition: all 0.2s ease;
        border-left: 3px solid transparent;
    }
    
    .mobile-nav-menu a:active {
        background: var(--bg-light);
    }
    
    .mobile-nav-menu a.current {
        background: rgba(229, 57, 53, 0.05);
        border-left-color: var(--primary-color);
        color: var(--primary-color);
    }
    
    .mobile-nav-divider {
        height: 1px;
        background: var(--border-light);
        margin: 16px 24px;
    }
    
    .mobile-nav-actions {
        padding: 20px;
        border-top: 1px solid var(--border-light);
    }
    
    .mobile-nav-actions .btn {
        width: 100%;
        justify-content: center;
        margin-bottom: 12px;
    }
}

/* ========================================
   3. Mobile Vehicle Cards - Optimized Layout
   ======================================== */

@media (max-width: 768px) {
    .vehicle-card,
    .model-card {
        border-radius: 12px;
        margin-bottom: 16px;
    }
    
    .vehicle-card-image,
    .model-image {
        height: 180px;
    }
    
    .vehicle-card-content {
        padding: 16px;
    }
    
    .vehicle-brand {
        font-size: 11px;
        margin-bottom: 4px;
    }
    
    .vehicle-title {
        font-size: 18px;
        margin-bottom: 8px;
        line-height: 1.25;
    }
    
    .vehicle-specs {
        gap: 0.4rem;
        margin-bottom: 0.5rem;
    }
    
    .spec-item {
        padding: 0.15rem 0.45rem;
        font-size: 0.72rem;
        border-radius: 3px;
    }
    
    .spec-icon {
        width: 16px;
        height: 16px;
    }
    
    .vehicle-price-area {
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    .vehicle-price-value {
        font-size: 1.1rem;
    }
    
    .vehicle-price {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }
    
    .vehicle-price::before {
        display: none;
    }
    
    /* Compact card variant for lists */
    .vehicle-card-compact {
        display: flex;
        gap: 12px;
        padding: 12px;
    }
    
    .vehicle-card-compact .vehicle-card-image {
        width: 120px;
        height: 90px;
        border-radius: 8px;
        flex-shrink: 0;
    }
    
    .vehicle-card-compact .vehicle-card-content {
        padding: 0;
        flex: 1;
        min-width: 0;
    }
    
    .vehicle-card-compact .vehicle-title {
        font-size: 15px;
        margin-bottom: 4px;
    }
    
    .vehicle-card-compact .vehicle-price {
        font-size: 18px;
        margin-bottom: 0;
    }
}

@media (max-width: 480px) {
    .vehicle-card-image,
    .model-image {
        height: 160px;
    }
    
    .vehicle-card-content {
        padding: 12px;
    }
    
    .vehicle-title {
        font-size: 16px;
    }
    
    .vehicle-price {
        font-size: 1rem;
    }
}

/* ========================================
   4. Mobile Touch & Interaction Optimizations
   ======================================== */

/* Touch targets - minimum 44px */
button,
a,
input[type="checkbox"],
input[type="radio"],
select {
    min-height: 44px;
    min-width: 44px;
}

/* Buttons - optimized for touch */
.btn {
    min-height: 48px;
    padding: 12px 24px;
    font-size: 16px;
}

.btn-sm {
    min-height: 40px;
    padding: 8px 16px;
    font-size: 14px;
}

.btn-lg {
    min-height: 56px;
    padding: 16px 32px;
    font-size: 18px;
}

/* Active states for touch */
.btn:active {
    transform: scale(0.96);
}

/* Form inputs - touch friendly */
.form-control,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
textarea,
select {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 8px;
}

textarea {
    min-height: 100px;
    padding-top: 12px;
}

/* Checkboxes & Radios */
input[type="checkbox"],
input[type="radio"] {
    width: 24px;
    height: 24px;
}

input[type="checkbox"] + label,
input[type="radio"] + label {
    padding-left: 12px;
    font-size: 16px;
    line-height: 24px;
    cursor: pointer;
}

/* ========================================
   5. Mobile Hero Section
   ======================================== */

@media (max-width: 768px) {
    .hero-modern {
        min-height: 480px;
        padding: 100px 16px 60px;
    }
    
    .hero-title-lg {
        font-size: 28px;
        line-height: 1.2;
        margin-bottom: 16px;
    }
    
    .hero-subtitle-lg {
        font-size: 15px;
        line-height: 1.6;
        margin-bottom: 32px;
        padding: 0 8px;
    }
    
    .hero-cta-buttons {
        display: flex;
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }
    
    .hero-cta-buttons .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .hero-modern {
        min-height: 420px;
        padding: 90px 12px 50px;
    }
    
    .hero-title-lg {
        font-size: 24px;
    }
    
    .hero-subtitle-lg {
        font-size: 14px;
    }
}

/* ========================================
   6. Mobile Grid & Layout
   ======================================== */

@media (max-width: 768px) {
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .section {
        padding: 48px 0;
    }
    
    .section-header {
        margin-bottom: 32px;
        text-align: left;
        padding: 0 4px;
    }
    
    .section-title {
        font-size: 24px;
        margin-bottom: 8px;
    }
    
    .section-title::after {
        left: 0;
        transform: translateX(0);
        width: 60px;
        height: 3px;
    }
    
    .section-subtitle {
        font-size: 15px;
        margin-top: 12px;
        text-align: left;
    }
    
    /* Grid adjustments */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .grid-2-mobile {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .section {
        padding: 40px 0;
    }
    
    .section-title {
        font-size: 22px;
    }
    
    .grid-2-mobile {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   7. Mobile Filter & Search
   ======================================== */

@media (max-width: 768px) {
    .filter-box {
        padding: 16px;
        margin-bottom: 20px;
        border-radius: 12px;
    }
    
    .filter-toggle-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 12px 16px;
        background: var(--bg-white);
        border: 2px solid var(--border-light);
        border-radius: 8px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        margin-bottom: 12px;
    }
    
    .filter-toggle-btn:active {
        background: var(--bg-light);
    }
    
    .filter-toggle-btn.active {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }
    
    .filter-content {
        display: none;
        padding-top: 16px;
        border-top: 1px solid var(--border-light);
    }
    
    .filter-content.show {
        display: block;
    }
    
    .filter-group {
        margin-bottom: 16px;
    }
    
    .filter-group:last-child {
        margin-bottom: 0;
    }
    
    .filter-group label {
        font-size: 13px;
        margin-bottom: 8px;
    }
    
    .filter-select,
    .filter-group select {
        padding: 12px 16px;
        font-size: 16px;
        border-radius: 8px;
    }
    
    .filter-actions {
        display: flex;
        gap: 12px;
        margin-top: 20px;
        padding-top: 16px;
        border-top: 1px solid var(--border-light);
    }
    
    .filter-actions .btn {
        flex: 1;
    }
}

/* ========================================
   8. Mobile Footer
   ======================================== */

@media (max-width: 768px) {
    .site-footer {
        padding: 48px 0 24px;
    }
    
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 32px;
    }
    
    .footer-col {
        text-align: center;
    }
    
    .footer-col h4 {
        font-size: 16px;
        margin-bottom: 16px;
    }
    
    .footer-menu {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px 16px;
    }
    
    .footer-menu a {
        font-size: 14px;
        padding: 4px 0;
    }
    
    .footer-menu a:hover {
        transform: none;
    }
    
    .footer-social-section {
        padding: 24px;
        margin-top: 32px;
    }
    
    .social-links {
        display: flex;
        justify-content: center;
        gap: 12px;
    }
    
    .social-link {
        width: 52px;
        height: 52px;
        border-radius: 12px;
    }
    
    .social-link:hover {
        transform: none;
    }
    
    .footer-bottom {
        padding-top: 24px;
        margin-top: 32px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        text-align: center;
    }
    
    .footer-bottom p {
        font-size: 13px;
    }
}

/* ========================================
   9. Mobile Floating Actions
   ======================================== */

@media (max-width: 768px) {
    .whatsapp-float {
        width: 56px;
        height: 56px;
        bottom: 20px;
        right: 16px;
        box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
    }
    
    .whatsapp-float::after {
        content: '';
        position: absolute;
        top: -2px;
        left: -2px;
        right: -2px;
        bottom: -2px;
        border-radius: 50%;
        border: 2px solid rgba(37, 211, 102, 0.3);
        animation: pulse 2s ease-out infinite;
    }
    
    @keyframes pulse {
        0% {
            transform: scale(0.9);
            opacity: 1;
        }
        100% {
            transform: scale(1.4);
            opacity: 0;
        }
    }
    
    .back-to-top {
        width: 44px;
        height: 44px;
        bottom: 88px;
        right: 16px;
    }
    
    /* Quick actions bar */
    .mobile-quick-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-white);
        border-top: 1px solid var(--border-light);
        padding: 8px 16px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 997;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    }
    
    .mobile-quick-action {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 8px 12px;
        border-radius: 8px;
        color: var(--text-secondary);
        font-size: 11px;
        font-weight: 500;
        text-decoration: none;
        transition: all 0.2s ease;
        min-width: 60px;
    }
    
    .mobile-quick-action:active {
        background: var(--bg-light);
    }
    
    .mobile-quick-action.active {
        color: var(--primary-color);
    }
    
    .mobile-quick-action svg {
        width: 24px;
        height: 24px;
    }
    
    /* Add padding for quick actions bar */
    body.has-mobile-quick-actions {
        padding-bottom: 70px;
    }
}

/* ========================================
   10. Mobile Single Vehicle Page
   ======================================== */

@media (max-width: 768px) {
    .single-vehicle-hero {
        padding-top: 80px;
        padding-bottom: 32px;
    }
    
    .vehicle-gallery {
        grid-template-columns: 1fr;
        gap: 16px;
        margin-bottom: 24px;
    }
    
    .main-vehicle-image {
        border-radius: 12px;
    }
    
    .thumbnail-gallery {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .thumbnail-item {
        border-radius: 8px;
        border-width: 2px;
    }
    
    .vehicle-details-sidebar {
        position: static;
        padding: 20px;
        border-radius: 12px;
        margin-top: 24px;
    }
    
    .price-display {
        font-size: 32px;
        margin-bottom: 20px;
    }
    
    .inquiry-form-section {
        padding: 20px;
        border-radius: 12px;
        margin-top: 24px;
    }
    
    /* Sticky CTA bar for mobile */
    .mobile-sticky-cta {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-white);
        border-top: 1px solid var(--border-light);
        padding: 12px 16px;
        display: flex;
        gap: 12px;
        z-index: 996;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-sticky-cta .btn {
        flex: 1;
        min-height: 48px;
    }
    
    body.has-sticky-cta {
        padding-bottom: 80px;
    }
}

/* ========================================
   11. Mobile Performance Optimizations
   ======================================== */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Lazy loading placeholders */
.lazy-image {
    background: var(--bg-gray);
    position: relative;
    overflow: hidden;
}

.lazy-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    100% {
        left: 100%;
    }
}

/* Optimize for different network speeds */
@media (slow) {
    .hero-modern {
        background: var(--bg-dark);
    }
}

/* ========================================
   12. Mobile Accessibility
   ======================================== */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    z-index: 1002;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-light: #000000;
        --text-secondary: #000000;
    }
}

/* ========================================
   13. Tablet Specific Optimizations
   ======================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .hero-modern {
        min-height: 580px;
    }
    
    .hero-title-lg {
        font-size: 36px;
    }
}

/* ========================================
   14. Landscape Mobile Optimizations
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .hero-modern {
        min-height: 360px;
        padding-top: 80px;
        padding-bottom: 40px;
    }
    
    .hero-title-lg {
        font-size: 24px;
    }
    
    .section {
        padding: 32px 0;
    }
    
    .vehicle-card-image,
    .model-image {
        height: 140px;
    }
}

/* ========================================
   15. Large Mobile (Phablet) Optimizations
   ======================================== */

@media (min-width: 481px) and (max-width: 768px) {
    .grid-2-mobile {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .vehicle-card-image,
    .model-image {
        height: 200px;
    }
}

/* ========================================
   16. Safe Area for Modern iPhones
   ======================================== */

@supports (padding-top: env(safe-area-inset-top)) {
    .site-header {
        padding-top: env(safe-area-inset-top);
    }
    
    .mobile-nav-panel {
        padding-top: env(safe-area-inset-top);
    }
    
    .mobile-sticky-cta,
    .mobile-quick-actions {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .whatsapp-float {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    .back-to-top {
        bottom: calc(88px + env(safe-area-inset-bottom));
    }
}

/* Ensure header-actions correct order: Search → Language → Menu */
.header-actions{display:flex !important;flex-direction:row !important;align-items:center !important;gap:12px !important;justify-content:flex-end !important;position:relative !important;z-index:99998 !important}
.header-actions .search-toggle{order:1 !important;display:flex !important;align-items:center !important;justify-content:center !important;pointer-events:auto !important;position:relative !important;z-index:99999 !important}
.header-actions .header-language{order:2 !important;display:flex !important;align-items:center !important;pointer-events:auto !important;position:relative !important;z-index:99999 !important}
.header-actions .mobile-menu-toggle{order:3 !important;display:flex !important;flex-direction:column !important;align-items:center !important;justify-content:center !important;gap:5px !important;pointer-events:auto !important;position:relative !important;z-index:99999 !important}
