/**
 * Modern Form Validation Styles
 * Beautiful, animated validation feedback
 */

/* ====================================
   VALIDATION STATES
   ==================================== */

.form-control {
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Valid State */
.form-control.is-valid {
    border-color: #10b981 !important;
    background-image: none !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

.form-control.is-valid:focus {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15) !important;
}

/* Invalid State */
.form-control.is-invalid {
    border-color: #ef4444 !important;
    background-image: none !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
    animation: shake 0.4s ease-in-out;
}

.form-control.is-invalid:focus {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15) !important;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(4px);
    }
}

/* ====================================
   VALIDATION ICONS
   ==================================== */

.validation-icon {
    position: absolute;
    right: 16px;
    top: 38px;
    /* Adjusted to align with input field */
    font-size: 18px;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 5;
}

/* For fields with labels, adjust icon position */
.mb-4:has(.form-label) .validation-icon {
    top: 68px;
    /* Account for label height */
}

/* For textarea fields */
.mb-4:has(textarea) .validation-icon {
    top: 68px;
}

.validation-icon.valid {
    color: #10b981;
    opacity: 1;
    animation: iconPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.validation-icon.invalid {
    color: #ef4444;
    opacity: 1;
    animation: iconPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes iconPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Adjust input padding for icon - but keep text readable */
.form-control:not(select):not(textarea) {
    padding-right: 45px !important;
}

/* ====================================
   VALIDATION FEEDBACK
   ==================================== */

.validation-feedback {
    display: none;
    margin-top: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    animation: slideDown 0.3s ease;
    position: relative;
    /* Not absolute - flows in document */
    width: 100%;
    box-sizing: border-box;
}

.validation-feedback.error,
.validation-feedback.success {
    display: flex;
    align-items: center;
    gap: 8px;
}

.validation-feedback.error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.05));
    border-left: 3px solid #ef4444;
    color: #991b1b;
}

.validation-feedback.success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.05));
    border-left: 3px solid #10b981;
    color: #065f46;
}

.validation-feedback i {
    font-size: 14px;
    flex-shrink: 0;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ====================================
   CHARACTER COUNTER
   ==================================== */

.character-counter {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
    font-size: 12px;
    color: #6b7280;
    font-weight: 500;
    transition: color 0.3s ease;
}

.character-counter .current {
    color: #374151;
    font-weight: 600;
    margin-right: 2px;
}

.character-counter.warning {
    color: #f59e0b;
    animation: pulse 1s ease-in-out infinite;
}

.character-counter.warning .current {
    color: #d97706;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

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

.form-control[type="file"].is-valid {
    border-color: #10b981 !important;
}

.form-control[type="file"].is-invalid {
    border-color: #ef4444 !important;
}

.file-validation-preview {
    margin-top: 12px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    border: 2px dashed #e5e7eb;
}

.file-validation-preview.valid {
    background: rgba(16, 185, 129, 0.05);
    border-color: #10b981;
}

.file-validation-preview.invalid {
    background: rgba(239, 68, 68, 0.05);
    border-color: #ef4444;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin-bottom: 6px;
    background: white;
    border-radius: 6px;
    font-size: 13px;
}

.file-preview-item i {
    font-size: 16px;
    color: #6b7280;
}

.file-preview-item.valid i {
    color: #10b981;
}

.file-preview-item.invalid i {
    color: #ef4444;
}

.file-preview-name {
    flex: 1;
    font-weight: 500;
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-size {
    font-size: 11px;
    color: #6b7280;
    font-weight: 500;
}

/* ====================================
   SUBMIT BUTTON STATES
   ==================================== */

button[type="submit"] {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(30%);
}

button[type="submit"].enabled {
    animation: buttonReady 0.5s ease;
}

@keyframes buttonReady {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

button[type="submit"]:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
}

button[type="submit"]:not(:disabled):active {
    transform: translateY(0);
}

/* ====================================
   FORM SECTIONS
   ==================================== */

.mb-4 {
    position: relative;
    margin-bottom: 24px !important;
}

/* Add extra spacing when validation errors/success are shown */
.mb-4:has(.validation-feedback.error) {
    margin-bottom: 36px !important;
}

.mb-4:has(.validation-feedback.success) {
    margin-bottom: 36px !important;
}

/* ====================================
   REQUIRED FIELD INDICATOR
   ==================================== */

.form-label.required-field::after {
    content: none;
    /* Remove default asterisk */
}

.form-label.required-field {
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-label.required-field .text-danger {
    font-size: 16px;
    line-height: 1;
    animation: asteriskPulse 2s ease-in-out infinite;
}

@keyframes asteriskPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* ====================================
   LOADING STATES
   ==================================== */

.btn-spinner,
.btn-loader {
    display: none;
}

.btn-spinner i,
.btn-loader i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ====================================
   RESPONSIVE ADJUSTMENTS
   ==================================== */

@media (max-width: 768px) {
    .validation-icon {
        right: 12px;
        font-size: 16px;
    }

    .validation-feedback {
        font-size: 12px;
        padding: 8px 12px;
    }

    .character-counter {
        font-size: 11px;
    }
}

/* ====================================
   ACCESSIBILITY
   ==================================== */

.validation-feedback:focus-visible,
.form-control:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-control.is-valid {
        border-width: 3px;
    }

    .form-control.is-invalid {
        border-width: 3px;
    }

    .validation-feedback {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    .form-control,
    .validation-icon,
    .validation-feedback,
    button[type="submit"] {
        animation: none !important;
        transition: none !important;
    }
}

/* ====================================
   DARK MODE SUPPORT (if needed)
   ==================================== */

@media (prefers-color-scheme: dark) {
    .validation-feedback.error {
        background: rgba(239, 68, 68, 0.15);
        color: #fca5a5;
    }

    .validation-feedback.success {
        background: rgba(16, 185, 129, 0.15);
        color: #6ee7b7;
    }

    .character-counter {
        color: #9ca3af;
    }

    .file-validation-preview {
        background: #1f2937;
        border-color: #374151;
    }

    .file-preview-item {
        background: #111827;
    }
}