/**
 * Car 360 View Widget Styles
 *
 * Styling for the 360-degree car rotation viewer with color switching.
 * Includes responsive design, RTL support, and accessibility features.
 */

/* ============================================
   Container
   ============================================ */
.car-360-container {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.car-360-container:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* ============================================
   Loading Indicator
   ============================================ */
.car-360-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    z-index: 100;
    transition: opacity 0.3s ease;
}

.car-360-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.car-360-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e0e0e0;
    border-top-color: #991A34;
    border-radius: 50%;
    animation: car-360-spin 1s linear infinite;
}

@keyframes car-360-spin {
    to {
        transform: rotate(360deg);
    }
}

.car-360-loading-text {
    margin-top: 16px;
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.car-360-loading-progress {
    width: 200px;
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    margin-top: 12px;
    overflow: hidden;
}

.car-360-loading-bar {
    height: 100%;
    background: linear-gradient(90deg, #991A34, #cc2244);
    width: 0%;
    transition: width 0.2s ease;
    border-radius: 2px;
}

/* ============================================
   360 Viewer
   ============================================ */
.car-360-viewer {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #f5f5f5;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.car-360-viewer:active {
    cursor: grabbing;
}

/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 16 / 9) {
    .car-360-viewer {
        height: 0;
        padding-bottom: 56.25%; /* 16:9 ratio */
    }
}

/* ============================================
   Color Layers
   ============================================ */
.car-360-color-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.car-360-color-layer.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   Frames (individual rotation images)
   ============================================ */
.car-360-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100% !important;
    object-fit: contain;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.car-360-frame.active {
    opacity: 1;
    visibility: visible;
}

/* No images placeholder */
.car-360-no-images {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #999;
    font-size: 14px;
}

/* ============================================
   Drag Hint
   ============================================ */
.car-360-drag-hint {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10;
    transition: opacity 0.5s ease;
    pointer-events: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.car-360-drag-hint svg {
    width: 20px;
    height: 20px;
    animation: car-360-hint-bounce 1.2s ease-in-out infinite;
}

.car-360-drag-hint svg:first-child {
    animation-direction: reverse;
}

@keyframes car-360-hint-bounce {
    0%, 100% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(5px);
    }
}

.car-360-drag-hint.fade-out,
.car-360-drag-hint.hidden {
    opacity: 0;
}

/* ============================================
   Color Swatches Container
   ============================================ */
.car-360-swatches {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 20px;
    position: absolute;
    z-index: 20;
}

/* Position Variants */
.car-360-swatches--bottom {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
}

.car-360-swatches--top {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
}

.car-360-swatches--left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 20px 15px;
}

.car-360-swatches--right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 20px 15px;
}

/* ============================================
   Individual Swatch
   ============================================ */
.car-360-swatch {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 2px rgba(255, 255, 255, 0.3);
    outline: none;
    padding: 0;
    flex-shrink: 0;
}

.car-360-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.car-360-swatch.active {
    border-color: #333;
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.car-360-swatch:focus-visible {
    outline: 2px solid #007bff;
    outline-offset: 3px;
}

/* Light color swatches need a border for visibility */
.car-360-swatch[style*="rgb(255, 255, 255)"],
.car-360-swatch[style*="#fff"],
.car-360-swatch[style*="#FFF"],
.car-360-swatch[style*="#ffffff"],
.car-360-swatch[style*="#FFFFFF"],
.car-360-swatch[style*="rgb(245"],
.car-360-swatch[style*="rgb(240"],
.car-360-swatch[style*="rgb(235"],
.car-360-swatch[style*="#F5F5F5"],
.car-360-swatch[style*="#f5f5f5"] {
    border-color: #ddd;
}

.car-360-swatch[style*="rgb(255, 255, 255)"].active,
.car-360-swatch[style*="#fff"].active,
.car-360-swatch[style*="#FFF"].active,
.car-360-swatch[style*="#ffffff"].active,
.car-360-swatch[style*="#FFFFFF"].active,
.car-360-swatch[style*="rgb(245"].active,
.car-360-swatch[style*="rgb(240"].active,
.car-360-swatch[style*="rgb(235"].active,
.car-360-swatch[style*="#F5F5F5"].active,
.car-360-swatch[style*="#f5f5f5"].active {
    border-color: #333;
}

/* ============================================
   Swatch Tooltip
   ============================================ */
.car-360-swatch-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 30;
}

