/* Mobile-Specific Fixes for iOS Safari and Chrome */

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix for iOS Safari button clicks */
    button, .btn, input[type="submit"], input[type="button"] {
        cursor: pointer;
        -webkit-appearance: none;
        appearance: none;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Fix for iOS Safari form inputs */
    input, textarea, select {
        -webkit-appearance: none;
        appearance: none;
        -webkit-border-radius: 16px;
        border-radius: 16px;
    }
}

/* General mobile fixes */
@media (max-width: 768px) {
    /* Ensure buttons are large enough for touch */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        touch-action: manipulation;
    }
    
    /* Fix for login form */
    .login-form, .register-form {
        padding: 20px;
        margin: 10px;
    }
    
    .login-form .form-control, 
    .register-form .form-control {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 48px;
        padding: 12px 16px;
        -webkit-appearance: none;
        appearance: none;
        border-radius: 16px;
    }
    
    /* Fix for slot selection */
    .time-slot {
        min-height: 44px;
        min-width: 44px;
        padding: 8px 12px;
        margin: 4px;
        font-size: 14px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }
    
    .time-slot:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }
    
    /* Fix for navbar toggle */
    .navbar-toggler {
        min-height: 44px;
        min-width: 44px;
        padding: 8px;
        border: none;
        background: transparent;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .navbar-toggler:focus {
        box-shadow: none;
        outline: none;
    }
    
    /* Fix for modal buttons */
    .modal .btn {
        min-height: 44px;
        margin: 4px 0;
    }
    
    /* Fix for card interactions */
    .card {
        margin-bottom: 16px;
    }
    
    .card-body {
        padding: 16px;
    }
    
    /* Fix for form groups */
    .form-group {
        margin-bottom: 16px;
    }
    
    /* Fix for dropdown menus */
    .dropdown-menu {
        min-width: 200px;
        font-size: 16px;
    }
    
    .dropdown-item {
        padding: 12px 16px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    /* Fix for tables on mobile */
    .table-responsive {
        font-size: 14px;
    }
    
    .table td, .table th {
        padding: 8px;
        vertical-align: middle;
    }

    /* Owner pricing rules: avoid horizontal scroll by stacking rows */
    .pricing-schedule-table {
        table-layout: fixed;
        width: 100%;
    }

    .pricing-schedule-table thead {
        display: none;
    }

    .pricing-schedule-table,
    .pricing-schedule-table tbody,
    .pricing-schedule-table tr,
    .pricing-schedule-table td {
        display: block;
        width: 100%;
    }

    .pricing-schedule-table tr {
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 12px;
        margin-bottom: 12px;
        overflow: hidden;
    }

    .pricing-schedule-table td {
        display: flex;
        gap: 10px;
        justify-content: space-between;
        align-items: center;
        padding: 10px 12px;
        border: 0;
        min-width: 0;
    }

    .pricing-schedule-table td::before {
        content: attr(data-label);
        color: rgba(255, 255, 255, 0.65);
        font-weight: 600;
        font-size: 12px;
        flex: 0 0 auto;
        max-width: 44%;
    }

    .pricing-schedule-table td > * {
        min-width: 0;
    }

    .pricing-schedule-table .badge {
        max-width: 100%;
        white-space: normal;
        word-break: break-word;
    }

    .pricing-schedule-table .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Fix for checkout page */
    .checkout-summary {
        position: sticky;
        top: 20px;
        margin-bottom: 20px;
    }
    
    /* Fix for hold slot modal */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100vw - 20px);
    }
    
    .modal-content {
        border-radius: 18px;
    }
    
    .modal-header, .modal-body, .modal-footer {
        padding: 16px;
    }
    
    /* Fix for bottom navigation */
    @media (max-width: 768px) {
        .bottom-nav {
            display: flex !important;
            box-sizing: border-box;
            align-items: center;
            justify-content: space-around;
            height: 68px;
            min-height: 68px;
            max-height: 68px;
            contain: layout paint;
            opacity: 1 !important;
            visibility: visible !important;
            transition: none !important;
        }

        body.ios-app .bottom-nav {
            height: 70px;
            min-height: 70px;
            max-height: 70px;
        }

        body.android-app .bottom-nav {
            height: 76px;
            min-height: 76px;
            max-height: 76px;
        }
    }
    
    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: none !important;
    }

    @media (max-width: 768px) {
        body.app-shell .modal-dialog {
            margin-bottom: calc(10px + var(--turfio-nav-bottom, 0px));
        }
        body.app-shell .modal-footer {
            padding-bottom: calc(16px + var(--turfio-nav-bottom, 0px));
        }
    }

    @media (max-width: 768px) {
        body.keyboard-open {
            padding-bottom: 0 !important;
        }

        body.keyboard-open .bottom-nav,
        body.keyboard-open .owner-bottom-nav {
            bottom: calc(8px + min(var(--turfio-nav-bottom, 0px), 56px)) !important;
        }
    }
    
    /* Fix for search filters */
    .filter-section {
        padding: 16px;
        margin-bottom: 16px;
    }
    
    .filter-section .btn-group {
        width: 100%;
    }
    
    .filter-section .btn-group .btn {
        flex: 1;
    }
    
    /* Fix for turf cards */
    .turf-card {
        margin-bottom: 16px;
        border-radius: 18px;
        overflow: hidden;
    }
    
    .turf-card .card-img-top {
        height: 200px;
        object-fit: cover;
    }
    
    /* Fix for booking steps */
    .booking-steps {
        padding: 16px;
        margin-bottom: 16px;
    }
    
    .step {
        padding: 12px;
        margin: 8px 0;
        border-radius: 16px;
    }
    
    /* Fix for payment section */
    .payment-methods {
        padding: 16px;
    }
    
    .payment-method {
        padding: 12px;
        margin: 8px 0;
        border: 1px solid rgba(255,255,255,0.12);
        border-radius: 16px;
        cursor: pointer;
        touch-action: manipulation;
    }
    
    .payment-method.selected {
        border-color: #007bff;
        background-color: rgba(0, 123, 255, 0.1);
    }
    
    /* Fix for alerts and toasts */
    .alert {
        margin: 10px;
        padding: 12px 16px;
        border-radius: 16px;
    }
    
    .toast {
        min-width: 280px;
        max-width: calc(100vw - 20px);
        margin: 10px;
    }
    
    /* Fix for loading states */
    .loading-spinner {
        width: 40px;
        height: 40px;
        border: 4px solid #f3f3f3;
        border-top: 4px solid #007bff;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Fix for date picker */
    .datepicker {
        font-size: 16px;
    }
    
    .datepicker input {
        font-size: 16px;
        min-height: 44px;
    }
    
    /* Fix for time slots grid */
    .time-slots-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 8px;
        padding: 16px;
    }
    
    /* 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;
    }
    
    /* Focus indicators for keyboard navigation */
    .btn:focus,
    .form-control:focus,
    .time-slot:focus {
        outline: 2px solid #007bff;
        outline-offset: 2px;
    }
    
    /* Dark mode adjustments for mobile */
    [data-mdb-theme="dark"] .bottom-nav {
        background: rgba(22, 22, 24, 0.82);
        border-color: rgba(255, 255, 255, 0.12);
    }
    
    [data-mdb-theme="dark"] .bottom-nav-item {
        color: rgba(255, 255, 255, 0.62);
    }
    
    [data-mdb-theme="dark"] .bottom-nav-item.active {
        color: #ffffff;
    }
    
    [data-mdb-theme="dark"] .payment-method {
        border-color: #404040;
        background-color: #2d2d2d;
    }
    
    [data-mdb-theme="dark"] .payment-method.selected {
        border-color: #00ff88;
        background-color: rgba(0, 255, 136, 0.1);
    }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .btn {
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .time-slot {
        font-size: 12px;
        padding: 6px 8px;
        min-width: 60px;
    }
    
    .modal-dialog {
        margin: 5px;
        max-width: calc(100vw - 10px);
    }
    
    .card-body {
        padding: 12px;
    }
}
