/**
 * Forms Component
 * 
 * Form elements and layouts
 */

/* ==========================================================================
   Base Form Styles
   ========================================================================== */
form {
    margin: 0;
}

fieldset {
    margin: 0 0 var(--space-lg);
    padding: var(--space-lg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

legend {
    padding: 0 var(--space-sm);
    font-weight: 600;
}

label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: 500;
    color: var(--text-color);
}

/* ==========================================================================
   Form Controls
   ========================================================================== */

/* Text inputs */
input[type="text"],
input[type="email"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="password"],
input[type="search"],
textarea,
select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Focus state */
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--color-bg-accent, rgba(0, 134, 123, 0.1));
}

/* Disabled state */
input:disabled,
textarea:disabled,
select:disabled {
    background-color: var(--light-gray);
    color: var(--text-light);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Invalid state */
input:invalid,
textarea:invalid,
select:invalid {
    border-color: var(--error-color);
}

input:invalid:focus,
textarea:invalid:focus,
select:invalid:focus {
    border-color: var(--error-color);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Placeholder */
::placeholder {
    color: var(--color-text-secondary, var(--text-light));
    opacity: 1;
}

/* Textarea */
textarea {
    min-height: 120px;
    resize: vertical;
}

/* Select */
select {
    padding-right: var(--space-2xl);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23374151' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-md) center;
    background-size: 12px;
}

/* Number input arrows */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    height: auto;
}

/* Search input */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

/* ==========================================================================
   Checkboxes and Radio Buttons
   ========================================================================== */

/* Container */
.form-check {
    display: flex;
    align-items: flex-start;
    margin-bottom: var(--space-sm);
}

/* Input */
input[type="checkbox"],
input[type="radio"] {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 2px;
    margin-right: var(--space-sm);
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    transition: all var(--transition-base);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
}

input[type="checkbox"] {
    border-radius: var(--radius-sm);
}

input[type="radio"] {
    border-radius: 50%;
}

/* Checked state */
input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    display: block;
    text-align: center;
    color: white;
    font-weight: bold;
    line-height: 16px;
}

input[type="radio"]:checked::after {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    margin: 4px;
    background-color: white;
    border-radius: 50%;
}

/* Focus state */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 134, 123, 0.2);
}

/* Label */
.form-check-label {
    font-weight: 400;
    margin-bottom: 0;
    cursor: pointer;
}

/* ==========================================================================
   Form Layouts
   ========================================================================== */

/* Form Group */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-group:last-child {
    margin-bottom: 0;
}

/* Form Row */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.form-col {
    flex: 1;
    min-width: 200px;
}

/* Inline Form */
.form-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-md);
}

.form-inline .form-group {
    margin-bottom: 0;
}

.form-inline label {
    margin-bottom: var(--space-xs);
}

/* ==========================================================================
   Form Components
   ========================================================================== */

/* Input Group */
.input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.input-group input {
    flex: 1;
    border-radius: 0;
}

.input-group input:first-child {
    border-top-left-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-md);
}

.input-group input:last-child {
    border-top-right-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background-color: var(--light-gray);
    border: 1px solid var(--border-color);
    color: var(--text-light);
}

.input-group-text:first-child {
    border-right: 0;
    border-top-left-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-md);
}

.input-group-text:last-child {
    border-left: 0;
    border-top-right-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

/* Form Help Text */
.form-text {
    margin-top: var(--space-xs);
    font-size: 0.875rem;
    color: var(--text-light);
}

/* Form Error */
.form-error {
    margin-top: var(--space-xs);
    font-size: 0.875rem;
    color: var(--error-color);
}

/* Form Success */
.form-success {
    margin-top: var(--space-xs);
    font-size: 0.875rem;
    color: var(--success-color);
}

/* ==========================================================================
   File Upload
   ========================================================================== */

.file-upload {
    position: relative;
    display: inline-block;
    cursor: pointer;
    width: 100%;
}

.file-upload input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    background-color: var(--light-gray);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    text-align: center;
    transition: all var(--transition-base);
}

.file-upload:hover .file-upload-label {
    border-color: var(--primary-color);
    background-color: rgba(0, 134, 123, 0.05);
}

.file-upload-icon {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-sm);
    color: var(--text-light);
}

.file-upload-text {
    font-size: 0.95rem;
    color: var(--text-light);
}

/* ==========================================================================
   Range Slider
   ========================================================================== */

input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--light-gray);
    border-radius: var(--radius-full);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-base);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--shadow-md);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all var(--transition-base);
}

/* ==========================================================================
   Toggle Switch
   ========================================================================== */

.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
}

.toggle-switch-label {
    position: relative;
    width: 48px;
    height: 24px;
    background-color: var(--border-color);
    border-radius: var(--radius-full);
    transition: background-color var(--transition-base);
}

.toggle-switch-label::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: white;
    border-radius: 50%;
    transition: transform var(--transition-base);
}

.toggle-switch input:checked + .toggle-switch-label {
    background-color: var(--primary-color);
}

.toggle-switch input:checked + .toggle-switch-label::after {
    transform: translateX(24px);
}

.toggle-switch-text {
    margin-left: var(--space-sm);
}

/* ==========================================================================
   Form Validation States
   ========================================================================== */

.is-valid {
    border-color: var(--success-color);
}

.is-valid:focus {
    border-color: var(--success-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.is-invalid {
    border-color: var(--error-color);
}

.is-invalid:focus {
    border-color: var(--error-color);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* ==========================================================================
   Contact Form 7 Styles
   ========================================================================== */

.wpcf7 form {
    margin: 0;
}

.wpcf7-form-control-wrap {
    display: block;
    margin-bottom: var(--space-lg);
}

.wpcf7-not-valid-tip {
    display: block;
    margin-top: var(--space-xs);
    font-size: 0.875rem;
    color: var(--error-color);
}

.wpcf7-response-output {
    margin: var(--space-lg) 0;
    padding: var(--space-md);
    border-radius: var(--radius-md);
}

.wpcf7-mail-sent-ok {
    background-color: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--success-color);
    color: var(--success-color);
}

.wpcf7-mail-sent-ng,
.wpcf7-aborted,
.wpcf7-spam-blocked,
.wpcf7-validation-errors {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    color: var(--error-color);
}

/* ==========================================================================
   Responsive Forms
   ========================================================================== */

@media (max-width: 768px) {
    /* Stack form rows on mobile */
    .form-row {
        flex-direction: column;
    }
    
    .form-col {
        width: 100%;
    }
    
    /* Full width inline forms */
    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-inline > * {
        width: 100%;
    }
    
    /* Larger touch targets */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
    }
    
    /* iOS zoom prevention */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px;
    }
}