/* =========================================================
   Trikot-Konfigurator — Frontend Styles
   ========================================================= */

/* ── Canvas Column (sits in the product image slot) ── */
.tk-canvas-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.tk-canvas-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    background: transparent;
    width: 100%;
    line-height: 0; /* prevent inline-block gap below canvas */
}

/* Fabric.js sets canvas-container width/height via JS — let it be */
.tk-canvas-wrap .canvas-container {
    display: block !important;
}

.tk-canvas-wrap canvas {
    display: block;
}

/* Fabric.js upper-canvas (interaction layer) must stay transparent */
.tk-canvas-wrap .upper-canvas {
    background: transparent !important;
}

.tk-canvas-controls {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* ── Options (sits in the product summary column) ── */
.tk-konfigurator {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 8px 0 16px;
    font-family: inherit;
}

/* ── Option Groups ── */
.tk-option-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tk-option-label {
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #555;
}

/* ── Button Group ── */
.tk-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tk-size-group {
    gap: 4px;
}

/* ── Buttons ── */
.tk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    line-height: 1;
}

.tk-btn:hover {
    border-color: #999;
}

.tk-btn.tk-active {
    border-color: #cc0000;
    background: #cc0000;
    color: #fff;
}

.tk-btn-outline {
    border-color: #cc0000;
    color: #cc0000;
    background: transparent;
}

.tk-btn-outline:hover {
    background: rgba(204, 0, 0, 0.08);
}

.tk-btn-primary {
    border-color: #cc0000;
    background: #cc0000;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 14px 28px;
    width: 100%;
    margin-top: 8px;
    border-radius: 4px;
}

.tk-btn-primary:hover {
    background: #aa0000;
    border-color: #aa0000;
}

.tk-size-btn {
    padding: 6px 10px;
    min-width: 52px;
    font-size: 0.8rem;
}

.tk-junior {
    border-style: dashed;
}

/* ── Radio Labels ── */
.tk-radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.925rem;
}

.tk-radio-label input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: #cc0000;
    cursor: pointer;
}

/* ── Sub-Options ── */
.tk-sub-options {
    padding-left: 24px;
}

.tk-hidden {
    display: none !important;
}

/* ── Inline Fields (Wunschname) ── */
.tk-inline-fields {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.tk-field-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tk-field-wrap label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
}

.tk-field-wrap input[type="text"],
.tk-field-wrap input[type="number"] {
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.925rem;
    width: 140px;
    transition: border-color 0.15s;
}

.tk-field-name input[type="text"] {
    width: 200px;
}

.tk-field-wrap input[type="number"],
.tk-field-nummer input[type="text"] {
    width: 80px;
}

.tk-field-wrap input:focus {
    border-color: #cc0000;
    outline: none;
    box-shadow: 0 0 0 2px rgba(204, 0, 0, 0.18);
}

.tk-field-hint {
    font-size: 0.75rem;
    color: #888;
}

/* ── Select ── */
.tk-select {
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.925rem;
    width: 100%;
    max-width: 280px;
    background: #fff;
    cursor: pointer;
}

.tk-select:focus {
    border-color: #cc0000;
    outline: none;
}

/* ── Summary / Price ── */
.tk-summary {
    border-top: 1px solid #eee;
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tk-price-display {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.tk-price-label {
    font-size: 0.875rem;
    color: #666;
}

.tk-price-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #cc0000;
    line-height: 1;
}

/* ── Error Messages ── */
.tk-error {
    color: #c62828;
    font-size: 0.825rem;
    margin-top: 4px;
}

#tk-form-error {
    background: #fdecea;
    border: 1px solid #ef9a9a;
    border-left: 4px solid #c62828;
    border-radius: 4px;
    padding: 12px 16px;
    font-size: 1rem;
    font-weight: 600;
    color: #b71c1c;
    margin-top: 10px;
    line-height: 1.4;
}

/* ── Not Available / Hinweis ── */
.tk-not-available {
    margin-top: 8px;
}

.tk-hinweis {
    display: inline-block;
    background: #fff4e5;
    border: 1px solid #f5a623;
    border-left: 4px solid #f5a623;
    border-radius: 4px;
    padding: 10px 14px;
    color: #7a4e00;
    font-size: 0.9rem;
    margin: 0;
}

/* ── [hidden] muss gegen display-Regeln (z. B. .tk-btn) gewinnen ── */
.tk-konfigurator [hidden],
.tk-canvas-col [hidden],
.tk-mini-preview[hidden] {
    display: none !important;
}

/* ── Live-Validierung ── */
#tk-wunschname {
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tk-field-wrap input.tk-invalid,
.tk-select.tk-invalid {
    border-color: #c62828;
    box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.18);
}

.tk-field-wrap input.tk-valid {
    border-color: #2e7d32;
}

.tk-field-error {
    display: block;
    min-height: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: #e53935;
    line-height: 1.3;
}

.tk-field-error:empty {
    display: none;
}

.tk-field-error.tk-note {
    color: #b26a00;
    font-weight: 500;
}

/* Das Theme färbt alle <span> in der Produkt-Summary weiß — per ID übersteuern. */
#tk-konfigurator .tk-field-error,
#tk-konfigurator .tk-error {
    color: #ff5a4f;
}

#tk-konfigurator .tk-field-error.tk-note {
    color: #ffb74d;
}

