/* ===================================================================
 * local_cookieconsent — banner / modal / floating button styles
 *
 * All selectors are namespaced `.cc-*` to avoid collisions with the
 * active Moodle theme. Critical visibility rules (hide-by-default)
 * live in helper::render_head() as inline CSS so the banner never
 * flashes before JS evaluates the cookie.
 * =================================================================== */

:root {
    /* --cc-primary is set per-site from the admin's color picker */
    --cc-primary: #1177d1;
    --cc-bg-light: #ffffff;
    --cc-fg-light: #1a1a1a;
    --cc-muted-light: #555;
    --cc-border-light: #e0e0e0;
    --cc-bg-dark: #1f1f1f;
    --cc-fg-dark: #f0f0f0;
    --cc-muted-dark: #aaa;
    --cc-border-dark: #333;
}

/* -------- Buttons (Accept and Reject share identical primary styling
 * per Italian DPA guidance n. 231/2021 — no dark pattern.) -------- */
.cc-btn {
    border: 0;
    padding: .625rem 1.25rem;
    font-size: .9rem;
    font-weight: 600;
    border-radius: .375rem;
    cursor: pointer;
    transition: transform .08s ease, opacity .15s ease;
    line-height: 1.2;
    min-width: 8rem;
    font-family: inherit;
}
.cc-btn:hover  { transform: translateY(-1px); }
.cc-btn:active { transform: translateY(0); }
.cc-btn:focus-visible {
    outline: 2px solid var(--cc-primary);
    outline-offset: 2px;
}

.cc-btn-primary {
    background: var(--cc-primary);
    color: #fff;
}
.cc-btn-secondary {
    background: transparent;
    color: var(--cc-primary);
    border: 1px solid var(--cc-primary);
}

/* -------- Modal -------- */
.cc-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 99998;
}

.cc-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 99999;
    width: min(36rem, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    border-radius: .5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
    font-family: inherit;
    box-sizing: border-box;
}

.cc-modal-inner { display: flex; flex-direction: column; }

.cc-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--cc-border-light);
}
.cc-modal-title { margin: 0; font-size: 1.15rem; font-weight: 700; }

.cc-modal-close {
    background: transparent;
    border: 0;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    padding: 0 .5rem;
}
.cc-modal-close:focus-visible {
    outline: 2px solid var(--cc-primary);
    outline-offset: 2px;
}

/* Forced mode (first visit): user must choose, no dismiss affordance. */
.cc-modal.cc-forced .cc-modal-close { display: none; }
.cc-modal-backdrop.cc-forced       { cursor: not-allowed; }

.cc-modal-body { padding: 1rem 1.25rem; }

.cc-modal-intro {
    margin: 0 0 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--cc-border-light);
    font-size: .95rem;
    line-height: 1.45;
}
.cc-modal-intro a {
    color: var(--cc-primary);
    font-weight: 600;
    text-decoration: underline;
}
.cc-theme-dark .cc-modal-intro,
.cc-theme-auto .cc-modal-intro { border-color: var(--cc-border-dark); }

.cc-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--cc-border-light);
    flex-wrap: wrap;
}

/* -------- Category rows in modal -------- */
.cc-category {
    padding: .75rem 0;
    border-bottom: 1px solid var(--cc-border-light);
}
.cc-category:last-child { border-bottom: 0; }

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

.cc-category-title { margin: 0; font-size: 1rem; font-weight: 600; }
.cc-category-desc  { margin: .35rem 0 0; font-size: .875rem; color: var(--cc-muted-light); }

.cc-toggle-locked {
    font-size: .75rem;
    font-weight: 600;
    color: var(--cc-primary);
    background: rgba(17, 119, 209, .12);
    padding: .25rem .5rem;
    border-radius: .25rem;
    white-space: nowrap;
}

