/* ============================================================
   Custom Handles — Inline Color Panel
   ============================================================ */

/* Inline color panel (rendered below the "Colours" button) */
.ch-color-inline {
    margin-top: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: var(--menu_text_color);
}

/* Handles / Knobs tab buttons — share .mc-select-tabs styling with the door-types
   tabs, but stretch each tab to fill half the row so the centered text reads as a
   centered column rather than sitting at the row's left/right edges. */
.ch-type-tabs > .ch-type-tab {
    flex: 1;
}

/* When no LEFT/RIGHT/HANDLE checkbox is checked, lock all handle picking — categories,
   order block, tabs — so the user has to re-enable a handle before they can touch the
   selectors. The .ch-handle-toggles row (the checkboxes themselves) is NOT scoped under
   this rule so the user can still re-enable.

   `pointer-events: none !important` on every descendant is needed because the
   category-radio change handler (custom-handles-menu.js line ~263) writes inline
   `pointer-events: auto` on `.ch-handle-colors / .ch-fp-section / .ch-led-section`,
   and inline styles otherwise beat the parent's `pointer-events: none`. */
.ch-locked .ch-category,
.ch-locked .ch-type-tabs {
    opacity: 0.4;
    pointer-events: none;
}

.ch-locked .ch-category *,
.ch-locked .ch-type-tabs * {
    pointer-events: none !important;
}

/* Handle-exists checkboxes — global checkbox style at layout.css:2224 uses
   `appearance: none` which strips the browser's default disabled grey-out. Add an
   explicit disabled visual so the user can tell when LEFT/RIGHT HANDLE toggles are
   locked (e.g., the lock is on and we don't want them disabling that leaf). */
.ch-checkbox-handle:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ch-handle-toggles label:has(.ch-checkbox-handle:disabled) {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Category thumb — stays at its natural image size by default; doubles (visually and in
   layout) when the category radio is checked. `zoom` is the easiest way to scale both
   the box and the image content together. Uses :has() to detect the selected state
   without needing a JS class toggle.
   Browser support: Chrome 105+, Safari 15.4+, Firefox 126+. */
.ch-cat-thumb {
    transition: zoom 0.25s ease;
}

.ch-category:has(.ch-cat-radio:checked) .ch-cat-thumb {
    zoom: 1.5;
}


/* Color pair block */
.ch-color-pair {
    /* Width of the optional palette-image column. Declared here so both the names row
       (.ch-pair-name-spacer) and the swatches row (.ch-pair-image) inherit the same
       value — change this one number to resize the image column. */
    --ch-pair-image-width: 56px;
    /* Upper bound for the palette image; under it the file keeps its own dimensions. */
    --ch-pair-image-max-height: 160px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--buttons_background_color);
}

.ch-color-pair:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* Category names row */
.ch-pair-names {
    display: flex;
    gap: 5px;
    margin-bottom: 4px;
}

/* Placeholder that reserves the palette-image column's width in the names row. */
.ch-pair-name-spacer {
    flex: 0 0 var(--ch-pair-image-width);
}

.ch-pair-name {
    flex: 1;
    min-width: 0;
    /* 8px panel padding + 1px panel border, so the heading text lines up with the
       first swatch inside its .ch-swatch-column panel. */
    padding-left: 9px;
    font-size: 13px;
    opacity: 0.8;
    color: var(--menu_text_color);
    /* Keep the heading on one line whatever the column width; the full name is on
       the element's title= tooltip (custom-handles-menu.js renderColorPair). */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ch-pair-name-primary {
    /* Matches the 3/4 - 1/4 split of the swatch columns below. */
    flex: 3;
}

/* Price row */
.ch-pair-price {
    text-align: center;
    margin-bottom: 6px;
}

/* Swatches row: image column + palettes. flex-start so a tall image never stretches
   the palette panels — those size to their own colors. */
.ch-pair-swatches {
    display: flex;
    gap: 5px;
    align-items: flex-start;
}

/* Wrapper around the palette panel(s). Being a single flex item, its height comes from
   its own content only; `stretch` inside it still keeps the primary and secondary
   panels equal in height to each other. */
.ch-pair-palettes {
    flex: 1;
    min-width: 0;
    display: flex;
    gap: 5px;
    align-items: stretch;
}

/* Optional per-palette image (CustomHandlePaintColor.palette_image) — a fixed-width
   column immediately left of the palettes of the pair it belongs to. The image itself
   keeps its own dimensions, bounded by that width and --ch-pair-image-max-height. */
.ch-pair-image {
    flex: 0 0 var(--ch-pair-image-width);
    min-width: 0;
}

.ch-pair-image img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: var(--ch-pair-image-max-height);
    border-radius: 4px;
}

/* In-panel category title — desktop labels the columns from .ch-pair-names instead;
   this one only appears in the stacked mobile layout. */
.ch-swatch-column-title {
    display: none;
}

/* Each category's swatches sit in their own panel, styled like .ch-color-inline
   (the "more colours" container) so the two palettes read as separate groups —
   which is why there's no divider rule between them. */
