/* Flatfox "Online-Service": trigger in the navbar, applet in a modal.
   Rendered by Partials/Page/Flatfox/{Trigger,Modal}.html */

/* --- Trigger, last item of the main navigation row --- */
/* Deliberately louder than the shared button size: this is the one call to
   action in the header and it was asked to carry more weight than the rest.

   Its width is left to the wording and never animated. Widening this button
   drags the whole navigation sideways - measured: 198px of extra padding
   pulled the menu 190px to the left - so nothing here touches it. */
.btn-flatfox {
    /* Both for the sweep below: it is positioned against the button and
       clipped to the pill's own shape. */
    position: relative;
    overflow: hidden;

    /* A disc, not a pill: the client wants it to break out of the header band
       and sit on the picture. Width and height are the same value, so the one
       variable decides how big it is. */
    /* 7% off the 9rem it carried while it was still sitting in the band -
       144px was too much of it once the disc moved onto the photo. Both
       labels still sit on two lines with room to spare: the French one, the
       longer of the two, measures 87x38, and at the height that text occupies
       the circle is still 128px wide. */
    --flatfox-size: 8.4rem;
    /* How much of the disc stays inside the band. It reaches up past the menu
       and leaves roughly its lower half on the picture - far enough up that
       its top edge clears the menu items and stops just under DE/FR. */
    --flatfox-overlap: 78px;
    /* 1 here, less when the bar condenses. It is a variable because the lift
       below has to know about it. */
    --flatfox-scale: 1;
    /* How far the disc is lifted up out of the band: by as much of it as is
       meant to show there, less a correction. scale() works from the centre,
       so a shrunken disc rises by half the height it gives up all on its own,
       and that much comes back off the lift - otherwise the overlap would
       grow as the disc got smaller. At scale 1 that term is 0 and the lift is
       just the overlap.
       One variable, because the entrance animation below has to set exactly
       the same transform as this rule does. */
    --flatfox-lift: calc(-1 * (
        var(--flatfox-overlap)
        + var(--flatfox-size) * (1 - var(--flatfox-scale)) / 2
    ));

    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--flatfox-size);
    height: var(--flatfox-size);
    margin-left: 1.5rem;
    margin-right: 1.5rem;
    /* In the layout the disc hangs entirely below the band: the margin cancels
       its height exactly, so its box is 0 tall and it has no say at all in how
       tall the bar is. Where it actually sits is the transform's business, and
       a transform costs the layout nothing - which is the point, because the
       disc now reaches far enough up that any of this in margins would push
       the whole bar open. */
    margin-bottom: calc(-1 * var(--flatfox-size));
    padding: .5em 1em;
    font-size: .95rem;
    font-weight: var(--button-font-weight, 500);
    line-height: 1.3;
    /* Two short lines inside the disc rather than one line running out of it. */
    white-space: normal;
    text-align: center;
    color: #fff;
    background-color: var(--main-color, #e73531);
    border: 1px solid var(--main-color, #e73531);
    border-radius: 50%;
    transform: translateY(var(--flatfox-lift)) scale(var(--flatfox-scale));
    transition: background-color .2s ease, border-color .2s ease,
                transform .28s ease-in-out;
    /* Comes in from the right edge once, on load: a beat of stillness first,
       then a slow glide, so it is a movement the eye follows rather than a
       flick it only half catches. transform only, so it moves nothing around
       it while it travels. Ends at 0.6 + 1.1 = 1.7s - the sweep below waits
       for that. */
    animation: btn-flatfox-enter 1.1s .6s cubic-bezier(.22, .61, .36, 1) backwards;
}

/* Scrolled, the bar condenses and the disc condenses with it - but it keeps
   hanging off the bar instead of being pulled back inside it: a short bar has
   no room for it, and it is meant to stay the one thing you cannot miss.
   Less of it shows inside the band than at rest, because there is less band:
   both states end up with its top edge about the same distance under the top
   of the bar. Only the two variables change here; the transform above does
   the arithmetic. */
nav.navbar.navbar-shadow .btn-flatfox {
    --flatfox-overlap: 55px;
    --flatfox-scale: .72;
}

.btn-flatfox:hover,
.btn-flatfox:active,
.btn-flatfox:focus {
    /* Stays red and goes a shade deeper. Inverting to white would have made it
       quieter on hover, which is the opposite of what it is here to do. */
    color: #fff;
    background-color: #c92b27;
    border-color: #c92b27;
}

/* A light crossing the button every five seconds. It is a band of white at
   low opacity, skewed so it reads as a reflection rather than as a bar, and
   clipped by the pill. The pass takes about a second and a half of the five,
   so the button is still for most of the cycle and the eye catches the
   movement without the header ever feeling busy. */
.btn-flatfox::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 45%;
    background: linear-gradient(
        100deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, .22) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    transform: translateX(-250%) skewX(-18deg);
    /* Starts after the button has finished arriving (1.7s), so the two never
       run over each other on the first load. */
    animation: btn-flatfox-shine 5s 2.2s ease-in-out infinite;
    pointer-events: none;
}

/* The sweep occupies the first 28% of the cycle - 1.4s of the 5s - and the
   remaining 3.6s is the pause. Slowing the pass is a matter of moving this one
   stop: later means slower, and the rest of the cycle shortens to match. */
@keyframes btn-flatfox-shine {
    0% {
        transform: translateX(-250%) skewX(-18deg);
    }
    28% {
        transform: translateX(350%) skewX(-18deg);
    }
    100% {
        transform: translateX(350%) skewX(-18deg);
    }
}