/* -------- Toggle switch -------- */
.cc-toggle {
    position: relative;
    display: inline-block;
    width: 2.75rem;
    height: 1.5rem;
    cursor: pointer;
    flex-shrink: 0;
}
.cc-toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.cc-toggle-slider {
    position: absolute;
    inset: 0;
    background: #ccc;
    border-radius: 9999px;
    transition: background .15s ease;
}
.cc-toggle-slider::before {
    content: "";
    position: absolute;
    width: 1.1rem;
    height: 1.1rem;
    left: .2rem;
    top: .2rem;
    background: #fff;
    border-radius: 50%;
    transition: transform .15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.cc-toggle-input:checked + .cc-toggle-slider { background: var(--cc-primary); }
.cc-toggle-input:checked + .cc-toggle-slider::before { transform: translateX(1.25rem); }
.cc-toggle-input:focus-visible + .cc-toggle-slider {
    outline: 2px solid var(--cc-primary);
    outline-offset: 2px;
}

.cc-sr-only {
    position: absolute;
    width: 1px; height: 1px; padding: 0;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* -------- Floating "manage cookies" button --------
 *
 * z-index chosen to sit ABOVE normal page content but BELOW Bootstrap 5
 * modals (z-index 1055) and their backdrop (1050), so the button does
 * not bleed through course/activity modals in Moodle.
 *
 * As a second safety net, hide the button entirely while a Moodle modal
 * is open: Bootstrap toggles `modal-open` on <body> for the duration. */
.cc-floating-btn {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    z-index: 1030;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: 0;
    background: var(--cc-primary);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
    transition: transform .15s ease;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.cc-floating-btn:hover { transform: scale(1.08); }
.cc-floating-btn:focus-visible {
    outline: 2px solid var(--cc-primary);
    outline-offset: 3px;
}
.cc-floating-icon { width: 1.5rem; height: 1.5rem; display: block; }

body.modal-open .cc-floating-btn,
body.modal-backdrop-open .cc-floating-btn,
body[data-modal-open] .cc-floating-btn,
body.cc-other-modal-open .cc-floating-btn { display: none !important; }

/* -------- Light theme (default) -------- */
.cc-theme-light {
    background: var(--cc-bg-light);
    color: var(--cc-fg-light);
}
.cc-theme-light.cc-modal-head,
.cc-theme-light .cc-modal-head,
.cc-theme-light .cc-modal-foot { border-color: var(--cc-border-light); }

/* -------- Dark theme -------- */
.cc-theme-dark {
    background: var(--cc-bg-dark);
    color: var(--cc-fg-dark);
}
.cc-theme-dark .cc-category-desc { color: var(--cc-muted-dark); }
.cc-theme-dark .cc-modal-head,
.cc-theme-dark .cc-modal-foot { border-color: var(--cc-border-dark); }
.cc-theme-dark .cc-btn-secondary { color: #fff; border-color: #fff; }

/* -------- Auto theme: follow OS preference -------- */
@media (prefers-color-scheme: dark) {
    .cc-theme-auto {
        background: var(--cc-bg-dark);
        color: var(--cc-fg-dark);
    }
    .cc-theme-auto .cc-category-desc { color: var(--cc-muted-dark); }
    .cc-theme-auto .cc-modal-head,
    .cc-theme-auto .cc-modal-foot { border-color: var(--cc-border-dark); }
    .cc-theme-auto .cc-btn-secondary { color: #fff; border-color: #fff; }
}
@media (prefers-color-scheme: light) {
    .cc-theme-auto {
        background: var(--cc-bg-light);
        color: var(--cc-fg-light);
    }
}

/* -------- Cookie Policy page table -------- */
.cc-policy-table { width: 100%; margin: 1rem 0; }
.cc-policy-table th { font-weight: 600; }
.cc-policy-table code { font-size: .875rem; }
.cc-policy-actions { margin-top: 1.5rem; }
.cc-policy-lastupdate { color: var(--cc-muted-light); margin-top: 2rem; font-size: .875rem; }

/* -------- Mobile -------- */
@media (max-width: 640px) {
    .cc-btn { flex: 1 1 100%; min-width: 0; }
}
