/**
 * NHL Bookly searchable dropdowns.
 *
 * Styles the type-to-filter combobox that replaces the native Care-centre /
 * Speciality / Staff <select>s on the booking form. Uses site design tokens
 * (--primary, --accent, --radius, --font-sans from the active theme) and matches Bookly's
 * own field metrics (14px text, full width, silver border).
 *
 * Scoped under .bookly-form so it sits inside the booking widget only.
 * The native <select> is hidden but kept in the DOM (Bookly's Svelte code
 * still reads its value), so it must be hidden with !important to beat
 * Bookly's own `display: inline-block !important`.
 */

.bookly-form select.nhl-bsearch__native {
    display: none !important;
}

/*
 * Match Bookly's other native dropdowns (e.g. the Start from / Finish by time
 * selects) to the searchable combobox trigger height/shape, so every dropdown
 * on the form lines up. Mirrors the .nhl-bsearch__trigger metrics below
 * (38px tall, 7px/12px padding, themed radius). Excludes the hidden natives.
 */
.bookly-form select:not(.nhl-bsearch__native) {
    min-height: 38px;
    /* Extra right padding leaves room for the native dropdown arrow so it
       doesn't crowd the text (e.g. the Start from / Finish by time selects). */
    padding: 7px 28px 7px 12px !important;
    border-radius: var(--radius, 6px) !important;
}

/*
 * Same height/shape for the form's text inputs (e.g. the date field, name,
 * email), so every field on the form lines up at 38px. Excludes our combobox
 * search input, which keeps its own padding to leave room for the search icon.
 * (The phone field is type="tel" + intlTelInput, so it is not matched here.)
 */
.bookly-form input[type="text"]:not(.nhl-bsearch__input) {
    min-height: 38px;
    padding: 7px 12px !important;
    border-radius: var(--radius, 6px) !important;
}

/*
 * The phone field (type="tel") uses intlTelInput, which manages the input's
 * left padding to leave room for the country-flag dropdown. Match only the
 * height and radius here — overriding the horizontal padding would push the
 * typed number under the flag.
 */
.bookly-form input[type="tel"] {
    min-height: 38px;
    border-radius: var(--radius, 6px) !important;
}

/*
 * Column spacing for the three chain fields is left to Bookly's native gap
 * (.bookly-form-group:not(:last-child) > div { margin-right: 14px }) in the
 * default table layout, and to `column-gap` in the doctor-first flex layout
 * below. We deliberately do NOT add side margins to the combobox wrapper:
 * that shifted each box right of its label and indented the first column away
 * from the rest of the form.
 */

/* Let the floating panel escape Bookly's overflow:hidden on .bookly-box */
.bookly-form .bookly-table.bookly-box:has(.nhl-bsearch.is-open),
.bookly-form .bookly-form-group.is-nhl-bsearch-open {
    overflow: visible !important;
}

.bookly-form .bookly-form-group.is-nhl-bsearch-open {
    position: relative;
    z-index: 2;
}

.bookly-form .nhl-bsearch {
    position: relative;
    width: 100%;
    font-family: var(--font-sans, "Inter", system-ui, sans-serif);
    font-size: 14px;
}

/* ── Trigger ──────────────────────────────────────────────────────────────── */

.bookly-form .nhl-bsearch__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-height: 38px;
    margin: 0;
    padding: 7px 12px;
    background: #fff;
    color: hsl(var(--primary, 216 100% 22%));
    border: 1px solid silver;
    border-radius: var(--radius, 6px);
    font: inherit;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.bookly-form .nhl-bsearch__trigger:hover {
    border-color: hsl(var(--primary, 216 100% 22%) / 0.5);
}

.bookly-form .nhl-bsearch.is-open .nhl-bsearch__trigger,
.bookly-form .nhl-bsearch__trigger:focus-visible {
    border-color: hsl(var(--primary, 216 100% 22%));
    box-shadow: 0 0 0 3px hsl(var(--primary, 216 100% 22%) / 0.15);
    outline: none;
}

/* Locked field (Care-centre in doctor-first mode): shows the derived value but
   is not user-editable. Higher specificity than the hover/open rules above. */
