/**
 * Image Reveal Row & Column Extension - Base Styles
 * Version: 0.1.2.16 - Fixed progress bar and reset button alignment at bottom
 * 
 * Best Practices Applied:
 * - CSS custom properties for theming
 * - will-change hints for animated elements
 * - contain property for layout isolation
 * - prefers-reduced-motion support
 * - No external dependencies (vanilla CSS)
 * 
 * NOTE: This CSS is ONLY loaded on the frontend.
 * In BB editor mode, the plugin outputs NOTHING (no HTML, CSS, or JS).
 * This ensures BB's editor works 100% normally.
 * 
 * @since 0.1.0.3
 * @updated 0.1.1.0 - Added column background support
 * @updated 0.1.1.1 - Fixed column rendering with output buffering
 * @updated 0.1.2.0 - Added YWPG licensing integration
 * @updated 0.1.2.8 - Complete editor isolation (frontend-only CSS)
 */

/* ============================================
 * REVEAL CONTAINER - FRONTEND ONLY
 * ============================================ */

/* Container - renders behind row/column content */
.bbir-reveal-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    z-index: 0;
    pointer-events: none;
}

/* ============================================
 * ROW BACKGROUND SUPPORT
 * ============================================ */

/* Ensure row has position context */
.fl-row:has(.bbir-reveal-container) {
    position: relative;
}

/* Ensure row content wrapper is above canvas */
.fl-row:has(.bbir-reveal-container) .fl-row-content-wrap {
    position: relative;
    z-index: 1;
}

/* CRITICAL: Ensure row content is above the reveal canvas */
.fl-row:has(.bbir-reveal-container) .fl-col,
.fl-row:has(.bbir-reveal-container) .fl-col-content,
.fl-row:has(.bbir-reveal-container) .fl-module,
.fl-row:has(.bbir-reveal-container) .fl-module-content {
    position: relative;
    z-index: 10;
}

/* ============================================
 * COLUMN BACKGROUND SUPPORT (NEW in 0.1.1.0)
 * ============================================ */

/* Ensure column has position context */
.fl-col:has(> .bbir-reveal-container) {
    position: relative;
}

/* Ensure column content wrapper is above canvas */
.fl-col:has(> .bbir-reveal-container) .fl-col-content {
    position: relative;
    z-index: 1;
}

/* CRITICAL: Ensure column content is above the reveal canvas */
.fl-col:has(> .bbir-reveal-container) .fl-module,
.fl-col:has(> .bbir-reveal-container) .fl-module-content {
    position: relative;
    z-index: 10;
}

/* ============================================
 * INTERACTION MODES
 * ============================================ */

/* Scratch mode: Block all touch scrolling */
.bbir-reveal-container[data-mode="scratch"] {
    touch-action: none;
}

/* Hover mode: Allow scrolling by default, JS handles spotlight */
.bbir-reveal-container[data-mode="hover"] {
    touch-action: auto;
}

/* ============================================
 * BOTTOM IMAGE (Revealed)
 * ============================================ */

.bbir-bottom-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    z-index: 1;
}

/* ============================================
 * CANVAS (Top Image Overlay)
 * ============================================ */

.bbir-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    pointer-events: auto;
    z-index: 2;
    will-change: contents;
}

/* Scratch mode canvas: Block all touch */
.bbir-reveal-container[data-mode="scratch"] .bbir-canvas {
    touch-action: none;
}

/* Hover mode canvas: Allow scrolling, JS handles detection */
.bbir-reveal-container[data-mode="hover"] .bbir-canvas {
    touch-action: auto;
}

/* Hover mode specific cursor */
.bbir-reveal-container[data-mode="hover"] .bbir-canvas {
    cursor: crosshair;
}

/* Scratch mode cursor */
.bbir-reveal-container[data-mode="scratch"] .bbir-canvas {
    cursor: grab;
}

.bbir-reveal-container[data-mode="scratch"] .bbir-canvas:active {
    cursor: grabbing;
}

/* ============================================
 * RESET BUTTON
 * ============================================ */

.bbir-reset-btn {
    position: absolute;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    pointer-events: auto !important;
    z-index: 3;
    transition: all 0.3s ease;
}

.bbir-reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.bbir-reset-btn:active {
    transform: translateY(0);
}

/* Reset Button Positions */
.bbir-reset-top-left {
    top: 20px;
    left: 20px;
}

.bbir-reset-top-right {
    top: 20px;
    right: 20px;
}

.bbir-reset-bottom-left {
    bottom: 20px;
    left: 20px;
}

.bbir-reset-bottom-right {
    bottom: 20px;
    right: 20px;
}

/* ============================================
 * COMPLETION MESSAGE
 * ============================================ */

.bbir-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px 40px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
    z-index: 10;
    animation: bbir-fade-in 0.3s ease;
}

