/*
 * Consent banner of juhe-it-solutions/contao-consent-bundle.
 * A small card at the bottom left (or a bar at the bottom), the settings as a
 * centered dialog. Other positions come from data-juhe-consent-position.
 * Themes adapt it through the custom properties; the font is inherited.
 *
 * Accessibility: text meets 4.5:1 and the switch track and knob 3:1 against
 * their background (WCAG 1.4.3, 1.4.11); targets are at least 44px; focus is
 * always visible and never hidden by the sticky buttons; motion stops with
 * prefers-reduced-motion; forced colors get native controls. A theme that
 * changes the colors keeps these ratios.
 */
.juhe-consent,
.juhe-consent-placeholder {
    --juhe-consent-background: #fff;
    --juhe-consent-text: #17191c;
    --juhe-consent-muted: #5b6068;
    --juhe-consent-line: #e3e5e9;
    --juhe-consent-surface: #f4f5f7;
    --juhe-consent-accent: #17191c;
    --juhe-consent-accent-text: #fff;
    --juhe-consent-switch-on: #1f7a4d;
    --juhe-consent-switch-off: #767b84;
    --juhe-consent-knob: #fff;
    --juhe-consent-focus: var(--juhe-consent-text);
    --juhe-consent-scrim: rgb(15 17 20 / 0.45);
    --juhe-consent-radius: 16px;
    --juhe-consent-shadow: 0 2px 6px rgb(0 0 0 / 0.06), 0 18px 48px rgb(0 0 0 / 0.16);
}

@media (prefers-color-scheme: dark) {
    .juhe-consent,
    .juhe-consent-placeholder {
        --juhe-consent-background: #1c1e22;
        --juhe-consent-text: #eef0f3;
        --juhe-consent-muted: #a9aeb6;
        --juhe-consent-line: #33363c;
        --juhe-consent-surface: #26292e;
        --juhe-consent-accent: #eef0f3;
        --juhe-consent-accent-text: #17191c;
        --juhe-consent-switch-on: #3fb27a;
        --juhe-consent-switch-off: #8a9099;
        --juhe-consent-knob: #17191c;
        --juhe-consent-shadow: 0 18px 48px rgb(0 0 0 / 0.5);
    }
}

/* The card */
.juhe-consent {
    position: fixed;
    z-index: 2147483000;
    inset: auto auto 1rem 1rem;
    box-sizing: border-box;
    width: min(100% - 2rem, 24rem);
    max-width: none;
    max-height: calc(100dvh - 2rem);
    margin: 0;
    padding: 0;
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--juhe-consent-line);
    border-radius: var(--juhe-consent-radius);
    background: var(--juhe-consent-background);
    color: var(--juhe-consent-text);
    box-shadow: var(--juhe-consent-shadow);
    font: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.juhe-consent[open] {
    animation: juhe-consent-in 0.25s ease-out;
}

@keyframes juhe-consent-in {
    from {
        opacity: 0;
        transform: translateY(0.75rem);
    }
}

/* Read by screen readers, not shown */
.juhe-consent-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.juhe-consent__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
    padding: 1.25rem;
}

.juhe-consent__headline {
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.3;
}

.juhe-consent__text {
    color: var(--juhe-consent-muted);
}

.juhe-consent__text > * {
    margin: 0 0 0.5em;
}

.juhe-consent__text > :last-child {
    margin-bottom: 0;
}

.juhe-consent a {
    color: inherit;
    text-underline-offset: 0.15em;
}