.bookly-form .nhl-bsearch.is-locked .nhl-bsearch__trigger {
    background: #f3f4f6;
    color: #6b7280;
    border-color: silver;
    box-shadow: none;
    cursor: not-allowed;
}

.bookly-form .nhl-bsearch.is-locked .nhl-bsearch__caret {
    opacity: 0.35;
}

.bookly-form .nhl-bsearch__value {
    flex: 1 1 auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.bookly-form .nhl-bsearch.is-placeholder .nhl-bsearch__value {
    color: #6b7280;
}

.bookly-form .nhl-bsearch__caret {
    flex: 0 0 auto;
    width: 9px;
    height: 9px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    opacity: 0.6;
    transition: transform 0.15s ease;
}

.bookly-form .nhl-bsearch.is-open .nhl-bsearch__caret {
    transform: rotate(-135deg) translateY(-1px);
}

/* ── Panel ────────────────────────────────────────────────────────────────── */

/* position set to fixed in JS so the list does not cover other fields */
.bookly-form .nhl-bsearch__panel {
    z-index: 100000;
    background: #fff;
    border: 1px solid #e2e6ea;
    border-radius: var(--radius, 6px);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.16);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.bookly-form .nhl-bsearch__search {
    position: relative;
    padding: 8px;
    border-bottom: 1px solid #eef1f4;
}

/* Magnifier glyph (kept off the input so Bookly's input rules can't move it). */
.bookly-form .nhl-bsearch__search::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 18px;
    width: 14px;
    height: 14px;
    transform: translateY(-50%);
    background: no-repeat center / contain
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    pointer-events: none;
}

.bookly-form .nhl-bsearch__input,
.bookly-form input[type="text"].nhl-bsearch__input {
    width: 100% !important;
    padding: 8px 10px 8px 34px !important;
    border: 1px solid silver !important;
    border-radius: var(--radius, 6px) !important;
    font-size: 14px !important;
    line-height: normal !important;
    background: #fff;
    box-shadow: none !important;
}

.bookly-form .nhl-bsearch__input:focus {
    border-color: hsl(var(--primary, 216 100% 22%)) !important;
    outline: none;
}

/* ── Options ──────────────────────────────────────────────────────────────── */

.bookly-form .nhl-bsearch__list {
    list-style: none;
    margin: 0;
    padding: 4px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.bookly-form .nhl-bsearch__option--hidden {
    display: none !important;
}

.bookly-form .nhl-bsearch__option {
    margin: 0;
    padding: 9px 12px;
    border-radius: calc(var(--radius, 6px) - 2px);
    color: #1f2937;
    line-height: 1.3;
    cursor: pointer;
}

.bookly-form .nhl-bsearch__option.is-active,
.bookly-form .nhl-bsearch__option:hover {
    background: hsl(var(--accent, 140 59% 28%) / 0.12);
}

.bookly-form .nhl-bsearch__option.is-selected {
    font-weight: 600;
    color: hsl(var(--primary, 216 100% 22%));
}

.bookly-form .nhl-bsearch__option.is-selected.is-active,
.bookly-form .nhl-bsearch__option.is-selected:hover {
    background: hsl(var(--accent, 140 59% 28%) / 0.18);
}

.bookly-form .nhl-bsearch__empty {
    margin: 0;
    padding: 12px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
}

/* ── "Do you know your doctor?" toggle ───────────────────────────────────────
 * Injected by nhl-bookly-doctor-mode.js immediately before the chain row.
 */

.bookly-form .nhl-docmode {
    margin: 0 0 20px;
    font-family: var(--font-sans, "Inter", system-ui, sans-serif);
}

.bookly-form .nhl-docmode__label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: hsl(var(--primary, 216 100% 22%));
}

.bookly-form .nhl-docmode__options {
    display: inline-flex;
    border: 1px solid silver;
    border-radius: var(--radius, 6px);
    overflow: hidden;
}

