/* Colors follow BRANDBOOK.md: primary #8F5AFF, hover #7142D4, border #DEDEDE, muted text #5F5F5F. */

/* ---------------------------------------------------------------------------
   Drop zone
   --------------------------------------------------------------------------- */

.cp-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2.5rem 1rem;
    border: 2px dashed #DEDEDE;
    border-radius: 0.5rem;
    background: #FAFAFA;
    transition: border-color .15s ease, background-color .15s ease;
}

#image-color-picker-tool.cp-dragging .cp-dropzone {
    border-color: #8F5AFF;
    background: #F5F0FF;
}

/* Once an image is loaded the drop zone is hidden, but the whole tool stays a target. */
#image-color-picker-tool.cp-dragging {
    outline: 2px dashed #8F5AFF;
    outline-offset: 8px;
    border-radius: 0.5rem;
}

.cp-dropzone-hint {
    font-size: 0.875rem;
    color: #5F5F5F;
}

.cp-dropzone-limits {
    font-size: 0.8125rem;
    color: #ADADAD;
}

.cp-url-row {
    max-width: 460px;
}

/* "Replace image" re-opens the upload zone above a still-visible workspace - give the
   two some air. Applies only while the zone is shown, so the empty state is unaffected. */
.cp-dropzone:not(.d-none) ~ #cp-workspace {
    margin-top: 1rem;
}

/* ---------------------------------------------------------------------------
   Workspace: viewport + rail
   --------------------------------------------------------------------------- */

.cp-workspace-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.cp-viewport-col {
    flex: 1 1 auto;
    min-width: 0;
}

.cp-side-col {
    flex: 0 0 300px;
    max-width: 300px;
}

.cp-viewport {
    position: relative;
    width: 100%;
    height: 560px;
    border: 1px solid #DEDEDE;
    border-radius: 0.375rem;
    overflow: hidden;
    cursor: crosshair;
    /* Wheel zoom and one-finger pan are handled in JS. */
    touch-action: none;
    user-select: none;
    /* Checkerboard shows through transparent pixels. */
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #F1F1F4 25%, transparent 25%),
        linear-gradient(-45deg, #F1F1F4 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #F1F1F4 75%),
        linear-gradient(-45deg, transparent 75%, #F1F1F4 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.cp-viewport canvas#cp-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.cp-viewport-hint {
    font-size: 0.8125rem;
    margin-top: 0.4rem;
}

.cp-zoom-controls {
    position: absolute;
    right: 0.5rem;
    top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    z-index: 2;
}

.cp-zoom-controls .btn {
    width: 2rem;
    padding: 0.125rem 0;
    border: 1px solid #DEDEDE;
    font-weight: 600;
    line-height: 1.4;
}

.cp-stage-badge {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    z-index: 2;
}

/* The magnifier canvas floats next to the cursor inside the viewport. */
.cp-loupe {
    position: absolute;
    z-index: 3;
    border: 1px solid #8F5AFF;
    border-radius: 0.25rem;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
    pointer-events: none;
}

.cp-actions {
    gap: 0.5rem;
}

/* ---------------------------------------------------------------------------
   Results rail
   --------------------------------------------------------------------------- */

.cp-panel {
    padding: 1rem;
    border: 1px solid #DEDEDE;
    border-radius: 0.375rem;
    background: #FAFAFA;
}

.cp-panel-label {
    font-weight: 500;
    font-size: 0.8125rem;
    color: #5F5F5F;
    margin-bottom: 0.4rem;
}

.cp-swatch-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.cp-swatch-main-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.cp-swatch-live-wrap {
    flex: 0 0 72px;
}

/* Checkerboard under every swatch so alpha is visible; the actual color sits in
   an inner span painted from JS. */
.cp-checker {
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #E8E8EC 25%, transparent 25%),
        linear-gradient(-45deg, #E8E8EC 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #E8E8EC 75%),
        linear-gradient(-45deg, transparent 75%, #E8E8EC 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.cp-swatch-main,
.cp-swatch-live {
    position: relative;
    height: 72px;
    border: 1px solid #DEDEDE;
    border-radius: 0.375rem;
    overflow: hidden;
}

.cp-swatch-main > span,
.cp-swatch-live > span {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

.cp-code-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.cp-code-label {
    flex: 0 0 2.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #5F5F5F;
}

.cp-code-input {
    flex: 1 1 auto;
    min-width: 0;
    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.8125rem;
    background: #fff !important; /* readonly inputs go grey by default and look disabled */
}

.cp-copy-btn {
    flex: 0 0 auto;
    line-height: 1;
    padding: 0.3rem 0.45rem;
}

.cp-history {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    min-height: 1.9rem;
}

.cp-history-cell {
    position: relative;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #DEDEDE;
    border-radius: 0.25rem;
    overflow: hidden;
    cursor: pointer;
}

.cp-history-cell:hover {
    border-color: #8F5AFF;
}

.cp-history-cell > span {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

/* ---------------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------------- */

.cp-toast {
    position: fixed;
    left: 50%;
    bottom: 2rem;
    transform: translateX(-50%) translateY(1rem);
    padding: 0.5rem 1.25rem;
    border-radius: 2rem;
    background: rgba(40, 40, 40, .92);
    color: #fff;
    font-size: 0.875rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    z-index: 1080;
}

.cp-toast-shown {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 991.98px) {
    .cp-workspace-row {
        flex-direction: column;
        align-items: stretch;
    }

    .cp-side-col {
        flex: 1 1 auto;
        max-width: 100%;
    }

    .cp-viewport {
        height: 60vw;
        max-height: 480px;
    }
}

@media (max-width: 575.98px) {
    .cp-actions .btn {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .cp-viewport {
        height: 70vw;
    }
}
