.template-panel {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    -ms-touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    opacity: 1;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    background-color: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.5rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    height: 100%;
}

.template-panel.hidden {
    max-height: 0;
    padding: 0;
    opacity: 0;
    border: 0;
    margin: 0;
}

.template-mode-tabs {
    display: flex;
    gap: 0.75rem;
    padding: 1vh 1%;
    margin-bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.5rem;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

.template-mode-tabs.hidden {
    max-height: 0;
    padding: 0;
    opacity: 0;
    border: 0;
    margin: 0;
}

.widget-template {
    background: rgba(30,30,30,0.7);
    border: 1px dashed rgba(255,255,255,0.2);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    color: white;
    height: 10vh;
    height: calc(var(--var-height) * 15vh) !important;
    width: calc(var(--var-width) * 15vw) !important;
    aspect-ratio: var(--template-aspect) !important;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    cursor: grab;
    user-select: none;
    position: relative;
    touch-action: pan-x pinch-zoom; 
    -ms-touch-action: pan-x;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}


.template-info {
    margin-bottom: 0.5rem;
    display:flex;
    flex-direction: column;
    align-items: start;
    gap: 0.2rem;
    width: 100%;
    text-align: center;
    pointer-events: none;
}

.template-name {
    font-weight: 300;
    font-size: 0.95rem;
    color: #00E5E2;
}

.template-info-details {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.template-size {
    font-size: 0.6rem;
    opacity: 0.8;
}

.template-status-pill {
    position: absolute;
    right: 0.75rem;
    bottom: 0.6rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 1.4vh;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background-color: rgba(255, 255, 255, 0.08);
    text-transform: uppercase;
}

.template-status-pill.used {
    border-color: rgba(0, 229, 226, 0.6);
    color: #00e5e2;
    background-color: transparent;
}

.template-status-pill.unused {
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.05);
}

.drag-enabled {
    cursor: grabbing !important;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.7);
    border: 2px dashed rgba(255, 255, 255, 0.8);
    opacity: 0.8;
    transform: scale(1.05);
}

.show-widgets-button {
    padding: 0.25rem 0.5rem;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    color: white;
    white-space: nowrap;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.show-widgets-button.active {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.35);
}

.show-widgets-button:disabled {
    opacity: 0.5;
    cursor: default;
}

.columns-display {
    margin: 0 0.5%;
    height: 4vh;
    display: flex;
    align-items: center;
    color: white;
    font-size: 2.5vh;
}

.template-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 1vh 1%;
    background-color: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.5rem;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

.template-tabs.hidden {
    max-height: 0;
    padding: 0;
    opacity: 0;
    border: 0;
    margin: 0;
}

.template-tab {
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.template-tab.active {
    background-color: rgba(0, 229, 226, 0.2);
    border-color: rgba(0, 229, 226, 0.4);
    color: #E4FFFF;
}

.template-tab:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.template-content {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    width: 100%;
    height: 100%;
    transform-origin: top left;
    pointer-events: none;
}

.template-content > .template-preview-target {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    justify-content: stretch;
}

/* Preserve base RGBW sizing while preventing preview shrink inside the reuse dialog */


.widget-reuse-dialog .template-preview-target .rgbw-bulb-widget,
.widget-reuse-dialog .template-preview-target .rgbw-slider-widget {
    width: 100%;
    max-width: 100%;
    align-items: center;
    gap: clamp(0.65rem, 1.2vh, 0.95rem);
    padding: clamp(0.75rem, 1.6vh, 1.05rem) clamp(0.9rem, 2vw, 1.4rem);
}

.widget-reuse-dialog .template-preview-target .rgbw-picker {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.5rem, 1.2vh, 0.85rem);
    width: 100%;
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
}

.widget-reuse-dialog .template-preview-target .rgbw-wheel {
/*    flex: 0 0 auto;
    width: 100%;
    max-width: 92%;
    max-height: 76%;
    aspect-ratio: 1;
    height: auto;
    align-self: center;*/

}

.widget-reuse-dialog .template-preview-target .rgbw-slider-widget .slider-div {
    margin-top: clamp(0.35rem, 1vh, 0.75rem);
    min-height: clamp(3.2rem, 5vh, 4.4rem);
    align-items: center;
    justify-content: center;
    height: auto;
    padding: clamp(0.5rem, 1vh, 0.8rem) clamp(0.6rem, 1.3vw, 1rem);
    width: 100%;
    overflow: visible;
    flex: 0 0 auto;
}

