/* Checkout Form Accessibility and Compatibility Styles */

/* Cross-browser compatibility */
.checkout-form {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;

    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Map container with fallback */
.map-container {
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);

    width: -webkit-fill-available;
    width: -moz-available;
    width: stretch;
    width: 100%;
}

/* Loading spinner with cross-browser support */
.spinner {
    -webkit-animation: spin 1s linear infinite;
    -moz-animation: spin 1s linear infinite;
    -o-animation: spin 1s linear infinite;
    animation: spin 1s linear infinite;
}

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

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

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

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

/* Form validation styling */
.form-field:focus {
    outline: 3px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
}

/* Custom scrollbar for better UX */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.5) transparent;

    scrollbar-gutter: stable;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.5);
    border-radius: 4px;
}

/* Accessibility improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-field {
        border-width: 2px;
    }

    .btn {
        border-width: 2px;
        font-weight: bold;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
    }

    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    .map-container {
        flex-direction: column;
    }

    .map-mini {
        max-width: 100%;
        margin-top: 1rem;
    }

    .form-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .form-buttons > * {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    /* Make map buttons stack vertically on mobile */
    .map-container > div:first-child {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Adjust map type buttons for mobile */
    [role="group"] {
        gap: 0.25rem;
    }

    /* Stack form fields vertically on mobile */
    .grid.grid-cols-1.md\\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    /* Improve touch targets */
    .map-type-btn {
        min-height: 40px;
        padding: 0.5rem 0.75rem;
    }

    /* Optimize text size for mobile */
    .checkout-form h1 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    .checkout-form h2 {
        font-size: 1.25rem;
        line-height: 1.4;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1023px) {
    .map-container {
        flex-direction: row;
        align-items: flex-start;
    }

    .map-mini {
        max-width: 50%;
    }

    /* Optimize map size for tablets */
    #delivery-map {
        height: 250px !important;
        min-height: 250px !important;
    }

    #delivery-map .leaflet-container {
        height: 250px !important;
    }

    /* Two-column layout for form fields */
    .grid.grid-cols-1.md\\:grid-cols-2 {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    /* Horizontal button layout */
    .form-buttons {
        flex-direction: row;
        justify-content: space-between;
    }
}

/* Large screen optimizations */
@media (min-width: 1024px) {
    .checkout-form {
        max-width: none;
    }

    /* Side-by-side layout for large screens */
    .checkout-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 2rem;
        align-items: start;
    }

    /* Larger map on desktop */
    #delivery-map {
        height: 300px !important;
        min-height: 300px !important;
    }

    #delivery-map .leaflet-container {
        height: 300px !important;
    }

    /* Better button layout for desktop */
    .form-buttons {
        justify-content: space-between;
        align-items: center;
    }

    /* Optimize form field widths */
    .form-field {
        transition: all 0.2s ease;
    }

    .form-field:hover {
        border-color: rgba(59, 130, 246, 0.3);
    }
}

/* Extra large screens */
@media (min-width: 1280px) {
    .checkout-form {
        margin: 0 auto;
        padding: 2rem;
    }

    /* Even larger map for XL screens */
    #delivery-map {
        height: 400px !important;
        min-height: 400px !important;
    }

    #delivery-map .leaflet-container {
        height: 400px !important;
    }
}
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .form-field {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Print styles */
@media print {
    .map-container,
    .btn[type="button"] {
        display: none !important;
    }

    .form-field {
        border: 1px solid #000 !important;
        background: white !important;
    }
}

/* Leaflet map specific fixes */
#delivery-map {
    height: 200px !important;
    min-height: 200px !important;
    width: 100% !important;
}

#delivery-map .leaflet-container {
    height: 200px !important;
    width: 100% !important;
}

.leaflet-control-container {
    display: none; /* Hide default controls for better UX */
}

/* Button group accessibility */
[role="group"] button {
    position: relative;
}

[role="group"] button:focus {
    z-index: 1;
}

/* Error message styling */
[role="alert"] {
    border-left: 4px solid currentColor;
}

/* Loading state styling */
[aria-live="polite"] {
    min-height: 1.25rem;
}