.car-360-swatch-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
}

.car-360-swatch:hover .car-360-swatch-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

/* Tooltip position adjustments for side swatches */
.car-360-swatches--left .car-360-swatch-tooltip {
    bottom: auto;
    left: calc(100% + 12px);
    transform: translateY(-50%);
    top: 50%;
}

.car-360-swatches--left .car-360-swatch-tooltip::after {
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: rgba(0, 0, 0, 0.9);
    border-top-color: transparent;
}

.car-360-swatches--left .car-360-swatch:hover .car-360-swatch-tooltip {
    transform: translateY(-50%) translateX(4px);
}

.car-360-swatches--right .car-360-swatch-tooltip {
    bottom: auto;
    left: auto;
    right: calc(100% + 12px);
    transform: translateY(-50%);
    top: 50%;
}

.car-360-swatches--right .car-360-swatch-tooltip::after {
    left: auto;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-left-color: rgba(0, 0, 0, 0.9);
    border-top-color: transparent;
}

.car-360-swatches--right .car-360-swatch:hover .car-360-swatch-tooltip {
    transform: translateY(-50%) translateX(-4px);
}

/* Top swatches - tooltip appears below */
.car-360-swatches--top .car-360-swatch-tooltip {
    bottom: auto;
    top: calc(100% + 12px);
}

.car-360-swatches--top .car-360-swatch-tooltip::after {
    top: auto;
    bottom: 100%;
    border: 6px solid transparent;
    border-bottom-color: rgba(0, 0, 0, 0.9);
    border-top-color: transparent;
}

.car-360-swatches--top .car-360-swatch:hover .car-360-swatch-tooltip {
    transform: translateX(-50%) translateY(4px);
}

/* ============================================
   Current Color Display
   ============================================ */
