/* ============================================================
   Noteroom - Custom Color Picker
   Glassmorphism-styled HSL picker replacing native <input color>
   ============================================================ */

/* ── Popover Container ── */
.cp-popover {
    position: fixed;
    z-index: 35000;
    width: 280px;
    max-width: min(280px, calc(100vw - 20px));
    padding: 12px;
    background: var(--header-bg);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-lg);
    isolation: isolate;

    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    transform-origin: top left;
    pointer-events: none;
    transition: opacity var(--ui-motion-medium) cubic-bezier(0.16, 1, 0.3, 1),
                transform var(--ui-motion-medium) cubic-bezier(0.16, 1, 0.3, 1);
}

.cp-popover.cp-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.cp-popover.cp-dropup {
    transform-origin: bottom left;
    transform: translateY(6px) scale(0.97);
}

.cp-popover.cp-dropup.cp-visible {
    transform: translateY(0) scale(1);
}

/* ── Saturation / Lightness Gradient Area ── */
.cp-sl-area {
    position: relative;
    width: 100%;
    height: 140px;
    border-radius: var(--radius-md);
    cursor: crosshair;
    overflow: hidden;
    border: 1px solid rgba(var(--accent-rgb), 0.06);
    touch-action: none;
}

.cp-sl-area::before,
.cp-sl-area::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
}

/* White → transparent (left to right) */
.cp-sl-area::before {
    background: linear-gradient(to right, #fff, transparent);
}

/* Transparent → black (top to bottom) */
.cp-sl-area::after {
    background: linear-gradient(to bottom, transparent, #000);
}

.cp-sl-thumb {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 2;
    transition: box-shadow 0.1s ease;
}

/* ── Hue Bar ── */
.cp-hue-bar {
    position: relative;
    width: 100%;
    height: 12px;
    margin-top: 10px;
    border-radius: var(--radius-pill);
    background: linear-gradient(to right,
        #ff0000 0%,
        #ffff00 17%,
        #00ff00 33%,
        #00ffff 50%,
        #0000ff 67%,
        #ff00ff 83%,
        #ff0000 100%
    );
    cursor: pointer;
    touch-action: none;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.cp-hue-thumb {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    transform: translate(-50%, -50%);
    transition: box-shadow 0.1s ease;
}

/* ── Preset Swatches ── */
.cp-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    justify-content: flex-start;
}

.cp-preset {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
    transition: border-color var(--ui-motion-fast) ease,
                transform 0.08s ease,
                box-shadow var(--ui-motion-fast) ease;
}

.cp-preset:hover {
    border-color: rgba(var(--accent-rgb), 0.3);
    transform: scale(1.15);
}

.cp-preset.cp-active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.2), inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

/* ── Footer: Preview + Hex Input ── */
.cp-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.cp-preview {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.cp-hex-input {
    flex: 1;
    min-width: 0;
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    font-size: var(--text-sm);
    padding: 5px 8px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(var(--accent-rgb), 0.08);
    background: var(--surface-1);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--ui-motion-fast) ease,
                box-shadow var(--ui-motion-fast) ease;
}

.cp-hex-input:focus {
    border-color: var(--accent-color);
    box-shadow: var(--focus-ring);
}

.cp-hex-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

/* ── Swatch Trigger (replaces native input) ── */
.cp-swatch-trigger {
    display: block;
    width: 100%;
    height: 32px;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid rgba(var(--accent-rgb), 0.08);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
    transition: border-color var(--ui-motion-fast) ease,
                box-shadow var(--ui-motion-fast) ease,
                transform 0.08s ease;
}

.cp-swatch-trigger:hover {
    border-color: rgba(var(--accent-rgb), 0.18);
    box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.cp-swatch-trigger:active {
    transform: scale(0.97);
}

/* Context-menu variant: compact square */
#context-menu .cp-swatch-trigger {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: var(--radius-sm);
}

/* Text-format toolbar variant */
#text-format-toolbar .cp-swatch-trigger {
    width: 24px;
    height: 24px;
    min-width: 24px;
    border-radius: var(--radius-sm);
}

/* Hidden native input when color picker is attached */
input[type="color"].cp-attached {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
}