.juhe-consent__buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.juhe-consent__button,
.juhe-consent-placeholder button {
    min-height: 44px;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--juhe-consent-accent);
    border-radius: 999px;
    background: var(--juhe-consent-accent);
    color: var(--juhe-consent-accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.juhe-consent__button:hover,
.juhe-consent-placeholder button:hover {
    opacity: 0.85;
}

/* "Settings" is a quiet full-width row under the two equal choices */
.juhe-consent__button--quiet {
    grid-column: 1 / -1;
    border-color: var(--juhe-consent-line);
    background: transparent;
    color: var(--juhe-consent-text);
}

.juhe-consent__button[hidden],
.juhe-consent__settings[hidden] {
    display: none;
}

.juhe-consent :focus-visible,
.juhe-consent-placeholder :focus-visible {
    outline: 2px solid var(--juhe-consent-focus);
    outline-offset: 2px;
}

/* Additional information below the groups, across all columns of the bar */
.juhe-consent__info {
    grid-column: 1 / -1;
    margin-top: 0.25rem;
    color: var(--juhe-consent-muted);
    font-size: 0.875rem;
}

.juhe-consent__info > * {
    margin: 0 0 0.5em;
}

.juhe-consent__info > :last-child {
    margin-bottom: 0;
}

.juhe-consent__links {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1rem;
    margin: 0;
    color: var(--juhe-consent-muted);
    font-size: 0.8125rem;
}

.juhe-consent__links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

/*
 * Other card positions. Each keeps the 1rem distance to the edges and the
 * size limits above, so the card never leaves the viewport and the page
 * scrolls under it. The settings rule below wins and centres the settings.
 */
.juhe-consent[data-juhe-consent-position="bottom-right"] {
    inset: auto 1rem 1rem auto;
}

.juhe-consent[data-juhe-consent-position="bottom-center"] {
    inset: auto 0 1rem;
    margin-inline: auto;
}

.juhe-consent[data-juhe-consent-position="center"] {
    inset: 0;
    margin: auto;
}

.juhe-consent[data-juhe-consent-position="top-left"] {
    inset: 1rem auto auto 1rem;
}

.juhe-consent[data-juhe-consent-position="top-right"] {
    inset: 1rem 1rem auto auto;
}

.juhe-consent[data-juhe-consent-position="top-center"] {
    inset: 1rem 0 auto;
    margin-inline: auto;
}

/* The settings dialog */
.juhe-consent.juhe-consent--settings {
    inset: 0;
    width: min(100% - 2rem, 36rem);
    max-height: min(100dvh - 2rem, 48rem);
    margin: auto;
}

/* The scrim; ::backdrop inherits the custom properties in current browsers */
.juhe-consent::backdrop {
    background: var(--juhe-consent-scrim, rgb(15 17 20 / 0.45));
    backdrop-filter: blur(2px);
}

.juhe-consent--settings .juhe-consent__inner {
    gap: 1rem;
    padding: 1.5rem;
}

.juhe-consent--settings .juhe-consent__headline {
    font-size: 1.25rem;
}

/*
 * The choices stay in view while the groups scroll; the scroll padding keeps a
 * focused element above them (WCAG 2.4.11). On short screens, e.g. at 400
 * percent zoom, they scroll with the rest.
 */
.juhe-consent--settings {
    scroll-padding-bottom: 6rem;
}

.juhe-consent--settings .juhe-consent__buttons {
    position: sticky;
    bottom: 0;
    order: 1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0 -1.5rem -1.5rem;
    padding: 1rem 1.5rem 1.5rem;
    border-top: 1px solid var(--juhe-consent-line);
    background: var(--juhe-consent-background);
}

.juhe-consent--settings .juhe-consent__button--quiet {
    grid-column: auto;
}

@media (max-width: 30rem) {
    .juhe-consent--settings {
        scroll-padding-bottom: 9rem;
    }

    .juhe-consent--settings .juhe-consent__buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .juhe-consent--settings .juhe-consent__button--quiet {
        grid-column: 1 / -1;
    }
}

@media (max-height: 30rem) {
    .juhe-consent--settings {
        scroll-padding-bottom: 0;
    }

    .juhe-consent--settings .juhe-consent__buttons {
        position: static;
    }
}

/* The bar: full width at the bottom, the groups always shown */
.juhe-consent[data-juhe-consent-layout="bar"] {
    inset: auto 0 0;
    width: 100%;
    border-width: 1px 0 0;
    border-radius: var(--juhe-consent-radius) var(--juhe-consent-radius) 0 0;
}

/* The bar at the top edge */
.juhe-consent[data-juhe-consent-layout="bar"][data-juhe-consent-position="top"] {
    inset: 0 0 auto;
    border-width: 0 0 1px;
    border-radius: 0 0 var(--juhe-consent-radius) var(--juhe-consent-radius);
}

.juhe-consent[data-juhe-consent-layout="bar"] .juhe-consent__inner {
    max-width: 72rem;
    margin-inline: auto;
}

.juhe-consent[data-juhe-consent-layout="bar"] .juhe-consent__button--quiet {
    grid-column: 1 / -1;
}

@media (min-width: 48rem) {
    .juhe-consent[data-juhe-consent-layout="bar"] .juhe-consent__settings {
        grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
        align-items: start;
    }

    .juhe-consent[data-juhe-consent-layout="bar"] .juhe-consent__buttons {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .juhe-consent[data-juhe-consent-layout="bar"] .juhe-consent__button--quiet {
        grid-column: auto;
    }
}

.juhe-consent__settings {
    display: grid;
    gap: 0.5rem;
}

.juhe-consent-group {
    padding: 0.875rem 1rem;
    border-radius: calc(var(--juhe-consent-radius) - 6px);
    background: var(--juhe-consent-surface);
}

.juhe-consent-group__head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    min-height: 44px;
    cursor: pointer;
}

.juhe-consent-group__title {
    flex: 1 1 8rem;
    min-width: 0;
    font-weight: 600;
}

.juhe-consent-group__always {
    color: var(--juhe-consent-muted);
    font-size: 0.8125rem;
}

.juhe-consent-group__description {
    margin: 0.125rem 0 0;
    color: var(--juhe-consent-muted);
}

/* Checkbox drawn as a switch; it stays a real checkbox for assistive technology */
.juhe-consent-switch {
    position: relative;
    flex: none;
    width: 2.75rem;
    height: 1.5rem;
    margin: 0;
    border-radius: 999px;
    background: var(--juhe-consent-switch-off);
    cursor: pointer;
    appearance: none;
    transition: background 0.15s;
}

.juhe-consent-switch::before {
    position: absolute;
    inset: 0.1875rem auto auto 0.1875rem;
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 50%;
    background: var(--juhe-consent-knob);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
    content: "";
    transition: transform 0.15s;
}

.juhe-consent-switch:checked {
    background: var(--juhe-consent-switch-on);
}

.juhe-consent-switch:checked::before {
    transform: translateX(1.25rem);
}

/* Mixed: some services of the group are on. The knob sits in the middle. */
.juhe-consent-switch:indeterminate {
    background: linear-gradient(90deg, var(--juhe-consent-switch-on) 50%, var(--juhe-consent-switch-off) 50%);
}

.juhe-consent-switch:indeterminate::before {
    transform: translateX(0.625rem);
}

.juhe-consent-switch:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

@media (forced-colors: active) {
    .juhe-consent-switch {
        border: 1px solid CanvasText;
        appearance: auto;
    }

    .juhe-consent-switch::before {
        display: none;
    }
}

.juhe-consent-group__services {
    margin-top: 0.375rem;
}

.juhe-consent-group__services summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    color: var(--juhe-consent-muted);
    font-size: 0.875rem;
    cursor: pointer;
}

