/**
 * TenderPipe Mobile Optimized Styles
 * 
 * Comprehensive mobile UX improvements for Pixel 7 Pro and other devices
 * Implements WCAG 2.1 AA accessibility standards
 * 
 * @package TenderPipe
 * @since   1.0.0
 */

/* ============================================
   BASE MOBILE STYLES
   ============================================ */

/* Ensure proper viewport behavior */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   TOUCH TARGET OPTIMIZATION
   ============================================ */

/* Minimum 48x48dp touch targets (WCAG 2.1 AA) */
.tp-delivery-card input[type="radio"] {
    width: 24px !important;
    height: 24px !important;
    margin-top: 4px !important;
    accent-color: #20a7c9;
    cursor: pointer;
    flex-shrink: 0;
}

.tp-delivery-label {
    min-height: 88px !important;
    padding: 20px 16px !important;
    display: flex !important;
    align-items: flex-start !important;
    gap: 14px !important;
    background: #eaf7fa;
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    -webkit-tap-highlight-color: rgba(32, 167, 201, 0.1);
}

/* Increase spacing between cards */
.tp-delivery-methods {
    display: grid;
    gap: 20px !important;
    margin-bottom: 24px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* ============================================
   TYPOGRAPHY & READABILITY
   ============================================ */

/* Improved text hierarchy */
.tp-step-title {
    font-size: 24px !important;
    font-weight: 700 !important;
    line-height: 1.3 !important;
    color: #1f2937 !important;
    margin-bottom: 12px !important;
}

.tp-step-description {
    font-size: 15px !important;
    line-height: 1.6 !important;
    color: #6b7280 !important;
    margin-bottom: 24px !important;
}

.tp-delivery-label h3 {
    font-size: 18px !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
    margin: 0 0 6px !important;
    color: #1f2937 !important;
}

.tp-delivery-label p {
	font-size: 14px !important;
	line-height: 1.5 !important;
	color: #4b5563 !important;
	margin: 0 !important;
}

/* Location step specific fixes - Base styles for all devices */
.tp-step-1 .tp-step-title {
	font-size: 24px !important;
	font-weight: 700 !important;
	color: #111827 !important;
}

.tp-step-1 .tp-step-description {
	font-size: 15px !important;
	color: #374151 !important;
	font-weight: 500 !important;
}

.tp-step-1 .tp-label {
	font-size: 15px !important;
	font-weight: 600 !important;
	color: #111827 !important;
}

.tp-step-1 .tp-select {
	width: 100% !important;
	max-width: 100% !important;
	font-size: 16px !important;
}

.tp-step-1 .tp-form-group {
	max-width: 100% !important;
}

/* Sources step specific fixes */
.tp-step-2 .tp-step-header {
	padding: 12px 0 16px !important;
	margin-bottom: 16px !important;
}

.tp-step-2 .tp-step-title {
	font-size: 24px !important;
	font-weight: 700 !important;
	color: #111827 !important;
	margin-bottom: 8px !important;
}

.tp-step-2 .tp-step-description {
	font-size: 15px !important;
	line-height: 1.5 !important;
	color: #374151 !important;
	font-weight: 500 !important;
}

/* ============================================
   ICON IMPROVEMENTS
   ============================================ */

.tp-delivery-icon {
    font-size: 32px !important;
    margin-bottom: 8px !important;
    display: block;
    line-height: 1;
}

/* ============================================
   BUTTON & NAVIGATION
   ============================================ */

/* WCAG compliant button sizes */
.tp-button {
    min-height: 48px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
    padding: 12px 24px !important;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.tp-button:active {
    transform: scale(0.98);
}

/* Safe area for buttons */
.tp-navigation-buttons {
    padding-bottom: max(20px, env(safe-area-inset-bottom)) !important;
}

.tp-navigation {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

/* ============================================
   FORM INPUT ENHANCEMENTS
   ============================================ */

/* Larger, more accessible inputs */
.tp-input,
.tp-select {
    min-height: 48px !important;
    font-size: 16px !important;
    padding: 12px 16px !important;
    border-radius: 8px !important;
    border: 2px solid #d1d5db !important;
    transition: all 0.2s ease;
    width: 100%;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.tp-input:focus,
.tp-select:focus {
    outline: 2px solid #2563eb !important;
    outline-offset: 2px !important;
    border-color: #2563eb !important;
}

/* Better placeholder visibility */
.tp-input::placeholder {
    color: #9ca3af !important;
    opacity: 1 !important;
}

/* Form group spacing - base styles */
.tp-label {
    font-size: 15px !important;
    font-weight: 600 !important;
    color: #374151 !important;
    display: block;
}

.tp-required {
    color: #dc2626 !important;
    margin-left: 4px;
}

.tp-optional {
    color: #6b7280 !important;
    font-weight: 400 !important;
    font-size: 14px !important;
}

.tp-help-text {
    font-size: 13px !important;
    color: #6b7280 !important;
    margin-top: 6px !important;
/* Delivery step specific fixes */
.tp-step-3 .tp-delivery-config {
	padding: 20px 16px !important;
	margin: 20px 0 !important;
}

.tp-step-3 .tp-form-group {
	margin-bottom: 20px !important;
}

.tp-step-3 .tp-input,
.tp-step-3 .tp-select {
	width: 100% !important;
	max-width: 100% !important;
	box-sizing: border-box !important;
}

.tp-step-3 .tp-label {
	font-size: 15px !important;
	font-weight: 600 !important;
	color: #111827 !important;
	margin-bottom: 8px !important;
}

    display: block;
    line-height: 1.5;
}

/* ============================================
   PROGRESS INDICATOR
   ============================================ */

.tp-progress-step {
    width: 44px !important;
    height: 44px !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.tp-progress-label {
    font-size: 13px !important;
    margin-top: 8px !important;
    font-weight: 500 !important;
    text-align: center;
}

.tp-progress-step.active {
    background: #2563eb !important;
    color: white !important;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2) !important;
}

.tp-progress-step.completed {
    background: #10b981 !important;
    color: white !important;
}

/* ============================================
   CARD INTERACTIONS
   ============================================ */

.tp-delivery-label:hover {
    border-color: #20a7c9 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
    transform: translateY(-2px);
}

.tp-delivery-label:active {
    transform: scale(0.98) !important;
    background: #dbeafe !important;
}

.tp-delivery-card input[type="radio"]:checked + .tp-delivery-content {
    /* Visual feedback when selected */
}

.tp-delivery-card input[type="radio"]:checked ~ .tp-delivery-label,
.tp-delivery-label:has(input[type="radio"]:checked) {
    border-color: #2563eb !important;
    background: #dbeafe !important;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.15) !important;
}

/* Fix text contrast in selected delivery card */
.tp-delivery-card input[type="radio"]:checked ~ .tp-delivery-label h3,
.tp-delivery-label:has(input[type="radio"]:checked) h3 {
    color: #111827 !important;
}

.tp-delivery-card input[type="radio"]:checked ~ .tp-delivery-label p,
.tp-delivery-label:has(input[type="radio"]:checked) p {
    color: #374151 !important;
}

/* ============================================
   UPGRADE BANNER OPTIMIZATION
   ============================================ */

.tp-upgrade-banner {
    padding: 12px 16px !important;
    font-size: 14px !important;
    border-radius: 8px !important;
    margin-bottom: 20px !important;
    background: #fef3c7 !important;
    border: 1px solid #fbbf24 !important;
    position: relative;
}

.tp-upgrade-banner a {
    font-weight: 600 !important;
    text-decoration: underline !important;
    color: #2563eb !important;
}

.tp-upgrade-banner .dismiss {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: #92400e;
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus indicators */
.tp-delivery-label:focus-within {
    outline: 3px solid #2563eb !important;
    outline-offset: 2px !important;
}

/* Skip to content link */
.tp-skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    z-index: 100;
}

.tp-skip-link:focus {
    top: 0;
}

/* Screen reader only text */
.tp-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================
   MOBILE-SPECIFIC LAYOUTS
   ============================================ */

@media (max-width: 768px) {
    /* ============================================
       AGGRESSIVE SPACE OPTIMIZATION FOR MOBILE
       Target: Fit all Step 1 content without scrolling
       ============================================ */
    
    /* Remove box shadow and reduce container padding */
    .tenderpipe-container {
        box-shadow: none !important;
        border-radius: 8px !important;
        padding: 16px !important;
    }
    
    /* Reduce progress container spacing */
    .tp-progress-container {
        margin-bottom: 20px !important;
    }
    
    /* Tighten step header spacing */
    .tp-step-header {
        padding: 8px 0 12px !important;
        margin-bottom: 16px !important;
    }
    
    /* Reduce step content bottom padding */
    .tp-step-content {
        padding-bottom: 16px !important;
        margin-bottom: 16px !important;
    }
    
    /* Optimize form group spacing */
    .tp-form-group {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 14px !important;
    }
    
    /* Tighten label spacing */
    .tp-label {
        margin-bottom: 6px !important;
    }
    
    /* Optimize select field height */
    .tp-select {
        min-height: 44px !important;
        padding: 10px 14px !important;
        padding-right: 40px !important;
    }
    
    /* Reduce navigation spacing */
    .tp-navigation {
        margin-top: 20px !important;
        padding-top: 16px !important;
    }
    
    /* Step 1 specific optimizations */
    .tp-step-1 .tp-step-header {
        padding: 8px 0 12px !important;
        margin-bottom: 14px !important;
    }
    
    .tp-step-1 .tp-step-title {
        margin-bottom: 6px !important;
        line-height: 1.2 !important;
    }
    
    .tp-step-1 .tp-step-description {
        margin-bottom: 0 !important;
        line-height: 1.4 !important;
    }
    
    .tp-step-1 .tp-form-group {
        margin-bottom: 14px !important;
    }
    
    .tp-step-1 .tp-label {
        margin-bottom: 6px !important;
    }
    
    /* Stack delivery methods vertically */
    .tp-delivery-methods {
        grid-template-columns: 1fr !important;
    }
    
    /* Adjust wizard container padding */
    .tp-wizard-container {
        padding-left: max(16px, env(safe-area-inset-left)) !important;
        padding-right: max(16px, env(safe-area-inset-right)) !important;
        padding-top: max(16px, env(safe-area-inset-top)) !important;
    }
    
    
    /* Adjust delivery config */
    .tp-delivery-config {
        max-width: 100% !important;
        margin: 20px 0 !important;
        padding: 16px !important;
    }
    
    /* Info box adjustments */
    .tp-info-box {
        padding: 12px !important;
        margin: 12px 0 !important;
    }
    
    .tp-info-box ol {
        padding-left: 20px !important;
    }
    
    /* Ensure selects don't overflow */
    .tp-select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Select2 specific fixes for mobile */
    .select2-container {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .select2-container .select2-selection {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
	
	/* Delivery step mobile fixes */
	.tp-step-3 .tp-delivery-config {
		padding: 16px !important;
		margin: 16px 0 !important;
	}
	
	.tp-step-3 .tp-input,
	.tp-step-3 .tp-select {
		width: 100% !important;
		max-width: 100% !important;
		box-sizing: border-box !important;
	}
	
	/* Error message styling */
	.tp-error-message {
		padding: 12px 16px !important;
		margin-top: 8px !important;
		background: #fee2e2 !important;
		border: 1px solid #fca5a5 !important;
		border-radius: 8px !important;
		font-size: 14px !important;
		line-height: 1.5 !important;
	}
    }
    
    .select2-container--default .select2-selection--single {
        min-height: 48px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .select2-dropdown {
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }
    
    /* Delivery step mobile fixes */
    .tp-step-3 .tp-delivery-config {
        padding: 16px !important;
        margin: 16px 0 !important;
    }
    
    .tp-step-3 .tp-input,
    .tp-step-3 .tp-select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Error message styling */
    .tp-error-message {
        padding: 12px 16px !important;
        margin-top: 8px !important;
        background: #fee2e2 !important;
        border: 1px solid #fca5a5 !important;
        border-radius: 8px !important;
        font-size: 14px !important;
        line-height: 1.5 !important;
    }
    
    .tp-info-box ol li {
        margin-bottom: 10px !important;
        line-height: 1.6 !important;
    }
}

/* Small devices (iPhone SE, etc.) */
@media (max-width: 375px) {
    .tp-step-title {
        font-size: 22px !important;
    }
    
    .tp-delivery-label h3 {
        font-size: 17px !important;
    }
    
    .tp-delivery-icon {
        font-size: 28px !important;
    }
}

/* Large devices (tablets in portrait) */
@media (min-width: 769px) and (max-width: 1024px) {
    .tp-delivery-methods {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .tp-step-content {
        padding-bottom: 80px !important;
    }
    
    .tp-step-header {
        padding: 12px 0 !important;
    }
    
    .tp-step-title {
        font-size: 20px !important;
        margin-bottom: 8px !important;
    }
    
    .tp-step-description {
        font-size: 14px !important;
        margin-bottom: 16px !important;
    }
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
    .tp-delivery-label {
        border-width: 3px !important;
    }
    
    .tp-input,
    .tp-select {
        border-width: 3px !important;
    }
    
    .tp-button {
        border: 3px solid currentColor !important;
    }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
    .tp-delivery-label {
        background: #1f2937 !important;
        color: #f9fafb !important;
    }
    
    .tp-delivery-label h3 {
        color: #f9fafb !important;
    }
    
    .tp-delivery-label p {
        color: #d1d5db !important;
    }
    
    .tp-input,
    .tp-select {
        background: #374151 !important;
        color: #f9fafb !important;
        border-color: #4b5563 !important;
    }
    
    .tp-step-title {
        color: #f9fafb !important;
    }
    
    .tp-step-description {
        color: #d1d5db !important;
    }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* Reduce layout shifts */
.tp-delivery-config {
    min-height: 200px;
}

/* Optimize animations */
.tp-delivery-label,
.tp-button {
    will-change: transform;
}

/* Prevent content jump */
img,
svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ============================================
   LOADING STATES
   ============================================ */

.tp-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.tp-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #2563eb;
    border-radius: 50%;
    border-top-color: transparent;
    animation: tp-spin 0.8s linear infinite;
}

@keyframes tp-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   ERROR STATES
   ============================================ */

.tp-input.error,
.tp-select.error {
    border-color: #dc2626 !important;
}

.tp-error-message {
    color: #dc2626 !important;
    font-size: 13px !important;
    margin-top: 6px !important;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tp-error-message::before {
    content: '⚠';
    font-size: 14px;
}

/* ============================================
   SUCCESS STATES
   ============================================ */

.tp-success-badge {
    background: #d1fae5 !important;
    color: #065f46 !important;
    padding: 12px 16px !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.tp-success-icon {
    font-size: 20px;
    color: #10b981;
}