/**
 * FaceBuilder Form Styles
 * Based on @tailwindcss/forms plugin
 * Clean HTML, automatic styling - just write <input>, get styled
 * Override with Tailwind classes when needed
 */

/* ==========================================================================
   Form Layout
   ========================================================================== */

.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Labels
   ========================================================================== */

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151; /* gray-700 */
    margin-bottom: 0.375rem;
}

/* Inline labels for checkbox/radio */
label.inline-flex {
    display: inline-flex;
    font-weight: 400;
    margin-bottom: 0;
}

/* ==========================================================================
   Text Inputs, Textarea, Select
   ========================================================================== */

[type='text'],
[type='email'],
[type='url'],
[type='password'],
[type='number'],
[type='date'],
[type='datetime-local'],
[type='month'],
[type='search'],
[type='tel'],
[type='time'],
[type='week'],
[multiple],
textarea,
select {
    display: block;
    width: 100%;
    appearance: none;
    background-color: #fff;
    border: 1px solid #d1d5db; /* gray-300 */
    border-radius: 0.5rem; /* rounded-lg */
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #111827; /* gray-900 */
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Focus state */
[type='text']:focus,
[type='email']:focus,
[type='url']:focus,
[type='password']:focus,
[type='number']:focus,
[type='date']:focus,
[type='datetime-local']:focus,
[type='month']:focus,
[type='search']:focus,
[type='tel']:focus,
[type='time']:focus,
[type='week']:focus,
[multiple]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #3b82f6; /* blue-500 */
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Placeholder */
::placeholder {
    color: #9ca3af; /* gray-400 */
    opacity: 1;
}

/* ==========================================================================
   Select
   ========================================================================== */

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 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
    print-color-adjust: exact;
}

select[multiple] {
    background-image: none;
    padding-right: 0.75rem;
}

/* ==========================================================================
   Checkbox & Radio
   ========================================================================== */

[type='checkbox'],
[type='radio'] {
    appearance: none;
    padding: 0;
    print-color-adjust: exact;
    display: inline-block;
    vertical-align: middle;
    background-origin: border-box;
    user-select: none;
    flex-shrink: 0;
    height: 1.125rem;
    width: 1.125rem;
    color: #3b82f6; /* blue-500 */
    background-color: #fff;
    border: 1px solid #d1d5db; /* gray-300 */
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

[type='checkbox'] {
    border-radius: 0.25rem;
}

[type='radio'] {
    border-radius: 100%;
}

/* Checked state */
[type='checkbox']:checked,
[type='radio']:checked {
    border-color: transparent;
    background-color: currentColor;
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
}

[type='checkbox']:checked {
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
}

[type='radio']:checked {
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e");
}

/* Focus state */
[type='checkbox']:focus,
[type='radio']:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Indeterminate checkbox */
[type='checkbox']:indeterminate {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");
    border-color: transparent;
    background-color: currentColor;
}

/* ==========================================================================
   File Input
   ========================================================================== */

[type='file'] {
    display: block;
    width: 100%;
    font-size: 0.875rem;
    color: #6b7280; /* gray-500 */
    cursor: pointer;
    background-color: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: 0.5rem;
}

[type='file']::file-selector-button {
    margin-right: 0.75rem;
    padding: 0.375rem 0.75rem;
    border: 0;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    background-color: #3b82f6;
    cursor: pointer;
    transition: background-color 0.15s;
}

[type='file']::file-selector-button:hover {
    background-color: #2563eb;
}

[type='file']:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* ==========================================================================
   Range Input
   ========================================================================== */

[type='range'] {
    width: 100%;
    height: 0.5rem;
    appearance: none;
    background: #e5e7eb; /* gray-200 */
    border-radius: 9999px;
    cursor: pointer;
}

[type='range']::-webkit-slider-thumb {
    appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

[type='range']::-moz-range-thumb {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

[type='range']:focus {
    outline: none;
}

[type='range']:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

/* ==========================================================================
   Help Text / Hints
   ========================================================================== */

.form-hint {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: #6b7280; /* gray-500 */
}

/* ==========================================================================
   Disabled State
   ========================================================================== */

input:disabled,
textarea:disabled,
select:disabled {
    cursor: not-allowed;
    background-color: #f3f4f6; /* gray-100 */
    opacity: 0.7;
}

[type='checkbox']:disabled,
[type='radio']:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* ==========================================================================
   Validation States
   ========================================================================== */

/* Invalid */
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown),
select:invalid {
    border-color: #ef4444; /* red-500 */
}

input:invalid:not(:placeholder-shown):focus,
textarea:invalid:not(:placeholder-shown):focus,
select:invalid:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Error message */
.form-error {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: #ef4444; /* red-500 */
}

/* Success */
.form-success {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: #10b981; /* green-500 */
}

/* ==========================================================================
   Button (Submit)
   ========================================================================== */

button[type='submit'],
input[type='submit'] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
    background-color: #3b82f6; /* blue-500 */
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
}

button[type='submit']:hover,
input[type='submit']:hover {
    background-color: #2563eb; /* blue-600 */
}

button[type='submit']:active,
input[type='submit']:active {
    transform: scale(0.98);
}

button[type='submit']:focus,
input[type='submit']:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

button[type='submit']:disabled,
input[type='submit']:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Reset button */
button[type='reset'],
input[type='reset'] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: #374151;
    background-color: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.15s;
}

