/* ===================================================================
   First view of the cookie bar and the styling of the library settings
   dialog.

   The bar HTML is a template in base.html (template id
   kupsised-riba-mall) that theme/static/js/kupsised.js clones into the
   only when there is no consent yet. The design follows the Bauhof
   example, see ehitus/kb/kupsised.md chapter 4b: full width dark bar at
   the bottom, logo on the left, category switches already in the first
   view, one colored button. The settings dialog stays the library's own
   (class .pm) but gets the same look; that whole part is at the end of
   this file, see kb chapter 4c. The library styling is here in full and
   not at the end of style.css, because this file loads last in
   base.html and outweighs both.

   The bar does not cover content: kupsised.js puts the class
   kupsised-riba-avatud and the variable --kupsised-riba-korgus on body,
   which lengthens the page at the bottom so the footer stays
   scrollable.
   =================================================================== */

body.kupsised-riba-avatud {
    padding-bottom: var(--kupsised-riba-korgus, 0px);
}

.kupsised-riba {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    /* Bootstrap sticky-top navbar is 1020, a modal 1055. The library
       settings dialog sits above that with its own variable. */
    z-index: 1045;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    background: #212529;
    color: #ffffff;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 0.95rem;
    line-height: 1.5;
}

.kupsised-riba__sisu {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "logo tekst nupud"
        "logo lulitid nupud";
    column-gap: 2rem;
    row-gap: 0.75rem;
    align-items: center;
    width: 100%;
    max-width: 1320px;
    min-height: 0;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
    box-sizing: border-box;
}

.kupsised-riba__logo {
    grid-area: logo;
}

.kupsised-riba__logo img {
    display: block;
    height: 48px;
    width: auto;
}

.kupsised-riba__tekst {
    grid-area: tekst;
    min-height: 0;
    overflow-y: auto;
}

.kupsised-riba__pealkiri {
    margin: 0 0 0.35rem;
    font-family: var(--font-headings, 'Playfair Display', serif);
    font-size: 1.25rem;
    font-weight: 600;
    color: #ffffff;
}

.kupsised-riba__loik {
    margin: 0;
    color: #ced4da;
}

.kupsised-riba__loik a {
    color: #ffffff;
    text-decoration: underline;
}

.kupsised-riba__loik a:hover,
.kupsised-riba__loik a:focus-visible {
    color: #3498db;
}

/* Switches */

.kupsised-riba__lulitid {
    grid-area: lulitid;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
}

.kupsised-luliti {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    cursor: pointer;
    user-select: none;
}

.kupsised-luliti [role="switch"] {
    position: relative;
    flex: none;
    width: 44px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #6c757d;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.kupsised-luliti [role="switch"]::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 0.2s ease;
}

.kupsised-luliti [role="switch"][aria-checked="true"] {
    background: #3498db;
}

.kupsised-luliti [role="switch"][aria-checked="true"]::after {
    transform: translateX(20px);
}

.kupsised-luliti [role="switch"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.kupsised-luliti:has([role="switch"]:disabled) {
    cursor: not-allowed;
}

.kupsised-luliti__silt {
    color: #ffffff;
    font-weight: 500;
}

/* Buttons: only the primary one carries the accent color, the rest are
   transparent with a white outline. */

.kupsised-riba__nupud {
    grid-area: nupud;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 200px;
}

.kupsised-nupp {
    display: block;
    width: 100%;
    padding: 0.6rem 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 0.375rem;
    background: transparent;
    color: #ffffff;
    font: inherit;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.kupsised-nupp:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: #ffffff;
}

.kupsised-nupp--esmane {
    background: #3498db;
    border-color: #3498db;
}

.kupsised-nupp--esmane:hover {
    background: #2980b9;
    border-color: #2980b9;
}

.kupsised-riba a:focus-visible,
.kupsised-riba button:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Mobile: the parts stack but stay compact (kb chapter 4b point 6).
   Logo, title and text are smaller, category switches sit in two
   columns and of the buttons only the primary one is full width, the
   other two side by side. The bar is at most 72vh tall; if the text
   does not fit, the text area scrolls while switches and buttons stay
   put at the bottom. */

@media (max-width: 767.98px) {
    .kupsised-riba {
        max-height: 72vh;
    }

    .kupsised-riba__sisu {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr) auto auto;
        grid-template-areas:
            "logo"
            "tekst"
            "lulitid"
            "nupud";
        align-items: start;
        row-gap: 0.5rem;
        padding: 0.85rem 1rem;
    }

    .kupsised-riba__logo img {
        height: 26px;
    }

    /* The text area stretches to its row height, otherwise it does not
       scroll but runs over the switches when the bar hits 72vh. */
    .kupsised-riba__tekst {
        align-self: stretch;
    }

    .kupsised-riba__pealkiri {
        margin: 0 0 0.25rem;
        font-size: 1.05rem;
    }

    .kupsised-riba__loik {
        font-size: 0.85rem;
        line-height: 1.4;
    }

    .kupsised-riba__lulitid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.4rem 0.75rem;
    }

    .kupsised-luliti__silt {
        font-size: 0.85rem;
    }

    .kupsised-luliti [role="switch"] {
        width: 40px;
        height: 22px;
    }

    .kupsised-luliti [role="switch"]::after {
        top: 3px;
        left: 3px;
        width: 16px;
        height: 16px;
    }

    .kupsised-luliti [role="switch"][aria-checked="true"]::after {
        transform: translateX(18px);
    }

    .kupsised-riba__nupud {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.4rem;
        min-width: 0;
    }

    /* The primary button is the widest consent, so it spans the row. */
    .kupsised-riba__nupud > :first-child {
        grid-column: 1 / -1;
    }

    .kupsised-nupp {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kupsised-luliti [role="switch"],
    .kupsised-luliti [role="switch"]::after,
    .kupsised-nupp {
        transition: none;
    }
}

