/* ==========================================================================
   Lukuro Color Selector Component Styles
   ========================================================================== */

/* ==========================================================================
   Component Base
   ========================================================================== */

lukuro-color-selector {
    display: block;
    position: relative;
    z-index: 2;
}

.lukuro-color-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: inherit;
    position: relative;
    z-index: 2;
}

.lukuro-color-selector-wrapper.lukuro-component {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lukuro-color-selector-wrapper.lukuro-initialized {
    opacity: 1;
}

/* ==========================================================================
   Label Styles
   ========================================================================== */

.lukuro-color-selector-label {
    display: none;
}

/* ==========================================================================
   Swatches Container
   ========================================================================== */

.lukuro-color-swatches {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* ==========================================================================
   Individual Swatch Styles
   ========================================================================== */

.lukuro-color-swatch {
    width: 16px;
    height: 16px;
    border: 1px solid transparent;
    border-radius: 0;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    padding: 2px;
    margin: 0;
    outline: none;
    position: relative;
    box-shadow: none;
    background-clip: content-box;
}

/* Hover state */
.lukuro-color-swatch:not(.active):hover {
    border-color: #bbb;
}

.lukuro-color-swatch:focus-visible {
    outline: 1px solid #007cba;
    outline-offset: 2px;
}

/* Active state — border color matches the swatch color */
.lukuro-color-swatch.active {
    border: 1px solid var(--lukuro-swatch-active-color, #222);
    padding: 2px;
}

/* Light color swatch — inner border to separate white color from white padding/background */
.lukuro-color-swatch.is-light::before {
    content: '';
    position: absolute;
    inset: 2px;
    border: 0.5px solid rgba(0, 0, 0, 0.13);
    pointer-events: none;
}

/* ==========================================================================
   Count Label (max visible swatches overflow)
   ========================================================================== */

.lukuro-color-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #999;
    white-space: nowrap;
    line-height: 1;
    letter-spacing: -0.02em;
}

/* ==========================================================================
   Accessibility Enhancements
   ========================================================================== */

/* Screen reader only text */
.lukuro-sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ==========================================================================
   Loading and Error States
   ========================================================================== */

.lukuro-color-selector-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.6;
}

.lukuro-color-selector-loading .lukuro-color-swatch {
    animation: lukuro-pulse 1.5s ease-in-out infinite;
}

.lukuro-color-selector-error {
    color: #d63638;
    font-size: 12px;
    font-style: italic;
}

/* ==========================================================================
   Placeholder Styles (Builder)
   ========================================================================== */

.lukuro-color-selector-placeholder {
    padding: 12px;
    background: #f0f0f1;
    border: 1px dashed #c3c4c7;
    border-radius: 4px;
    text-align: center;
    color: #646970;
    font-size: 12px;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes lukuro-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes lukuro-swatch-select {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1.05);
    }
}

.lukuro-color-swatch.selecting {
    animation: lukuro-swatch-select 0.3s ease;
}

/* ==========================================================================
   Variation Label — Active Color Name (TASK 2a)
   ========================================================================== */

.lukuro-active-color-name {
    font-weight: 400;
    color: inherit;
    pointer-events: none;
}

/* ==========================================================================
   Bricks Swatch — Active Border Color (TASK 2b)
   ========================================================================== */

.bricks-swatch-color li[data-value],
[data-attribute_name="attribute_pa_kolor"] li[data-value],
[data-attribute_name="attribute_pa_color"] li[data-value] {
    width: 24px;
    height: 24px;
    border: 1px solid transparent;
    border-radius: 0;
    padding: 2px;
    transition: border-color 0.2s ease;
}

.bricks-swatch-color li[data-value] > div,
[data-attribute_name="attribute_pa_kolor"] li[data-value] > div,
[data-attribute_name="attribute_pa_color"] li[data-value] > div {
    border-radius: 0;
}

.bricks-swatch-color li.bricks-swatch-selected,
[data-attribute_name="attribute_pa_kolor"] li.bricks-swatch-selected,
[data-attribute_name="attribute_pa_color"] li.bricks-swatch-selected {
    border-color: var(--lukuro-swatch-active-color, #222);
}

/* Bricks swatch — light color inner border via JS class on <li> */
.bricks-swatch-color li.is-light-swatch > div,
[data-attribute_name="attribute_pa_kolor"] li.is-light-swatch > div,
[data-attribute_name="attribute_pa_color"] li.is-light-swatch > div {
    box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.13);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .lukuro-color-selector-wrapper {
        gap: 8px;
    }

    .lukuro-color-swatch {
        width: 14px;
        height: 14px;
    }

    .lukuro-color-swatches {
        gap: 5px;
    }

    .lukuro-color-selector-label {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .lukuro-color-swatch {
        width: 14px;
        height: 14px;
    }
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
    .lukuro-color-swatch {
        border-width: 2px;
    }

    .lukuro-color-swatch.active {
        border-width: 3px;
    }
}

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

@media (prefers-reduced-motion: reduce) {
    .lukuro-color-swatch {
        transition: none;
    }

    .lukuro-color-selector-wrapper.lukuro-component {
        transition: none;
    }

    .lukuro-color-selector-loading .lukuro-color-swatch {
        animation: none;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .lukuro-color-selector-label {
        color: #f0f0f1;
    }

    .lukuro-color-swatch {
        border-color: rgba(255, 255, 255, 0.2);
    }

    .lukuro-color-swatch:hover {
        border-color: rgba(255, 255, 255, 0.4);
    }

    .lukuro-color-selector-placeholder {
        background: #1e1e1e;
        border-color: #555;
        color: #f0f0f1;
    }
}
