/* =====================================================
   COOKIE CONSENT (209)
   First-layer banner (injected by wwwroot/js/consent-runtime.js),
   the persistent "Cookie settings" reopen control (Step F8)
   and the shared preferences panel surfaces (Steps F5-F7).
   WCAG 2.1 AA Compliant.

   THEME: every color comes from the community theme tokens
   (community-theme-light.css / community-theme-dark.css) plus
   the per-community brand vars injected by CommunityLayout
   (--community-primary / --community-accent), so the banner
   follows the community's light/dark mode automatically.
   Hex values appear ONLY as var() fallbacks (ios-toggle.css
   precedent) — never as direct declarations.
   ===================================================== */

/* =====================================================
   BASE / SHARED
   ===================================================== */

.cookie-consent-root {
    position: fixed;
    z-index: 10000; /* above .modal-overlay (9998) / .confirmation-modal (9999) */
    font-size: var(--font-size-sm, 0.875rem);
}

.cookie-consent-surface {
    background: var(--surface);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem;
    animation: cookie-consent-enter 0.25s ease-out;
}

.cookie-consent-message {
    margin: 0;
    color: var(--text-primary);
    line-height: 1.5;
}

/* Title + message vertical block (211): keeps the title stacked ABOVE the message in
   every variant — including the flex-row Bar, where this block is the growing middle
   column between the logo and the action buttons. */
.cookie-consent-text {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0; /* let long words/links wrap instead of overflowing the flex row */
}

/* Banner title (210) — plain-text heading above the message.
   Theme-token color only, so it follows the community light/dark mode. */
.cookie-consent-title {
    margin: 0;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.3;
    color: var(--text-primary);
}

/* Markdown-rendered message content (210): links follow the community brand,
   and paragraph/list spacing keeps multi-line copy tidy across the
   bar / flyout / modal surfaces. */