button[type='reset']:hover,
input[type='reset']:hover {
    background-color: #e5e7eb;
}

/* ==========================================================================
   Form Layout Utilities (can be overridden by Tailwind)
   ========================================================================== */

.space-y-2 > * + * {
    margin-top: 0.5rem;
}

.space-y-4 > * + * {
    margin-top: 1rem;
}

.space-y-6 > * + * {
    margin-top: 1.5rem;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 0.75rem;
}

.items-center {
    align-items: center;
}

.inline-flex {
    display: inline-flex;
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    /* Labels */
    label {
        color: #d1d5db; /* gray-300 */
    }
    
    /* Text inputs, textarea, select */
    [type='text'],
    [type='email'],
    [type='url'],
    [type='password'],
    [type='number'],
    [type='date'],
    [type='datetime-local'],
    [type='month'],
    [type='search'],
    [type='tel'],
    [type='time'],
    [type='week'],
    [multiple],
    textarea,
    select {
        background-color: #1f2937; /* gray-800 */
        border-color: #4b5563; /* gray-600 */
        color: #f9fafb; /* gray-50 */
    }
    
    /* Focus state dark */
    [type='text']:focus,
    [type='email']:focus,
    [type='url']:focus,
    [type='password']:focus,
    [type='number']:focus,
    [type='date']:focus,
    [type='datetime-local']:focus,
    [type='month']:focus,
    [type='search']:focus,
    [type='tel']:focus,
    [type='time']:focus,
    [type='week']:focus,
    [multiple]:focus,
    textarea:focus,
    select:focus {
        border-color: #60a5fa; /* blue-400 */
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
    }
    
    /* Placeholder dark */
    ::placeholder {
        color: #6b7280; /* gray-500 */
    }
    
    /* Select arrow dark */
    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='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    }
    
    /* Checkbox & Radio dark */
    [type='checkbox'],
    [type='radio'] {
        background-color: #1f2937;
        border-color: #4b5563;
    }
    
    [type='checkbox']:focus,
    [type='radio']:focus {
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
    }
    
    /* File input dark */
    [type='file'] {
        color: #9ca3af;
        background-color: #1f2937;
        border-color: #4b5563;
    }
    
    [type='file']::file-selector-button {
        background-color: #3b82f6;
    }
    
    [type='file']::file-selector-button:hover {
        background-color: #60a5fa;
    }
    
    /* Range dark */
    [type='range'] {
        background: #374151;
    }
    
    /* Disabled dark */
    input:disabled,
    textarea:disabled,
    select:disabled {
        background-color: #374151;
    }
    
    /* Form hint dark */
    .form-hint {
        color: #9ca3af;
    }
    
    /* Error message dark */
    .form-error {
        color: #f87171; /* red-400 */
    }
    
    /* Success dark */
    .form-success {
        color: #34d399; /* green-400 */
    }
    
    /* Submit button dark */
    button[type='submit'],
    input[type='submit'] {
        background-color: #3b82f6;
    }
    
    button[type='submit']:hover,
    input[type='submit']:hover {
        background-color: #60a5fa;
    }
    
    button[type='submit']:focus,
    input[type='submit']:focus {
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.4);
    }
    
    /* Reset button dark */
    button[type='reset'],
    input[type='reset'] {
        color: #d1d5db;
        background-color: #374151;
        border-color: #4b5563;
    }
    
    button[type='reset']:hover,
    input[type='reset']:hover {
        background-color: #4b5563;
    }
}

/* ==========================================================================
   Explicit Dark Mode Classes (for manual control)
   ========================================================================== */

.dark label {
    color: #d1d5db;
}

.dark [type='text'],
.dark [type='email'],
.dark [type='url'],
.dark [type='password'],
.dark [type='number'],
.dark [type='date'],
.dark [type='datetime-local'],
.dark [type='month'],
.dark [type='search'],
.dark [type='tel'],
.dark [type='time'],
.dark [type='week'],
.dark [multiple],
.dark textarea,
.dark select {
    background-color: #1f2937;
    border-color: #4b5563;
    color: #f9fafb;
}

.dark [type='checkbox'],
.dark [type='radio'] {
    background-color: #1f2937;
    border-color: #4b5563;
}

.dark .form-hint {
    color: #9ca3af;
}

/* ==========================================================================
   Tailwind CSS Forms Plugin Classes (form-input, form-select, etc.)
   These work with both Tailwind utility classes and standalone
   ========================================================================== */

.form-input,
.form-textarea,
.form-select,
.form-multiselect {
    appearance: none;
    background-color: #fff;
    border-color: #d1d5db;
    border-width: 1px;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus,
.form-multiselect:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-checkbox,
.form-radio {
    appearance: none;
    padding: 0;
    display: inline-block;
    vertical-align: middle;
    background-origin: border-box;
    user-select: none;
    flex-shrink: 0;
    color: #3b82f6;
    background-color: #fff;
    border-color: #d1d5db;
    border-width: 1px;
}

.form-checkbox {
    border-radius: 0.25rem;
}

.form-radio {
    border-radius: 100%;
}

.form-checkbox:checked,
.form-radio:checked {
    border-color: transparent;
    background-color: currentColor;
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
}

.form-checkbox:checked {
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
}

.form-radio:checked {
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e");
}

.form-checkbox:focus,
.form-radio:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
