/*
 * CWH form controls — text, date, email, number, textarea, native <select>.
 *
 * Loaded globally via https/classes/layout/sharedCSS.php. Mirrors the trigger styling
 * of bootstrap-multiselect (bootstrap-multiselect-bs5.css) and Select2
 * (select2.css) so every input on a form sits on the same baseline:
 *   - same height
 *   - same border (cwh-border, 10px radius)
 *   - same font family / weight / size
 *   - same dark-blue text colour
 *   - same focus state (open-blue border + soft brand-blue glow)
 *
 * !important is used on colour/border/font properties because per-portal
 * theme.min.css and Bootstrap's own .form-control rules (loaded earlier in
 * each portal head) target the same selectors.
 */

@import url('brandingPalette.css');

/* ── Base form-control (covers text, email, password, search, number, tel,
        url, date, time, datetime-local, month, week, and textarea) ──────── */

.form-control,
.form-control-sm,
input.form-control,
textarea.form-control,
select.form-control,
select.form-select {
    height: calc(1.5em + 0.75rem + 2px);
    border: 1px solid var(--cwh-border) !important;
    border-radius: 10px !important;
    background-color: var(--cwh-white) !important;
    color: var(--cwh-dark-grey) !important;
    font-family: var(--cwh-font-family) !important;
    /* font-weight: var(--cwh-font-medium); */
    font-size: 0.875rem;
    line-height: 1.5;
    padding: 0.375rem 0.75rem;
    box-shadow: none;
}

/* Textarea — height auto so it grows with rows attribute */
textarea.form-control {
    height: auto;
    min-height: calc(1.5em + 0.75rem + 2px);
}