.cookie-consent-message a {
    color: var(--community-primary, #6A4A9E);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cookie-consent-message a:hover {
    color: color-mix(in srgb, var(--community-primary, #6A4A9E) 85%, var(--text-primary));
}

.cookie-consent-message p {
    margin: 0 0 0.5rem;
}

.cookie-consent-message p:last-child {
    margin-bottom: 0;
}

.cookie-consent-message ul,
.cookie-consent-message ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.cookie-consent-logo {
    height: 2.25rem;
    width: auto;
    max-width: 100%;
    align-self: flex-start;
    flex-shrink: 0;
}

.cookie-consent-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

/* =====================================================
   SHAPE (1=Rounded, 2=Square)
   ===================================================== */

.cookie-consent-rounded .cookie-consent-surface {
    border-radius: 1rem;
}

.cookie-consent-square .cookie-consent-surface {
    border-radius: 0;
}

/* A full-width bar cannot carry rounded outer corners */
.cookie-consent-bar.cookie-consent-rounded .cookie-consent-surface {
    border-radius: 0;
}

.cookie-consent-rounded .cookie-consent-btn {
    border-radius: 9999px;
}

.cookie-consent-square .cookie-consent-btn {
    border-radius: 0.25rem;
}

/* =====================================================
   BAR VARIANT (full-width, top or bottom)
   ===================================================== */

.cookie-consent-bar {
    left: 0;
    right: 0;
}

.cookie-consent-bar-top {
    top: 0;
}

.cookie-consent-bar-bottom {
    bottom: 0;
}

.cookie-consent-bar .cookie-consent-surface {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 2rem;
    box-shadow: 0 -2px 12px var(--card-shadow);
}

.cookie-consent-bar-top .cookie-consent-surface {
    border-bottom: 1px solid var(--border-strong);
    box-shadow: 0 2px 12px var(--card-shadow);
}

.cookie-consent-bar-bottom .cookie-consent-surface {
    border-top: 1px solid var(--border-strong);
}

.cookie-consent-bar .cookie-consent-text {
    flex: 1 1 16rem;
}

.cookie-consent-bar .cookie-consent-logo {
    align-self: center;
}

/* =====================================================
   FLYOUT VARIANT (fixed corner card)
   ===================================================== */

.cookie-consent-flyout {
    width: min(24rem, calc(100vw - 2rem));
}

.cookie-consent-flyout .cookie-consent-surface {
    border: 1px solid var(--border-strong);
    box-shadow: 0 8px 24px var(--card-shadow);
}

.cookie-consent-flyout-br {
    right: 1.5rem;
    bottom: 1.5rem;
}

.cookie-consent-flyout-bl {
    left: 1.5rem;
    bottom: 1.5rem;
}

.cookie-consent-flyout-tr {
    right: 1.5rem;
    top: 1.5rem;
}

.cookie-consent-flyout-tl {
    left: 1.5rem;
    top: 1.5rem;
}

/* =====================================================
   MODAL VARIANT (centered dialog + scrim)
   ===================================================== */

.cookie-consent-modal {
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.cookie-consent-scrim {
    position: absolute;
    inset: 0;
    background: var(--scrim);
}

.cookie-consent-modal .cookie-consent-surface {
    position: relative; /* above the scrim */
    width: 100%;
    max-width: 480px;
    border: 1px solid var(--border-strong);
    box-shadow: 0 16px 56px var(--card-shadow-hover);
    padding: 2.25rem;
    gap: 1rem;
}

/* =====================================================
   ACTION BUTTONS
   WCAG: 44px targets, visible focus, AA contrast from
   the server-computed --community-primary-text pair.
   ===================================================== */

.cookie-consent-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.625rem 1.25rem;
    font-family: inherit;
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.cookie-consent-btn:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
}

.cookie-consent-btn-accept {
    background: var(--community-primary, #6A4A9E);
    color: var(--community-primary-text, #ffffff);
}

.cookie-consent-btn-accept:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 85%, var(--text-primary));
}

.cookie-consent-btn-reject {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.cookie-consent-btn-reject:hover {
    background: var(--surface-sunken);
}

.cookie-consent-btn-manage {
    background: transparent;
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cookie-consent-btn-manage:hover {
    color: var(--text-primary);
}

/* =====================================================
   PERSISTENT "COOKIE SETTINGS" REOPEN CONTROL (Step F8)
   Fixed-corner GDPR Art. 7(3) withdrawal affordance —
   rendered by CookieConsentHost, calls PulseConsent.reopen().
   Bottom-LEFT so it never collides with the default
   bottom-right flyout banner.
   ===================================================== */

.cookie-consent-reopen {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    z-index: 900; /* above page content, below modals and the banner */
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: 0 2px 8px var(--card-shadow);
    transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.cookie-consent-reopen:hover {
    color: var(--community-primary, #6A4A9E);
    border-color: var(--community-primary, #6A4A9E);
    box-shadow: 0 4px 12px var(--card-shadow-hover);
}

.cookie-consent-reopen:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
}

.cookie-consent-reopen i {
    font-size: 1.125rem;
}

/* =====================================================
   MOTION + RESPONSIVE
   ===================================================== */

@keyframes cookie-consent-enter {
    from {
        transform: translateY(0.5rem);
        opacity: 0;
    }
    to {
        transform: none;
        opacity: 1;
    }
}

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

    .cookie-consent-btn,
    .cookie-consent-reopen {
        transition: none;
    }
}

@media (max-width: 640px) {
    .cookie-consent-flyout {
        left: 1rem;
        right: 1rem;
        width: auto;
    }

    .cookie-consent-bar .cookie-consent-surface {
        flex-direction: column;
        align-items: stretch;
    }

    .cookie-consent-bar .cookie-consent-message {
        flex-basis: auto;
    }

    .cookie-consent-actions {
        flex-direction: column;
        align-items: stretch;
    }
}

/* =====================================================
   COOKIE PREFERENCES PANEL (.cookie-panel-*)
   PLACEHOLDER — DO NOT REMOVE THIS MARKER.
   The shared CookiePreferencesPanel / CookieConsentHost /
   /cookie-preferences page styles (Steps F5-F7, Wave 5)
   are appended BELOW this banner as .cookie-panel-* rules.
   Everything ABOVE this marker belongs to the first-layer
   banner + reopen control and must not be edited by the
   panel step.
   ===================================================== */

/* Shared second-layer panel (Step F5). Hosted inside the
   CookieConsentHost modal overlay AND the /cookie-preferences
   page, both of which sit over theme-token surfaces — so the
   panel styles only its own content and stays width-fluid. */

.cookie-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    color: var(--text-primary);
}

.cookie-panel-heading {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.cookie-panel-intro {
    color: var(--text-secondary);
    line-height: 1.5;
}

.cookie-panel-intro p {
    margin: 0 0 0.5rem;
}

/* Plain-text intro title (210) above the Markdown intro message. */
.cookie-panel-intro-title {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Branded links inside the Markdown-rendered panel intro (210). */
.cookie-panel-intro a {
    color: var(--community-primary, #6A4A9E);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cookie-panel-intro a:hover {
    color: color-mix(in srgb, var(--community-primary, #6A4A9E) 85%, var(--text-primary));
}

.cookie-panel-categories {
    display: flex;
    flex-direction: column;
}

.cookie-panel-category {
    padding: 0.875rem 0;
    border-bottom: 1px solid var(--border, var(--border-strong));
}

.cookie-panel-category:last-child {
    border-bottom: none;
}

.cookie-panel-toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
}

.cookie-panel-category-text {
    flex: 1;
    min-width: 0;
}

.cookie-panel-category-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cookie-panel-category-name {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.cookie-panel-always-on {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--community-primary, #6A4A9E);
}

.cookie-panel-category-description {
    margin: 0.25rem 0 0;
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Per-category cookie disclosure (native <details> for built-in
   keyboard/screen-reader semantics; chevron rotates on open). */

.cookie-panel-details {
    margin-top: 0.5rem;
}

.cookie-panel-details-summary {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 44px; /* WCAG touch target */
    cursor: pointer;
    list-style: none;
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--text-secondary);
}

.cookie-panel-details-summary::-webkit-details-marker {
    display: none;
}

.cookie-panel-details-summary:hover {
    color: var(--text-primary);
}

.cookie-panel-details-summary:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
}

.cookie-panel-details-summary i {
    transition: transform 0.2s;
}

.cookie-panel-details[open] > .cookie-panel-details-summary i {
    transform: rotate(180deg);
}

/* Wide table scrolls inside its own container — the panel
   (and the host's 480px modal) must never scroll sideways. */
.cookie-panel-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border, var(--border-strong));
    border-radius: 0.5rem;
}

.cookie-panel-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm, 0.875rem);
}

.cookie-panel-table th,
.cookie-panel-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border, var(--border-strong));
}

.cookie-panel-table thead th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-sunken);
    white-space: nowrap;
}

.cookie-panel-table tbody tr:last-child th,
.cookie-panel-table tbody tr:last-child td {
    border-bottom: none;
}

.cookie-panel-table td {
    color: var(--text-secondary);
}

.cookie-panel-cookie-name {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

/* Action row — Accept / Save / Reject share identical sizing so
   rejecting stays as easy as accepting (GDPR equal prominence). */

.cookie-panel-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 0.25rem;
}

.cookie-panel-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.625rem 1.25rem;
    font-family: inherit;
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 9999px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.cookie-panel-btn:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
}

.cookie-panel-btn-accept {
    background: var(--community-primary, #6A4A9E);
    color: var(--community-primary-text, #ffffff);
}

.cookie-panel-btn-accept:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 85%, var(--text-primary));
}

.cookie-panel-btn-save {
    background: transparent;
    border-color: var(--community-primary, #6A4A9E);
    color: var(--community-primary, #6A4A9E);
}

.cookie-panel-btn-save:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 12%, transparent);
}

.cookie-panel-btn-reject {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.cookie-panel-btn-reject:hover {
    background: var(--surface-sunken);
}

@media (prefers-reduced-motion: reduce) {
    .cookie-panel-btn,
    .cookie-panel-details-summary i {
        transition: none;
    }
}

@media (max-width: 640px) {
    .cookie-panel-actions {
        flex-direction: column;
        align-items: stretch;
    }
}
