/**
 * Better Cookie Manager — Front-end Banner & Modal Styles
 *
 * Scoped under .bcm-* to avoid collisions with theme CSS.
 * No !important except where strictly needed to override theme resets.
 * Responsive: works down to 320px wide.
 */

/* ============================================================
   RESET / BASE
   ============================================================ */
.bcm-banner *,
.bcm-modal * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Screen-reader-only text. Ships with the plugin so the visually-hidden
   labels work even when the active theme does not define these WP-core
   utility classes. */
.bcm-banner .screen-reader-text,
.bcm-modal .screen-reader-text,
.bcm-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   BANNER
   ============================================================ */
.bcm-banner {
    position: fixed;
    z-index: 999990;
    left: 0;
    right: 0;
    padding: 16px 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    transition: transform 0.35s ease, opacity 0.35s ease;
    /* background and color are set inline by PHP */
}

/* --- Position variants --- */
.bcm-banner--bottom {
    bottom: 0;
    top: auto;
    border-top: 3px solid rgba(255, 255, 255, 0.1);
}
.bcm-banner--top {
    top: 0;
    bottom: auto;
    border-bottom: 3px solid rgba(255, 255, 255, 0.1);
}
.bcm-banner--center {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* --- Layout: bar vs modal --- */
.bcm-banner--bar .bcm-banner__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
}
.bcm-banner--bar .bcm-banner__content {
    flex: 1 1 300px;
}
.bcm-banner--bar .bcm-banner__actions {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bcm-banner--modal .bcm-banner__inner {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.bcm-banner--modal .bcm-banner__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

/* --- Hidden state --- */
.bcm-banner--hidden {
    display: none !important;
}

/* --- Overlay for center-modal layout --- */
.bcm-banner__overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: -1;
}

/* --- Text --- */
.bcm-banner__title {
    font-weight: 700;
    font-size: 1.05em;
    margin-bottom: 4px;
}
.bcm-banner__message {
    font-size: 0.93em;
    opacity: 0.9;
}

/* --- Dismiss (X) button: upper-right corner --- */
.bcm-banner__close {
    position: absolute;
    top: 6px;
    right: 8px;
    z-index: 1;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: inherit;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.15s ease;
}
.bcm-banner__close:hover {
    opacity: 1;
}
.bcm-banner__close:focus-visible {
    opacity: 1;
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.65);
}
/* Fallback for browsers without :focus-visible */
.bcm-banner__close:focus {
    opacity: 1;
    outline: 2px solid #fff;
    outline-offset: 2px;
}
/* Keep the dismiss button clear of the action buttons on the bar layout. */
.bcm-banner--bar .bcm-banner__actions {
    padding-right: 28px;
}

/* --- Animations --- */
.bcm-banner--bottom.bcm-banner--slide-in {
    animation: bcm-slide-up 0.35s ease forwards;
}
.bcm-banner--top.bcm-banner--slide-in {
    animation: bcm-slide-down 0.35s ease forwards;
}
.bcm-banner--fade-in {
    animation: bcm-fade 0.35s ease forwards;
}

@keyframes bcm-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
@keyframes bcm-slide-down {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}
@keyframes bcm-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* --- Logo --- */
.bcm-banner__logo img {
    display: block;
    max-height: 36px;
    width: auto;
}

/* --- Footer links --- */
.bcm-banner__footer,
.bcm-banner__ccpa {
    font-size: 0.82em;
    margin-top: 4px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.bcm-btn {
    display: inline-block;
    padding: 9px 18px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    transition: opacity 0.15s ease, filter 0.15s ease;
    white-space: nowrap;
    line-height: 1.4;
}
.bcm-btn:hover {
    opacity: 0.85;
}
/* Visible focus indicator — solid, high-contrast (WCAG 2.4.7 / 1.4.11).
   Double ring (dark + light) guarantees ≥3:1 against either a light or dark
   banner background. */
.bcm-btn:focus-visible,
.bcm-link:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.65);
}
/* Fallback for browsers without :focus-visible */
.bcm-btn:focus,
.bcm-link:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
.bcm-btn--secondary {
    background: transparent !important;
    border: 1px solid currentColor;
    color: inherit !important;
}
.bcm-btn--link {
    background: transparent !important;
    border: none;
    color: inherit !important;
    text-decoration: underline;
    padding: 9px 6px;
}
.bcm-link {
    color: inherit;
    /* No opacity dimming — keeps full inherited-text contrast for WCAG 1.4.3. */
    font-size: 0.88em;
    text-decoration: underline;
}
.bcm-link:hover {
    text-decoration: none;
}

