/**
 * UI/UX Enhancements
 * - Accessibility improvements
 * - Loading states
 * - Form validation styles
 * - Inline error messages
 */

/* ===========================================
   1. ACCESSIBILITY ENHANCEMENTS
   =========================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #3b82f6 !important;
    outline-offset: 2px !important;
}

/* Skip link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #3b82f6;
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 0;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast focus states */
.form-control:focus,
.btn:focus,
select:focus,
textarea:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25) !important;
}

/* Ensure sufficient color contrast for placeholders */
::placeholder {
    color: #6b7280 !important;
    opacity: 1;
}

/* ===========================================
   2. LOADING STATES
   =========================================== */

/* Button loading spinner */
.btn-loading {
    position: relative;
    pointer-events: none;
    color: transparent !important;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

.btn-loading.btn-outline-primary::after,
.btn-loading.btn-outline-secondary::after,
.btn-loading.btn-light::after {
    border-color: rgba(59, 130, 246, 0.3);
    border-top-color: #3b82f6;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Page loading overlay */
.page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.page-loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.page-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-button {
    height: 38px;
    width: 100px;
}

.skeleton-card {
    height: 200px;
    border-radius: 8px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Progress bar for bulk operations */
.progress-wrapper {
    margin: 1rem 0;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: #6b7280;
}

.progress {
    height: 8px;
    border-radius: 4px;
    background-color: #e5e7eb;
    overflow: hidden;
}

.progress-bar {
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    transition: width 0.3s ease;
}

.progress-bar.progress-bar-animated {
    background-image: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.15) 25%,
        transparent 25%,
        transparent 50%,
        rgba(255, 255, 255, 0.15) 50%,
        rgba(255, 255, 255, 0.15) 75%,
        transparent 75%,
        transparent
    );
    background-size: 1rem 1rem;
    animation: progress-bar-stripes 1s linear infinite;
}

@keyframes progress-bar-stripes {
    0% { background-position: 1rem 0; }
    100% { background-position: 0 0; }
}

/* ===========================================
   3. FORM VALIDATION STYLES
   =========================================== */

/* Form group with validation */
.form-group {
    position: relative;
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #374151;
    font-size: 0.875rem;
}

.form-group label .required {
    color: #ef4444;
    margin-left: 2px;
}

/* Valid state */
.form-control.is-valid {
    border-color: #10b981 !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2310b981' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.9rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
    padding-right: calc(1.5em + 1.8rem) !important;
}

/* Invalid state */
.form-control.is-invalid {
    border-color: #ef4444 !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23ef4444'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23ef4444' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.9rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
    padding-right: calc(1.5em + 1.8rem) !important;
}

.form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
}

.form-control.is-valid:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25) !important;
}

/* Input group validation icon positioning */
.input-group .form-control.is-valid,
.input-group .form-control.is-invalid {
    background-position: right calc(0.375em + 0.2rem) center;
}

/* ===========================================
   4. INLINE ERROR MESSAGES
   =========================================== */

/* Error message below input */
.invalid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.35rem;
    font-size: 0.8125rem;
    color: #ef4444;
    align-items: center;
    gap: 0.25rem;
}

.invalid-feedback::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23ef4444'%3e%3cpath fill-rule='evenodd' d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z' clip-rule='evenodd'/%3e%3c/svg%3e");
    background-size: contain;
    flex-shrink: 0;
}

.form-control.is-invalid ~ .invalid-feedback,
.was-validated .form-control:invalid ~ .invalid-feedback,
.input-group .form-control.is-invalid ~ .invalid-feedback {
    display: flex;
}

/* Success message */
.valid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.35rem;
    font-size: 0.8125rem;
    color: #10b981;
    align-items: center;
    gap: 0.25rem;
}

.valid-feedback::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2310b981'%3e%3cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z' clip-rule='evenodd'/%3e%3c/svg%3e");
    background-size: contain;
    flex-shrink: 0;
}

.form-control.is-valid ~ .valid-feedback {
    display: flex;
}

/* Password strength indicator */
.password-strength {
    margin-top: 0.5rem;
}

.password-strength-bar {
    height: 4px;
    border-radius: 2px;
    background: #e5e7eb;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.password-strength-fill {
    height: 100%;
    transition: width 0.3s, background-color 0.3s;
    border-radius: 2px;
}

.password-strength-fill.weak { width: 25%; background: #ef4444; }
.password-strength-fill.fair { width: 50%; background: #f59e0b; }
.password-strength-fill.good { width: 75%; background: #3b82f6; }
.password-strength-fill.strong { width: 100%; background: #10b981; }

.password-strength-text {
    font-size: 0.75rem;
    color: #6b7280;
}

.password-strength-text.weak { color: #ef4444; }
.password-strength-text.fair { color: #f59e0b; }
.password-strength-text.good { color: #3b82f6; }
.password-strength-text.strong { color: #10b981; }

/* Password requirements list */
.password-requirements {
    margin-top: 0.5rem;
    padding: 0;
    list-style: none;
    font-size: 0.75rem;
}

.password-requirements li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #6b7280;
    margin-bottom: 0.25rem;
    transition: color 0.2s;
}

.password-requirements li::before {
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #e5e7eb;
    transition: background 0.2s;
}

.password-requirements li.valid {
    color: #10b981;
}

.password-requirements li.valid::before {
    background: #10b981;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='white' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/%3e%3c/svg%3e");
    background-size: 6px;
    background-repeat: no-repeat;
    background-position: center;
}

/* Character counter */
.char-counter {
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: right;
    margin-top: 0.25rem;
}

.char-counter.warning {
    color: #f59e0b;
}

.char-counter.danger {
    color: #ef4444;
}

/* ===========================================
   5. FORM ANIMATIONS
   =========================================== */

/* Shake animation for errors */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

/* Fade in for validation messages */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.invalid-feedback,
.valid-feedback {
    animation: fadeInDown 0.2s ease-out;
}

/* ===========================================
   6. TOAST IMPROVEMENTS
   =========================================== */

/* Custom toast positioning */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.custom-toast {
    display: flex;
    align-items: flex-start;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    max-width: 400px;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.custom-toast.toast-error {
    border-left: 4px solid #ef4444;
}

.custom-toast.toast-success {
    border-left: 4px solid #10b981;
}

.custom-toast.toast-warning {
    border-left: 4px solid #f59e0b;
}

.custom-toast.toast-info {
    border-left: 4px solid #3b82f6;
}

.custom-toast-icon {
    width: 24px;
    height: 24px;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.custom-toast-content {
    flex: 1;
}

.custom-toast-title {
    font-weight: 600;
    color: #111827;
    margin-bottom: 0.25rem;
}

.custom-toast-message {
    font-size: 0.875rem;
    color: #6b7280;
}

.custom-toast-close {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: #9ca3af;
    margin-left: 0.5rem;
}

.custom-toast-close:hover {
    color: #6b7280;
}

/* ===========================================
   7. RESPONSIVE ADJUSTMENTS
   =========================================== */

@media (max-width: 576px) {
    .toast-container {
        left: 1rem;
        right: 1rem;
    }

    .custom-toast {
        max-width: none;
    }

    .invalid-feedback,
    .valid-feedback {
        font-size: 0.75rem;
    }
}