.car-360-current-color {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    z-index: 15;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.car-360-current-color-name {
    transition: opacity 0.2s ease;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 992px) {
    .car-360-swatch {
        width: 32px;
        height: 32px;
    }

    .car-360-drag-hint {
        bottom: 70px;
        padding: 10px 20px;
        font-size: 13px;
    }
}

@media (max-width: 768px) {

    .car-360-swatches {
        padding: 15px;
        gap: 8px;
    }

    .car-360-swatch {
        width: 28px;
        height: 28px;
    }

    .car-360-drag-hint {
        padding: 8px 16px;
        font-size: 12px;
        bottom: 60px;
        gap: 8px;
    }

    .car-360-drag-hint svg {
        width: 16px;
        height: 16px;
    }

    .car-360-current-color {
        top: 10px;
        left: 10px;
        padding: 8px 14px;
        font-size: 12px;
    }

    /* Force bottom position on mobile for side swatches */
    .car-360-swatches--left,
    .car-360-swatches--right {
        left: 50%;
        right: auto;
        top: auto;
        bottom: 0;
        transform: translateX(-50%);
        flex-direction: row;
        padding: 15px;
    }

    /* Reset tooltip for repositioned swatches */
    .car-360-swatches--left .car-360-swatch-tooltip,
    .car-360-swatches--right .car-360-swatch-tooltip {
        bottom: calc(100% + 12px);
        left: 50%;
        right: auto;
        top: auto;
        transform: translateX(-50%);
    }

    .car-360-swatches--left .car-360-swatch-tooltip::after,
    .car-360-swatches--right .car-360-swatch-tooltip::after {
        left: 50%;
        right: auto;
        top: 100%;
        bottom: auto;
        transform: translateX(-50%);
        border: 6px solid transparent;
        border-top-color: rgba(0, 0, 0, 0.9);
    }

    .car-360-swatches--left .car-360-swatch:hover .car-360-swatch-tooltip,
    .car-360-swatches--right .car-360-swatch:hover .car-360-swatch-tooltip {
        transform: translateX(-50%) translateY(-4px);
    }

    .car-360-loading-progress {
        width: 150px;
    }
}

@media (max-width: 480px) {
    .car-360-swatch {
        width: 24px;
        height: 24px;
    }

    .car-360-swatches {
        gap: 6px;
        padding: 12px;
    }

    .car-360-drag-hint {
        bottom: 50px;
        padding: 6px 12px;
        font-size: 11px;
    }

    .car-360-current-color {
        padding: 6px 10px;
        font-size: 11px;
    }

    .car-360-loading-spinner {
        width: 36px;
        height: 36px;
        border-width: 3px;
    }

    .car-360-loading-text {
        font-size: 12px;
    }

    .car-360-loading-progress {
        width: 120px;
    }
}

/* ============================================
   RTL Support
   ============================================ */
[dir="rtl"] .car-360-current-color {
    left: auto;
    right: 20px;
}

[dir="rtl"] .car-360-swatches--left {
    left: auto;
    right: 0;
}

[dir="rtl"] .car-360-swatches--right {
    right: auto;
    left: 0;
}

[dir="rtl"] .car-360-swatches--left .car-360-swatch-tooltip {
    left: auto;
    right: calc(100% + 12px);
}

[dir="rtl"] .car-360-swatches--left .car-360-swatch-tooltip::after {
    left: auto;
    right: -12px;
    border-right-color: transparent;
    border-left-color: rgba(0, 0, 0, 0.9);
}

[dir="rtl"] .car-360-swatches--right .car-360-swatch-tooltip {
    right: auto;
    left: calc(100% + 12px);
}

[dir="rtl"] .car-360-swatches--right .car-360-swatch-tooltip::after {
    right: auto;
    left: -6px;
    border-left-color: transparent;
    border-right-color: rgba(0, 0, 0, 0.9);
}

@media (max-width: 768px) {
    [dir="rtl"] .car-360-current-color {
        left: auto;
        right: 10px;
    }

    [dir="rtl"] .car-360-swatches--left,
    [dir="rtl"] .car-360-swatches--right {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}

/* ============================================
   Elementor Editor Styles
   ============================================ */
.elementor-editor-active .car-360-drag-hint {
    display: none;
}

.elementor-editor-active .car-360-loading {
    display: none;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .car-360-swatches,
    .car-360-loading,
    .car-360-drag-hint,
    .car-360-current-color {
        display: none !important;
    }

    .car-360-color-layer,
    .car-360-frame {
        opacity: 1 !important;
        visibility: visible !important;
        position: relative !important;
    }

    .car-360-viewer {
        height: auto !important;
    }
}

/* ============================================
   Accessibility - Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .car-360-loading-spinner {
        animation: none;
        border-top-color: #991A34;
        border-right-color: #991A34;
    }

    .car-360-drag-hint svg {
        animation: none;
    }

    .car-360-swatch,
    .car-360-swatch-tooltip,
    .car-360-color-layer,
    .car-360-frame,
    .car-360-loading,
    .car-360-loading-bar {
        transition: none;
    }
}

/* ============================================
   High Contrast Mode
   ============================================ */
@media (prefers-contrast: high) {
    .car-360-swatch {
        border-width: 4px;
    }

    .car-360-swatch.active {
        border-color: #000;
    }

    .car-360-current-color {
        border: 2px solid #000;
    }

    .car-360-swatch-tooltip {
        background: #000;
    }
}
