@import 'variables';
@import 'mixins';

.pickr {
    position: relative;
    overflow: visible;
    z-index: 1;

    * {
        box-sizing: border-box;
    }
}

.pickr .pcr-button {
    position: relative;
    height: 2em;
    width: 2em;
    padding: 0.5em;
    border-radius: $border-radius-mid;
    cursor: pointer;
    background: transparent;
    transition: background-color 0.3s;
    font-family: $font-family;
    @include transparency-background;

    &::after {
        @include pseudo-reset;
        height: 100%;
        width: 100%;
        background: $icon-x no-repeat center;
        background-size: 70%;
        opacity: 0;
    }

    &.clear::after {
        opacity: 1;
    }

    &.disabled {
        cursor: not-allowed;
    }
}

.pcr-app {
    position: absolute;
    display: flex;
    flex-direction: column;
    z-index: 10000;
    font-family: $font-family;
    box-shadow: $box-shadow-app;
    top: 5px;
    height: 15em;
    width: 28em;
    max-width: 95vw;
    padding: 0.8em;
    border-radius: 0.1em;
    background: #fff;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;

    &.visible {
        visibility: visible;
        opacity: 1;
    }
}

.pcr-app .swatches {

    // Flex fallback
    display: flex;
    flex-wrap: wrap;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(1.6em, 1fr));
    margin-top: 0.75em;

    > div {
        position: relative;
        width: 1.5em;
        height: 1.5em;
        border-radius: 0.15em;
        cursor: pointer;
        margin: 0 2px 2px 0;
        flex-shrink: 0;
        justify-self: center;
        transition: all 0.3s;
        overflow: hidden;
        @include transparency-background(6px);

        &::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: currentColor;
            border: 1px solid rgba(black, 0.05);
            border-radius: 0.15em;
            box-sizing: border-box;
        }

        &:hover {
            filter: brightness(1.1);
        }
    }
}

.pcr-app .pcr-interaction {
    display: flex;
    align-items: center;
    margin: 0.75em -0.2em 0 -0.2em;

    > * {
        margin: 0 0.2em;
    }

    input {
        border: none;
        outline: none;
        letter-spacing: 0.07em;
        font-size: 0.75em;
        text-align: center;
        cursor: pointer;
        color: $palette-darkgray;
        background: $palette-snowwhite;
        border-radius: $border-radius-mid;
        transition: all 0.15s;
        box-shadow: 0 0 0 2px transparent;
        padding: 0.45em 0.5em;

        &:hover {
            filter: brightness(0.975);
        }

        &:focus {
            box-shadow: 0 0 0 2px rgba($palette-cloud-blue, 0.8);
        }
    }

    .pcr-result {
        color: $palette-darkgray;
        text-align: left;
        flex-grow: 1;
        min-width: 1em;
        transition: all 0.2s;
        border-radius: $border-radius-mid;
        background: $palette-snowwhite;
        cursor: text;

        &::selection {
            background: $palette-cloud-blue;
            color: #fff;
        }
    }

    .pcr-type.active {
        color: #fff;
        background: $palette-cloud-blue;
    }

    .pcr-clear,
    .pcr-save {
        color: #fff;
        width: auto;
    }

    .pcr-save,
    .pcr-clear{
        color: #fff;

        &:hover {
            filter: brightness(0.925);
        }
    }

    .pcr-save {
        background: $palette-cloud-blue;
    }

    .pcr-clear {
        background: $palette-soft-red;
    }
}

.pcr-app .pcr-selection {
    display: flex;
    justify-content: space-between;
    flex-grow: 1;

    .pcr-picker {
        position: absolute;
        height: 18px;
        width: 18px;
        border: 2px solid #fff;
        border-radius: 100%;
        user-select: none;
        cursor: -moz-grab;
        cursor: -webkit-grabbing;
    }

    .pcr-color-preview {
        position: relative;
        z-index: 1;
        width: 2em;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        @include transparency-background;
        margin-right: 0.75em;

        .pcr-last-color {
            cursor: pointer;
            transition: background-color 0.3s;
            border-radius: 0.15em 0.15em 0 0;
        }

        .pcr-current-color {
            border-radius: 0 0 0.15em 0.15em;
        }

        .pcr-last-color,
        .pcr-current-color {
            background: transparent;
            width: 100%;
            height: 50%;
        }
    }

    .pcr-color-palette,
    .pcr-color-chooser,
    .pcr-color-opacity {
        position: relative;
        user-select: none;
        display: flex;
        flex-direction: column;
    }

    .pcr-color-palette {
        width: 100%;
        z-index: 1;

        .pcr-palette {
            height: 100%;
            border-radius: $border-radius-mid;
            @include transparency-background;
        }
    }

    .pcr-color-chooser,
    .pcr-color-opacity {
        margin-left: 0.75em;

        .pcr-picker {
            left: 50%;
            transform: translateX(-50%);
        }

        .pcr-slider {
            width: 8px;
            height: 100%;
            border-radius: 50em;
        }
    }

    .pcr-color-chooser .pcr-slider {
        background: $color-rainbow;
    }

    .pcr-color-opacity .pcr-slider {
        background: linear-gradient(to bottom, transparent, black), $icon-transparency;
        background-size: 100%, 50%;
    }
}
