/**
 * Prime Circle Finance - Form Validation Styles
 * Modern inline error messages, success states, and toast notifications
 *
 * Features:
 * - Inline error messages below each field
 * - Success/valid state indicators
 * - Accessible ARIA-compatible error announcements
 * - Toast/banner notification for summary errors
 * - Mobile-responsive design
 * - Smooth animations and transitions
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
    /* Error colors */
    --pcf-error-color: #dc2626;
    --pcf-error-bg: #fef2f2;
    --pcf-error-border: #fecaca;

    /* Success colors */
    --pcf-success-color: #16a34a;
    --pcf-success-bg: #f0fdf4;
    --pcf-success-border: #bbf7d0;

    /* Warning colors */
    --pcf-warning-color: #d97706;
    --pcf-warning-bg: #fffbeb;
    --pcf-warning-border: #fde68a;

    /* Info colors */
    --pcf-info-color: #2563eb;
    --pcf-info-bg: #eff6ff;
    --pcf-info-border: #bfdbfe;

    /* Animation timing */
    --pcf-transition-fast: 150ms;
    --pcf-transition-normal: 200ms;
    --pcf-transition-slow: 300ms;

    /* Spacing */
    --pcf-error-spacing: 4px;
    --pcf-toast-spacing: 16px;
}

/* ============================================
   Form Field States
   ============================================ */

/* Base input styling enhancement */
.pcf-form-group {
    position: relative;
    margin-bottom: 16px;
}

.pcf-form-group .form-control,
.pcf-form-group select.form-control {
    transition: border-color var(--pcf-transition-normal) ease,
                box-shadow var(--pcf-transition-normal) ease,
                background-color var(--pcf-transition-normal) ease;
}

/* Error state - input border */
.pcf-input-error,
.form-control.pcf-input-error,
select.pcf-input-error,
.input-group .pcf-input-error {
    border-color: var(--pcf-error-color) !important;
    background-color: var(--pcf-error-bg) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

.pcf-input-error:focus {
    border-color: var(--pcf-error-color) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2) !important;
}

/* Success state - input border */
.pcf-input-valid,
.form-control.pcf-input-valid,
select.pcf-input-valid {
    border-color: var(--pcf-success-color) !important;
    background-color: var(--pcf-success-bg) !important;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1) !important;
}

.pcf-input-valid:focus {
    border-color: var(--pcf-success-color) !important;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2) !important;
}

/* ============================================
   Inline Error Messages
   ============================================ */

/* Error message container */
.pcf-field-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: var(--pcf-error-spacing);
    padding: 8px 10px;
    background-color: var(--pcf-error-bg);
    border: 1px solid var(--pcf-error-border);
    border-radius: 6px;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transform: translateY(-8px);
    transition: opacity var(--pcf-transition-normal) ease,
                max-height var(--pcf-transition-slow) ease,
                transform var(--pcf-transition-normal) ease,
                margin var(--pcf-transition-normal) ease,
                padding var(--pcf-transition-normal) ease;
}

/* Error message visible state */
.pcf-field-error.visible {
    opacity: 1;
    max-height: 100px;
    transform: translateY(0);
}

/* Error icon */
.pcf-field-error::before {
    content: '';
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-top: 1px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23dc2626'%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;
    background-repeat: no-repeat;
}

/* Error text */
.pcf-field-error-text {
    color: var(--pcf-error-color);
    font-size: 12px;
    line-height: 1.4;
    font-weight: 500;
}

/* Legacy validation-error class (backward compatibility) */
.validation-error {
    display: none;  /* Hidden by default - shown only after user interaction */
    color: var(--pcf-error-color);
    font-size: 12px;
    line-height: 1.4;
    margin-top: var(--pcf-error-spacing);
}

.validation-error.visible {
    display: block;  /* Show when has 'visible' class */
    opacity: 1;
}

/* ============================================
   Success Indicator (Checkmark)
   ============================================ */

.pcf-field-success {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    opacity: 0;
    transition: opacity var(--pcf-transition-normal) ease;
    pointer-events: none;
}

.pcf-field-success.visible {
    opacity: 1;
}

.pcf-field-success::before {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2316a34a'%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;
    background-repeat: no-repeat;
}