.widget-reuse-dialog .template-preview-target .rgbw-slider-widget .slider-div input[type="range"] {
    width: 88%;
/*    min-height: clamp(1.1rem, 2vh, 1.35rem);*/
/*    height: clamp(0.9rem, 1.6vh, 1.2rem);*/
    height: 15%;
}

.widget-reuse-dialog .template-preview-target .rgbw-slider-widget .chosen-color,
.widget-reuse-dialog .template-preview-target .rgbw-bulb-widget .chosen-color,
.widget-reuse-dialog .template-preview-target .rgbw-slider-widget input[type="color"],
.widget-reuse-dialog .template-preview-target .rgbw-bulb-widget input[type="color"] {
    width: clamp(2.2rem, 4.2vw, 2.6rem);
    height: clamp(2.2rem, 4.2vw, 2.6rem);
    min-width: clamp(2.2rem, 4.2vw, 2.6rem);
    min-height: clamp(2.2rem, 4.2vw, 2.6rem);
    align-self: center;
}

.widget-reuse-dialog .template-preview-target .rgbw-slider-widget .slider-range::-webkit-slider-thumb,
.widget-reuse-dialog .template-preview-target .rgbw-slider-widget .slider-range::-moz-range-thumb {
    width: clamp(1.1rem, 2.4vh, 1.35rem);
    height: clamp(1.1rem, 2.4vh, 1.35rem);
    margin-top: clamp(-0.32rem, -0.6vh, -0.2rem);
    box-shadow: inset 0 0 0 0.4rem #f0f0f0;
}

/* Hide the disabled overlay in the widget chooser previews only; keep it visible
   in creator/existing dialogs and on the configured panel. */
.template-panel .widget-template .widget-disabled-overlay {
    display: none;
}

.widget-template.fuel-tank {
    min-height: 30vmin;
}

.template-empty {
    width: 100%;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 2vh;
    padding: 1rem 0;
}

.widget-reuse-dialog .template-preview-target .rgbw-slider-widget .slider-div .slider-range::-webkit-slider-thumb {
    margin-top: -0.4rem;
}
    
    
    
/* === MEDIA === */

/* Mobile  */

@media (max-width: 699px) {
        .template-tabs {
            width: 100%;
            overflow-x: auto;
            padding: 0.75rem;
            flex-shrink: 0;
        }

        .template-tab {
            flex-shrink: 0;
        }

        .widget-template {
            height: calc(var(--var-height) * 16vh) !important;
            width: 95vw !important;
        }

        .template-panel {
            min-height: 50vh;
        }

            .template-panel.hidden {
                max-height: 0;
                min-height: unset;
            }
    }
    /* WVGA / WVGA-Narrow (720x480, 800x480) */

    @media (min-width: 700px) and (max-width: 880px) {
        .template-tabs {
            width: 100%;
            overflow-x: auto;
            padding: 0.5rem;
        }

        .template-tab {
            flex-shrink: 0;
        }
    }
    /* WSVGA / XGA (1024x600, 1024x768) */

    @media (min-width: 881px) and (max-width: 1150px) {
    }
    /* WXGA / HD720 / SXGA (1280x720/800/1024) */

    @media (min-width: 1151px) and (max-width: 1600px) {

        .page-buttons {
            gap: 0.5rem;
        }

        .show-widgets-button {
            font-size: 0.85rem;
        }
    }
    /* HD / WUXGA (1920x1080, 1920x1200) */

    @media (min-width: 1601px) and (max-width: 2879px) {
        /* standard styles */
    }
    /* 4K (3840x2160) */

    @media (min-width: 2880px) {

        .widget-template {
            padding: 1rem 2rem;
        }

        .show-widgets-button {
            padding: 0.5rem 1rem;
            font-size: 2rem;
        }

        .template-tab {
            padding: 0.5rem 1rem;
            font-size: 2rem;
        }

        .template-name {
            font-size: 1.75rem;
        }

        .template-size {
            font-size: 1.25rem;
        }
    }
    /* Low height */

    @media (min-width: 1000px) and (max-height: 650px) {
        .template-tabs {
            width: 100%;
            overflow-x: auto;
            padding: 0.5rem;
        }

        .template-tab {
            flex-shrink: 0;
        }
    }
    /* Override for 1024x600 */

    @media (width: 1024px) and (height: 600px) {
        .template-tabs {
            width: 100%;
            overflow-x: auto;
            padding: 0.5rem;
        }

        .template-tab {
            flex-shrink: 0;
        }
    }