/* Mobile-First Optimization for Pickleball Scheduler - Refined Version */

/* ===================================
   MOBILE-FIRST BASE STYLES
   =================================== */

/* Touch-friendly minimum sizes with proper contrast */
button, .btn, input[type="button"], input[type="submit"], .tab-btn {
    min-height: 44px; /* Apple's recommended minimum touch target */
    min-width: 44px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 16px; /* Prevents zoom on iOS */
    line-height: 1.4; /* Better readability */
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500; /* Ensure text is readable */
}

/* Input fields optimized for mobile with better contrast */
input[type="text"], input[type="email"], input[type="password"], 
input[type="number"], input[type="date"], input[type="time"], 
textarea, select {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    border: 1px solid #d1d5db; /* Softer border */
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    background-color: #ffffff;
    color: #1f2937; /* Ensure dark text on light background */
}

/* Enhanced focus states for accessibility */
input:focus, textarea:focus, select:focus, button:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* ===================================
   MOBILE NAVIGATION & HEADER
   =================================== */

/* Tab navigation optimization - keep original styles but ensure readability */
@media (max-width: 768px) {
    .tab-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .tab-container::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        flex-shrink: 0;
        white-space: nowrap;
        font-size: 14px;
        padding: 12px 16px;
        min-width: auto;
        color: #6b7280; /* Ensure readable gray */
    }

    .tab-btn.border-green-500 {
        color: #059669; /* Darker green for better contrast */
        border-bottom-color: #10b981;
    }
}

/* ===================================
   MOBILE LAYOUT & SPACING
   =================================== */

@media (max-width: 768px) {
    /* Container optimizations - don't override all containers */
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Responsive grid adjustments */
    .md\:grid-cols-2 {
        grid-template-columns: 1fr;
    }
    
    .md\:grid-cols-3 {
        grid-template-columns: 1fr;
    }
    
    .lg\:grid-cols-4 {
        grid-template-columns: 1fr;
    }

    /* Improve spacing on mobile */
    .space-x-4 > * + * {
        margin-left: 0.5rem;
    }

    .space-x-2 > * + * {
        margin-left: 0.25rem;
    }
}

/* ===================================
   MOBILE MODAL OPTIMIZATIONS
   =================================== */

