/**
 * Embed Consent Plugin - Styles
 *
 * Provides consent-protected embed styling with:
 * - Responsive aspect ratio containers
 * - Theme-aware border-radius
 * - Light/dark mode support
 * - Accessible UI components
 *
 * @version 2.1.0
 */

/* ========================================
   CSS Custom Properties (Theme Integration)
   ======================================== */

:root {
    /* Default border radius - can be overridden by theme */
    --embed-consent-radius: var(--radius-default, 0.5rem);

    /* Color scheme - light mode defaults */
    --embed-consent-bg: rgba(255, 255, 255, 0.95);
    --embed-consent-text: #1a1a1a;
    --embed-consent-text-muted: #666;
    --embed-consent-border: rgba(0, 0, 0, 0.1);
    --embed-consent-overlay-bg: rgba(245, 245, 245, 0.95);

    /* Button colors */
    --embed-consent-button-bg: #2563eb;
    --embed-consent-button-text: #ffffff;
    --embed-consent-button-hover-bg: #1d4ed8;

    /* Icon color */
    --embed-consent-icon-color: rgba(255, 255, 255, 0.9);

    /* Overlay text colors */
    --embed-consent-overlay-text: rgba(30, 30, 30, 0.95);
    --embed-consent-overlay-text-strong: rgba(30, 30, 30, 1);
    --embed-consent-overlay-text-muted: rgba(60, 60, 60, 0.85);
}

/* Dark mode support - consolidated to avoid duplication */
@media (prefers-color-scheme: dark) {
    :root {
        --embed-consent-bg: rgba(30, 30, 30, 0.95);
        --embed-consent-text: #e5e5e5;
        --embed-consent-text-muted: #a3a3a3;
        --embed-consent-border: rgba(255, 255, 255, 0.1);
        --embed-consent-overlay-bg: rgba(30, 30, 30, 0.95);

        --embed-consent-button-bg: #3b82f6;
        --embed-consent-button-text: #ffffff;
        --embed-consent-button-hover-bg: #2563eb;

        /* Overlay text colors for dark mode */
        --embed-consent-overlay-text: rgba(255, 255, 255, 0.95);
        --embed-consent-overlay-text-strong: rgba(255, 255, 255, 1);
        --embed-consent-overlay-text-muted: rgba(255, 255, 255, 0.8);
    }
}

/* Allow explicit dark mode class override (inherits from media query above) */
.dark,
[data-theme="dark"] {
    color-scheme: dark;
}

/* Force dark mode colors when explicitly set via class/attribute */
.dark .embed-consent-wrapper,
[data-theme="dark"] .embed-consent-wrapper {
    /* Colors are already set via @media query, just ensure they apply */
    --embed-consent-bg: rgba(30, 30, 30, 0.95);
    --embed-consent-text: #e5e5e5;
    --embed-consent-text-muted: #a3a3a3;
    --embed-consent-border: rgba(255, 255, 255, 0.1);
    --embed-consent-overlay-bg: rgba(30, 30, 30, 0.95);
    --embed-consent-button-bg: #3b82f6;
    --embed-consent-button-text: #ffffff;
    --embed-consent-button-hover-bg: #2563eb;
    --embed-consent-overlay-text: rgba(255, 255, 255, 0.95);
    --embed-consent-overlay-text-strong: rgba(255, 255, 255, 1);
    --embed-consent-overlay-text-muted: rgba(255, 255, 255, 0.8);
}

/* ========================================
   Embed Container (Aspect Ratio)
   ======================================== */

.embed-consent-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    background-color: transparent;
    border-radius: var(--embed-consent-radius);

    /* Aspect ratio using padding-bottom trick for older browsers */
    padding-bottom: var(--aspect-ratio-padding, 56.25%);
    height: 0;
}

/* Modern aspect-ratio property (with fallback above) */
@supports (aspect-ratio: 16 / 9) {
    .embed-consent-wrapper {
        aspect-ratio: var(--iframe-aspect-ratio, 16 / 9);
        padding-bottom: 0;
        height: auto;
    }
}

.embed-consent-wrapper.embed-consent-fixed-height {
    padding-bottom: 0;
    height: var(--fixed-iframe-height, 400px);
    min-height: var(--fixed-iframe-height, 400px);
}

@supports (aspect-ratio: 16 / 9) {
    .embed-consent-wrapper.embed-consent-fixed-height {
        aspect-ratio: auto;
    }
}

/* Active state: Allow wrapper to adapt to actual iframe size */
.embed-consent-wrapper.embed-consent-active {
    padding-bottom: 0;
    height: auto;
    background-color: transparent;
}

@supports (aspect-ratio: 16 / 9) {
    .embed-consent-wrapper.embed-consent-active {
        aspect-ratio: unset;
    }
}

.embed-consent-wrapper.embed-consent-fixed-height.embed-consent-active {
    height: var(--fixed-iframe-height, 400px);
}

/* ========================================
   Iframe Styling
   ======================================== */

.embed-consent-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: var(--embed-consent-radius);

    /* Clip to rounded corners */
    overflow: hidden;
}

/* Hide iframe until consent is given */
.embed-consent-wrapper:not(.embed-consent-active) .embed-consent-iframe {
    opacity: 0;
    pointer-events: none;
}