/* Position adjustment for input groups */
.input-group + .pcf-field-success,
.form-group .input-group ~ .pcf-field-success {
    right: 50px;
}

/* ============================================
   Toast Notification System
   ============================================ */

/* Toast container - fixed position */
.pcf-toast-container {
    position: fixed;
    top: var(--pcf-toast-spacing);
    right: var(--pcf-toast-spacing);
    left: var(--pcf-toast-spacing);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

/* Individual toast */
.pcf-toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15),
                0 2px 10px rgba(0, 0, 0, 0.1);
    transform: translateY(-20px);
    opacity: 0;
    transition: transform var(--pcf-transition-slow) cubic-bezier(0.4, 0, 0.2, 1),
                opacity var(--pcf-transition-slow) ease;
    pointer-events: auto;
    max-width: 420px;
    margin-left: auto;
}

.pcf-toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.pcf-toast.hiding {
    transform: translateY(-20px);
    opacity: 0;
}

/* Toast icon container */
.pcf-toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Toast content */
.pcf-toast-content {
    flex: 1;
    min-width: 0;
}

.pcf-toast-title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    line-height: 1.3;
}

.pcf-toast-message {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
    margin: 0;
}

.pcf-toast-message ul {
    margin: 8px 0 0 0;
    padding-left: 18px;
}

.pcf-toast-message li {
    font-size: 12px;
    margin-bottom: 4px;
    color: #6b7280;
}

/* Toast close button */
.pcf-toast-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--pcf-transition-fast) ease;
    color: #9ca3af;
}

.pcf-toast-close:hover {
    background-color: #f3f4f6;
    color: #6b7280;
}

.pcf-toast-close svg {
    width: 18px;
    height: 18px;
}

/* Toast variants */

/* Error toast */
.pcf-toast--error {
    border-left: 4px solid var(--pcf-error-color);
}

.pcf-toast--error .pcf-toast-icon {
    background-color: var(--pcf-error-bg);
    color: var(--pcf-error-color);
}

.pcf-toast--error .pcf-toast-icon::before {
    content: '';
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23dc2626'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-size: contain;
}

/* Success toast */
.pcf-toast--success {
    border-left: 4px solid var(--pcf-success-color);
}

.pcf-toast--success .pcf-toast-icon {
    background-color: var(--pcf-success-bg);
    color: var(--pcf-success-color);
}

.pcf-toast--success .pcf-toast-icon::before {
    content: '';
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2316a34a'%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;
}

/* Warning toast */
.pcf-toast--warning {
    border-left: 4px solid var(--pcf-warning-color);
}

.pcf-toast--warning .pcf-toast-icon {
    background-color: var(--pcf-warning-bg);
    color: var(--pcf-warning-color);
}

.pcf-toast--warning .pcf-toast-icon::before {
    content: '';
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23d97706'%3E%3Cpath fill-rule='evenodd' d='M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-size: contain;
}

/* Info toast */
.pcf-toast--info {
    border-left: 4px solid var(--pcf-info-color);
}

.pcf-toast--info .pcf-toast-icon {
    background-color: var(--pcf-info-bg);
    color: var(--pcf-info-color);
}

.pcf-toast--info .pcf-toast-icon::before {
    content: '';
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%232563eb'%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 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-size: contain;
}

/* Toast progress bar (auto-dismiss indicator) */
.pcf-toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

.pcf-toast-progress-bar {
    height: 100%;
    background-color: currentColor;
    transform-origin: left;
    animation: pcf-toast-progress 5s linear forwards;
}

@keyframes pcf-toast-progress {
    from {
        transform: scaleX(1);
    }
    to {
        transform: scaleX(0);
    }
}

/* ============================================
   Form Error Summary Banner
   ============================================ */

.pcf-error-banner {
    display: none;
    background-color: var(--pcf-error-bg);
    border: 1px solid var(--pcf-error-border);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 20px;
    animation: pcf-shake 0.5s ease-in-out;
}

.pcf-error-banner.visible {
    display: block;
}

.pcf-error-banner-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.pcf-error-banner-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.pcf-error-banner-icon svg {
    width: 100%;
    height: 100%;
    fill: var(--pcf-error-color);
}

