/**
 * Mobile Forms Optimization
 * Enhanced form inputs and controls for mobile devices
 */

/* Base form improvements for touch */
@media (max-width: 968px) {
    /* Increase touch targets */
    .form-input,
    .form-select,
    textarea,
    select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="time"] {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 16px;
        border-radius: 8px;
        border-width: 2px;
    }
    
    /* Better focus states */
    .form-input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 4px var(--link-bg-alpha);
        outline: none;
    }
    
    /* Larger labels */
    .form-label {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 8px;
        display: block;
    }
    
    /* Form groups spacing */
    .form-group {
        margin-bottom: 24px;
    }
    
    /* Checkbox and radio improvements */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        margin-right: 12px;
        flex-shrink: 0;
        cursor: pointer;
    }
    
    /* Labels for checkboxes/radios */
    label:has(input[type="checkbox"]),
    label:has(input[type="radio"]) {
        display: flex;
        align-items: flex-start;
        cursor: pointer;
        padding: 8px 0;
        font-size: 16px;
        line-height: 1.5;
    }
    
    /* Select dropdown improvements */
    select {
        appearance: none;
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23333' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 16px center;
        padding-right: 40px;
    }
    
    /* Textarea improvements */
    textarea {
        min-height: 120px;
        resize: vertical;
        line-height: 1.5;
    }
    
    /* Button spacing in forms */
    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin-top: 32px;
    }
    
    .form-actions .btn {
        width: 100%;
        justify-content: center;
        font-size: 16px;
        padding: 14px 24px;
        font-weight: 600;
    }
    
    /* File upload areas */
    .file-upload-area {
        min-height: 120px;
        border: 2px dashed var(--border-color);
        border-radius: 12px;
        padding: 20px;
        text-align: center;
    }
    
    .upload-prompt {
        font-size: 16px;
    }
    
    /* Form hints and errors */
    .form-hint,
    .form-error,
    small {
        font-size: 14px;
        margin-top: 6px;
        display: block;
        line-height: 1.4;
    }
    
    /* Inline form elements */
    .form-row {
        flex-direction: column;
        gap: 24px;
    }
    
    .form-row .form-group {
        width: 100%;
        margin-bottom: 0;
    }
    
    /* Date inputs - native on mobile */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        position: relative;
    }
    
    /* Number input spinners */
    input[type="number"] {
        -moz-appearance: textfield;
    }
    
    input[type="number"]::-webkit-inner-spin-button,
    input[type="number"]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
        height: 44px;
        width: 44px;
        cursor: pointer;
    }
    
    /* Password visibility toggle */
    .password-field-wrapper {
        position: relative;
    }
    
    .password-toggle {
        position: absolute;
        right: 12px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: var(--text-light);
        cursor: pointer;
        padding: 8px;
        font-size: 20px;
    }
    
    /* Floating labels for better UX */
    .floating-label-group {
        position: relative;
        margin-bottom: 24px;
    }
    
    .floating-label-group input:focus + label,
    .floating-label-group input:not(:placeholder-shown) + label {
        transform: translateY(-24px) scale(0.85);
        color: var(--primary-color);
    }
    
    .floating-label-group label {
        position: absolute;
        left: 16px;
        top: 14px;
        transition: all 0.2s ease;
        pointer-events: none;
        color: var(--text-light);
    }
    
    /* Search inputs */
    input[type="search"] {
        -webkit-appearance: none;
        padding-left: 44px;
    }
    
    .search-wrapper {
        position: relative;
    }
    
    .search-icon {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-light);
    }
    
    /* Form section headers */
    .form-section {
        margin-bottom: 32px;
        padding: 20px;
        background: var(--bg-surface);
        border-radius: 12px;
        box-shadow: var(--shadow-sm);
    }
    
    .form-section h3 {
        font-size: 20px;
        margin-bottom: 20px;
        color: var(--primary-color);
    }
    
    /* Progress indicators for multi-step forms */
    .form-progress {
        display: flex;
        justify-content: space-between;
        margin-bottom: 32px;
        padding: 0;
        list-style: none;
    }
    
    .form-progress li {
        flex: 1;
        text-align: center;
        position: relative;
        font-size: 14px;
    }
    
    /* Autocomplete suggestions */
    .autocomplete-suggestions {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-surface);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: var(--shadow-md);
        max-height: 200px;
        overflow-y: auto;
        z-index: 100;
    }
    
    .autocomplete-suggestion {
        padding: 12px 16px;
        cursor: pointer;
        font-size: 16px;
    }
    
    .autocomplete-suggestion:hover {
        background: var(--bg-color);
    }
    
    /* Toggle switches */
    .toggle-switch {
        position: relative;
        display: inline-block;
        width: 60px;
        height: 32px;
    }
    
    .toggle-switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }
    
    .toggle-slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: var(--border-default);
        transition: .4s;
        border-radius: 34px;
    }
    
    .toggle-slider:before {
        position: absolute;
        content: "";
        height: 24px;
        width: 24px;
        left: 4px;
        bottom: 4px;
        background-color: white;
        transition: .4s;
        border-radius: 50%;
    }
    
    input:checked + .toggle-slider {
        background-color: var(--primary-color);
    }
    
    input:checked + .toggle-slider:before {
        transform: translateX(28px);
    }
    
    /* Accessibility improvements */
    .form-input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        outline: 3px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    /* Loading states */
    .form-input.loading {
        background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 3.5A6.5 6.5 0 0 0 3.5 10 .75.75 0 0 1 2 10a8 8 0 1 1 8 8 .75.75 0 0 1 0-1.5A6.5 6.5 0 0 0 10 3.5z' fill='%23666' fill-rule='evenodd'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 10 10' to='360 10 10' dur='1s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 44px;
    }
    
    /* Validation states */
    .form-input.is-valid {
        border-color: var(--success-color);
        padding-right: 44px;
        background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%2338a169' fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
    }
    
    .form-input.is-invalid {
        border-color: var(--error-color);
        padding-right: 44px;
        background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23e53e3e' fill-rule='evenodd' d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
    }
}

/* Smaller mobile devices */
@media (max-width: 480px) {
    .form-input,
    select,
    textarea {
        font-size: 16px; /* Ensure no zoom on iOS */
        padding: 10px 14px;
    }
    
    .form-section {
        padding: 16px;
        margin-bottom: 24px;
    }
    
    .form-actions {
        gap: 10px;
        margin-top: 24px;
    }
    
    .form-actions .btn {
        padding: 12px 20px;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 968px) and (orientation: landscape) {
    .form-container {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .form-section {
        padding: 16px;
    }
    
    .form-group {
        margin-bottom: 16px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .form-input,
    select,
    textarea {
        background-color: var(--bg-surface-dark);
        color: var(--text-primary-dark);
        border-color: var(--border-default-dark);
    }
    
    .form-input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--link-dark);
        box-shadow: 0 0 0 4px var(--link-bg-alpha);
    }
    
    .form-section {
        background: var(--bg-card-dark);
    }
}