.ch-swatch-column {
    flex: 1;
    min-width: 0;
    padding: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
}

.ch-swatch-column-primary {
    /* Paired palettes: primary gets 3 of the 4 sub-columns, secondary the last one. */
    flex: 3;
}

.ch-swatch-column-primary + .ch-swatch-column {
    flex: 1;
}

.ch-swatch-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 6px;
    row-gap: 4px;
}

/* Single-palette pair (no secondary colour): swatches fill the row 4-up. Keyed on the
   class rather than :only-child — the optional .ch-pair-image is a sibling column. */
.ch-swatch-column-single .ch-swatch-grid {
    grid-template-columns: repeat(4, 1fr);
}

/* Two-palette pair: 3 swatch columns on the primary side, 1 on the secondary. */
.ch-swatch-column-primary .ch-swatch-grid {
    grid-template-columns: repeat(3, 1fr);
}

.ch-swatch-column-primary + .ch-swatch-column .ch-swatch-grid {
    grid-template-columns: 1fr;
}

/* Biometric field — laid out as a row so the optional SitesMeta.biometric_image sits
   left of the label + dropdown. Without an image the body is the only child and the
   row behaves exactly as the plain block did. */
.ch-handle-fp {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.ch-fp-body {
    flex: 1;
    min-width: 0;
}

/* Same treatment as the palette image: a fixed-width column, with the file keeping its
   own dimensions inside it up to --ch-fp-image-max-height. Without the cap a tall image
   would stretch this row far below the dropdown. The two knobs live on .ch-category so
   .ch-led-indent below can read them too. */
.ch-category {
    --ch-fp-image-width: 56px;
    --ch-fp-image-max-height: 120px;
}

.ch-fp-image {
    flex: 0 0 var(--ch-fp-image-width);
    min-width: 0;
}

.ch-fp-image img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: var(--ch-fp-image-max-height);
    border-radius: 4px;
}

/* The biometric image column spans the LED field too, so the LED label + dropdown are
   pushed across by that column's width plus .ch-handle-fp's 10px gap — leaving the LED
   dropdown exactly as wide as, and flush with, the Biometric one above it. Only applied
   (from custom-handles-menu.js) when the image is set and a Biometric field is rendered. */
.ch-led-indent {
    padding-left: calc(var(--ch-fp-image-width) + 10px);
}

/* "Colours" toggle button */
.ch-color-popup-btn {
    font-size: 13px;
    padding: 6px 16px;
    cursor: pointer;
    border: 1px solid var(--buttons_background_color);
    background: var(--buttons_background_color);
    color: var(--buttons_text_color);
    border-radius: 4px;
    width: 100%;
}

.ch-color-popup-btn:hover {
    background: var(--active_buttons_background_color);
    color: var(--active_buttons_text_color);
}

.ch-color-popup-btn.ch-color-btn-open {
    background: var(--active_buttons_background_color);
    color: var(--active_buttons_text_color);
}

/* ============================================================
   Mobile responsive
   ============================================================ */
@media (max-width: 600px) {
    /* The columns stack, so the shared names row above the price can no longer line up
       with them — each panel carries its own title instead (swatchColumnTitle in
       custom-handles-menu.js). */
    .ch-pair-names {
        display: none;
    }

    .ch-swatch-column-title {
        display: block;
        margin-bottom: 6px;
        font-size: 13px;
        opacity: 0.8;
        color: var(--menu_text_color);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Stacked: `stretch` so the palettes fill the menu width (the desktop rule is
       flex-start, which would shrink them to their content here), with the image
       pinned to the left at its own width. */
    .ch-pair-swatches {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .ch-pair-palettes {
        flex-direction: column;
    }

    .ch-pair-image {
        flex: 0 0 auto;
        align-self: flex-start;
    }

    .ch-pair-image img {
        max-height: 90px;
    }

    /* Same treatment for the Biometric row: label + dropdown full width, image above
       it at its own size. */
    .ch-handle-fp {
        flex-direction: column;
        align-items: stretch;
    }

    .ch-fp-image {
        flex: 0 0 auto;
        align-self: flex-start;
    }

    .ch-fp-image img {
        max-height: 90px;
    }

    /* Stacked: the image no longer sits beside the fields, so nothing to indent past. */
    .ch-led-indent {
        padding-left: 0;
    }

    /* Stacked: every column is full width again, so back to 2-up everywhere. */
    .ch-swatch-grid,
    .ch-swatch-column-single .ch-swatch-grid,
    .ch-swatch-column-primary .ch-swatch-grid,
    .ch-swatch-column-primary + .ch-swatch-column .ch-swatch-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 380px) {
    .ch-swatch-grid,
    .ch-swatch-column-single .ch-swatch-grid,
    .ch-swatch-column-primary .ch-swatch-grid,
    .ch-swatch-column-primary + .ch-swatch-column .ch-swatch-grid {
        grid-template-columns: 1fr;
    }
}