/* Both keyframes carry the resting transform whole - the lift and the scale -
   and only add the journey in front of it. Leave either out and the disc
   animates in at the wrong height or the wrong size and corrects itself with
   a jump the moment the animation hands the transform back. The scale matters
   because the page can load already scrolled: reload halfway down and the bar
   is condensed from the first frame, so the disc has to arrive small.
   translateX sits before scale, so the distance it travels is its own, not
   the scaled one. */
@keyframes btn-flatfox-enter {
    from {
        transform: translateY(var(--flatfox-lift))
                   translateX(calc(100% + 3rem))
                   scale(var(--flatfox-scale));
        opacity: 0;
    }
    to {
        transform: translateY(var(--flatfox-lift))
                   translateX(0)
                   scale(var(--flatfox-scale));
        opacity: 1;
    }
}

/* Someone who has asked their system for less movement gets the button where
   it belongs, immediately. */
@media (prefers-reduced-motion: reduce) {
    .btn-flatfox {
        animation: none;
    }

    .btn-flatfox::after {
        display: none;
    }
}

/* The switcher no longer follows the button (it sits in the top right corner
   now), so the button ends the row. It keeps 20px off the right edge: hanging
   over the picture, flush right put it half outside the composition. Below
   ~1400px it also has to give room back to the menu items. */
@media (min-width: 1200px) {
    .btn-flatfox {
        margin-right: 20px;
    }

    /* .navbar-collapse centres the boxes of the row, so the disc's resting
       point would depend on how tall the menu items happen to be - and they
       get shorter the moment you scroll. Pinning the box that carries it to
       the bottom edge of the bar instead leaves --flatfox-overlap as the only
       thing deciding where it sits, in both states. */
    .navbar-collapse .languages-cal {
        align-self: flex-end;
    }
}

@media (min-width: 1200px) and (max-width: 1399.98px) {
    .btn-flatfox {
        margin-left: .75rem;
    }
}

/* --- Trigger as a bar, below the burger breakpoint only --- */
.btn-flatfox-bar {
    display: none;
}

@media (max-width: 1199.98px) {
    /* The trigger in the collapsed menu would be a second, hidden copy of the
       bar, so only the bar is shown. */
    .navbar-collapse .btn-flatfox {
        display: none;
    }

    .btn-flatfox-bar {
        display: block;
        width: 100%;
        padding: 10px 0;
        border: 0;
        border-radius: 0;
        /* The brand red, like the button it stands in for on wider screens. */
        color: #fff;
        background-color: var(--main-color, #e73531);
        font-size: var(--button-font-size, .9rem);
        font-weight: var(--button-font-weight, 500);
        line-height: 1.2;
        transition: color .15s ease-in-out, background-color .15s ease-in-out;
    }

    .btn-flatfox-bar:hover,
    .btn-flatfox-bar:active,
    .btn-flatfox-bar:focus {
        color: var(--main-color, #e73531);
        background-color: var(--grey-color, #f1f1f1);
    }
}

/* --- Modal ---
   The applet iframe carries scrolling="no" and overflow:hidden, and
   iframe-resizer grows it to its full content height. So the iframe must never
   sit inside its own scroll container (no .modal-dialog-scrollable): the wheel
   would be captured by the iframe and nothing would move. Letting .modal scroll
   the whole dialog is what iframe-resizer expects. */
#flatfoxAnliegen .modal-dialog {
    margin-top: 1.75rem;
    margin-bottom: 1.75rem;
}

/* The applet opens with its own headline ("Anliegen melden") in Flatfox's own
   typeface, right under our header. Two headlines in two fonts, a few pixels
   apart, is what made the dialog look busy. We only own the upper one - the
   applet sits in an iframe on flatfox.ch - so it steps back and reads as a
   window label instead of a second heading: the same small uppercase style the
   footer uses. That leaves one headline on screen, theirs. */
#flatfoxAnliegen .modal-title {
    font-size: 12px;
    font-weight: var(--button-font-weight, 500);
    line-height: 1.4;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #6f6f6f;
    margin-bottom: 0;
}

#flatfoxAnliegen .modal-body {
    /* The applet ends flush with its last element, so the breathing room at the
       bottom has to come from here, otherwise the dialog looks cut off. */
    padding: .5rem .75rem 2.5rem;
}

#flatfoxAnliegen iframe {
    display: block;
    width: 100%;
}

@media (max-width: 575.98px) {
    #flatfoxAnliegen .modal-body {
        padding: .25rem 1rem 2rem;
    }
}

/* --- Our own logo, in place of the applet's --- */

#flatfoxAnliegen .flatfox-logo {
    padding: 1.5rem 0 .25rem;
    text-align: center;
}

#flatfoxAnliegen .flatfox-logo img {
    width: 264px;
    max-width: 62%;
    height: auto;
}

/* Clip the applet's own logo away. It is the first element of their document,
   sits flush at the top, and is drawn at the file's own 480x243 - their CSS
   gives it no width, only max-width: 100%. So at any frame wider than 480px
   the block is exactly 243px tall. */
#flatfoxAnliegen .flatfox-frame {
    overflow: hidden;
}

#flatfoxAnliegen .flatfox-frame iframe {
    /* Their block is 243px tall while the frame is at least 480px wide. Below
       that, max-width: 100% takes over and it scales with the frame, so the
       clip has to scale too: 243 / 480 = 50.625% of the frame's width (a
       percentage margin resolves against the containing block, the frame).
       max() picks whichever is the smaller cut, so the two meet exactly where
       they should at any width - no breakpoint to keep in sync with the
       padding below. */
    margin-top: max(-243px, -50.625%);
}