/* Native <select> — give it the same chevron position as the styled controls */
select.form-control,
select.form-select {
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%2300337e' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px 10px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* ── Booking-link sub-domain field ───────────────────────────────────────────
 *
 * The booking-link input group (`<span.domainLeft>https://</span>` + input +
 * `<span.domainRight>.domain/pharmacy</span>`) must read as one flat control,
 * not separate rounded pills. Square every segment's corners. The class is
 * doubled (specificity 0,2,0) so it outranks per-portal `.domainLeft` /
 * `.domainRight` radius rules (0,1,0 !important) that load later (e.g. secure
 * custom.pharmacy.css), making the field square across every portal that uses
 * it — head office, corporate, store, and the booking portal. */
.domainLeft.domainLeft,
.domainRight.domainRight,
.skip-border-radius.skip-border-radius {
    border-radius: 0 !important;
}

/* ── Placeholder text ────────────────────────────────────────────────────── */

.form-control::placeholder,
input.form-control::placeholder,
textarea.form-control::placeholder {
    color: var(--cwh-light-grey) !important;
    font-weight: var(--cwh-font-medium);
    opacity: 1; /* Firefox lowers placeholder opacity by default */
}

/* ── Focus state — matches the dropdown trigger focus ────────────────────── */

.form-control:focus,
input.form-control:focus,
textarea.form-control:focus,
select.form-control:focus,
select.form-select:focus {
    border-color: var(--cwh-open-blue) !important;
    box-shadow: 0 0 0 0.15rem rgba(0, 51, 126, 0.10) !important;
    outline: 0;
    background-color: var(--cwh-white) !important;
    color: var(--cwh-dark-grey) !important;
}

/* ── Search input — light-blue fill that clears to white on focus ────────────
 *
 * Used by the list-page search bars (Store List, Pharmacy Groups, and the
 * service-management master lists) so the search field stands out against the
 * white page. While focused/typing it returns to the standard white control
 * background. `input.` prefix outranks the base `.form-control` rule above. */
input.cwh-search-input {
    background-color: #eaf4ff !important;
    color: var(--cwh-dark-blue) !important;
}
input.cwh-search-input::placeholder {
    color: var(--cwh-dark-blue) !important;
    opacity: 1;
}
.cwh-search-wrap .cwh-search-icon {
    color: var(--cwh-dark-blue);
}
/* Focused (white) state — revert to the standard control colours. */
input.cwh-search-input:focus {
    background-color: var(--cwh-white) !important;
    color: var(--cwh-dark-grey) !important;
}
input.cwh-search-input:focus::placeholder {
    color: var(--cwh-light-grey) !important;
}
.cwh-search-wrap:has(input:focus) .cwh-search-icon {
    color: var(--cwh-light-grey);
}

/* ── Disabled / read-only ─────────────────────────────────────────────────── */

.form-control:disabled,
.form-control[readonly],
input.form-control:disabled,
input.form-control[readonly],
textarea.form-control:disabled,
textarea.form-control[readonly],
select.form-control:disabled {
    background-color: var(--cwh-white) !important;
    color: var(--cwh-light-grey) !important;
    cursor: not-allowed;
}

/* ── Labels above inputs ─────────────────────────────────────────────────── */

label,
.form-label {
    color: var(--cwh-dark-blue);
    font-family: var(--cwh-font-family);
    font-weight: var(--cwh-font-medium);
    font-size: 0.875rem;
    margin-bottom: 0.35rem;
}

/* ── Field-info icon + hover tooltip ─────────────────────────────────────────
 *
 * A small "why do we ask this?" affordance that sits INSIDE the field at the
 * right edge — the same spot a password-manager extension (e.g. Keeper) drops
 * its icon — vertically centred on the input. Hovering or keyboard-focusing it
 * reveals a short brand-styled bubble. Pure CSS (no JS init) so it works on
 * dynamically cloned rows (e.g. the booking participant step's clones).
 *
 *     <label for="email_1">Email <b style="color:red;">*</b></label>
 *     <div class="cwh-field-control">
 *         <input id="email_1" type="email" class="form-control form-control-sm cwh-has-info">
 *         <span class="cwh-field-info" tabindex="0" role="note"
 *               aria-label="Why we ask for your email">
 *             <i class="fa fa-info-circle" aria-hidden="true"></i>
 *             <span class="cwh-field-info__bubble">We use this to contact you about your booking.</span>
 *         </span>
 *     </div>
 *
 * Add .cwh-field-control--date on the wrapper for native date inputs so the
 * icon clears the browser's calendar-picker button.
 */
.cwh-field-control {
    position: relative;
}

/* formValidator injects the `.invalid-feedback` message as a sibling of the
 * input INSIDE this wrapper. Left in flow it grows the wrapper, which drags the
 * vertically-centred info icon (top: 50% of the wrapper) downward. Pull the
 * message out of flow so the wrapper stays the input's height and the icon
 * stays centred on the field; the message still renders just beneath it. */
.cwh-field-control .invalid-feedback {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
}

/* Reserve room at the right of the input so its text/value never runs under
 * the icon. */
.cwh-has-info {
    padding-right: 2rem !important;
}
/* Date input: fill the wrapper and show a pointer cursor so the whole field
 * reads as clickable. Height/padding match the sibling text inputs via the
 * shared `#msform input[type=date]` rule in booking-pharmacy.css
 * (min-height: 47px) — do NOT pin a height here or the date box renders shorter
 * than the others. */
.cwh-field-control--date .cwh-has-info {
    width: 100%;
    cursor: pointer;
}

/* Hide the visible calendar button but keep it clickable by stretching the
 * native picker indicator transparently across the whole input — clicking
 * anywhere in the field then opens the native date picker, no JS required.
 * (WebKit/Blink: Chrome, Edge, Safari. Firefox keeps its own native control.) */
.cwh-field-control--date .cwh-has-info::-webkit-calendar-picker-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    opacity: 0;
    cursor: pointer;
    background: transparent;
}

.cwh-field-info {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    z-index: 4;
    display: inline-flex;
    align-items: center;
    color: var(--cwh-open-blue);
    cursor: help;
    font-size: 0.95rem;
    line-height: 1;
}

/* The icon glyph itself sits at 50% opacity (subtle, like a password-manager
 * field icon) and brightens to full on hover/focus to read as interactive. */
.cwh-field-info > i {
    opacity: 0.5;
    transition: opacity 0.12s ease;
}
.cwh-field-info:hover > i,
.cwh-field-info:focus > i,
.cwh-field-info:focus-within > i {
    opacity: 1;
}

