/*
 * Styles inside the shadow roots of <privacy-dialog> and <privacy-manage-cookies>.
 * Nothing from the site reaches in here, and nothing leaks out. The two accent colours
 * come from the settings as --privacy-main-color and --privacy-hover-color.
 */

:host {
    all: initial;
    display: contents;
    --main: var(--privacy-main-color, #0061ae);
    --hover: var(--privacy-hover-color, #156eb5);
    --text: #1c1c1c;
    --muted: #4d4d4d;
    --line: #e2e2e2;
    --surface: #ffffff;
    --ground: #f3f3f3;
    --radius: 1.5625rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Typography is set here, never inherited from the site */
dialog,
.button {
    font-family: 'Privacy Open Sans', 'Open Sans', Arial, sans-serif;
    font-size: .875rem;
    font-weight: 400;
    font-style: normal;
    line-height: 1.5;
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-align: left;
    text-indent: 0;
    text-wrap: pretty;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* Dialog */

dialog {
    width: min(59.375rem, 95vw);
    height: 90dvh;
    min-height: min(31.25rem, 100dvh);
    max-width: none;
    max-height: none;
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: var(--ground);
    box-shadow: .0625rem .125rem .5rem rgba(0, 0, 0, .35);
    overflow: hidden;
    opacity: 0;
    transform: translateY(1rem);
    transition: opacity .3s, transform .3s, overlay .3s allow-discrete, display .3s allow-discrete;
}

dialog[open] {
    opacity: 1;
    transform: none;
}

dialog::backdrop {
    background: rgba(17, 17, 17, .5);
    opacity: 0;
    transition: opacity .3s, overlay .3s allow-discrete, display .3s allow-discrete;
}

dialog[open]::backdrop {
    opacity: 1;
}

@starting-style {
    dialog[open] {
        opacity: 0;
        transform: translateY(1rem);
    }

    dialog[open]::backdrop {
        opacity: 0;
    }
}

.panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    container-type: inline-size;
}

/* Bar with the close button */

.bar {
    position: relative;
    min-height: 3.5625rem;
    background: var(--surface);
    border-bottom: .0625rem solid var(--line);
}

.close {
    position: absolute;
    top: .6875rem;
    right: .6875rem;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    opacity: .85;
    cursor: pointer;
    transition: opacity .2s, background-color .2s;
}

.close:hover {
    opacity: 1;
    background: var(--ground);
}

.close svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.25;
    stroke-linecap: round;
}

/* Title */

header {
    padding: 1.25rem 3.3125rem 1.875rem;
    background: var(--surface);
    border-bottom: .125rem solid var(--main);
}

h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
}

/* The title takes the first focus, so screen readers start there; it is not interactive */
h2:focus {
    outline: none;
}

header p {
    margin: .5625rem 0 0;
    line-height: 1.6;
}

header p a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: rgba(0, 0, 0, .3);
    text-underline-offset: .2em;
    transition: color .2s, text-decoration-color .2s;
}

/* Statement */