.tk-field-hint {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.tk-counter {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#tk-add-to-cart-btn[disabled] {
    opacity: 0.7;
    cursor: wait;
}

/* ── Ladeanzeige beim Mockup-Wechsel ── */
.tk-canvas-wrap.tk-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid rgba(204, 0, 0, 0.25);
    border-top-color: #cc0000;
    border-radius: 50%;
    animation: tk-spin 0.8s linear infinite;
}

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

/* ── Mini-Vorschau (nur mobil, per JS eingeblendet) ── */
.tk-mini-preview {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 9990;
    display: block;
    width: 96px;
    height: 96px;
    padding: 4px;
    border: 2px solid #cc0000;
    border-radius: 8px;
    background: rgba(20, 20, 20, 0.92);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    cursor: pointer;
}

.tk-mini-preview canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ── Beschreibung & Musterbilder (unter dem Konfigurator) ── */
.tk-details {
    display: flex;
    flex-direction: column;
    gap: 36px;
    margin-top: 32px;
    padding-top: 28px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.tk-details-title {
    margin: 0 0 14px;
}

/* Das Theme setzt im Extra-Bereich keine Textfarbe — ohne diese Regel wäre der Text dunkelgrau auf dunkel. */
.tk-description-content {
    color: var(--text-weiss, #f2f2f2);
    line-height: 1.6;
}

.tk-description-content p,
.tk-description-content ul,
.tk-description-content ol,
.tk-description-content table,
.tk-description-content h3,
.tk-description-content h4 {
    margin: 0 0 0.9em;
}

.tk-description-content ul,
.tk-description-content ol {
    padding-left: 1.4em;
}

.tk-description-content li {
    margin: 0.2em 0;
}

.tk-description-content > :first-child {
    margin-top: 0;
}

.tk-description-content > :last-child {
    margin-bottom: 0;
}

.tk-description-content img {
    max-width: 100%;
    height: auto;
}

.tk-description-content table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
}

.tk-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tk-gallery-item {
    margin: 0;
}

.tk-gallery-link {
    display: block;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
}

.tk-gallery-link .tk-gallery-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.25s ease;
}

.tk-gallery-link:hover .tk-gallery-img,
.tk-gallery-link:focus-visible .tk-gallery-img {
    transform: scale(1.05);
}

.tk-gallery-link:focus-visible {
    outline: 2px solid #cc0000;
    outline-offset: 2px;
}

.tk-gallery-caption {
    margin: 6px 0 0;
    font-size: 0.85rem;
    line-height: 1.35;
    opacity: 0.85;
}

/* Lightbox — Position explizit, weil der Theme-Reset margin:auto des <dialog> aufhebt. */
.tk-lightbox[open] {
    position: fixed;
    inset: 0;
    width: fit-content;
    height: fit-content;
    margin: auto;
}

.tk-lightbox {
    max-width: 100vw;
    max-height: 100vh;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}

.tk-lightbox::backdrop {
    background: rgba(0, 0, 0, 0.88);
}

.tk-lightbox figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 0 56px;
}

.tk-lightbox img {
    display: block;
    max-width: calc(100vw - 112px);
    max-height: 84vh;
    object-fit: contain;
    border-radius: 4px;
}

.tk-lightbox figcaption {
    max-width: 700px;
    margin-top: 12px;
    color: #fff;
    text-align: center;
}

.tk-lb-btn {
    position: fixed;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
}

.tk-lb-btn:hover,
.tk-lb-btn:focus-visible {
    background: #cc0000;
}

.tk-lb-close {
    top: 14px;
    right: 14px;
}

.tk-lb-prev {
    top: 50%;
    left: 6px;
    transform: translateY(-50%);
}

.tk-lb-next {
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
}

.tk-lightbox.tk-lb-single .tk-lb-prev,
.tk-lightbox.tk-lb-single .tk-lb-next {
    display: none;
}

/* ── Responsive ── */
@media ( max-width: 768px ) {
    .tk-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .tk-lightbox figure {
        padding: 0 8px;
    }

    .tk-lightbox img {
        max-width: calc(100vw - 16px);
        max-height: 78vh;
    }

    .tk-lb-prev,
    .tk-lb-next {
        top: auto;
        bottom: 16px;
        transform: none;
    }

    .tk-lb-prev {
        left: calc(50% - 60px);
    }

    .tk-lb-next {
        right: calc(50% - 60px);
    }

    .tk-btn-primary {
        font-size: 1rem;
        padding: 14px;
    }

    /* Touch-Ziele mind. 44 px */
    .tk-btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .tk-radio-label {
        min-height: 32px;
    }

    .tk-radio-label input[type="radio"] {
        width: 20px;
        height: 20px;
    }

    /* 16 px verhindert das automatische Hineinzoomen von iOS beim Fokussieren */
    .tk-field-wrap input[type="text"],
    .tk-field-wrap input[type="number"],
    .tk-select {
        font-size: 16px;
        min-height: 44px;
    }

    .tk-select {
        max-width: none;
    }

    .tk-sub-options {
        padding-left: 0;
    }

    .tk-inline-fields {
        flex-wrap: nowrap;
    }

    .tk-field-name {
        flex: 1 1 auto;
        min-width: 0;
    }

    .tk-field-name input[type="text"] {
        width: 100%;
    }

    .tk-field-nummer {
        flex: 0 0 84px;
    }

    .tk-field-nummer input[type="text"] {
        width: 100%;
    }
}

@media ( max-width: 480px ) {
    .tk-size-btn {
        padding: 8px 6px;
        min-width: 44px;
    }
}
