﻿/* =========================================================
   1. FORM CONTROL & VALIDATION
   ========================================================= */

.form-control {
    border: 1px solid var(--bootstrap-border-color) !important;
    color: var(--text-main);
}

    .form-control:focus {
        border-color: var(--primary) !important;
        background-color: #fff;
        outline: none !important;
        box-shadow: var(--primary-box-shadow) !important;
    }

/* Custom Checkbox (Smartmeter) */
.form-check-input {
    border: 1px solid var(--bootstrap-border-color);
    cursor: pointer;
}

    .form-check-input:checked {
        background-color: var(--primary) !important;
        border-color: var(--primary) !important;
    }

    .form-check-input:focus {
        border-color: var(--primary);
        box-shadow: var(--primary-box-shadow) !important;
    }

/* Validation Stability Logic */
:has(> .invalid-feedback) {
    position: relative;
}

.form-control.is-invalid, .was-validated .form-control:invalid,
.form-control.is-valid, .was-validated .form-control:valid {
    background-image: none !important;
}

.was-validated .form-control:invalid, .form-control.is-invalid {
    border: 2px solid var(--primary) !important;
}

.invalid-feedback {
    display: none;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: bold;
    margin-top: 0.25rem;
    /* Keeps the error in the flow so it doesn't overlap the next row */
    position: relative;
}

.input-unit {
    top: 0;
    height: 38px;
    display: flex;
    align-items: center;
    z-index: 5;
    pointer-events: none;
}

/* =========================================================
   2. DROPDOWNS & INPUT GROUPS
   ========================================================= */

.dropdown-menu {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--bootstrap-border-color) !important;
    padding: 0;
    width: 100%;
}

.dropdown-item {
    padding: 10px 15px;
    color: var(--text-main);
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

    .dropdown-item:hover, .dropdown-item:focus {
        background-color: var(--secondary) !important;
        color: white !important;
    }

/* Number input reset */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

/* Modal Close Button */
.btn-close {
    filter: grayscale(1);
}
    .btn-close:focus {
        outline: 2px solid var(--primary) !important;
    }

/* Dropdown Arrow & Animation
   Anchored to the top (1.1875rem = ~19px) to remain perfectly centered 
   within the input field regardless of the error text appearing below.
*/
.dropdown input ~ .arrow {
    position: absolute;
    right: 0.5rem;
    top: 1.1875rem !important;
    width: 20px !important;
    height: 20px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--secondary);
    pointer-events: none;
    transform: translateY(-50%) rotate(0deg) !important;
    transition: transform 0.2s ease-in-out, color 0.2s ease !important;
}

.dropdown input.show ~ .arrow {
    transform: translateY(-50%) rotate(180deg) !important;
    color: var(--primary);
}

/* =========================================================
   INVISIBLE NATIVE MOBILE SELECT OVERLAY
   ========================================================= */
.mobile-select-overlay {
    display: none;
}

/* Activated via JS device detection */
body.is-mobile-device .mobile-select-overlay {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0; /* Fully invisible */
    cursor: pointer;
    z-index: 10; /* Captures the tap before the input does */
    appearance: none;
    -webkit-appearance: none;
}

/* Disable the Bootstrap dropdown from triggering on mobile */
body.is-mobile-device .dropdown-toggle {
    pointer-events: none;
}

/* Optional: Flip the arrow when the native wheel is focused/open */
body.is-mobile-device .mobile-select-overlay:focus ~ .arrow,
body.is-mobile-device .mobile-select-overlay:active ~ .arrow {
    transform: translateY(-50%) rotate(180deg) !important;
    color: var(--primary);
}