/* ===================================================================
   The library settings dialog in the look of the bar (kb chapter 4c,
   key kujundus.seadete_aken with value riba_stiilis).

   The dialog itself stays the library's: the library builds the HTML
   (.pm), we only give it a look. This file loads after cookieconsent.css
   and style.css in base.html, so selectors of equal weight beat the
   library ones without !important; !important is only where the
   library's own rule is !important too (the mobile media query).

   This whole part hangs under the class kupsised-seaded, which
   kupsised.js puts on the library root element only when the key is
   riba_stiilis. With any other value the library keeps its own look.

   Two things drove kb chapter 4c: the library .pm--box stretched to the
   window height even with short content, and on mobile the dialog was
   full screen. Both are back to content height and centered here.
   =================================================================== */

#cc-main.kupsised-seaded {
    --cc-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --cc-modal-border-radius: 14px;
    --cc-btn-border-radius: 0.375rem;
    --cc-bg: #212529;
    --cc-primary-color: #ffffff;
    --cc-secondary-color: #ced4da;
    --cc-btn-primary-bg: #3498db;
    --cc-btn-primary-border-color: #3498db;
    --cc-btn-primary-color: #ffffff;
    --cc-btn-primary-hover-bg: #2980b9;
    --cc-btn-primary-hover-border-color: #2980b9;
    --cc-btn-primary-hover-color: #ffffff;
    --cc-btn-secondary-bg: transparent;
    --cc-btn-secondary-color: #ffffff;
    --cc-btn-secondary-border-color: rgba(255, 255, 255, 0.7);
    --cc-btn-secondary-hover-bg: rgba(255, 255, 255, 0.12);
    --cc-btn-secondary-hover-color: #ffffff;
    --cc-btn-secondary-hover-border-color: #ffffff;
    --cc-separator-border-color: rgba(255, 255, 255, 0.15);
    --cc-cookie-category-block-bg: rgba(255, 255, 255, 0.06);
    --cc-cookie-category-block-border: rgba(255, 255, 255, 0.15);
    --cc-cookie-category-block-hover-bg: rgba(255, 255, 255, 0.12);
    --cc-cookie-category-block-hover-border: rgba(255, 255, 255, 0.3);
    --cc-cookie-category-expanded-block-bg: rgba(255, 255, 255, 0.1);
    --cc-cookie-category-expanded-block-hover-bg: rgba(255, 255, 255, 0.3);
    --cc-toggle-on-bg: #3498db;
    --cc-toggle-off-bg: #6c757d;
    --cc-toggle-on-knob-bg: #ffffff;
    --cc-toggle-off-knob-bg: #ffffff;
    --cc-toggle-readonly-bg: rgba(52, 152, 219, 0.6);
    --cc-toggle-readonly-knob-bg: #ffffff;
    --cc-link-color: #ffffff;
    --cc-overlay-bg: rgba(0, 0, 0, 0.65);
    /* The title inherits the color, the variable alone is not enough. */
    color: var(--cc-primary-color);
}

/* Height follows content: the library's own rule stretches the dialog
   to the screen height even when the content is short (kb chapter 4c
   point 5). */

#cc-main.kupsised-seaded .pm--box {
    height: auto;
    max-height: min(37.5em, calc(100% - 2em));
    max-width: 36em;
}

/* Header: logo next to the title. kupsised.js adds the logo from the
   bar template, so there is no file name here. */

#cc-main.kupsised-seaded .pm__header {
    column-gap: 1rem;
}

#cc-main.kupsised-seaded .pm__title {
    font-family: var(--font-headings, 'Playfair Display', serif);
    font-size: 1.25rem;
    margin-right: 0.5em;
}

.kupsised-seaded__logo {
    display: block;
    flex: none;
    height: 34px;
    width: auto;
}

#cc-main.kupsised-seaded .pm__close-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border-color: rgba(255, 255, 255, 0.7);
}

#cc-main.kupsised-seaded .pm__close-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: #ffffff;
}

#cc-main.kupsised-seaded .pm__close-btn svg,
#cc-main.kupsised-seaded .pm__close-btn:hover svg {
    stroke: #ffffff;
}

/* Buttons: the library .pm__btn is accent colored by default. Here all
   buttons are transparent with a white outline and only the one that
   kupsised.js marks by the kb key kujundus.esmane_nupp is colored. */

