/* ============================================================
   components/color.css — Majestic V2 color control
   ------------------------------------------------------------
   Track C. A swatch plus an editable hex value, backed by a native
   <input type="color"> that stays the submitted fallback source.
   The saturation/value area, hue and (opt-in) alpha sliders live in
   a portalled panel anchored on desktop and presented as a bottom
   sheet on narrow phones. Six-digit hex is the default format.

   Namespaced (.majestic-color-field / .majestic-color-panel) away
   from the legacy .majestic-color-* picker.
   ============================================================ */

.majestic-color-field {
    display: grid;
    gap: 6px;
    min-width: 0;
    font-family: var(--font-input);
}
.majestic-color-field__legend {
    color: var(--text-muted-color);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Native input is retained (fallback source) but visually removed post-mount. */
.majestic-color-field[data-color-field-init] .majestic-color-field__native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.majestic-color-field__control {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--control-height);
    padding: 3px 10px 3px 4px;
    background: var(--input-background);
    border: 1px solid var(--input-border-color);
    border-radius: var(--radius-control);
    box-shadow: var(--control-inset-shadow);
    transition: border-color var(--motion-default) var(--ease-out);
}
.majestic-color-field__control:hover { border-color: var(--border-color-strong); }
.majestic-color-field:has(.majestic-color-field__text:focus-visible) .majestic-color-field__control,
.majestic-color-field:has(.majestic-color-field__swatch:focus-visible) .majestic-color-field__control {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-focus);
}

/* The swatch sits over a token checkerboard so alpha reads correctly. */
.majestic-color-field__swatch {
    flex: 0 0 auto;
    width: calc(var(--control-height) - 8px);
    height: calc(var(--control-height) - 8px);
    padding: 0;
    border: 1px solid var(--border-color-strong);
    border-radius: calc(var(--radius-control) - 2px);
    cursor: pointer;
    background-color: var(--swatch-color, var(--primary-color));
    background-image:
        linear-gradient(var(--swatch-color, var(--primary-color)), var(--swatch-color, var(--primary-color))),
        conic-gradient(var(--checker) 0 25%, transparent 0 50%, var(--checker) 0 75%, transparent 0);
    background-size: 100% 100%, 10px 10px;
    --checker: color-mix(in srgb, var(--text-color) 22%, transparent);
}
.majestic-color-field__swatch:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }

.majestic-color-field__text {
    flex: 1 1 auto;
    min-width: 0;
    height: calc(var(--control-height) - 8px);
    padding: 0 4px;
    color: var(--text-color);
    background: transparent;
    border: 0;
    outline: none;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    text-transform: uppercase;
}
.majestic-color-field__text::placeholder { color: var(--text-subtle-color); }

.majestic-color-field__message { margin: 0; color: var(--text-muted-color); font-size: 0.75rem; line-height: 1.4; }
.majestic-color-field__message:empty { display: none; }
.majestic-color-field--invalid .majestic-color-field__control { border-color: var(--danger-border-color); }
.majestic-color-field--invalid .majestic-color-field__message { color: var(--danger-color); }

/* ==========================================================================
   PANEL (portalled)
   ========================================================================== */

.majestic-color-panel {
    position: fixed;
    z-index: var(--z-dropdown);
    display: none;
    flex-direction: column;
    gap: 12px;
    width: 248px;
    padding: 12px;
    background: var(--dropdown-bg);
    border: 1px solid var(--border-color-strong);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-floating);
    font-family: var(--font-input);
}
.majestic-color-panel--open { display: flex; }

.majestic-color-panel__area {
    position: relative;
    width: 100%;
    height: 150px;
    border-radius: var(--radius-inner);
    overflow: hidden;
    cursor: crosshair;
    touch-action: none;
}
.majestic-color-panel__area canvas { display: block; width: 100%; height: 100%; }
.majestic-color-panel__area-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid var(--on-accent-color);
    border-radius: 50%;
    box-shadow: var(--color-handle-shadow);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.majestic-color-panel__sliders { display: grid; gap: 12px; }
.majestic-color-panel__slider {
    position: relative;
    height: 12px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    touch-action: none;
}
.majestic-color-panel__slider--hue {
    background: var(--color-picker-spectrum);
}
.majestic-color-panel__slider--alpha {
    background-image:
        linear-gradient(to right, transparent, var(--alpha-color, var(--primary-color))),
        conic-gradient(var(--checker) 0 25%, transparent 0 50%, var(--checker) 0 75%, transparent 0);
    background-size: 100% 100%, 10px 10px;
    --checker: color-mix(in srgb, var(--text-color) 22%, transparent);
}
.majestic-color-panel__slider-thumb {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    border: 2px solid var(--on-accent-color);
    border-radius: 50%;
    box-shadow: var(--color-handle-shadow);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.majestic-color-panel__fields { display: flex; align-items: center; gap: 8px; }
.majestic-color-panel__hex {
    flex: 1 1 auto;
    min-width: 0;
    height: 32px;
    padding: 0 8px;
    color: var(--text-color);
    background: var(--input-background);
    border: 1px solid var(--input-border-color);
    border-radius: var(--radius-control);
    outline: none;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    text-transform: uppercase;
}
.majestic-color-panel__hex:focus-visible { border-color: var(--primary-color); box-shadow: var(--shadow-focus); }

@media (max-width: 40rem) {
    .majestic-color-panel--sheet {
        left: 0 !important;
        right: 0 !important;
        bottom: 0;
        top: auto !important;
        width: 100% !important;
        border-radius: var(--radius-card) var(--radius-card) 0 0;
        animation: majestic-color-sheet-in var(--motion-expressive) var(--ease-out);
    }
    @keyframes majestic-color-sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

.majestic-color-panel__backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-dropdown) - 1);
    display: none;
    background: var(--overlay-background);
}

.majestic-color-panel__area:focus-visible,
.majestic-color-panel__slider:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }
.majestic-color-field[data-disabled] { opacity: 0.55; }
.majestic-color-panel__backdrop--open { display: block; }

@media (prefers-reduced-motion: reduce) {
    .majestic-color-field__control { transition-duration: 0.01ms; }
    .majestic-color-panel--sheet { animation: none; }
}

@media (forced-colors: active) {
    .majestic-color-field__control,
    .majestic-color-panel { border-color: ButtonText; }
    .majestic-color-field__swatch { border-color: ButtonText; }
}