/* The title and its switch share the first row; the details span both columns */
.juhe-consent-service {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 0.75rem;
    align-items: center;
    padding: 0.75rem 0;
    border-top: 1px solid var(--juhe-consent-line);
    font-size: 0.875rem;
}

.juhe-consent-service > :not(.juhe-consent-service__title, .juhe-consent-service__switch) {
    grid-column: 1 / -1;
}

.juhe-consent-service__title {
    margin: 0 0 0.375rem;
    font-size: 0.9375rem;
}

/* The whole box around a service switch takes the click: at least 44px */
.juhe-consent-service__switch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
}

.juhe-consent-service dl {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.25rem 0.875rem;
    margin: 0;
}

@media (min-width: 30rem) {
    .juhe-consent-service dl {
        grid-template-columns: minmax(6.5rem, max-content) minmax(0, 1fr);
    }
}

.juhe-consent-service dt {
    color: var(--juhe-consent-muted);
}

.juhe-consent-service dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.juhe-consent-service dd a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

/*
 * Blocked iframes: a framed card with a glyph for the kind of content, the
 * service name, the notice and the two buttons. Video and map keep the shape
 * of the content they stand in for; the card grows when its text needs more.
 * The glyph is decorative; in forced colors it draws in the system colors.
 */
.juhe-consent-placeholder {
    display: grid;
    gap: 0.75rem;
    place-content: center;
    justify-items: center;
    box-sizing: border-box;
    min-height: 16rem;
    padding: clamp(1.25rem, 4vw, 2.5rem);
    border: 1px solid var(--juhe-consent-line);
    border-radius: var(--juhe-consent-radius);
    background: var(--juhe-consent-surface);
    color: var(--juhe-consent-text);
    font-size: 0.9375rem;
    line-height: 1.5;
    text-align: center;
}

