/**
 * TXL Gen4 Design System - Forms
 * 
 * Composants de formulaires cohérents
 */

/* ============================================
   FORM GROUPS
   ============================================ */

.form-group {
    margin-bottom: var(--spacing-6);
}

.form-label {
    display: inline-block;
    margin-bottom: var(--spacing-2);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.form-label-required::after {
    content: " *";
    color: var(--color-error-500);
}

.form-help {
    display: block;
    margin-top: var(--spacing-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* ============================================
   INPUTS
   ============================================ */

.form-input,
.form-select,
.form-textarea {
    display: block;
    width: 100%;
    padding: var(--spacing-3) var(--spacing-4);
    font-family: var(--font-family-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    background-clip: padding-box;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: 0;
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--color-text-disabled);
    opacity: 1;
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
    background-color: var(--color-neutral-100);
    opacity: var(--opacity-60);
    cursor: not-allowed;
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* ============================================
   TAILLES D'INPUTS
   ============================================ */

.form-input-sm,
.form-select-sm {
    padding: var(--spacing-2) var(--spacing-3);
    font-size: var(--font-size-sm);
}

.form-input-lg,
.form-select-lg {
    padding: var(--spacing-4) var(--spacing-6);
    font-size: var(--font-size-lg);
}

/* ============================================
   ÉTATS DE VALIDATION
   ============================================ */

.form-input-success,
.form-select-success,
.form-textarea-success {
    border-color: var(--color-success-500);
}

.form-input-success:focus,
.form-select-success:focus,
.form-textarea-success:focus {
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.form-input-error,
.form-select-error,
.form-textarea-error {
    border-color: var(--color-error-500);
}

.form-input-error:focus,
.form-select-error:focus,
.form-textarea-error:focus {
    box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.1);
}

.form-feedback {
    display: block;
    margin-top: var(--spacing-2);
    font-size: var(--font-size-sm);
}

.form-feedback-success {
    color: var(--color-success-600);
}

.form-feedback-error {
    color: var(--color-error-600);
}

/* ============================================
   INPUT GROUPS
   ============================================ */

.input-group {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    width: 100%;
}

.input-group .form-input {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}

.input-group-prepend,
.input-group-append {
    display: flex;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: var(--spacing-3) var(--spacing-4);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-normal);
    color: var(--color-text-secondary);
    text-align: center;
    white-space: nowrap;
    background-color: var(--color-neutral-100);
    border: 1px solid var(--color-border);
}

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

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

.input-group-prepend + .form-input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.form-input + .input-group-append {
    margin-left: -1px;
}

.form-input + .input-group-append .input-group-text {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* ============================================
   CHECKBOXES & RADIOS
   ============================================ */

.form-check {
    position: relative;
    display: block;
    padding-left: var(--spacing-6);
    margin-bottom: var(--spacing-3);
}

.form-check-input {
    position: absolute;
    margin-top: 0.25rem;
    margin-left: calc(var(--spacing-6) * -1);
}

.form-check-input[type="checkbox"],
.form-check-input[type="radio"] {
    width: 1.25em;
    height: 1.25em;
    cursor: pointer;
    accent-color: var(--color-primary-500);
}

.form-check-label {
    display: inline-block;
    cursor: pointer;
    user-select: none;
}

.form-check-inline {
    display: inline-flex;
    align-items: center;
    padding-left: 0;
    margin-right: var(--spacing-6);
}

.form-check-inline .form-check-input {
    position: static;
    margin-top: 0;
    margin-right: var(--spacing-2);
    margin-left: 0;
}

/* Custom Checkboxes */
.custom-checkbox,
.custom-radio {
    position: relative;
    display: block;
    padding-left: var(--spacing-8);
    margin-bottom: var(--spacing-3);
}

.custom-checkbox input,
.custom-radio input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.custom-checkbox-indicator,
.custom-radio-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 1.25rem;
    height: 1.25rem;
    background-color: var(--color-surface);
    border: 2px solid var(--color-border);
    transition: all var(--transition-base);
}

.custom-checkbox-indicator {
    border-radius: var(--radius-sm);
}

.custom-radio-indicator {
    border-radius: 50%;
}

.custom-checkbox input:checked ~ .custom-checkbox-indicator,
.custom-radio input:checked ~ .custom-radio-indicator {
    background-color: var(--color-primary-500);
    border-color: var(--color-primary-500);
}

.custom-checkbox-indicator::after {
    content: "";
    position: absolute;
    display: none;
    left: 0.375rem;
    top: 0.125rem;
    width: 0.375rem;
    height: 0.625rem;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.custom-checkbox input:checked ~ .custom-checkbox-indicator::after {
    display: block;
}

.custom-radio-indicator::after {
    content: "";
    position: absolute;
    display: none;
    top: 50%;
    left: 50%;
    width: 0.5rem;
    height: 0.5rem;
    background: white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.custom-radio input:checked ~ .custom-radio-indicator::after {
    display: block;
}

/* ============================================
   SWITCH (Toggle)
   ============================================ */

.form-switch {
    position: relative;
    display: inline-block;
    width: 3rem;
    height: 1.5rem;
}

.form-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.form-switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-neutral-300);
    transition: var(--transition-base);
    border-radius: var(--radius-full);
}

.form-switch-slider::before {
    position: absolute;
    content: "";
    height: 1.125rem;
    width: 1.125rem;
    left: 0.1875rem;
    bottom: 0.1875rem;
    background-color: white;
    transition: var(--transition-base);
    border-radius: 50%;
}

.form-switch input:checked + .form-switch-slider {
    background-color: var(--color-primary-500);
}

.form-switch input:checked + .form-switch-slider::before {
    transform: translateX(1.5rem);
}

.form-switch input:focus + .form-switch-slider {
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/* ============================================
   SELECT CUSTOM
   ============================================ */

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M7 7l3 3 3-3' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--spacing-3) center;
    background-size: 1.5em 1.5em;
    padding-right: var(--spacing-10);
}

/* ============================================
   FILE INPUT
   ============================================ */

.form-file {
    position: relative;
    display: inline-block;
}

.form-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.form-file-label {
    display: inline-block;
    padding: var(--spacing-3) var(--spacing-6);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
}

.form-file-label:hover {
    background-color: var(--color-surface-hover);
}

.form-file-input:focus + .form-file-label {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

/* ============================================
   RANGE INPUT
   ============================================ */

.form-range {
    width: 100%;
    height: 1.5rem;
    padding: 0;
    background-color: transparent;
    appearance: none;
}

.form-range:focus {
    outline: 0;
}

.form-range::-webkit-slider-thumb {
    width: 1rem;
    height: 1rem;
    margin-top: -0.375rem;
    background-color: var(--color-primary-500);
    border: 0;
    border-radius: 50%;
    appearance: none;
    cursor: pointer;
    transition: background-color var(--transition-base);
}

.form-range::-webkit-slider-thumb:hover {
    background-color: var(--color-primary-600);
}

.form-range::-webkit-slider-runnable-track {
    width: 100%;
    height: 0.25rem;
    color: transparent;
    cursor: pointer;
    background-color: var(--color-neutral-200);
    border-color: transparent;
    border-radius: var(--radius-full);
}

.form-range::-moz-range-thumb {
    width: 1rem;
    height: 1rem;
    background-color: var(--color-primary-500);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color var(--transition-base);
}

.form-range::-moz-range-thumb:hover {
    background-color: var(--color-primary-600);
}

.form-range::-moz-range-track {
    width: 100%;
    height: 0.25rem;
    cursor: pointer;
    background-color: var(--color-neutral-200);
    border-color: transparent;
    border-radius: var(--radius-full);
}

/* ============================================
   FORM ROW & GRID
   ============================================ */

.form-row {
    display: flex;
    flex-wrap: wrap;
    margin-right: calc(var(--spacing-3) * -1);
    margin-left: calc(var(--spacing-3) * -1);
}

.form-row > .form-group {
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
    padding-right: var(--spacing-3);
    padding-left: var(--spacing-3);
}

.form-row > .col {
    flex: 1 0 0%;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-6);
}