.content {
    flex: 1;
    min-height: 0;
    padding: 2.1875rem 3.125rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    --scrollbar: .5rem;
    --mask: 2.1875rem;
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 var(--mask), #000 calc(100% - var(--mask)), transparent), linear-gradient(#000, #000);
    mask-image: linear-gradient(to bottom, transparent, #000 var(--mask), #000 calc(100% - var(--mask)), transparent), linear-gradient(#000, #000);
    -webkit-mask-size: calc(100% - var(--scrollbar)) 100%, var(--scrollbar) 100%;
    mask-size: calc(100% - var(--scrollbar)) 100%, var(--scrollbar) 100%;
    -webkit-mask-position: 0 0, 100% 0;
    mask-position: 0 0, 100% 0;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

.content::-webkit-scrollbar {
    width: var(--scrollbar);
    height: var(--scrollbar);
}

.content::-webkit-scrollbar-track {
    background: #dadada;
}

.content::-webkit-scrollbar-thumb {
    background: var(--main);
    border-radius: .3125rem;
}

/* Browsers without the webkit scrollbar (Firefox) */
@supports not selector(::-webkit-scrollbar) {
    .content {
        scrollbar-width: thin;
        scrollbar-color: var(--main) #dadada;
    }
}

.content:focus-visible {
    outline: none;
}

.statement {
    animation: appear .6s;
}

.statement> :first-child {
    margin-top: 0;
}

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

.statement h3 {
    margin: 1.25rem 0 .75rem;
    font-size: .9375rem;
    font-weight: 700;
    line-height: 1.5;
}

.statement p,
.statement ul,
.statement ol {
    margin: 0 0 .75rem;
}

.statement ul,
.statement ol {
    padding-left: 2.5rem;
}

.statement strong {
    font-weight: 600;
}

.statement a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: .15em;
}

.statement a:hover {
    color: var(--muted);
    text-decoration: none;
}

.loading {
    width: 1.75rem;
    height: 1.75rem;
    margin: 3rem auto;
    border: .1875rem solid #dadada;
    border-top-color: var(--main);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

/* Footer */

footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .625rem;
    padding: .9375rem 1.5rem;
    background: var(--surface);
    border-top: .0625rem solid var(--line);
}

footer .primary:only-child {
    margin-left: auto;
}

/* Accept and reject equally wide, as in the banner */
.preferences footer .primary {
    min-width: 11.5rem;
}

/* Cookie preferences too narrow for the three buttons on one line: accept and reject side by
   side at the same width, "save choices" full width below; under each other when even that
   does not fit */
@container (max-width: 44rem) {
    .preferences footer {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .preferences footer .spacer {
        display: none;
    }

    .preferences footer .button {
        min-width: 0;
        padding: .5rem 1rem;
        line-height: 1.5rem;
        white-space: normal;
    }

    .preferences footer .secondary {
        grid-column: 1 / -1;
    }
}

@container (max-width: 23.5rem) {
    .preferences footer {
        grid-template-columns: 1fr;
    }
}

/* Buttons, also used by <privacy-manage-cookies> */

.button {
    display: inline-block;
    min-width: 6.4375rem;
    margin: 0;
    padding: 0 1.5625rem;
    border: .0625rem solid var(--main);
    border-radius: 1.875rem;
    background: var(--main);
    color: #ffffff;
    font-size: .8125rem;
    font-weight: 700;
    line-height: 3;
    letter-spacing: 2%;
    text-align: center;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .25s, border-color .25s, color .1s;
}

.button:hover {
    background: var(--hover);
    border-color: var(--hover);
}

.button:active {
    transform: translateY(.0625rem);
}

.button.secondary {
    border-color: var(--muted);
    background: var(--surface);
    color: var(--muted);
}

.button.secondary:hover {
    background: #ebebeb;
}

:host(privacy-manage-cookies) .button {
    margin: .5rem 0 .75rem;
}

/* Keyboard focus */

.button:focus-visible,
.close:focus-visible,
.statement a:focus-visible {
    outline: .125rem solid var(--main);
    outline-offset: .125rem;
}

/* Small screens: the dialog fills the screen */

@media (max-width: 30rem) {
    dialog {
        width: 100%;
        height: 100%;
        min-height: 0;
        border-radius: 0;
    }

    .bar {
        min-height: 3rem;
    }

    .close {
        top: .375rem;
        right: .375rem;
    }

    header {
        max-height: 8.75rem;
        padding: .8125rem 1.25rem;
        overflow-y: auto;
    }

    .content {
        padding: 1.25rem;
    }

    .statement ul,
    .statement ol {
        padding-left: 1.5rem;
    }

    footer {
        padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
    }

    footer .button {
        flex: 1 1 calc(50% - .3125rem);
        min-width: 0;
        padding: .75rem 1rem;
        line-height: 1.3;
        white-space: normal;
    }

    /* Accept and reject on one row, "save choices" full width below */
    footer .secondary {
        flex-basis: 100%;
        order: 3;
    }
}

@media (prefers-reduced-motion: reduce) {

    dialog,
    dialog::backdrop,
    .statement {
        transition: none;
        animation: none;
    }

    .loading {
        animation-duration: 2s;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes appear {
    from {
        opacity: 0;
    }
}

/* Cookie banner */

.banner {
    position: fixed;
    left: 1.5rem;
    bottom: 1.5rem;
    z-index: 2147483000;
    width: min(27rem, calc(100vw - 3rem));
    padding: 1.75rem 2.375rem 1.25rem;
    border: .0625rem solid rgba(0, 0, 0, .06);
    border-radius: 1.25rem;
    background: var(--surface);
    box-shadow: 0 .0625rem .125rem rgba(0, 0, 0, .06), 0 1.25rem 3rem -.75rem rgba(0, 0, 0, .35);
    font-family: 'Privacy Open Sans', 'Open Sans', Arial, sans-serif;
    font-size: .875rem;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    text-wrap: pretty;
    color: var(--text);
    /* The movement eases out slowly, the fade is quick and linear */
    animation: rise 2s cubic-bezier(0.16, 1, 0.3, 1), appear .4s linear;
}

.banner[hidden] {
    display: none;
}

.banner-head {
    display: flex;
    align-items: center;
    gap: .75rem;
}

/* The same cookie as the floating button, so visitors recognise it later */
.badge {
    display: grid;
    flex: none;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #f3f3f3;
    background: color-mix(in srgb, var(--main) 10%, #ffffff);
    color: var(--main);
}

.badge svg {
    width: 1.375rem;
    height: 1.375rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linejoin: round;
}

.badge circle {
    fill: currentColor;
    stroke: none;
}

.banner h2 {
    font-size: 1.125rem;
}

.banner p {
    margin: .875rem 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.banner .policy {
    margin: .5rem 0 1.25rem;
    font-size: .8125rem;
}

.banner .policy a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: rgba(0, 0, 0, .3);
    text-underline-offset: .2em;
    transition: color .2s, text-decoration-color .2s;
}

.banner .policy a:hover,
header p a:hover {
    color: var(--main);
    text-decoration-color: currentColor;
}

.banner .policy a:active,
header p a:active {
    opacity: .7;
}

.banner .policy a:focus-visible,
header p a:focus-visible {
    outline: .125rem solid var(--main);
    outline-offset: .125rem;
    border-radius: .125rem;
}

/* "Set preferences": quieter than the two choices, which must stay equally visible */
.text-button {
    display: inline-flex;
    flex-basis: 100%;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    margin: .5rem 0 0;
    padding: .5rem;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: .8125rem;
    font-weight: 700;
    letter-spacing: 2%;
    text-transform: uppercase;
    cursor: pointer;
    transition: color .2s;
}

.text-button svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .2s;
}

.text-button:hover {
    color: var(--main);
}

.text-button:hover svg {
    transform: translateX(.125rem);
}

.text-button:focus-visible {
    outline: .125rem solid var(--main);
    outline-offset: .125rem;
    border-radius: .5rem;
}

/* Floating button to change the choice */

.reopen {
    position: fixed;
    left: 1rem;
    bottom: 1rem;
    z-index: 2147483000;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--main);
    box-shadow: 0 0 .75rem rgba(0, 0, 0, .05);
    cursor: pointer;
    transition: transform .2s;
}

.reopen[hidden] {
    display: none;
}

.reopen:hover {
    transform: scale(1.08);
}

.reopen:focus-visible {
    outline: .125rem solid var(--main);
    outline-offset: .125rem;
}

.reopen svg {
    width: 1.375rem;
    height: 1.375rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linejoin: round;
}

.reopen circle {
    fill: currentColor;
    stroke: none;
}

/* Accept and reject side by side at the same width, refusing as visible as accepting; under
   each other at full width when the banner is too narrow for both labels */
.actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(10.25rem, 100%), 1fr));
    gap: .5rem;
}