/* Improve modals on mobile without making them full-screen */
@media (max-width: 640px) {
    .fixed.inset-0 .modal-content {
        margin: 20px;
        max-height: calc(100vh - 40px);
        width: calc(100% - 40px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-header {
        padding: 20px 16px 16px;
        text-align: center;
    }
    
    .modal-body {
        padding: 16px;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 16px;
    }

    /* Ensure modal content is readable */
    .modal-content {
        background-color: #ffffff;
        color: #1f2937;
    }

    .modal-content h2 {
        color: #1f2937;
        font-size: 1.5rem;
    }

    .modal-content p {
        color: #6b7280;
    }
}

/* ===================================
   MOBILE FORM OPTIMIZATIONS
   =================================== */

/* Form layout for mobile */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (min-width: 640px) {
    .form-row.sm\:flex-row {
        flex-direction: row;
    }
    
    .form-row.sm\:flex-row > * {
        flex: 1;
    }
}

/* Select dropdowns for mobile */
select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
}

/* ===================================
   MOBILE CARD COMPONENTS
   =================================== */

/* Improve existing cards on mobile without overriding */
@media (max-width: 768px) {
    .bg-white {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        border-radius: 8px;
        background-color: #ffffff;
    }

    /* Improve button readability in cards */
    .bg-green-600 {
        background-color: #059669 !important; /* Darker green for better contrast */
    }

    .bg-blue-600 {
        background-color: #1d4ed8 !important; /* Darker blue for better contrast */
    }

    .bg-red-600 {
        background-color: #dc2626 !important; /* Keep red as is */
    }

    .bg-yellow-600 {
        background-color: #d97706 !important; /* Darker yellow for better contrast */
    }

    /* Improve text readability in cards */
    .card-hover h3,
    .card-hover h4,
    .card-hover p {
        color: #1f2937;
    }

    /* Ensure icon visibility */
    .text-gray-500 i,
    .text-gray-400 i {
        color: #6b7280 !important;
    }

    /* Better button spacing */
    .space-x-2 > * + * {
        margin-left: 0.5rem;
    }

    .space-x-4 > * + * {
        margin-left: 1rem;
    }
}

/* ===================================
   MOBILE CALENDAR OPTIMIZATIONS
   =================================== */

.calendar-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.calendar-grid {
    min-width: 320px;
    display: grid;
    grid-template-columns: 80px repeat(7, 1fr);
    gap: 1px;
    background: #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.calendar-day-header {
    padding: 12px 8px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    background: #f9fafb;
}

.calendar-time-slot {
    padding: 8px 4px;
    font-size: 11px;
    text-align: center;
    background: #f9fafb;
    color: #6b7280;
}

.calendar-session {
    margin: 2px;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 10px;
    line-height: 1.2;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.calendar-session:active {
    transform: scale(0.95);
}

/* ===================================
   MOBILE TYPOGRAPHY
   =================================== */

/* Optimized typography for mobile readability */
@media (max-width: 768px) {
    body {
        font-size: 16px;
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        color: #1f2937; /* Ensure dark text for readability */
    }

    /* Don't override all headings globally, only improve mobile-specific ones */
    .text-3xl {
        font-size: 1.75rem; /* Smaller on mobile */
    }

    .text-2xl {
        font-size: 1.5rem;
    }

    .text-xl {
        font-size: 1.25rem;
    }

    /* Ensure text contrast */
    .text-gray-900 {
        color: #111827 !important;
    }

    .text-gray-800 {
        color: #1f2937 !important;
    }

    .text-gray-700 {
        color: #374151 !important;
    }

    .text-gray-600 {
        color: #4b5563 !important;
    }

    .text-gray-500 {
        color: #6b7280 !important;
    }
}

/* ===================================
   MOBILE UTILITIES
   =================================== */

/* Safe area handling for iOS */
.safe-area-top {
    padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

/* Scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Disable text selection on UI elements */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ===================================
   MOBILE ACCESSIBILITY
   =================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bg-white {
        border: 2px solid #000;
    }
    
    button {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Color consistency improvements */
@media (max-width: 768px) {
    /* Ensure consistent green theme */
    .text-green-600 {
        color: #059669 !important;
    }

    .text-green-500 {
        color: #10b981 !important;
    }

    .border-green-500 {
        border-color: #10b981 !important;
    }

    .bg-green-50 {
        background-color: #ecfdf5 !important;
    }

    /* Improve form field appearance */
    .focus\:ring-green-500:focus {
        --tw-ring-color: rgba(16, 185, 129, 0.5) !important;
    }

    .focus\:border-green-500:focus {
        border-color: #10b981 !important;
    }
}

/* Remove dark mode override to prevent readability issues */
/* Users can implement dark mode separately if needed */

/* ===================================
   MOBILE-SPECIFIC ANIMATIONS
   =================================== */

@keyframes mobileSlideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes mobileSlideDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

.mobile-slide-up {
    animation: mobileSlideUp 0.3s ease-out;
}

.mobile-slide-down {
    animation: mobileSlideDown 0.3s ease-in;
}

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

/* GPU acceleration for smooth scrolling */
.scroll-smooth {
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
}

/* Optimize repaints */
.transform-gpu {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize touch interactions */
.touch-action-manipulation {
    touch-action: manipulation;
}

button, .btn, .tab-btn {
    touch-action: manipulation;
}

/* ===================================
   CRITICAL READABILITY FIXES
   =================================== */

/* Ensure text remains readable on all backgrounds */
@media (max-width: 768px) {
    /* Fix any text that might be hard to read */
    .text-white {
        color: #ffffff !important;
    }

    /* Ensure sufficient contrast for status badges */
    .bg-green-100 {
        background-color: #dcfce7 !important;
    }

    .text-green-800 {
        color: #166534 !important;
    }

    .bg-yellow-100 {
        background-color: #fef3c7 !important;
    }

    .text-yellow-800 {
        color: #92400e !important;
    }

    .bg-red-100 {
        background-color: #fee2e2 !important;
    }

    .text-red-800 {
        color: #991b1b !important;
    }

    .bg-blue-100 {
        background-color: #dbeafe !important;
    }

    .text-blue-800 {
        color: #1e40af !important;
    }

    /* Ensure form labels are readable */
    label {
        color: #374151 !important;
        font-weight: 500;
    }

    /* Ensure error messages are visible */
    .text-red-600 {
        color: #dc2626 !important;
    }

    .bg-red-50 {
        background-color: #fef2f2 !important;
    }

    /* Ensure success messages are visible */
    .text-green-600 {
        color: #059669 !important;
    }

    .bg-green-50 {
        background-color: #f0fdf4 !important;
    }
}

/* ===================================
   MOBILE-SPECIFIC BUTTON IMPROVEMENTS
   =================================== */

@media (max-width: 768px) {
    /* Improve button contrast and readability */
    button:not(.bg-transparent):not(.border-transparent) {
        font-weight: 500;
        border: 1px solid transparent;
    }

    .bg-green-600:hover {
        background-color: #047857 !important;
    }

    .bg-blue-600:hover {
        background-color: #1e40af !important;
    }

    .bg-red-600:hover {
        background-color: #b91c1c !important;
    }

    /* Ensure button text is always readable */
    .bg-green-600, .bg-blue-600, .bg-red-600, .bg-yellow-600 {
        color: #ffffff !important;
    }

    /* Improve secondary button appearance */
    .border-gray-300 {
        border-color: #d1d5db !important;
        background-color: #ffffff !important;
        color: #374151 !important;
    }

    .border-gray-300:hover {
        border-color: #9ca3af !important;
        background-color: #f9fafb !important;
    }
}