/*
 * Styles for the CustomFileInput component.
 * These classes mimic the native Bootstrap 5 file picker button as closely as possible. The whole purpose is to have a Bootstrap-native file picker button with localized text.
 */

.custom-file-input-group {
    position: relative;
}

.custom-file-input-group input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.custom-file-input-group input[type="file"]:disabled {
    cursor: not-allowed;
}

/* Focus styling */
.custom-file-input-group input[type="file"]:focus ~ .input-group {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Hover styling - matches Bootstrap's button hover */
.custom-file-input-group input[type="file"]:hover:not(:disabled) ~ .input-group .input-group-text {
    background-color: var(--bs-secondary-bg);
}

/* Disabled styling */
.custom-file-input-group input[type="file"]:disabled ~ .input-group {
    opacity: 1;
}

.custom-file-input-group input[type="file"]:disabled ~ .input-group .input-group-text {
    cursor: not-allowed;
}

.custom-file-input-group input[type="file"]:disabled ~ .input-group .form-control {
    background-color: var(--bs-secondary-bg);
    opacity: 1;
    cursor: not-allowed;
}

/* Remove default input-group border to control it ourselves */
.custom-file-input-group .input-group {
    border: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    pointer-events: none;
}

.custom-file-input-group .input-group > * {
    border: none;
}

/* Apply Bootstrap's margin-left rule for input-group children */
.custom-file-input-group .input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Button styling with inner border */
.custom-file-input-group .input-group-text {
    border-inline-end-width: var(--bs-border-width);
    border-inline-end-style: solid;
    border-inline-end-color: var(--bs-border-color);
    border-radius: var(--bs-border-radius) 0 0 var(--bs-border-radius);
    transition: background-color 0.15s ease-in-out, border-inline-end-color 0.15s ease-in-out;
}

.custom-file-input-group .form-control {
    border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
    pointer-events: none; /* Make text input completely non-interactive */
    padding-right: calc(1.5em + 0.75rem);
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Prevent focus on readonly input */
.custom-file-input-group .form-control:focus {
    outline: none;
    box-shadow: none;
}

/* Focus state changes the internal border color */
.custom-file-input-group input[type="file"]:focus ~ .input-group .input-group-text {
    border-inline-end-color: #86b7fe;
}

/* Invalid styling */
.custom-file-input-group.is-invalid input[type="file"] ~ .input-group {
    border-color: #dc3545;
}

.custom-file-input-group.is-invalid input[type="file"] ~ .input-group .input-group-text {
    border-inline-end-color: #dc3545;
}

.custom-file-input-group.is-invalid input[type="file"] ~ .input-group .form-control {
    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='%23dc3545'%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='%23dc3545' stroke='none'/%3e%3c/svg%3e");
}

.custom-file-input-group.is-invalid input[type="file"]:focus ~ .input-group {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

.custom-file-input-group.is-invalid input[type="file"]:focus ~ .input-group .input-group-text {
    border-inline-end-color: #dc3545;
}

/* Valid styling */
.custom-file-input-group.is-valid input[type="file"] ~ .input-group {
    border-color: #198754;
}

.custom-file-input-group.is-valid input[type="file"] ~ .input-group .input-group-text {
    border-inline-end-color: #198754;
}

.custom-file-input-group.is-valid input[type="file"] ~ .input-group .form-control {
    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");
}

.custom-file-input-group.is-valid input[type="file"]:focus ~ .input-group {
    border-color: #198754;
    box-shadow: 0 0 0 0.25rem rgba(25, 135, 84, 0.25);
}

.custom-file-input-group.is-valid input[type="file"]:focus ~ .input-group .input-group-text {
    border-inline-end-color: #198754;
}