/* Cookie consent: a floating FAB + pill on the category overview, and a
   blurred-backdrop settings modal that slides up from the bottom. */

.cookie-root {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 2500;
}

.cookie-root[hidden] {
    display: none;
}

/* One continuous pill: a circle when closed (just the cookie FAB), widening to
   reveal the labelled option buttons when open. Border-radius stays 999px
   throughout, so animating width morphs circle -> pill smoothly (no jagged
   straight edge). The open width is measured and set in JS (ui.js) so the pill
   grows to fit its labels and never clips them — collapsing the buttons to
   icons one by one (stage-1..3) as the available space tightens. */
.cookie-banner {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* keep the FAB visible at the right when collapsed */
    width: 48px;
    height: 48px;
    overflow: hidden;
    background: var(--bg-color);
    border: 1px solid var(--text-color);
    border-radius: 999px;
    transition: width 0.4s cubic-bezier(0.2, 0, 0.2, 1);
}

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

.cookie-fab {
    position: relative; /* anchors the ::before/::after X to the FAB, not .cookie-root */
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Cookie icon, cross-fading into an X (close) when the pill is open — mirrors
   the header ⋮ and the search toggles. */
.cookie-fab-glyph {
    position: absolute;
    font-size: 24px;
    transition: opacity 0.2s ease;
}

.cf-close { opacity: 0; }
.cookie-fab[aria-expanded="true"] .cf-open { opacity: 0; }
.cookie-fab[aria-expanded="true"] .cf-close { opacity: 1; }

/* Labelled option buttons that reveal as the pill widens out of the FAB. */
.cookie-pill {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
    /* Match the Settings button's gap to the banner edge to its top/bottom gap
       ((48px banner − 38px button) / 2 ≈ 4px), so it reads as evenly inset. */
    padding-left: 4px;
}

/* Vertical dividers, one trailing each consent button — shown only once that
   button has collapsed to its icon (see the staged rules below). When every
   label is visible there is no divider at all. */
.cookie-divider {
    display: none;
    flex-shrink: 0;
    width: 1px;
    height: 24px;
    margin: 0 0.25rem;
    background: var(--text-color);
}

.cookie-icon-btn {
    flex-shrink: 0;
    height: 38px;
    padding: 0 0.6rem;
    /* A transparent border by default so the hover state can light it up
       without nudging the layout (box-sizing keeps the 38px height stable). */
    border: 1px solid transparent;
    background: transparent;
    border-radius: 999px;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
    transition: border-color 0.2s ease, var(--page-color-transition);
}

.cookie-icon-btn .ms-icon {
    font-size: 22px;
}

.cookie-icon-label {
    font-family: var(--font-body);
    font-size: calc((1.05rem) * var(--font-scale));
    line-height: 1;
}

/* Staged collapse as the available width shrinks (stage classes are cumulative,
   set in ui.js): each button in turn drops its label and grows a trailing
   divider — Settings first, then Only technical, then Allow all. */
.cookie-banner.stage-1 .cookie-icon-btn[data-cookie-action="settings"] .cookie-icon-label,
.cookie-banner.stage-2 .cookie-icon-btn[data-cookie-action="technical"] .cookie-icon-label,
.cookie-banner.stage-3 .cookie-icon-btn[data-cookie-action="all"] .cookie-icon-label {
    display: none;
}

.cookie-banner.stage-1 .cd-settings,
.cookie-banner.stage-2 .cd-technical,
.cookie-banner.stage-3 .cd-all {
    display: block;
}

/* Hover indicator: a 1px solid border in the current theme colour (no fill). */
.cookie-icon-btn:hover {
    border-color: var(--text-color);
}

/* Modal action button (Save choices). */
.cookie-btn {
    font-family: var(--font-body);
    font-size: calc((1rem) * var(--font-scale));
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    border: 1px solid var(--text-color);
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s ease, var(--page-color-transition);
}

.cookie-btn-primary {
    background: var(--text-color);
    color: var(--bg-color);
}

.cookie-btn:hover {
    background: var(--text-color);
    color: var(--bg-color);
}

.cookie-btn-primary:hover {
    background: color-mix(in srgb, var(--text-color) 75%, var(--bg-color));
}

/* --- Settings modal ----------------------------------------------------- */
.cookie-modal {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cookie-modal[hidden] {
    display: none;
}

.cookie-modal-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--bg-color) 70%, transparent);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cookie-modal.active .cookie-modal-backdrop {
    opacity: 1;
}

.cookie-modal-panel {
    position: relative;
    width: min(520px, calc(100vw - 2rem));
    background: var(--bg-color);
    border: 1px solid var(--text-color);
    border-radius: 20px;
    padding: 1.75rem;
    transform: translateY(24px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1), opacity 0.3s ease;
}

.cookie-modal.active .cookie-modal-panel {
    transform: translateY(0);
    opacity: 1;
}

.cookie-modal-panel h2 {
    margin: 0 0 1.25rem;
    font-family: var(--font-heading);
    font-size: calc((1.7rem) * var(--font-scale));
    font-weight: 400;
}

.cookie-cat {
    padding: 0.9rem 0;
    border-top: 1px solid var(--text-color);
}

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

.cookie-cat-name {
    font-family: var(--font-body);
    font-size: calc((1.2rem) * var(--font-scale));
}

.cookie-cat-locked {
    font-size: calc((1.2rem) * var(--font-scale));
}

.cookie-cat-desc {
    margin: 0.35rem 0 0;
    font-size: calc((0.95rem) * var(--font-scale));
    line-height: 1.35;
}

/* Toggle switch */
.cookie-switch {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    cursor: pointer;
}

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

.cookie-switch-track {
    width: 42px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid var(--text-color);
    position: relative;
    transition: background 0.2s ease, var(--page-color-transition);
}

.cookie-switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-color);
    transition: transform 0.2s ease, var(--page-color-transition);
}

.cookie-switch input:checked + .cookie-switch-track {
    background: var(--text-color);
}

.cookie-switch input:checked + .cookie-switch-track::after {
    transform: translateX(18px);
    background: var(--bg-color);
}

.cookie-switch input:focus-visible + .cookie-switch-track {
    outline: 2px dashed var(--text-color);
    outline-offset: 2px;
}

.cookie-modal-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

.cookie-modal-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

@media (prefers-reduced-motion: reduce) {
    .cookie-modal-panel,
    .cookie-modal-backdrop {
        transition: none;
    }
}