/* Show iframe after consent */
.embed-consent-wrapper.embed-consent-active .embed-consent-iframe {
    position: relative;
    width: 100%;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease-in-out;
}

.embed-consent-wrapper.embed-consent-fixed-height .embed-consent-iframe,
.embed-consent-wrapper.embed-consent-fixed-height.embed-consent-active .embed-consent-iframe {
    height: 100%;
}

/* Only apply aspect-ratio if wrapper has valid dimensions */
.embed-consent-wrapper.embed-consent-active[data-has-aspect-ratio="true"] .embed-consent-iframe {
    aspect-ratio: var(--iframe-aspect-ratio, 16 / 9);
    height: auto;
}

/* ========================================
   Consent Overlay
   ======================================== */

.embed-consent-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--embed-consent-overlay-bg);
    border-radius: var(--embed-consent-radius);
    z-index: 10;
    padding: 1.5rem;
    box-sizing: border-box;
}

/* Hide overlay after consent */
.embed-consent-wrapper.embed-consent-active .embed-consent-overlay {
    display: none;
}

/* ========================================
   Thumbnail Background
   ======================================== */

.embed-consent-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.3;
    filter: blur(8px);
    border-radius: var(--embed-consent-radius);
}

/* ========================================
   Consent Content (Text and Actions)
   ======================================== */

.embed-consent-content {
    position: relative;
    z-index: 20;
    text-align: center;
    width: 100%;
    max-width: min(80%, 1100px);
    margin: 0 auto;
    background-color: transparent;
    padding: 2rem 1.5rem;
}

/* ========================================
   Icon
   ======================================== */

.embed-consent-icon {
    margin-bottom: 1rem;
    color: var(--embed-consent-icon-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.embed-consent-icon svg {
    width: 48px;
    height: 48px;
    opacity: 0.9;
}

.embed-consent-icon img {
    display: block;
    max-width: 120px;
    max-height: 48px;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* ========================================
   Text
   ======================================== */

.embed-consent-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--embed-consent-overlay-text);
    margin: 0 0 1.5rem 0;
}

.embed-consent-text strong {
    display: block;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--embed-consent-overlay-text-strong);
}

.embed-consent-privacy-link {
    color: var(--embed-consent-button-bg);
    text-decoration: underline;
    font-weight: 500;
}

.embed-consent-privacy-link:hover {
    color: var(--embed-consent-button-hover-bg);
}

/* ========================================
   Actions (Button and Checkbox)
   ======================================== */

.embed-consent-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

/* ========================================
   Button
   ======================================== */

.embed-consent-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--embed-consent-button-text);
    background-color: var(--embed-consent-button-bg);
    border: none;
    border-radius: calc(var(--embed-consent-radius) * 0.8);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    min-width: 150px;
}

.embed-consent-button:hover,
.embed-consent-button:focus {
    background-color: var(--embed-consent-button-hover-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transform: translateY(-1px);
}

.embed-consent-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.embed-consent-button:focus {
    outline: 2px solid var(--embed-consent-button-bg);
    outline-offset: 2px;
}

/* ========================================
   Checkbox
   ======================================== */

.embed-consent-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--embed-consent-overlay-text-muted);
    user-select: none;
}

.embed-consent-checkbox-input {
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
    margin: 0;
    accent-color: var(--embed-consent-button-bg);
}

.embed-consent-checkbox-label {
    cursor: pointer;
    line-height: 1.4;
}

.embed-consent-checkbox:hover .embed-consent-checkbox-label {
    color: var(--embed-consent-overlay-text-strong);
}

/* ========================================
   No-JavaScript Fallback
   ======================================== */

.embed-consent-noscript {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    padding: 2rem;
    background-color: var(--embed-consent-bg);
    border-radius: var(--embed-consent-radius);
    color: var(--embed-consent-text);
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 15;
}

.embed-consent-noscript a {
    color: var(--embed-consent-button-bg);
    text-decoration: underline;
    font-weight: 500;
}

.embed-consent-noscript a:hover {
    color: var(--embed-consent-button-hover-bg);
}

/* ========================================
   Error State
   ======================================== */

.embed-consent-error {
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.6;
}

.embed-consent-error code {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 640px) {
    .embed-consent-content {
        padding: 1.5rem 1rem;
    }

    .embed-consent-text {
        font-size: 0.875rem;
    }

    .embed-consent-text strong {
        font-size: 1rem;
    }

    .embed-consent-button {
        padding: 0.625rem 1.5rem;
        font-size: 0.9375rem;
        min-width: 120px;
    }

    .embed-consent-icon svg {
        width: 40px;
        height: 40px;
    }

    .embed-consent-checkbox {
        font-size: 0.8125rem;
    }
}

/* ========================================
   Reduced Motion Support
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .embed-consent-iframe,
    .embed-consent-button {
        transition: none;
    }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .embed-consent-overlay {
        display: none;
    }

    .embed-consent-wrapper {
        border: 1px solid #ccc;
    }

    .embed-consent-wrapper::after {
        content: "[Embedded content]";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: #666;
        font-size: 1rem;
    }
}
