/* =========================================
   RGBA Color Picker
   Layout (top → bottom):
   1. SV (saturation/value) box
   2. Hue bar (horizontal)
   3. Four channel rows: label + slider + value input (R, G, B, A)
   4. Footer: preview swatch (checkerboard) + editable rgba() string
   ========================================= */
.rgba-picker {
    position: fixed;
    z-index: 9999;
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--ui-bg-panel);
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    user-select: none;
    color: var(--ui-text-main);
}
.rgba-picker.visible {
    display: flex;
}

/* ── SV (saturation/value) area ── */
.rgba-picker-sat {
    position: relative;
    width: 220px;
    height: 150px;
    border-radius: 6px;
    cursor: crosshair;
    overflow: hidden;
    border: 1px solid var(--ui-border);
    flex-shrink: 0;
}
.rgba-picker-sat canvas {
    display: block;
    width: 100%;
    height: 100%;
}
.rgba-picker-sat-cur {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* ── Hue bar (horizontal) ── */
.rgba-picker-hue {
    position: relative;
    width: 220px;
    height: 14px;
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
    border: 1px solid var(--ui-border);
    flex-shrink: 0;
}
.rgba-picker-hue canvas {
    display: block;
    width: 100%;
    height: 100%;
}
.rgba-picker-hue-cur {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 4px;
    border: 2px solid #fff;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
    transform: translateX(-50%);
    pointer-events: none;
}

/* ── RGBA channel rows ── */
.rgba-picker-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.rgba-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.rgba-picker-row label {
    width: 14px;
    flex-shrink: 0;
    text-align: right;
    font-size: 11px;
    font-weight: 600;
    color: var(--ui-text-muted);
}
/* Slider: the JS paints a per-channel preview gradient via --track-bg */
.rgba-picker-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 12px;
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    background: var(--track-bg, var(--ui-bg-base));
    background-size: var(--track-size, auto);
    background-position: var(--track-pos, 0 0);
    outline: none;
    cursor: pointer;
    box-sizing: border-box;
}
.rgba-picker-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
    cursor: pointer;
    box-sizing: border-box;
}
.rgba-picker-row input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
    cursor: pointer;
    box-sizing: border-box;
}
.rgba-picker-row input[type="range"]::-moz-range-track {
    height: 12px;
    border-radius: 6px;
    background: var(--track-bg, var(--ui-bg-base));
    background-size: var(--track-size, auto);
    background-position: var(--track-pos, 0 0);
}
/* Value inputs: fixed width, right-aligned monospace */
.rgba-picker-ch-val {
    width: 44px;
    height: 22px;
    padding: 0 6px;
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    background: var(--ui-bg-base);
    color: var(--ui-text-main);
    font-size: 11px;
    font-family: ui-monospace, monospace;
    text-align: right;
    outline: none;
    box-sizing: border-box;
    flex-shrink: 0;
}
.rgba-picker-ch-val:focus {
    border-color: var(--ui-accent);
}

/* ── Footer: preview swatch + rgba string ── */
.rgba-picker-footer {
    display: flex;
    align-items: center;
    gap: 8px;
}
.rgba-picker-preview {
    position: relative;
    width: 40px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--ui-border);
    overflow: hidden;
    flex-shrink: 0;
}
.rgba-picker-preview-checker {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(45deg, #d8d8d8 25%, transparent 25%),
        linear-gradient(-45deg, #d8d8d8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d8d8d8 75%),
        linear-gradient(-45deg, transparent 75%, #d8d8d8 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}
.rgba-picker-preview-fill {
    position: absolute;
    inset: 0;
}
.rgba-picker-rgba-text {
    flex: 1;
    min-width: 0;
    height: 24px;
    padding: 0 8px;
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    background: var(--ui-bg-base);
    color: var(--ui-text-main);
    font-size: 11px;
    font-family: ui-monospace, monospace;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.rgba-picker-rgba-text:focus {
    border-color: var(--ui-accent);
}
/* Brief error feedback when an unparseable string is entered */
.rgba-picker-rgba-text.invalid {
    border-color: #e5484d;
    box-shadow: 0 0 0 1px #e5484d;
}