.actions .button {
    min-width: 0;
    padding: .5rem 1rem;
    line-height: 1.5rem;
    white-space: normal;
}

.actions .text-button {
    grid-column: 1 / -1;
}

/* Preferences: categories with a switch */

.category+.category {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: .0625rem solid #dadada;
}

.category-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.category-head h3 {
    margin: 0;
}

.category p {
    margin: .375rem 0 0;
}

.always {
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: 2%;
    text-transform: uppercase;
    color: var(--main);
    white-space: nowrap;
}

.switch {
    position: relative;
    flex: none;
    width: 2.75rem;
    height: 1.5rem;
    cursor: pointer;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.switch span {
    position: absolute;
    inset: 0;
    border-radius: 1rem;
    background: #c9c9c9;
    transition: background-color .2s;
    pointer-events: none;
}

.switch span::after {
    content: '';
    position: absolute;
    top: .1875rem;
    left: .1875rem;
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 .0625rem .1875rem rgba(0, 0, 0, .3);
    transition: transform .2s;
}

.switch input:checked+span {
    background: var(--main);
}

.switch input:checked+span::after {
    transform: translateX(1.25rem);
}

.switch input:focus-visible+span {
    outline: .125rem solid var(--main);
    outline-offset: .125rem;
}

details {
    margin-top: .75rem;
}

/* "2 cookies": a small toggle in the accent colour, with an arrow that turns */
summary {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--main);
    font-size: .8125rem;
    font-weight: 700;
    list-style: none;
    cursor: pointer;
}