/* min-height auto keeps the content's height as the minimum, so text never overflows the ratio */
.juhe-consent-placeholder--video {
    min-height: auto;
    aspect-ratio: 16 / 9;
}

.juhe-consent-placeholder--map {
    min-height: auto;
    aspect-ratio: 3 / 2;
}

.juhe-consent-placeholder p {
    margin: 0;
    max-width: 34rem;
}

/* Both sizes set: with height auto, the grid sizes its row too short inside a ratio box */
.juhe-consent-glyph {
    width: 5.5rem;
    height: 4.125rem;
    margin-block-end: 0.5rem;
    color: var(--juhe-consent-accent);
}

.juhe-consent-glyph__frame {
    fill: var(--juhe-consent-background);
    stroke: var(--juhe-consent-line);
}

.juhe-consent-glyph__line {
    stroke: var(--juhe-consent-muted);
    opacity: 0.5;
}

.juhe-consent-glyph__dot {
    fill: var(--juhe-consent-muted);
    opacity: 0.5;
}

.juhe-consent-glyph__knock {
    fill: var(--juhe-consent-accent-text);
}

.juhe-consent-placeholder__title {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.juhe-consent-placeholder__kind {
    display: block;
    margin-block-end: 0.125rem;
    color: var(--juhe-consent-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.juhe-consent-placeholder__text {
    color: var(--juhe-consent-muted);
}

.juhe-consent-placeholder__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-block-start: 0.25rem;
}

.juhe-consent-placeholder [data-juhe-consent-allow] {
    border-color: var(--juhe-consent-line);
    background: var(--juhe-consent-background);
    color: var(--juhe-consent-text);
}

.juhe-consent-placeholder__privacy a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--juhe-consent-muted);
    font-size: 0.875rem;
}

@media (forced-colors: active) {
    .juhe-consent-placeholder {
        border-color: CanvasText;
    }

    .juhe-consent-glyph * {
        stroke: CanvasText;
        opacity: 1;
    }

    .juhe-consent-glyph__frame,
    .juhe-consent-glyph__knock {
        fill: Canvas;
    }

    .juhe-consent-glyph__knock {
        stroke: none;
    }

    .juhe-consent-glyph__mark,
    .juhe-consent-glyph__dot {
        fill: CanvasText;
    }
}

/* Last, so it wins over every transition above */
@media (prefers-reduced-motion: reduce) {
    .juhe-consent[open] {
        animation: none;
    }

    .juhe-consent *,
    .juhe-consent *::before,
    .juhe-consent-placeholder button {
        transition: none;
    }
}
