:root:has(.cookie-consent-banner:not([hidden])) {
    --cookie-banner-offset: max(0.75rem, env(safe-area-inset-bottom));
    --cookie-banner-clearance: calc(var(--cookie-banner-height, 0px) + var(--cookie-banner-offset) + 0.25rem);
    scroll-padding-block-end: var(--cookie-banner-clearance);
}

body:has(.cookie-consent-banner:not([hidden])) {
    padding-block-end: var(--cookie-banner-clearance);
}

.cookie-consent-banner,
.cookie-consent-dialog {
    padding: clamp(1rem, 2.2vw, 1.5rem);
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--popover);
    color: var(--popover-foreground);
    box-shadow: var(--egg-panel-shadow), 0 14px 48px rgb(0 0 0 / 35%);
    font-family: var(--brand-font-ui);
}

.cookie-consent-banner {
    position: fixed;
    z-index: 50;
    inset: auto 0 var(--cookie-banner-offset) 0;
    width: min(65rem, calc(100% - 2rem));
    max-height: 60vh;
    max-height: 60dvh;
    margin-inline: auto;
    overflow-y: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem 1.5rem;
}

.cookie-consent-banner[hidden],
.cookie-consent-dialog:not([open]),
.footer-cookie-settings[hidden] {
    display: none;
}

.cookie-consent-banner h2,
.cookie-consent-dialog h2 {
    margin: 0 0 0.375rem;
    font-size: 1.25rem;
    font-weight: 750;
    line-height: 1.2;
}

.cookie-consent-banner-copy p,
.cookie-consent-dialog-header p,
.cookie-consent-category p,
.cookie-consent-description,
.cookie-consent-status {
    margin: 0;
    color: var(--muted-foreground);
    font-size: 0.875rem;
    line-height: 1.5;
}

.cookie-consent-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.cookie-consent-actions .btn {
    min-height: 2.75rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    text-transform: none;
}

.cookie-consent-actions .btn-secondary,
.cookie-consent-close.btn-secondary {
    color: var(--secondary-foreground);
}

.cookie-consent-actions .cookie-consent-customize {
    background: transparent;
    box-shadow: none;
}

.cookie-consent-actions .cookie-consent-customize:hover {
    background: var(--egg-cta-hover-bg);
}

.cookie-consent-status {
    grid-column: 1 / -1;
    color: var(--foreground);
}

.cookie-consent-status:empty {
    position: absolute;
}

.cookie-consent-dialog {
    width: min(35rem, calc(100% - 2rem));
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    margin: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.cookie-consent-dialog::backdrop {
    background: rgb(4 13 10 / 65%);
}

.cookie-consent-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.cookie-consent-close.btn {
    flex: 0 0 2.75rem;
    min-height: 2.75rem;
    padding: 0;
}

.cookie-consent-close .site-icon {
    width: 1.125rem;
    height: 1.125rem;
}

.cookie-consent-categories {
    margin-block: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.cookie-consent-category {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
}

.cookie-consent-category + .cookie-consent-category {
    border-block-start: 1px solid var(--border);
    border-start-start-radius: 0;
    border-start-end-radius: 0;
}

.cookie-consent-category h3,
.cookie-consent-category-title {
    display: block;
    margin: 0 0 0.25rem;
    font-size: 0.9375rem;
    font-weight: 700;
}

.cookie-consent-description {
    display: block;
    font-weight: 400;
}

.cookie-consent-essential {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.cookie-consent-essential .site-icon {
    width: 0.9375rem;
    height: 0.9375rem;
}

.cookie-consent-optional {
    cursor: pointer;
}

.cookie-consent-optional:hover {
    background: var(--muted);
}

.cookie-consent-optional input {
    position: absolute;
    inset-block-start: 50%;
    inset-inline-end: 0.875rem;
    width: 2.75rem;
    height: 1.5rem;
    margin: 0;
    opacity: 0;
    transform: translateY(-50%);
}

.cookie-consent-switch {
    position: relative;
    pointer-events: none;
    width: 2.75rem;
    height: 1.5rem;
    border: 1px solid var(--muted-foreground);
    border-radius: 2rem;
    background: var(--secondary);
}

.cookie-consent-switch::before {
    content: "";
    position: absolute;
    inset: 0.1875rem auto 0.1875rem 0.1875rem;
    width: 1rem;
    border-radius: 50%;
    background: var(--foreground);
}

.cookie-consent-optional input:checked + .cookie-consent-switch {
    border-color: var(--primary);
    background: var(--primary);
}

.cookie-consent-optional input:checked + .cookie-consent-switch::before {
    inset-inline-start: auto;
    inset-inline-end: 0.1875rem;
    background: var(--primary-foreground);
}

.cookie-consent-optional input:focus-visible + .cookie-consent-switch {
    outline: 2px solid var(--ring);
    outline-offset: 3px;
}

.footer-legal .footer-cookie-settings {
    position: relative;
    min-height: 1.5rem;
    padding: 0 0.625rem;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    white-space: nowrap;
    cursor: pointer;
}

.footer-legal .footer-cookie-settings:hover {
    color: var(--rev-brand-green);
}

@media (max-width: 980px) {
    .footer-legal .footer-cookie-settings {
        padding-inline: 0.5rem;
    }
}

@media (max-width: 820px) {
    .cookie-consent-banner {
        width: calc(100% - 1.5rem);
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 480px) {
    .cookie-consent-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cookie-consent-actions > :last-child {
        grid-column: 1 / -1;
    }

    .cookie-consent-dialog .cookie-consent-actions .btn {
        padding-inline: 0.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cookie-consent-actions .btn,
    .cookie-consent-close.btn {
        transition: none;
    }
}

@media (forced-colors: active) {
    .cookie-consent-optional input {
        position: static;
        width: 1.5rem;
        opacity: 1;
        transform: none;
    }

    .cookie-consent-switch {
        display: none;
    }
}
