/*
 * The one country list of the site (resources/views/components/country-select.blade.php,
 * public/js/country-select.js): a searchable list whose options and closed field carry the
 * country's flag. The flag is the sprite the phone field already ships (.iti__flag .iti__xx);
 * this file only places it.
 */
.r2e-country-flag {
  display: inline-block;
  flex: none;
  vertical-align: middle;
  margin-right: var(--r2e-space-2);
  /* A flag taller than the line (a few are 15px) must not push the list item taller. */
  margin-top: -2px;
}

.r2e-country-choices {
  margin-bottom: 0;
}

.r2e-country-choices .choices__list--single .choices__item,
.r2e-country-choices .choices__list--dropdown .choices__item {
  display: flex;
  align-items: center;
}

/* The small form field: the same height as .form-control-sm / .form-select-sm. */
.r2e-country-choices.r2e-country-sm .choices__inner {
  min-height: calc(1.5em + 0.5rem + 2px);
  padding-top: var(--r2e-space-1);
  padding-bottom: var(--r2e-space-1);
  font-size: var(--r2e-text-xs);
}

/* The server refused the value: the closed field reads like any other invalid input. */
.r2e-country-choices.is-invalid .choices__inner {
  border-color: var(--bs-form-invalid-border-color, var(--bs-info));
}

.r2e-country-choices.is-invalid ~ .invalid-feedback {
  display: block;
}

/*
 * The phone layer (<x-country-select phone-fullscreen>, public/js/country-select.js): under 768 px the open list
 * covers the screen, the way the trip date picker does (public/css/fullscreen-date-picker.css): the same header
 * (a close button, the title), the same safe-area margins, the same colours and radii. It is Choices' own
 * dropdown dressed differently, so what the list posts does not change; nothing here applies without the
 * .r2e-country-fs class, which only a list that asked for it carries, and from 768 px up the dropdown is the
 * page's own. Tokens only.
 */
.r2e-cfs-top {
    display: none;
}

@media (max-width: 767.98px) {
    html.r2e-cfs-lock,
    html.r2e-cfs-lock body {
        overflow: hidden;
    }

    .r2e-country-choices.r2e-country-fs .choices__list--dropdown.is-active {
        position: fixed !important;
        inset: 0 !important;
        display: flex !important;
        flex-direction: column;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: var(--bs-mode);
        overflow: hidden;
        word-break: normal;
        z-index: 1;
    }

    .r2e-country-fs .choices__list--dropdown > * {
        flex: none;
    }

    /* The header: close, title. Always on screen. */
    .r2e-country-fs .r2e-cfs-top {
        display: block;
        padding: max(var(--r2e-space-3), env(safe-area-inset-top)) max(var(--r2e-space-4), env(safe-area-inset-right)) var(--r2e-space-2) max(var(--r2e-space-4), env(safe-area-inset-left));
        background: var(--bs-mode);
    }

    .r2e-country-fs .r2e-cfs-toprow {
        display: grid;
        grid-template-columns: 44px 1fr 44px;
        align-items: center;
    }

    .r2e-country-fs .r2e-cfs-title {
        margin: 0;
        text-align: center;
        font-size: var(--r2e-text-lg);
        font-weight: 600;
        color: var(--r2e-ink);
    }

    .r2e-country-fs .r2e-cfs-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 0;
        border-radius: var(--r2e-radius-pill);
        background: none;
        color: var(--r2e-ink);
        font-size: var(--r2e-text-lg);
        cursor: pointer;
    }

    /* The search box, full width. Its text is 16px at least: under that, iOS Safari zooms the page on focus. */
    .r2e-country-choices.r2e-country-fs .choices__list--dropdown > .choices__input {
        display: block;
        box-sizing: border-box;
        width: auto;
        height: 48px;
        margin: 0 max(var(--r2e-space-4), env(safe-area-inset-right)) var(--r2e-space-2) max(var(--r2e-space-4), env(safe-area-inset-left));
        padding: 0 var(--r2e-space-3);
        border: 1px solid var(--bs-gray-200) !important;
        border-radius: var(--r2e-radius);
        background: var(--bs-mode);
        font-size: max(16px, var(--r2e-text-base));
        outline: none;
    }

    .r2e-country-choices.r2e-country-fs .choices__list--dropdown > .choices__input:focus {
        border-color: var(--bs-primary) !important;
    }

    /* The list scrolls under the header; the page behind it does not. */
    .r2e-country-choices.r2e-country-fs .choices__list--dropdown > .choices__list {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        padding-bottom: env(safe-area-inset-bottom);
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    /* A row is a touch target: 48px at least, the flag then the name, the chosen country marked at the end. */
    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item--choice.choices__item--selectable,
    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item {
        min-height: 48px;
        padding: 0 max(var(--r2e-space-4), env(safe-area-inset-right)) 0 max(var(--r2e-space-4), env(safe-area-inset-left));
        font-size: var(--r2e-text-base);
    }

    /* The empty choice is the title already ("Country"): no grey row repeating it above the countries. */
    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item--choice.choices__placeholder {
        display: none;
    }
    /* Unless the page names it (data-fullscreen-all): then it is the first row, "All countries", like any other row. */
    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item--choice.choices__placeholder.r2e-cfs-all {
        display: flex;
        opacity: 1;
        font-weight: 600;
        color: var(--bs-secondary) !important;
    }

    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item--choice .r2e-country-flag {
        margin-right: var(--r2e-space-3);
    }

    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item--choice.is-selected {
        font-weight: 600;
    }

    .r2e-country-choices.r2e-country-fs .choices__list--dropdown .choices__item--choice.is-selected::after {
        content: "\f00c";
        display: inline-block;
        position: static;
        margin-left: auto;
        padding-left: var(--r2e-space-3);
        /* Font Awesome's own solid face (its weight comes with it). */
        font: var(--fa-font-solid);
        font-size: var(--r2e-text-base);
        opacity: 1;
        color: var(--bs-primary);
    }
}
