/* ============================================================================
 * Spectrum.js (kartik\widgets\ColorInput) — ui-refresh modernization
 *
 * Spectrum injects its picker as a child of <body>; since `.ui-refresh` lives
 * on <body>, scoping under `.ui-refresh` cleanly upgrades only ui-refresh
 * pages while legacy surfaces keep stock Spectrum.
 *
 * IMPORTANT: Spectrum's saturation/hue/preview boxes are absolute-positioned
 * with pixel dimensions computed by JS at open-time, and `.sp-container`
 * itself uses `box-sizing: content-box` for all children. Touching either
 * `.sp-container`'s padding or any of those absolute-positioned children's
 * borders / overflow can collapse the picker. Stay on outer chrome + the
 * independent inner elements (swatches, input, buttons).
 *
 * Specificity: one class deeper than the vendor's `.sp-krajee ...` rules,
 * so overrides win without `!important` — except where the vendor itself
 * uses `!important` (sp-cancel color).
 * ========================================================================= */

/* ===== Outer popup — chrome only, no padding/layout touch ===== */
.ui-refresh .sp-krajee.sp-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-family: var(--font-family);
    color: var(--fg-default);
}

/* Vendor sets a `1px solid #ccc` divider between the palette and picker columns. */
.ui-refresh .sp-krajee .sp-palette-container {
    border-right-color: var(--border-subtle);
}

/* Vendor: `.sp-color, .sp-hue { border: 1px solid #666 }`. Color-only override —
 * keep the 1px width since these are absolute-positioned with JS-computed
 * dimensions per the file-level note. */
.ui-refresh .sp-krajee .sp-color,
.ui-refresh .sp-krajee .sp-hue {
    border-color: var(--border-subtle);
}

/* ===== Swatch grid =====
 * `.sp-thumb-inner` is absolute-positioned filling `.sp-thumb-el` — without
 * `overflow: hidden` on the parent, the rounded corners would let the inner
 * color rectangle bleed past, showing the parent's background at each corner. */
.ui-refresh .sp-krajee .sp-thumb-el {
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.ui-refresh .sp-krajee .sp-palette .sp-thumb-el:hover {
    transform: scale(1.08);
    box-shadow: 0 0 0 2px var(--bg-muted);
}
.ui-refresh .sp-krajee .sp-palette .sp-thumb-el.sp-thumb-active {
    box-shadow: 0 0 0 2px var(--accent-primary);
}

/* ===== Current / new color preview (.sp-initial) =====
 * `.sp-initial` is float-based (not absolute) so it's safe to round + clip.
 * Match the hex-input neighbor: var(--space-8) height, var(--input-radius)
 * corners, var(--border-default) border. */
.ui-refresh .sp-krajee .sp-initial {
    box-sizing: border-box;
    height: var(--space-8);
    border: 1px solid var(--border-default);
    border-radius: var(--input-radius);
    overflow: hidden;
}
.ui-refresh .sp-krajee .sp-initial span {
    height: var(--space-8);
}
/* The `.sp-thumb-el` rule above gives every swatch in the palette its own
 * rounded corners — but the two thumbs inside `.sp-initial` sit edge-to-edge,
 * so their inner radii leave white slivers where they meet. Strip the radius
 * for thumbs inside the preview; the outer `.sp-initial` border owns the
 * rounded shape. */
.ui-refresh .sp-krajee .sp-initial .sp-thumb-el {
    border-radius: 0;
}

/* ===== Hex input ===== */
.ui-refresh .sp-krajee .sp-input {
    height: 32px;
    padding: 0 var(--space-3);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    color: var(--fg-default);
    background: var(--bg-surface);
    border: 1px solid var(--input-border);
    border-radius: var(--input-radius);
    box-shadow: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ui-refresh .sp-krajee .sp-input:focus {
    border-color: var(--accent-primary);
    box-shadow: var(--focus-ring);
    outline: none;
}

/* ===== Buttons (Cancel + Choose) — shared base ===== */
.ui-refresh .sp-krajee .sp-button-container {
    display: flex;
    gap: var(--space-2);
    width: 100%;
}
/* `.sp-cf` is Spectrum's clearfix; its `::before`/`::after` would otherwise
 * become extra flex items and break the 50/50 split between cancel/choose. */
.ui-refresh .sp-krajee .sp-button-container::before,
.ui-refresh .sp-krajee .sp-button-container::after {
    display: none;
}
.ui-refresh .sp-krajee .sp-cancel,
.ui-refresh .sp-krajee .sp-choose {
    display: inline-flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    height: var(--btn-height);
    padding: 0;
    font-family: var(--font-family);
    font-size: var(--font-size-btn);
    font-weight: var(--font-weight-medium);
    line-height: 1;
    text-transform: capitalize;
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: background-color var(--transition-fast),
                color var(--transition-fast),
                border-color var(--transition-fast);
    text-shadow: none;
    box-shadow: none;
    background-image: none;
}

/* Cancel — neutral .btn.btn-default look */
.ui-refresh .sp-krajee .sp-cancel {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    color: var(--fg-default) !important;
    margin-right: 0;
}
.ui-refresh .sp-krajee .sp-cancel:hover,
.ui-refresh .sp-krajee .sp-cancel:focus,
.ui-refresh .sp-krajee .sp-cancel:active {
    background-color: var(--bg-muted);
    border-color: var(--border-default);
    color: var(--fg-default) !important;
    box-shadow: none;
}

/* Choose — primary action */
.ui-refresh .sp-krajee .sp-choose {
    background-color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    color: var(--fg-on-accent);
}
.ui-refresh .sp-krajee .sp-choose:hover,
.ui-refresh .sp-krajee .sp-choose:focus,
.ui-refresh .sp-krajee .sp-choose:active {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--fg-on-accent);
    box-shadow: none;
}

/* ===== Trigger swatch (.sp-replacer — the inline button next to the input) ===== */
.ui-refresh .sp-krajee.sp-replacer {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    padding: 0;
    overflow: hidden;
    transition: border-color var(--transition-fast);
}
.ui-refresh .sp-krajee.sp-replacer:hover,
.ui-refresh .sp-krajee.sp-replacer.sp-active {
    border-color: var(--accent-primary);
}