summary::-webkit-details-marker {
    display: none;
}

summary::before {
    content: '';
    width: .375rem;
    height: .375rem;
    margin-top: -.125rem;
    border-right: .125rem solid currentColor;
    border-bottom: .125rem solid currentColor;
    transform: rotate(45deg);
    transition: transform .2s;
}

details[open]>summary::before {
    margin-top: .125rem;
    transform: rotate(-135deg);
}

summary:hover {
    color: var(--hover);
}

summary:focus-visible {
    outline: .125rem solid var(--main);
    outline-offset: .25rem;
    border-radius: .25rem;
}

footer .spacer {
    flex: 1;
}

/* Cookie declaration tables, in the preferences and in the statement: a white card with
   the same column widths in every category */

.cookie-declaration {
    width: 100%;
    margin: .75rem 0 0;
    border: .0625rem solid var(--line);
    border-radius: .75rem;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    overflow: hidden;
    background: var(--surface);
    font-size: .8125rem;
    line-height: 1.45;
}

.cookie-declaration th,
.cookie-declaration td {
    padding: .625rem .875rem;
    border-bottom: .0625rem solid var(--line);
    text-align: left;
    vertical-align: top;
}

.cookie-declaration tbody tr:last-child td {
    border-bottom: 0;
}

.cookie-declaration th {
    background: var(--ground);
    color: var(--muted);
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.cookie-declaration th:nth-child(1) {
    width: 23%;
}

.cookie-declaration th:nth-child(2) {
    width: 16%;
}

.cookie-declaration th:nth-child(4) {
    width: 17%;
}

.cookie-declaration td:first-child {
    font-weight: 700;
    overflow-wrap: anywhere;
}

.cookie-declaration td:nth-child(2),
.cookie-declaration td:nth-child(4) {
    color: var(--muted);
}

@media (max-width: 30rem) {
    .banner {
        left: 0;
        bottom: 0;
        width: 100%;
        padding: 1.5rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
        border-width: .0625rem 0 0;
        border-radius: 1.25rem 1.25rem 0 0;
        border-radius: 0;
    }

    .cookie-declaration thead {
        display: none;
    }

    /* One block per cookie: name, provider, purpose, duration */
    .cookie-declaration,
    .cookie-declaration tbody {
        display: block;
    }

    .cookie-declaration tr {
        display: block;
        padding: .75rem .875rem;
        border-bottom: .0625rem solid var(--line);
    }

    .cookie-declaration tbody tr:last-child {
        border-bottom: 0;
    }

    .cookie-declaration td {
        display: block;
        padding: 0;
        border: 0;
    }

    .cookie-declaration td:nth-child(2),
    .cookie-declaration td:nth-child(4) {
        font-size: .75rem;
    }

    .cookie-declaration td:nth-child(3) {
        margin: .25rem 0;
    }

    footer .spacer {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .banner {
        animation: none;
    }
}

@keyframes rise {
    from {
        transform: translateY(1rem);
    }
}