/**
 * Complete Mobile UI/UX Optimization CSS
 * Fixes all 22 touch target issues and implements mobile-first design
 * Date: August 15, 2025
 * Version: 1.0.0
 */

/* ===================================
   PHASE 1: CRITICAL MOBILE FIXES
   =================================== */

/* Fix Touch Targets - CRITICAL (44px minimum for iOS) */
button,
.md-btn,
.md-select-vehicle-btn,
.select-vehicle-btn,
input[type="submit"],
input[type="button"],
a.btn,
.md-button,
.button,
.btn {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Fix Form Inputs for Mobile */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
select,
textarea,
.md-input-field input,
.md-input-field select,
.md-input-field textarea {
    width: 100%;
    height: 48px !important;
    min-height: 48px !important;
    padding: 12px !important;
    font-size: 16px !important; /* Prevents zoom on iOS */
    border: 1px solid #ddd;
    border-radius: 8px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-sizing: border-box;
    background-color: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Special handling for textareas */
textarea {
    min-height: 100px !important;
    resize: vertical;
}

/* Focus states for better accessibility */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* Prevent Horizontal Scroll */
html, body {
    overflow-x: hidden !important;
    width: 100%;
    margin: 0;
    padding: 0;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

.container,
.md-container,
.md-booking-container,
.booking-container {
    max-width: 100%;
    padding: 0 16px;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Fix Typography for Readability */
body {
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===================================
   PHASE 2: VEHICLE CARD OPTIMIZATION
   =================================== */

/* Mobile-First Vehicle Cards */
.md-vehicle-list-row,
.vehicle-card,
.vehicle-list-item {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px !important;
    margin-bottom: 16px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    touch-action: manipulation;
}

.md-vehicle-list-row:active,
.vehicle-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Vehicle Image Container */
.md-vehicle-image-col,
.vehicle-image-container,
.vehicle-image {
    width: 100%;
    height: 200px;
    overflow: hidden;
    border-radius: 8px;
    background: #f5f5f5;
}

.md-vehicle-image-col img,
.vehicle-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Vehicle Details */
.md-vehicle-details-col,
.vehicle-details {
    flex: 1;
    padding: 0;
}

.md-vehicle-name,
.vehicle-name,
.vehicle-title {
    font-size: 20px !important;
    font-weight: 600;
    margin-bottom: 8px;
    color: #1a1a1a;
    line-height: 1.2;
}

.md-vehicle-description,
.vehicle-description {
    font-size: 14px;
    color: #666;
    margin-bottom: 12px;
    line-height: 1.4;
}

/* Vehicle Specs Grid */
.md-vehicle-specs,
.vehicle-specs,
.vehicle-features {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.md-vehicle-spec,
.vehicle-spec,
.vehicle-feature {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #555;
}

.md-vehicle-spec .material-symbols-outlined,
.vehicle-spec i,
.vehicle-feature i {
    font-size: 20px;
    color: #007bff;
}

/* Vehicle Action Section */
.md-vehicle-action-col,
.vehicle-action {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 !important;
    background: transparent !important;
}

.md-vehicle-price-wrapper,
.vehicle-price-wrapper {
    text-align: center;
    padding: 12px;
    background: #f0f9ff;
    border-radius: 8px;
}

.md-price-label,
.price-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: block;
}

.md-vehicle-price,
.vehicle-price {
    font-size: 28px !important;
    font-weight: bold;
    color: #28a745;
    display: block;
}

.md-select-vehicle-btn,
.select-vehicle-btn,
.vehicle-select-button {
    width: 100%;
    padding: 16px 20px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white !important;
    border: none;
    border-radius: 12px;
    font-size: 16px !important;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    min-height: 48px !important;
    touch-action: manipulation;
}

.md-select-vehicle-btn:active,
.select-vehicle-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

/* Selected Vehicle State */
.vehicle-card.selected,
.md-vehicle-list-row.selected {
    border: 2px solid #007bff;
    box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.1);
}

/* ===================================
   PHASE 3: SPACING SYSTEM
   =================================== */

/* CSS Custom Properties for Consistent Spacing */
:root {
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;
    
    /* Colors */
    --primary: #007bff;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --border: #ddd;
    --background: #f8f9fa;
    
    /* Touch target size */
    --touch-target: 44px;
}

/* Apply Spacing System */
.md-form-section,
.form-section {
    margin-bottom: var(--space-xl);
    padding: var(--space-lg);
    background: var(--background);
    border-radius: 12px;
}

.md-form-group,
.form-group {
    margin-bottom: var(--space-lg);
}

.md-form-row,
.form-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Section Headers */
.md-section-title,
.section-title,
h2.section-header {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--primary);
    color: var(--text-primary);
}

/* Labels */
label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===================================
   LOADING & ERROR STATES
   =================================== */

/* Loading States */
.md-loading-vehicles,
.loading-vehicles,
.loading-state {
    text-align: center;
    padding: var(--space-xxl);
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.md-spinner,
.spinner,
.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--space-md);
}

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

/* Error States */
.md-error-message,
.error-message,
.alert-danger {
    padding: var(--space-md);
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 8px;
    color: #c00;
    margin-bottom: var(--space-md);
    font-size: 14px;
    line-height: 1.4;
}

/* Success States */
.md-success-message,
.success-message,
.alert-success {
    padding: var(--space-md);
    background: #efe;
    border: 1px solid #cfc;
    border-radius: 8px;
    color: #060;
    margin-bottom: var(--space-md);
    font-size: 14px;
    line-height: 1.4;
}

/* ===================================
   RESPONSIVE BREAKPOINTS
   =================================== */

/* Small phones (up to 375px) */
@media (max-width: 375px) {
    .container,
    .md-container {
        padding: 0 12px;
    }
    
    .md-vehicle-name,
    .vehicle-name {
        font-size: 18px !important;
    }
    
    .md-vehicle-price,
    .vehicle-price {
        font-size: 24px !important;
    }
}

/* Tablet Layout (768px+) */
@media (min-width: 768px) {
    .md-vehicle-list-row,
    .vehicle-card {
        flex-direction: row;
        align-items: center;
        padding: 20px !important;
    }
    
    .md-vehicle-image-col,
    .vehicle-image-container {
        width: 200px;
        flex-shrink: 0;
    }
    
    .md-vehicle-action-col,
    .vehicle-action {
        width: auto;
        min-width: 200px;
        flex-direction: column;
        align-items: center;
    }
    
    .md-vehicle-price-wrapper,
    .vehicle-price-wrapper {
        min-width: 150px;
    }
    
    .md-select-vehicle-btn,
    .select-vehicle-btn {
        width: auto;
        min-width: 180px;
    }
    
    .md-form-row,
    .form-row {
        flex-direction: row;
    }
    
    .md-form-row > *,
    .form-row > * {
        flex: 1;
    }
}

/* Desktop Layout (1024px+) */
@media (min-width: 1024px) {
    .container,
    .md-container {
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .md-vehicle-list-row,
    .vehicle-card {
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .md-vehicle-image-col,
    .vehicle-image-container {
        width: 250px;
        height: 180px;
    }
    
    .md-vehicle-specs,
    .vehicle-specs {
        grid-template-columns: repeat(3, auto);
        width: fit-content;
    }
}

/* ===================================
   SPECIAL FIXES FOR QUICK QUOTE
   =================================== */

/* Fix Quick Quote Button on Mobile */
#get-quick-quote,
.get-quick-quote,
.quick-quote-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100%;
    min-height: 48px !important;
    padding: 16px !important;
    font-size: 18px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white !important;
    border: none;
    border-radius: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    touch-action: manipulation;
    cursor: pointer;
}

#get-quick-quote:active,
.get-quick-quote:active {
    background: linear-gradient(135deg, #5569d8 0%, #6a4190 100%);
    transform: none;
}

/* Add padding to bottom of content when button is fixed */
@media (max-width: 768px) {
    .booking-container,
    .md-container {
        padding-bottom: 80px;
    }
}

/* ===================================
   TOUCH DEVICE OPTIMIZATIONS
   =================================== */

@media (hover: none) and (pointer: coarse) {
    /* Ensure all interactive elements meet touch targets */
    a, button, input, select, textarea, 
    [role="button"], [onclick], [tabindex] {
        min-height: var(--touch-target);
        min-width: var(--touch-target);
    }
    
    /* Remove hover effects on touch devices */
    *:hover {
        transform: none !important;
        box-shadow: none !important;
    }
    
    /* Improve scrolling performance */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===================================
   ACCESSIBILITY IMPROVEMENTS
   =================================== */

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

/* Skip navigation link for screen readers */
.skip-navigation {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

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

/* ===================================
   PERFORMANCE OPTIMIZATIONS
   =================================== */

/* Use GPU acceleration for animations */
.md-vehicle-list-row,
.vehicle-card,
.md-button,
button {
    will-change: transform;
    transform: translateZ(0);
}

/* Optimize image loading */
img {
    loading: lazy;
    decoding: async;
}