/**
 * Forms Module CSS
 * Styles for form elements, inputs, and form layouts
 */

/* Form Container */
.form-container {
    max-width: 600px;
    margin: 0 auto;
}

.form-container.wide {
    max-width: 800px;
}

.form-container.narrow {
    max-width: 400px;
}

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

.form-group label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.form-group .help-text {
    margin-top: var(--spacing-xs);
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
}

/* Form Row (Horizontal Layout) */
.form-row {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

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

/* MD Outlined Text Field Customizations */
md-outlined-text-field {
    width: 100%;
    --md-outlined-text-field-container-shape: var(--md-sys-shape-corner-small);
}

md-outlined-text-field[type="textarea"] {
    --md-outlined-text-field-container-shape: var(--md-sys-shape-corner-small);
}

/* Native Input Styling (fallback) */
.md-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-small);
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    font-size: 16px;
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-sizing: border-box;
}

.md-input:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

.md-input:disabled {
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    cursor: not-allowed;
}

.md-input::placeholder {
    color: var(--md-sys-color-on-surface-variant);
}

/* Textarea */
textarea.md-input {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

/* Select Dropdown */
.md-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-small);
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%235f6368' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

[data-theme="dark"] .md-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23c4c7c5' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
}

.md-select:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

/* Checkbox & Radio Groups */
.checkbox-group,
.radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.checkbox-group.horizontal,
.radio-group.horizontal {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.checkbox-item,
.radio-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* File Input */
.file-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

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

.file-input-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-lg);
    border: 2px dashed var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-medium);
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface-variant);
    transition: all var(--transition-fast);
    text-align: center;
}

.file-input-label:hover {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.file-input-label.dragover {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

.form-actions.center {
    justify-content: center;
}

.form-actions.spread {
    justify-content: space-between;
}

/* Error States */
.form-group.error .md-input,
.form-group.error .md-select {
    border-color: var(--md-sys-color-error);
}

.form-group.error .md-input:focus,
.form-group.error .md-select:focus {
    box-shadow: 0 0 0 2px var(--md-sys-color-error-container);
}

.error-message {
    color: var(--md-sys-color-error);
    font-size: 12px;
    margin-top: var(--spacing-xs);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.error-message md-icon {
    font-size: 16px;
}

/* Success States */
.form-group.success .md-input {
    border-color: var(--md-sys-color-success);
}

/* Required Field Indicator */
.required::after {
    content: " *";
    color: var(--md-sys-color-error);
}

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

.form-inline .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}

/* Search Form */
.search-form {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.search-form .md-input {
    flex: 1;
    border-radius: var(--md-sys-shape-corner-extra-large);
    padding-left: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%235f6368' d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

[data-theme="dark"] .search-form .md-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23c4c7c5' d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E");
}

/* Responsive */
@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
    }
    
    .form-row .form-group {
        min-width: 100%;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions md-filled-button,
    .form-actions md-outlined-button,
    .form-actions md-text-button {
        width: 100%;
    }
    
    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }
}