.cwh-field-info__bubble {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    width: max-content;
    max-width: 240px;
    padding: 8px 10px;
    background: var(--cwh-dark-blue);
    color: var(--cwh-white);
    font-family: var(--cwh-font-family);
    font-weight: var(--cwh-font-medium);
    font-size: 0.75rem;
    line-height: 1.35;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 51, 126, 0.20);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-2px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s linear 0.12s;
    pointer-events: none;
}

/* Caret pointing up toward the info icon. */
.cwh-field-info__bubble::before {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 8px;
    border: 6px solid transparent;
    border-bottom-color: var(--cwh-dark-blue);
}

.cwh-field-info:hover .cwh-field-info__bubble,
.cwh-field-info:focus .cwh-field-info__bubble,
.cwh-field-info:focus-within .cwh-field-info__bubble {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.12s ease, transform 0.12s ease;
}

/* ── Validation states (keep Bootstrap red/green semantics, brand-tinted) ── */

/* Red border on every invalid field, text inputs and native selects
 * (.form-control and select.form-select) alike. The cwh base border uses
 * !important, so the invalid state must too or the grey base border wins
 * while unfocused. */
.form-control.is-invalid,
input.form-control.is-invalid,
textarea.form-control.is-invalid,
select.form-control.is-invalid,
select.form-select.is-invalid {
    border-color: var(--cwh-danger) !important;
}

.form-control.is-invalid:focus,
input.form-control.is-invalid:focus,
textarea.form-control.is-invalid:focus,
select.form-control.is-invalid:focus,
select.form-select.is-invalid:focus {
    border-color: var(--cwh-danger) !important;
    box-shadow: 0 0 0 0.15rem rgba(220, 53, 69, 0.15) !important;
}

/* An invalid native select keeps the brand chevron and shows Bootstrap's invalid icon
 * beside it, as an invalid text input shows it. The base select rule above replaces
 * Bootstrap's background-image with the chevron alone, which drops the icon; CSS can't
 * append a layer, so the chevron (same URL as the base rule) is repeated here.
 * Bootstrap sets --bs-form-select-bg-icon and padding-right on this same selector. */
select.form-select.is-invalid:not([multiple]):not([size]) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%2300337e' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E"), var(--bs-form-select-bg-icon, none);
    background-position: right 0.75rem center, center right 2.25rem;
    background-size: 12px 10px, calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Fields that already carry our own right-aligned info icon (.cwh-has-info —
 * Email / DOB on the participant step) suppress Bootstrap's invalid background
 * icon so its red exclamation doesn't stack on top of the info icon. The red
 * border alone signals the error. Fields WITHOUT an info icon (names) keep
 * Bootstrap's icon as normal. */
.cwh-has-info.is-invalid,
.cwh-has-info.is-invalid:focus {
    background-image: none !important;
    padding-right: 2rem !important;
}

/* ── Radio / checkbox rows ───────────────────────────────────────────────────
 *
 * Shared component for a radio or checkbox followed by its label text, sized
 * and aligned the same everywhere. Browser-rendered radios sit at the text
 * baseline by default which leaves the label visually below the radio's
 * centre on multi-line layouts. Wrapping in `.cwh-radio-row` (or
 * `.cwh-checkbox-row`) flips that to a flexbox with explicit vertical
 * centring, brand-tinted accent colour, and consistent spacing.
 *
 * Use whenever you render `<input type="radio">` or `<input type="checkbox">`
 * alongside a label, instead of repeating the alignment rules per component.
 * Recommended markup — either inline with `<span>`:
 *
 *     <label class="cwh-radio-row">
 *         <input type="radio" name="example" value="yes">
 *         <span>Yes</span>
 *     </label>
 *
 * — or a separate `<label>` referencing the input by id:
 *
 *     <div class="cwh-radio-row">
 *         <input type="radio" id="example_yes" name="example" value="yes">
 *         <label for="example_yes">Yes</label>
 *     </div>
 *
 * The `<label>` inside the row inherits the override below so the global
 * `label { margin-bottom: 0.35rem; }` rule doesn't push the text off-centre.
 */