.bookly-form .nhl-docmode__opt {
    margin: 0;
    padding: 9px 16px;
    background: #fff;
    color: hsl(var(--primary, 216 100% 22%));
    border: 0;
    border-right: 1px solid silver;
    font: inherit;
    font-size: 14px;
    line-height: 1.3;
    text-align: center;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.bookly-form .nhl-docmode__opt:last-child {
    border-right: 0;
}

.bookly-form .nhl-docmode__opt:hover {
    background: hsl(var(--primary, 216 100% 22%) / 0.08);
}

.bookly-form .nhl-docmode__opt.is-active {
    background: hsl(var(--primary, 216 100% 22%));
    color: #fff;
}

/* ── Appointment type (Physical / Online) segmented control ──────────────────
 * Injected by nhl-bookly-appt-type.js above the doctor toggle. Filters the
 * speciality (service) list to services of the chosen type. Mirrors .nhl-docmode.
 */

.bookly-form .nhl-appttype {
    margin: 0 0 20px;
    font-family: var(--font-sans, "Inter", system-ui, sans-serif);
}

.bookly-form .nhl-appttype__label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #002d70;
}

.bookly-form .nhl-appttype__options {
    display: inline-flex;
    border: 1px solid silver;
    border-radius: var(--radius, 6px);
    overflow: hidden;
}

.bookly-form .nhl-appttype__opt {
    margin: 0;
    padding: 9px 16px;
    background: #fff;
    color: #1c7339;
    border: 0;
    border-right: 1px solid silver;
    font: inherit;
    font-size: 14px;
    line-height: 1.3;
    text-align: center;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.bookly-form .nhl-appttype__opt:last-child {
    border-right: 0;
}

.bookly-form .nhl-appttype__opt:hover {
    background: rgba(28, 115, 57, 0.08);
}

.bookly-form .nhl-appttype__opt.is-active {
    background: #1c7339;
    color: #fff;
}

@media screen and (max-width: 650px) {
    .bookly-form .nhl-appttype__options {
        display: flex;
        width: 100%;
    }

    .bookly-form .nhl-appttype__opt {
        flex: 1 1 0;
    }
}

/* Desktop & tablet: put the Appointment Type control on the same line as the
   "Do you know your doctor?" toggle, Appointment Type first. The two controls
   are adjacent siblings ([appt-type][doctor][chain]); making them inline-block
   lays them out left→right, and the chain box (a block) drops to the next line.
   Below 651px the default block layout (+ the mobile rules above) keeps them
   stacked, so the mobile layout is unchanged. */
@media screen and (min-width: 651px) {
    .bookly-form .nhl-appttype,
    .bookly-form .nhl-docmode {
        display: inline-block;
        vertical-align: top;
        margin-bottom: 38px;
    }

    .bookly-form .nhl-appttype {
        margin-right: 40px;
    }

    /* Breathing room below the Category / Speciality / Doctor dropdown row
     * (the Svelte-rendered chain box), separating it from the date / week-days
     * row underneath. Scoped via :has() to the single row that holds the chain
     * fields, mirroring the doctor-first reorder rule below; other rows keep
     * Bookly's default spacing, and mobile (<651px) is unchanged. */
    .bookly-form .bookly-table.bookly-box:has(> .bookly-form-group[data-type="category"], > .bookly-form-group[data-type="service"], > .bookly-form-group[data-type="staff"]) {
        margin-bottom: 32px !important;
    }
}

/* ── Doctor-first reorder (only when the patient says they know their doctor) ──
 * Bookly's chain row is display:table (cells don't honour `order`), so override
 * it to flex and reorder. Scoped via :has() to the single row that holds the
 * three chain fields; other rows and "unknown" mode are left untouched.
 */

.bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    column-gap: 14px; /* even gaps between columns; no edge indent */
}

.bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group {
    flex: 1 1 0;
    min-width: 0;
    order: 4; /* any non-chain field (e.g. number of persons) lands after the three */
}

/* Spacing comes from column-gap above, so drop Bookly's per-cell right margin
   (it would make the gaps uneven once the columns are reordered). */
.bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group > div {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group[data-type="staff"]    { order: 1; }
.bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group[data-type="service"]  { order: 2; }
.bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group[data-type="category"] { order: 3; }

@media screen and (max-width: 650px) {
    .bookly-form .nhl-docmode__options {
        display: flex;
        width: 100%;
    }

    .bookly-form .nhl-docmode__opt {
        flex: 1 1 0;
    }

    /* Stack the chain top-to-bottom in doctor-first order. */
    .bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) {
        flex-direction: column;
    }

    .bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group {
        width: 100% !important;
        margin: 0 0 20px !important;
    }

    /* Care-centre is visually last in known mode — drop its trailing gap. */
    .bookly-form[data-nhl-doctor-mode="known"] .bookly-table.bookly-box:has(> .bookly-form-group[data-type="staff"]) > .bookly-form-group[data-type="category"] {
        margin-bottom: 0 !important;
    }
}

/* The service description sits between the chain dropdowns and the availability
   block. Without spacing it sits flush against both (most noticeable on
   tablet/desktop where the columns are close above it), so give it room. */
.bookly-form .bookly-service-info {
    margin-top: 24px;
    margin-bottom: 24px;
}

/* Pre-form loader. While Bookly's script boots, the form shows a class-less,
   centered <img alt="Loading..."> (the WordPress loader.gif) — NOT .bookly-loading
   (that is Bookly's later step-transition spinner). On mobile this loader sits at
   the bottom of the form area, flush against the footer below. Pad its wrapper —
   padding, not margin, because a bottom margin here collapses through .bookly-form
   and never reaches the footer (that was why the earlier margin "didn't impact"). */
.bookly-form > div:has(> img[alt="Loading..."]) {
    padding-top: 24px;
    padding-bottom: 24px;
}

/* Required-field markers (red asterisk). Two rendering styles on the form need
   two hooks, but neither keys off the label text — so the markers survive admin
   label renames and the translation/swap pipeline, and ::after keeps the "*"
   out of the label string entirely:

   - Step 1 chain fields (Speciality) have no per-field class, so we hook the
     native data-type="service" wrapper — the same attribute the combobox JS
     keys off.
   - Details-step fields carry a stable for="bookly-<field>-<form_id>" label
     prefix. We match the prefix (^=), not the form_id suffix, so it's immune to
     the id changing. "Full name" becomes First + Last name when Bookly is
     configured that way (showFirstLastName), so all three are covered; the
     email match excludes bookly-email-confirm- so only the primary Email is
     marked. */
.bookly-form .bookly-form-group[data-type="service"] > label::after,
.bookly-form label[for^="bookly-full-name-"]::after,
.bookly-form label[for^="bookly-first-name-"]::after,
.bookly-form label[for^="bookly-last-name-"]::after,
.bookly-form label[for^="bookly-phone-"]::after,
.bookly-form label[for^="bookly-email-"]:not([for^="bookly-email-confirm-"])::after,
.bookly-form label[for^="bookly-terms-"]:not(.bookly-checkbox)::after,
.bookly-form .nhl-patient-nationality-field > label::after {
    content: " *";
    color: #dc3232;
    font-weight: 700;
}

/* Error messages restyled to match the checkout's inline errors (Fluid
   Checkout's .fc-inline-error, which the client referenced): the theme font
   (var(--font-sans) — the same font the product/checkout section uses), red
   text and a red octagon alert icon. Applied to both Bookly's native field
   errors and our own Patient Nationality error so the whole booking form reads
   the same as the checkout.

   :not(:empty) is important: Bookly keeps an (empty) .bookly-label-error div in
   the DOM for every field and only fills it on failure — without this guard a
   stray icon would show under every field. */
.bookly-form .bookly-label-error:not(:empty),
.bookly-form .nhl-field-error:not(:empty) {
    margin-top: 6px;
    padding-left: 24px;
    font-family: var(--font-sans, "Inter", system-ui, sans-serif) !important;
    font-size: 15px !important;
    font-weight: 400 !important;
    line-height: 1.4;
    color: #dc3232 !important;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23dc3232' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") no-repeat left center;
    background-size: 18px 18px;
}

.bookly-form select.nhl-js-patient-nationality.bookly-error {
    border-color: #dc3232 !important;
}