/* ============================================================
   MODAL OVERLAY
   ============================================================ */
.bcm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999991;
}

/* ============================================================
   PREFERENCES MODAL
   ============================================================ */
.bcm-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999992;
    width: 90%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 8px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
}

.bcm-hidden {
    display: none !important;
}

body.bcm-modal-open {
    overflow: hidden;
}

/* --- Modal header --- */
.bcm-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.bcm-modal__header h2 {
    font-size: 1.2em;
    font-weight: 700;
    margin: 0;
}
.bcm-modal__close {
    background: transparent;
    border: none;
    font-size: 1.6em;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    line-height: 1;
    padding: 0 4px;
}
.bcm-modal__close:hover {
    opacity: 1;
}

/* --- Modal body --- */
.bcm-modal__body {
    padding: 20px 24px;
    flex: 1;
    overflow-y: auto;
}
.bcm-modal__intro {
    font-size: 0.9em;
    opacity: 0.85;
    margin-bottom: 20px;
}

/* --- Category rows --- */
.bcm-category {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.bcm-category:last-child {
    border-bottom: none;
}
.bcm-category__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}
.bcm-category__info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.bcm-category__name {
    font-size: 1em;
    font-weight: 600;
}
.bcm-badge-always-active {
    font-size: 0.74em;
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 7px;
    border-radius: 20px;
    font-weight: 500;
    white-space: nowrap;
}
.bcm-category__desc {
    font-size: 0.85em;
    opacity: 0.75;
    margin-bottom: 8px;
}

/* --- Toggle switch --- */
.bcm-toggle {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
    flex-shrink: 0;
}
.bcm-toggle[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}
.bcm-toggle__input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.bcm-toggle__slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}
.bcm-toggle__slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.bcm-toggle__input:checked + .bcm-toggle__slider {
    background: #4caf50;
}
.bcm-toggle__input:checked + .bcm-toggle__slider::before {
    transform: translateX(22px);
}
.bcm-toggle__input:focus + .bcm-toggle__slider,
.bcm-toggle__input:focus-visible + .bcm-toggle__slider {
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.65);
}

/* --- Cookie details table in modal --- */
.bcm-category__details {
    margin-top: 8px;
}
.bcm-category__details summary {
    cursor: pointer;
    font-size: 0.82em;
    opacity: 0.7;
    user-select: none;
}
.bcm-category__details summary:hover {
    opacity: 1;
}
.bcm-category__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8em;
    margin-top: 8px;
    opacity: 0.85;
}
.bcm-category__table th,
.bcm-category__table td {
    padding: 4px 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    text-align: left;
}
.bcm-category__table th {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.06);
}

/* --- Modal footer --- */
.bcm-modal__footer {
    padding: 16px 24px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
    .bcm-banner--bar .bcm-banner__inner {
        flex-direction: column;
        align-items: flex-start;
    }
    .bcm-banner--bar .bcm-banner__actions {
        width: 100%;
    }
    .bcm-btn {
        flex: 1 1 auto;
        text-align: center;
    }
    .bcm-modal {
        width: 96%;
        max-height: 96vh;
    }
    .bcm-modal__footer {
        flex-direction: column;
    }
    .bcm-modal__footer .bcm-btn {
        width: 100%;
        text-align: center;
    }
}

/* ============================================================
   POLICY PAGE (shortcode output)
   ============================================================ */
.bcm-policy h1 { font-size: 1.8em; margin-bottom: 0.5em; }
.bcm-policy h2 { font-size: 1.3em; margin: 1.4em 0 0.5em; }
.bcm-policy h3 { font-size: 1.1em; margin: 1.2em 0 0.4em; }
.bcm-policy p  { margin-bottom: 1em; }
.bcm-policy-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    font-size: 0.9em;
}
.bcm-policy-table th,
.bcm-policy-table td {
    padding: 8px 12px;
    border: 1px solid #ddd;
    text-align: left;
}
.bcm-policy-table th {
    background: #f5f5f5;
    font-weight: 600;
}

/* ============================================================
   REDUCED MOTION (WCAG 2.3.3)
   Respect users who prefer minimal animation: drop slide/fade
   transitions and snap banner/modal into place.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .bcm-banner,
    .bcm-banner--slide-in,
    .bcm-banner--fade-in,
    .bcm-toggle__slider,
    .bcm-toggle__slider::before,
    .bcm-btn {
        animation: none !important;
        transition: none !important;
    }
}