.pcf-error-banner-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--pcf-error-color);
    margin: 0;
}

.pcf-error-banner-list {
    margin: 0;
    padding-left: 34px;
    list-style: none;
}

.pcf-error-banner-list li {
    position: relative;
    font-size: 13px;
    color: #7f1d1d;
    padding: 4px 0;
    padding-left: 16px;
}

.pcf-error-banner-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    width: 6px;
    height: 6px;
    background-color: var(--pcf-error-color);
    border-radius: 50%;
}

.pcf-error-banner-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pcf-error-color);
    transition: background-color var(--pcf-transition-fast) ease;
}

.pcf-error-banner-close:hover {
    background-color: rgba(220, 38, 38, 0.1);
}

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

/* ============================================
   Screen Reader Only (Accessibility)
   ============================================ */

.pcf-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;
}

/* Live region for screen reader announcements */
.pcf-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

@media (max-width: 768px) {
    .pcf-toast-container {
        top: auto;
        bottom: var(--pcf-toast-spacing);
        left: var(--pcf-toast-spacing);
        right: var(--pcf-toast-spacing);
    }

    .pcf-toast {
        max-width: 100%;
        margin-left: 0;
        transform: translateY(20px);
    }

    .pcf-toast.visible {
        transform: translateY(0);
    }

    .pcf-toast.hiding {
        transform: translateY(20px);
    }

    .pcf-field-error {
        padding: 6px 8px;
    }

    .pcf-field-error-text {
        font-size: 11px;
    }

    .pcf-error-banner {
        padding: 12px 16px;
        margin-bottom: 16px;
    }

    .pcf-error-banner-list {
        padding-left: 24px;
    }

    .pcf-error-banner-list li {
        font-size: 12px;
    }
}

/* Extra small screens */
@media (max-width: 380px) {
    .pcf-toast {
        padding: 12px;
        gap: 10px;
    }

    .pcf-toast-title {
        font-size: 13px;
    }

    .pcf-toast-message {
        font-size: 12px;
    }

    .pcf-toast-close {
        width: 28px;
        height: 28px;
    }
}

/* ============================================
   Dark Theme Support (for dark form backgrounds)
   ============================================ */

.pcf-dark-theme .pcf-toast {
    background: #1f2937;
    border-color: #374151;
}

.pcf-dark-theme .pcf-toast-title {
    color: #f9fafb;
}

.pcf-dark-theme .pcf-toast-message {
    color: #9ca3af;
}

.pcf-dark-theme .pcf-toast-close {
    color: #6b7280;
}

.pcf-dark-theme .pcf-toast-close:hover {
    background-color: #374151;
    color: #9ca3af;
}

/* ============================================
   Registration Form Specific Styles
   ============================================ */

/* Registration form validation error styling */
#registerForm .validation-error {
    display: none;
    margin-top: 4px;
    padding: 6px 10px;
    background-color: var(--pcf-error-bg);
    border: 1px solid var(--pcf-error-border);
    border-radius: 6px;
    font-size: 12px;
    color: var(--pcf-error-color);
    line-height: 1.4;
}

#registerForm .validation-error.visible {
    display: flex;
    align-items: center;
    gap: 6px;
}

#registerForm .validation-error::before {
    content: '';
    flex-shrink: 0;
    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='%23dc2626'%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;
    background-repeat: no-repeat;
}

/* Birthday row error state */
.birthday-row.pcf-input-error .birthday-input,
.birthday-row.pcf-input-error input[type="date"] {
    border-color: var(--pcf-error-color) !important;
}

/* ID row error styling */
.id-row-mobile .pcf-input-error {
    border-color: var(--pcf-error-color) !important;
}

/* Password field with toggle - error state */
.input-group:has(.pcf-input-error) .input-group-append,
.input-group:has(.pcf-input-error) .password_toggle {
    border-color: var(--pcf-error-color) !important;
}

/* Ensure password hint stays visible but styled appropriately */
.password-hint {
    transition: color var(--pcf-transition-normal) ease;
}

.password-hint.pcf-hint-error {
    color: var(--pcf-error-color);
}

.password-hint.pcf-hint-valid {
    color: var(--pcf-success-color);
}
