/**
 * CNPERP Component Library - Forms & Inputs
 */

/* ============================================ */
/* FORM CONTAINER */
/* ============================================ */

.form {
    max-width: 100%;
}

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

.form-section {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-color);
}

.form-section:last-child {
    border-bottom: none;
}

.form-section-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-4);
    color: var(--text-primary);
}

/* ============================================ */
/* FORM LABELS */
/* ============================================ */

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

label.required::after {
    content: ' *';
    color: var(--danger);
    margin-left: var(--space-1);
}

.form-text {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-top: var(--space-1);
    display: block;
}

/* ============================================ */
/* INPUT FIELDS */
/* ============================================ */

.form-control,
.form-select,
textarea {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-base);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--duration-base) var(--timing-smooth);
    appearance: none;
    min-height: 40px;
}

.form-control:focus,
.form-select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
    background-color: var(--bg-primary);
}

.form-control:disabled,
.form-select:disabled,
textarea:disabled {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.form-control::placeholder {
    color: var(--text-tertiary);
}

/* ============================================ */
/* SELECT STYLING */
/* ============================================ */

.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23212529' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    background-size: 16px 12px;
    padding-right: var(--space-8);
}

.form-select:focus {
    background-color: var(--bg-primary);
}

/* ============================================ */
/* TEXTAREA */
/* ============================================ */

textarea {
    min-height: 100px;
    resize: vertical;
}

textarea.form-control-sm {
    min-height: 60px;
}

textarea.form-control-lg {
    min-height: 140px;
}

/* ============================================ */
/* FORM VALIDATION */
/* ============================================ */

.form-control.is-valid,
.form-select.is-valid {
    border-color: var(--success);
}

.form-control.is-valid:focus,
.form-select.is-valid:focus {
    border-color: var(--success);
    box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--danger);
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.invalid-feedback {
    display: block;
    color: var(--danger);
    font-size: var(--text-xs);
    margin-top: var(--space-1);
}

.valid-feedback {
    display: block;
    color: var(--success);
    font-size: var(--text-xs);
    margin-top: var(--space-1);
}

.form-control.invalid-feedback,
.form-select.invalid-feedback {
    display: none;
}

.form-control.is-invalid~.invalid-feedback,
.form-select.is-invalid~.invalid-feedback {
    display: block;
}

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

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

.input-group>.form-control,
.input-group>.form-select {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
    border-radius: 0;
    margin-bottom: 0;
}

.input-group>.form-control:focus,
.input-group>.form-select:focus {
    z-index: 3;
}

.input-group>.form-control:first-child,
.input-group>.form-select:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.input-group>.form-control:last-child,
.input-group>.form-select:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    font-weight: var(--font-medium);
    line-height: var(--leading-normal);
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

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

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

/* ============================================ */
/* CHECKBOX & RADIO */
/* ============================================ */

.form-check {
    display: block;
    padding-left: var(--space-5);
    margin-bottom: var(--space-3);
}

.form-check-input {
    float: left;
    margin-left: calc(var(--space-5) * -1);
    margin-top: 0.3em;
    accent-color: var(--primary);
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.form-check-input:focus {
    border-color: var(--primary-light);
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.form-check-label {
    cursor: pointer;
    user-select: none;
    font-weight: var(--font-normal);
    color: var(--text-primary);
}

/* ============================================ */
/* SWITCH */
/* ============================================ */

.form-switch {
    padding-left: var(--space-8);
}

.form-switch .form-check-input {
    width: 2.5em;
    margin-left: calc(var(--space-8) * -1);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%28255,255,255,0.25%29'/%3e%3c/svg%3e");
    background-position: left center;
    border-radius: 2.5em;
    transition: background-position var(--duration-base) var(--timing-smooth);
}

.form-switch .form-check-input:checked {
    background-position: right center;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%28255,255,255,0.25%29'/%3e%3c/svg%3e");
}

/* ============================================ */
/* FORM ROW */
/* ============================================ */

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

.row>[class*='col-']>.form-group {
    margin-bottom: var(--space-4);
}

/* ============================================ */
/* INPUT SIZES */
/* ============================================ */

.form-control-sm,
.form-select-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    min-height: 32px;
    border-radius: var(--radius-sm);
}

.form-control-lg,
.form-select-lg {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    min-height: 48px;
    border-radius: var(--radius-lg);
}

/* ============================================ */
/* FLOATING LABELS */
/* ============================================ */

.form-floating>label {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    padding: var(--space-3);
    margin-bottom: 0;
    overflow: hidden;
    pointer-events: none;
    border: 1px solid transparent;
    transform-origin: 0 0;
    transition: opacity var(--duration-base) var(--timing-ease-in-out), transform var(--duration-base) var(--timing-ease-in-out);
}

.form-floating>.form-control:focus~label,
.form-floating>.form-control:not(:placeholder-shown)~label,
.form-floating>.form-select~label {
    opacity: 0.65;
    transform: scale(0.85) translateY(-1.5rem) translateX(0.15rem);
}

/* ============================================ */
/* FORM FEEDBACK */
/* ============================================ */

.form-feedback {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    margin-top: var(--space-2);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.form-feedback.success {
    background-color: var(--success-lighter);
    color: var(--success-dark);
    border: 1px solid var(--success-light);
}

.form-feedback.error {
    background-color: var(--danger-light);
    color: var(--danger-dark);
    border: 1px solid var(--danger);
}

.form-feedback.warning {
    background-color: var(--warning-lighter);
    color: #856404;
    border: 1px solid var(--warning-light);
}

.form-feedback.info {
    background-color: var(--info-lighter);
    color: var(--info-dark);
    border: 1px solid var(--info-light);
}
