/**
 * BERKEI Variation Swatches – CSS
 *
 * Styles für Swatch-Buttons auf Produktseiten, in der Produktübersicht
 * und im Produkt-Filter. CSS Custom Properties für einfache Theme-Anpassung.
 *
 * @package BerkeiScriptCollection
 * @author  BERKEI
 * @created 2026-03-29
 * @version 1.1
 */

/* ── Custom Properties ─────────────────────────────── */
:root {
    --berkei-swatch-border:        2px solid #ccc;
    --berkei-swatch-selected-bg:   #177797;
    --berkei-swatch-selected-border: #177797;
    --berkei-swatch-hover-border:  #177797;
    --berkei-swatch-unavail-opacity: 0.35;
    --berkei-swatch-radius:        6px;
    --berkei-swatch-gap:           6px;
}

/* ── Container ────────────────────────────────────────
   Productseite: ersetzt die WC-Variations-Tabellen-Zelle
   ───────────────────────────────────────────────────── */
.berkei-swatches-container {
    display: flex !important;
    flex-wrap: wrap;
    gap: var(--berkei-swatch-gap);
    align-items: center;
    margin: 0;
    padding: 0;
}

table.variations td.value .berkei-swatches-container {
    list-style: none;
    width: 100%;
}

/* ── Base Button ──────────────────────────────────────── */
.berkei-swatch {
    /* Reset */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 0;
    padding: 5px 10px;
    cursor: pointer;
    border: var(--berkei-swatch-border);
    border-radius: var(--berkei-swatch-radius);
    background: #fff;
    color: #333;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    user-select: none;
    outline: none;
    position: relative;
    overflow: hidden;
}

/* Color swatch: no padding, circle-ish */
.berkei-swatch--color {
    padding: 0;
    border-radius: var(--berkei-swatch-radius);
    border: 2px solid rgba(0,0,0,0.12);
}

/* Image swatch: no padding, border tight */
.berkei-swatch--image {
    padding: 0;
    overflow: hidden;
    background: transparent;
    border: var(--berkei-swatch-border);
}

.berkei-swatch--image img {
    display: block;
    pointer-events: none;
}

/* Label swatch */
.berkei-swatch--label {
    min-width: 36px;
}

/* ── States ─────────────────────────────────────────── */

.berkei-swatch:hover:not(.berkei-swatch--unavailable) {
    border-color: var(--berkei-swatch-hover-border);
    background: color-mix(in srgb, var(--berkei-swatch-hover-border) 10%, #fff);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Color/Image swatches: only border highlight on hover */
.berkei-swatch--color:hover:not(.berkei-swatch--unavailable),
.berkei-swatch--image:hover:not(.berkei-swatch--unavailable) {
    border-color: var(--berkei-swatch-hover-border);
    background: inherit;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--berkei-swatch-hover-border) 30%, transparent);
}

/* Selected */
.berkei-swatch--selected.berkei-swatch--label {
    background: var(--berkei-swatch-selected-bg);
    border-color: var(--berkei-swatch-selected-border);
    color: #fff;
    box-shadow: 0 2px 6px color-mix(in srgb, var(--berkei-swatch-selected-bg) 30%, transparent);
}

.berkei-swatch--selected.berkei-swatch--color,
.berkei-swatch--selected.berkei-swatch--image {
    border-color: var(--berkei-swatch-selected-border);
    border-width: 3px;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--berkei-swatch-selected-bg) 40%, transparent);
}

/* Unavailable (out of stock / not valid combination) */
.berkei-swatch--unavailable {
    opacity: var(--berkei-swatch-unavail-opacity);
    cursor: not-allowed;
    position: relative;
}

/* Diagonal strikethrough line for all unavailable swatches */
.berkei-swatch--unavailable::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to top right,
        transparent calc(50% - 0.7px),
        rgba(180, 40, 40, 0.55) calc(50% - 0.7px),
        rgba(180, 40, 40, 0.55) calc(50% + 0.7px),
        transparent calc(50% + 0.7px)
    );
    border-radius: inherit;
    pointer-events: none;
}

/* ── Tooltips (CSS-only, via data-label) ─────────────── */
.berkei-swatch[data-label] {
    position: relative;
}

.berkei-swatch[data-label]::before {
    content: attr(data-label);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    padding: 4px 8px;
    border-radius: 5px;
    background: #1d2327;
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
    z-index: 10;
}

.berkei-swatch[data-label]:hover::before,
.berkei-swatch[data-label]:focus::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

/* ── Loop Swatches ──────────────────────────────────── */
.berkei-loop-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    padding: 0;
}

.berkei-loop-swatch-group {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.berkei-loop-swatches .berkei-swatch {
    box-shadow: none;
}

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 782px) {
    .berkei-swatch {
        font-size: 0.82rem;
        padding: 4px 8px;
    }

    .variations_form table.variations td.value .berkei-swatch {
        min-width: 28px !important;
        min-height: 28px !important;
        padding: 2px 6px !important;
        font-size: 0.78rem;
    }

    .variations_form table.variations td.value .berkei-swatch--image img {
        width: 100% !important;
        height: 100% !important;
    }

    .berkei-swatches-container {
        gap: 4px;
        align-items: flex-start;
    }
}