#cc-main.kupsised-seaded .pm__btn {
    min-height: 40px;
    background: var(--cc-btn-secondary-bg);
    border-color: var(--cc-btn-secondary-border-color);
    color: var(--cc-btn-secondary-color);
    font-size: 0.9rem;
    font-weight: 500;
}

#cc-main.kupsised-seaded .pm__btn:hover {
    background: var(--cc-btn-secondary-hover-bg);
    border-color: var(--cc-btn-secondary-hover-border-color);
    color: var(--cc-btn-secondary-hover-color);
}

#cc-main.kupsised-seaded .pm__btn.kupsised-seaded__nupp--esmane {
    background: #3498db;
    border-color: #3498db;
    color: #ffffff;
}

#cc-main.kupsised-seaded .pm__btn.kupsised-seaded__nupp--esmane:hover {
    background: #2980b9;
    border-color: #2980b9;
}

/* Switches as on the bar: same size and same colors, without the tick
   and the cross (kb chapter 4c point 4). */

#cc-main.kupsised-seaded .section__toggle,
#cc-main.kupsised-seaded .section__toggle-wrapper,
#cc-main.kupsised-seaded .toggle__icon,
#cc-main.kupsised-seaded .toggle__label {
    width: 44px;
    height: 24px;
    border-radius: 12px;
}

#cc-main.kupsised-seaded .toggle__icon {
    box-shadow: none;
}

#cc-main.kupsised-seaded .toggle__icon-circle {
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    box-shadow: none;
}

#cc-main.kupsised-seaded .toggle__icon-on,
#cc-main.kupsised-seaded .toggle__icon-off {
    display: none;
}

#cc-main.kupsised-seaded .section__toggle:checked ~ .toggle__icon {
    box-shadow: none;
}

#cc-main.kupsised-seaded .section__toggle:checked ~ .toggle__icon .toggle__icon-circle {
    transform: translateX(20px);
}

#cc-main.kupsised-seaded .section__toggle:checked:disabled ~ .toggle__icon {
    box-shadow: none;
}

/* Category blocks: the switch and arrow must not run over the title. */

#cc-main.kupsised-seaded .pm__section--toggle .pm__section-title {
    min-height: 48px;
    padding: 0.8em 4.4em 0.8em 1.2em;
}

#cc-main.kupsised-seaded .pm__section--expandable .pm__section-title {
    padding-left: 3.4em;
}

#cc-main.kupsised-seaded .pm__section-title {
    font-size: 0.95rem;
}

#cc-main.kupsised-seaded .pm__section--expandable .pm__section-arrow {
    background: rgba(255, 255, 255, 0.15);
}

#cc-main.kupsised-seaded .pm__section--expandable .pm__section-arrow svg {
    stroke: #ffffff;
}

/* Mobile. The breakpoint is the same 640px as the library's, because
   the library full screen rules are in that query and ours comes later
   in file order. The dialog is centered, with a margin from the edges
   and rounded corners; buttons as on the bar (kb chapter 4c point 6). */

@media screen and (max-width: 640px) {
    #cc-main.kupsised-seaded .pm {
        top: 50%;
        bottom: auto;
        left: var(--cc-modal-margin);
        right: var(--cc-modal-margin);
        height: auto;
        max-height: calc(100% - 2em);
        max-width: 36em !important;
        border-radius: var(--cc-modal-border-radius);
        transform: translateY(calc(-50% + 1.6em));
    }

    .show--preferences #cc-main.kupsised-seaded .cc--anim .pm {
        transform: translateY(-50%) !important;
    }

    #cc-main.kupsised-seaded .pm__header,
    #cc-main.kupsised-seaded .pm__body,
    #cc-main.kupsised-seaded .pm__footer {
        padding: 0.9em 1em !important;
    }

    #cc-main.kupsised-seaded .pm__footer {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.4rem;
    }

    /* The buttons go into the footer grid, so the groups themselves
       drop out of the layout. */
    #cc-main.kupsised-seaded .pm__btn-group {
        display: contents !important;
    }

    /* Full width goes to the button that kupsised.js marks by the kb
       key kujundus.esmane_nupp, same as on the bar. */
    #cc-main.kupsised-seaded .pm__btn.kupsised-seaded__nupp--esmane {
        grid-column: 1 / -1;
    }

    #cc-main.kupsised-seaded .pm__btn + .pm__btn,
    #cc-main.kupsised-seaded .pm__btn-group + .pm__btn-group {
        margin: 0 !important;
    }

    /* Switches in the same size as on the bar on a phone. */
    #cc-main.kupsised-seaded .section__toggle,
    #cc-main.kupsised-seaded .section__toggle-wrapper,
    #cc-main.kupsised-seaded .toggle__icon,
    #cc-main.kupsised-seaded .toggle__label {
        width: 40px;
        height: 22px;
        border-radius: 11px;
    }

    #cc-main.kupsised-seaded .toggle__icon-circle {
        width: 16px;
        height: 16px;
    }

    #cc-main.kupsised-seaded .section__toggle:checked ~ .toggle__icon .toggle__icon-circle {
        transform: translateX(18px);
    }
}
