/* ============================================================
   Form Validator Styles
   Works with Bootstrap 5 and supports light / dark themes.
   ============================================================ */

:root {
    --fv-valid-color: #198754;
    --fv-valid-bg: rgba(25, 135, 84, 0.08);
    --fv-invalid-color: #dc3545;
    --fv-invalid-bg: rgba(220, 53, 69, 0.08);
    --fv-text-muted: #6c757d;
    --fv-transition-speed: 0.25s;
    --fv-strength-weak: #dc3545;
    --fv-strength-fair: #fd7e14;
    --fv-strength-strong: #198754;
    --fv-strength-very-strong: #0d6efd;
}

/* Dark theme overrides (auto or manual) */
[data-bs-theme="dark"],
.dark-theme,
body.dark {
    --fv-valid-color: #4ade80;
    --fv-valid-bg: rgba(74, 222, 128, 0.1);
    --fv-invalid-color: #f87171;
    --fv-invalid-bg: rgba(248, 113, 113, 0.1);
    --fv-text-muted: #9ca3af;
    --fv-strength-weak: #f87171;
    --fv-strength-fair: #fbbf24;
    --fv-strength-strong: #4ade80;
    --fv-strength-very-strong: #60a5fa;
}

/* ── Valid / Invalid input states ───────────────────────── */

form[data-validate] .form-control.is-valid,
form[data-validate] .form-select.is-valid {
    border-color: var(--fv-valid-color);
    background-color: var(--fv-valid-bg);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73.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 0.75rem center;
    background-size: 1rem 1rem;
    padding-right: 2.5rem;
    transition: border-color var(--fv-transition-speed) ease, background-color var(--fv-transition-speed) ease;
}

form[data-validate] .form-control.is-invalid,
form[data-validate] .form-select.is-invalid {
    border-color: var(--fv-invalid-color);
    background-color: var(--fv-invalid-bg);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23dc3545' stroke-width='1.5'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem 1rem;
    padding-right: 2.5rem;
    transition: border-color var(--fv-transition-speed) ease, background-color var(--fv-transition-speed) ease;
}

/* Input-group children */
form[data-validate] .input-group .form-control.is-valid,
form[data-validate] .input-group .form-control.is-invalid {
    background-position: right 0.5rem center;
}

/* Focus ring tinting */
form[data-validate] .form-control.is-valid:focus {
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.2);
}

form[data-validate] .form-control.is-invalid:focus {
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.2);
}

/* ── Feedback messages ──────────────────────────────────── */

.fv-feedback {
    font-size: 0.8125rem;
    margin-top: 0.3rem;
    animation: fvSlideIn var(--fv-transition-speed) ease forwards;
}

.fv-feedback.field-error {
    color: var(--fv-invalid-color);
}

.fv-feedback.field-success {
    color: var(--fv-valid-color);
}

@keyframes fvSlideIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Password strength meter ────────────────────────────── */

.password-strength-meter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.strength-bar {
    flex: 1;
    height: 5px;
    background: rgba(128, 128, 128, 0.2);
    border-radius: 3px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    width: 0;
    border-radius: 3px;
    transition: width 0.4s ease, background-color 0.4s ease;
}

.strength-fill.strength-weak {
    background-color: var(--fv-strength-weak);
}

.strength-fill.strength-fair {
    background-color: var(--fv-strength-fair);
}

.strength-fill.strength-strong {
    background-color: var(--fv-strength-strong);
}

.strength-fill.strength-very-strong {
    background-color: var(--fv-strength-very-strong);
}

.strength-label {
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 5.5rem;
    text-align: right;
}

.strength-label.strength-weak {
    color: var(--fv-strength-weak);
}

.strength-label.strength-fair {
    color: var(--fv-strength-fair);
}

.strength-label.strength-strong {
    color: var(--fv-strength-strong);
}

.strength-label.strength-very-strong {
    color: var(--fv-strength-very-strong);
}

/* ── Character count ────────────────────────────────────── */

.char-count {
    font-size: 0.75rem;
    color: var(--fv-text-muted);
    text-align: right;
    margin-top: 0.2rem;
    transition: color var(--fv-transition-speed) ease;
}

.char-count--warn {
    color: var(--fv-strength-fair);
}

.char-count--over {
    color: var(--fv-invalid-color);
    font-weight: 600;
}
