/* Language menu and light / dark toggle (Components/PreferenceControls.razor), the same look as the WebbuilderFrontEnd
   header. Used in the top bar of the platform sites and the Editor; each site loads it on every page. */

/* ---------- language menu (same look as the WebbuilderFrontEnd header) ---------- */

.upc-lang {
    position: relative;
}

.upc-lang-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--app-line);
    border-radius: 999px;
    background: var(--app-surface);
    /* A crowded top bar on a narrow phone must not squeeze the language name onto two lines */
    white-space: nowrap;
    font-family: var(--app-font-family);
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    color: var(--app-text);
    cursor: pointer;
    transition: border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

/* Touch screens: tapped over at least 44 x 44 px, as every control (app-ui.css, touch hit areas) */
@media (pointer: coarse) {
    :where(.upc-lang-toggle) {
        position: relative;
    }

    .upc-lang-toggle::after {
        content: "";
        position: absolute;
        inset: min(0px, calc((100% - 44px) / 2));
    }
}

/* Optical correction: Boxicons glyphs are drawn inside their box with a built-in inset (the globe about 1.4px on each
   side, the caret about 4.2px). Pulling each icon out by its inset makes the visible space before the globe equal to
   the space after the last item, and the space around the language name even, in every language. */
.upc-lang-toggle .bx-globe {
    display: inline-block;
    margin-inline-start: -1px;
    font-size: 18px;
    line-height: 1;
}

.upc-lang[data-open] .upc-lang-toggle {
    border-color: var(--app-accent);
    color: var(--app-accent);
    box-shadow: var(--app-field-focus);
}

@media (hover: hover) {
    .upc-lang-toggle:hover {
        border-color: var(--app-accent);
        color: var(--app-accent);
    }

    /* The globe turns once around its own axis (the caret's nudge is the platform's arrow, app-ui.css .app-caret) */
    .upc-lang-toggle:hover .bx-globe {
        animation: upc-globe-turn 0.9s var(--app-ease-out);
    }
}

@keyframes upc-globe-turn {
    from {
        transform: perspective(60px) rotateY(0deg);
    }

    to {
        transform: perspective(60px) rotateY(360deg);
    }
}

/* The platform's arrow (app-ui.css .app-caret), pulled out by its glyph's inset */
.upc-lang-caret {
    margin-inline: -3px -4px;
    font-size: 16px;
}

.upc-lang-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 5;
    min-width: 184px;
    margin: 0;
    padding: 6px;
    border: 1px solid var(--app-line);
    border-radius: 14px;
    background: var(--app-surface);
    box-shadow: var(--app-shadow-menu);
    list-style: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.94);
    transform-origin: top right;
    transition: opacity 0.2s ease, transform 0.35s var(--app-ease-spring), visibility 0.2s;
}

.upc-lang[data-open] .upc-lang-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
}

/* Options cascade in after the menu opens */
.upc-lang-menu li {
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 0.25s ease, transform 0.35s var(--app-ease-out);
}

.upc-lang[data-open] .upc-lang-menu li {
    opacity: 1;
    transform: none;
}

.upc-lang[data-open] .upc-lang-menu li:nth-child(2) {
    transition-delay: 0.04s;
}

.upc-lang[data-open] .upc-lang-menu li:nth-child(3) {
    transition-delay: 0.08s;
}

.upc-lang-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.3;
    color: var(--app-text);
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

@media (hover: hover) {
    .upc-lang-option:hover {
        background: var(--app-bg-soft);
        color: var(--app-accent);
    }
}

.upc-lang-check {
    font-size: 18px;
    line-height: 1;
    visibility: hidden;
}

.upc-lang-option-active {
    font-weight: 600;
    color: var(--app-accent);
}

.upc-lang-option-active .upc-lang-check {
    visibility: visible;
}

/* ---------- theme toggle ---------- */

/* The sun or the moon: a 20px square (an even size, so it sits on whole pixels in the middle of the round button), kept
   on its own layer so turning it never shifts it by a pixel when the turn ends. Which of the two shows is app-ui.css's
   (app-theme-moon, app-theme-sun), so the display is left to it. */
.upc-theme i {
    width: 1em;
    height: 1em;
    font-size: 20px;
    line-height: 1;
    will-change: transform;
    /* It spins in every time it appears, i.e. after each theme switch */
    animation: upc-theme-icon-in 0.6s var(--app-ease-spring) both;
    transition: rotate 0.45s var(--app-ease-spring);
}

/* Pointing at it turns only the icon, around its own centre; the button stays where it is. The turn uses the rotate
   property, so it adds to the spin-in animation (which holds transform) instead of fighting it. */
@media (hover: hover) {
    .upc-theme:hover i {
        rotate: -20deg;
    }
}

@keyframes upc-theme-icon-in {
    from {
        opacity: 0;
        transform: rotate(-120deg) scale(0.4);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (max-width: 767.98px) {
    /* Without the caret, the globe and the language name sit between equal paddings, the same visible inset as the
       round icon buttons next to it, which leaves the page title room on a 320px phone */
    .upc-lang-toggle {
        height: 40px;
        padding: 0 10px;
    }

    .upc-lang-caret {
        display: none;
    }

    .upc-theme {
        width: 40px;
        height: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .upc-lang-menu,
    .upc-lang-menu li,
    .upc-theme i {
        transition: none;
    }

    .upc-theme i,
    .upc-lang-toggle:hover .bx-globe {
        animation: none;
    }

    .upc-theme:hover i {
        rotate: none;
    }
}