@keyframes bbir-fade-in {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ============================================
 * PROGRESS INDICATOR - NEW in 0.1.0.6
 * ============================================ */

/* Base progress container styles */
.bbir-progress-container {
    position: absolute;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 5;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Progress Position - Full Width (Top/Bottom) */
.bbir-progress-top {
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    max-width: 80%;
}

.bbir-progress-bottom {
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    max-width: 80%;
}

/* Progress Position - Corners */
.bbir-progress-top-left {
    top: 15px;
    left: 15px;
}

.bbir-progress-top-right {
    top: 15px;
    right: 15px;
}

.bbir-progress-bottom-left {
    bottom: 15px;
    left: 15px;
}

.bbir-progress-bottom-right {
    bottom: 15px;
    right: 15px;
}

/* Progress Bar Style */
.bbir-progress-bar {
    flex: 1;
    min-width: 100px;
    height: 8px;
    background: var(--progress-bg, #e0e0e0);
    border-radius: 4px;
    overflow: hidden;
}

.bbir-progress-bar-fill {
    height: 100%;
    background: var(--progress-fill, #4CAF50);
    border-radius: 4px;
    transition: width 0.15s ease-out;
    will-change: width;
}

/* Progress Text Style */
.bbir-progress-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--progress-text, #333);
    min-width: 40px;
    text-align: right;
}

/* Percentage Only Style */
.bbir-progress-style-percentage .bbir-progress-text {
    min-width: auto;
    font-size: 16px;
}

/* Bar + Percentage Style */
.bbir-progress-style-bar_percentage {
    flex-direction: row;
}

.bbir-progress-style-bar_percentage .bbir-progress-bar {
    flex: 1;
}

/* Circular Progress Style */
.bbir-progress-style-circle {
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
}

.bbir-progress-circle {
    width: 60px;
    height: 60px;
    transform: rotate(-90deg);
}

.bbir-progress-circle-bg {
    stroke: var(--progress-bg, #e0e0e0);
}

.bbir-progress-circle-fill {
    stroke: var(--progress-fill, #4CAF50);
    stroke-linecap: round;
    transition: stroke-dasharray 0.15s ease-out;
}

.bbir-progress-circle-text {
    font-size: 8px;
    font-weight: 600;
    fill: var(--progress-text, #333);
    text-anchor: middle;
    dominant-baseline: middle;
    transform: rotate(90deg);
    transform-origin: center;
}

/* Loading State */
.bbir-reveal-container.bbir-loading .bbir-canvas {
    cursor: wait;
    opacity: 0.5;
}

/* ============================================
 * COMBINED BOTTOM CONTROLS BAR (NEW in 0.1.2.16)
 * Progress bar and reset button aligned in one bar
 * ============================================ */

.bbir-bottom-controls-bar {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10;
    pointer-events: auto;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    min-width: 200px;
    max-width: 80%;
}

/* Progress container inside combined bar - no background/shadow */
.bbir-bottom-controls-bar .bbir-progress-container {
    position: static;
    padding: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-radius: 0;
    flex: 1;
    min-width: 100px;
}

/* Reset button inside combined bar */
.bbir-bottom-controls-bar .bbir-reset-btn {
    position: static;
    flex-shrink: 0;
    margin: 0;
    padding: 8px 16px;
    box-shadow: none;
}

/* ============================================
 * MOBILE OPTIMIZATIONS
 * ============================================ */

@media (max-width: 768px) {
    /* Combined bottom controls bar - mobile */
    .bbir-bottom-controls-bar {
        padding: 6px 10px;
        gap: 8px;
        min-width: 150px;
        max-width: 95%;
        bottom: 10px;
    }
    
    .bbir-bottom-controls-bar .bbir-reset-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .bbir-reset-btn {
        padding: 8px 16px;
        font-size: 12px;
    }
    
    .bbir-reset-top-left,
    .bbir-reset-top-right {
        top: 10px;
    }
    
    .bbir-reset-bottom-left,
    .bbir-reset-bottom-right {
        bottom: 10px;
    }
    
    .bbir-reset-top-left,
    .bbir-reset-bottom-left {
        left: 10px;
    }
    
    .bbir-reset-top-right,
    .bbir-reset-bottom-right {
        right: 10px;
    }
    
    /* Mobile Progress Adjustments */
    .bbir-progress-container {
        padding: 6px 10px;
    }
    
    .bbir-progress-top,
    .bbir-progress-bottom {
        min-width: 150px;
        max-width: 90%;
    }
    
    .bbir-progress-top-left,
    .bbir-progress-top-right {
        top: 10px;
    }
    
    .bbir-progress-bottom-left,
    .bbir-progress-bottom-right {
        bottom: 10px;
    }
    
    .bbir-progress-top-left,
    .bbir-progress-bottom-left {
        left: 10px;
    }
    
    .bbir-progress-top-right,
    .bbir-progress-bottom-right {
        right: 10px;
    }
    
    .bbir-progress-bar {
        height: 6px;
        min-width: 80px;
    }
    
    .bbir-progress-text {
        font-size: 12px;
    }
    
    .bbir-progress-circle {
        width: 50px;
        height: 50px;
    }
    
    .bbir-progress-circle-text {
        font-size: 7px;
    }
}

/* ============================================
 * ACCESSIBILITY
 * ============================================ */

.bbir-reveal-container:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* High contrast mode support for progress */
@media (prefers-contrast: high) {
    .bbir-progress-container {
        background: white;
        border: 2px solid black;
    }
    
    .bbir-progress-bar {
        border: 1px solid black;
    }
    
    .bbir-bottom-controls-bar {
        background: white;
        border: 2px solid black;
    }
    
    .bbir-controls-wrapper {
        background: white;
        border: 2px solid black;
        padding: 4px;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .bbir-progress-bar-fill,
    .bbir-progress-circle-fill {
        transition: none;
    }
    
    .bbir-message {
        animation: none;
    }
    
    .bbir-reset-btn {
        transition: none;
    }
}

/* ============================================
 * PRINT STYLES
 * ============================================ */

@media print {
    .bbir-canvas {
        display: none;
    }
    
    .bbir-bottom-image {
        display: block;
    }
    
    .bbir-reset-btn,
    .bbir-progress-container,
    .bbir-bottom-controls-bar,
    .bbir-controls-wrapper {
        display: none;
    }
}