/* `.cwh-radio-row.cwh-radio-row` and `.cwh-checkbox-row.cwh-checkbox-row`
 * double-class their selectors to bump specificity above any per-portal
 * `form label { display: block }` resets that would otherwise collapse the
 * flex row back to a stacked layout. */
.cwh-radio-row.cwh-radio-row,
.cwh-checkbox-row.cwh-checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    margin: 0 0 6px;
    font-family: var(--cwh-font-family);
    font-size: 0.875rem;
    font-weight: var(--cwh-font-medium);
    color: var(--cwh-dark-blue);
    line-height: 1.3;
    user-select: none;
}

.cwh-radio-row:last-child,
.cwh-checkbox-row:last-child {
    margin-bottom: 0;
}

.cwh-radio-row input[type="radio"],
.cwh-checkbox-row input[type="checkbox"] {
    appearance: auto;
    -webkit-appearance: auto;
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--cwh-dark-blue);
    flex-shrink: 0;
    cursor: pointer;
}

/* ── Checkbox / radio normalisation (project-wide) ───────────────────────────
 *
 * Render checkboxes and radios as clean native controls tinted with the brand
 * accent colour, instead of the heavy bordered/rounded box that Bootstrap's
 * `.form-check-input` and some per-portal themes draw. This is the global fix
 * for stray borders showing on checkboxes across every portal.
 *
 * Bootstrap toggle SWITCHES (`.form-switch .form-check-input`) are deliberately
 * excluded — their border + background IS the switch track, so they keep
 * Bootstrap's rendering. The multiselect-plugin and `.cwh-toggle` checkboxes
 * manage their own appearance and are unaffected by the native reset here. */
input[type="checkbox"]:not(.form-check-input),
input[type="radio"]:not(.form-check-input),
.form-check:not(.form-switch) > .form-check-input {
    appearance: auto;
    -webkit-appearance: auto;
    border: 0 !important;
    border-radius: 0 !important;
    background-color: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    accent-color: var(--cwh-dark-blue);
}

/* Per-row label sits to the right of the input — strip the global label
 * margin-bottom so it stays centred on the radio's geometric middle, and
 * keep it clickable but not draggable. */
.cwh-radio-row > label,
.cwh-radio-row > span,
.cwh-checkbox-row > label,
.cwh-checkbox-row > span {
    margin: 0;
    line-height: 1.3;
    cursor: pointer;
    color: inherit;
    font-weight: inherit;
    font-size: inherit;
}

/* Disabled state — dim the whole row so the customer doesn't try to click it. */
.cwh-radio-row.is-disabled,
.cwh-checkbox-row.is-disabled,
.cwh-radio-row input:disabled,
.cwh-checkbox-row input:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

/* Vertical stack helper — use on a parent <div> when several radio rows
 * belong to the same question, so each row is its own line with consistent
 * spacing. */
.cwh-radio-group,
.cwh-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 4px 0 0;
}

/* ── Field validation count (FLG-576, OQ-085 section 4) ─────────────────────
 *
 * "3 fields need attention" beside a form's save button, written by
 * public/js/fieldValidation.js (cwhField_validate / cwhField_check) into a
 * `.cwh-field-count` (or `[data-cwh-count-for="<containerId>"]`). Empty when
 * every field is valid, so it takes no room until there is something to say.
 * Same red as the inline messages, same 13px as `.cwh-card-description`. */
.cwh-field-count {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    align-self: center;
    font-family: var(--cwh-font-family);
    font-size: 13px;
    font-weight: var(--cwh-font-medium);
    color: var(--cwh-danger);
    white-space: nowrap;
}

.cwh-field-count:empty {
    display: none;
}

.cwh-field-count::before {
    font-family: 'boxicons';
    content: '\ea5d'; /* bx-error-circle */
    font-size: 15px;
    line-height: 1;
}

/* The message the engine inserts when a field has no pre-rendered line. */
.cwh-field-error {
    font-family: var(--cwh-font-family);
    font-size: 13px;
}
