@import "flatpickr_vars";

@keyframes fpFadeInDown {
    from {
        opacity: 0;
        transform: translate3d( 0, -20px, 0 );
    }

    to {
        opacity: 1;
        transform: translate3d( 0, 0, 0 );
    }
}

.flatpickr-calendar {
    animation: none;
    background: transparent;
    border: 0;
    border-radius: 5px;
    box-sizing: border-box;
    direction: ltr;
    display: none;
    font-size: 14px;
    gap: 2px;
    line-height: 24px;
    opacity: 0;
    padding: 0;
    position: absolute;
    text-align: center;
    touch-action: manipulation;
    visibility: hidden;
    width: $calendarWidth;

    @if variable-exists( "noCalendarBorder" ) {
        box-shadow: 0 3px 13px rgb( #000 .08 );
    } @else {
        background: $calendarBackground;
        box-shadow: 1px 1px 3px 0 #666;
    }

    &.open,
    &.inline {
        max-height: 640px;
        opacity: 1;
        visibility: visible;
    }

    &.open {
        display: inline-block;
        z-index: 99999;
    }

    &.animate.open {
        animation: fpFadeInDown 300ms $bezier;
    }

    &.inline {
        display: block;
        position: relative;
        top: 2px;
    }

    &.static {
        position: absolute;
        top: calc( 100% + 2px );

        &.open {
            display: block;
            z-index: 999;
        }
    }

    &.multiMonth {
        .flatpickr-days .dayContainer:nth-child( n+1 ) {
            & .flatpickr-day.inRange:nth-child( 7n+7 ) {
                box-shadow: none !important;
            }
        }

        .flatpickr-days .dayContainer:nth-child( n+2 ) {
            & .flatpickr-day.inRange:nth-child( 7n+1 ) {
                box-shadow: -2px 0 0 #E6E6E6, 5px 0 0 #E6E6E6;
            }
        }
    }

    .hasWeeks,
    .hasTime {
        .dayContainer {
            border-bottom: 0;
            border-bottom-left-radius: 0;
            border-bottom-right-radius: 0;
        }
    }

    @if variable-exists( "noCalendarBorder" ) {
        .hasWeeks .dayContainer {
            border-left: 0;
        }
    }

    &.hasTime {
        .flatpickr-time {
            border-top: 1px solid $calendarBorderColor;
            height: $timeHeight;
        }

        @if variable-exists( "noCalendarBorder" ) {
            .flatpickr-innerContainer {
                border-bottom: 0;
            }

            .flatpickr-time {
                border: 1px solid $calendarBorderColor;
            }
        }
    }

    &.noCalendar.hasTime {
        .flatpickr-time {
            height: auto;
        }
    }

    &::before,
    &::after {
        border: solid transparent;
        content: "";
        display: block;
        height: 0;
        left: 22px;
        pointer-events: none;
        position: absolute;
        width: 0;
    }

    &.rightMost,
    &.arrowRight {
        &::before,
        &::after {
            left: auto;
            right: 22px;
        }
    }

    &.arrowCenter {
        &::before,
        &::after {
            left: 50%;
            right: 50%;
        }
    }

    &::before {
        border-width: 5px;
        margin: 0 -5px;
    }

    &::after {
        border-width: 4px;
        margin: 0 -4px;
    }

    &.arrowTop {
        &::before,
        &::after {
            bottom: 100%;
        }

        &::before {
            border-bottom-color: $calendarBorderColor;
        }

        &::after {
            @if variable-exists( "noCalendarBorder" ) {
                border-bottom-color: $monthBackground;
            } @else {
                border-bottom-color: $calendarBackground;
            }
        }
    }

    &.arrowBottom {
        &::before,
        &::after {
            top: 100%;
        }

        &::before {
            border-top-color: $calendarBorderColor;
        }

        &::after {
            @if variable-exists( "noCalendarBorder" ) {
                border-top-color: $monthBackground;
            } @else {
                border-top-color: $calendarBackground;
            }
        }
    }

    &:focus {
        outline: 0;
    }
}

.flatpickr-wrapper {
    display: inline-block;
    position: relative;
}

.flatpickr-months {
    display: flex;

    .flatpickr-month {
        @if variable-exists( "noCalendarBorder" ) {
            border-radius: 5px 5px 0 0;
        }

        background: $monthBackground;
        color: $monthForeground;
        fill: $monthForeground;
        flex: 1;
        height: $monthNavHeight;
        line-height: 1;
        overflow: hidden;
        position: relative;
        text-align: center;
        user-select: none;
    }

    .flatpickr-prev-month,
    .flatpickr-next-month {
        color: $monthForeground;
        cursor: pointer;
        fill: $monthForeground;
        height: $monthNavHeight;
        padding: 10px;
        position: absolute;
        text-decoration: none;
        top: 0;
        z-index: 3;

        &.flatpickr-disabled {
            display: none;
        }

        i {
            position: relative;
        }

        &.flatpickr-prev-month {
            left: 0;
        }

        &.flatpickr-next-month {
            right: 0;
        }

        &:hover {
            color: $todayColor;

            svg {
                @if variable-exists( "arrow_hover_color" ) {
                    fill: $arrow_hover_color;
                } @else {
                    fill: $todayColor;
                }
            }
        }

        svg {
            height: 14px;
            width: 14px;

            path {
                fill: inherit;
                transition: fill .1s;
            }
        }
    }
}

.numInputWrapper {
    height: auto;
    position: relative;

    input,
    span {
        display: inline-block;
    }

    input {
        width: 100%;

        &::-ms-clear {
            display: none;
        }

        &::-webkit-outer-spin-button,
        &::-webkit-inner-spin-button {
            appearance: none;
            margin: 0;
        }
    }

    span {
        border: 1px solid rgba( $dayForeground, .15 );
        box-sizing: border-box;
        cursor: pointer;
        height: 50%;
        line-height: 50%;
        opacity: 0;
        padding: 0 4px 0 2px;
        position: absolute;
        right: 0;
        width: $timecontrols;

        &:hover {
            background: rgba( $invertedBg, .1 );
        }

        &:active {
            background: rgba( $invertedBg, .2 );
        }

        &::after {
            content: "";
            display: block;
            position: absolute;
        }

        &.arrowUp {
            border-bottom: 0;
            top: 0;

            &::after {
                border-bottom: 4px solid rgba( $dayForeground, .6 );
                border-left: 4px solid transparent;
                border-right: 4px solid transparent;
                top: 26%;
            }
        }

        &.arrowDown {
            top: 50%;

            &::after {
                border-left: 4px solid transparent;
                border-right: 4px solid transparent;
                border-top: 4px solid rgba( $dayForeground, .6 );
                top: 40%;
            }
        }

        svg {
            height: auto;
            width: inherit;

            path {
                fill: rgba( $monthForeground, .5 );
            }
        }
    }

    &:hover {
        background: rgba( $invertedBg, .05 );

        span {
            opacity: 1;
        }
    }
}

.flatpickr-current-month {
    color: inherit;
    display: inline-block;
    font-size: 135%;
    font-weight: 300;
    height: $monthNavHeight;
    left: 12.5%;
    line-height: inherit;
    line-height: 1;
    padding: .22 * $monthNavHeight 0 0 0;
    position: absolute;
    text-align: center;
    transform: translate3d( 0, 0, 0 );
    width: 75%;

    span.cur-month {
        color: inherit;
        display: inline-block;
        font-family: inherit;
        font-weight: 700;
        margin-left: .5ch;
        padding: 0;

        &:hover {
            background: rgba( $invertedBg, .05 );
        }
    }

    .numInputWrapper {
        display: inline-block;
        width: 8ch;

        span.arrowUp::after {
            border-bottom-color: $monthForeground;
        }

        span.arrowDown::after {
            border-top-color: $monthForeground;
        }
    }

    input.cur-year {
        appearance: textfield;
        background: transparent;
        border: 0;
        border-radius: 0;
        box-sizing: border-box;
        color: inherit;
        cursor: text;
        display: inline-block;
        font-family: inherit;
        font-size: inherit;
        font-weight: 300;
        height: auto;
        line-height: inherit;
        margin: 0;
        padding: 0 0 0 .5ch;
        vertical-align: initial;

        &:focus {
            outline: 0;
        }

        &[disabled],
        &[disabled]:hover {
            background: transparent;
            color: rgba( $monthForeground, .5 );
            font-size: 100%;
            pointer-events: none;
        }
    }

    .flatpickr-monthDropdown-months {
        appearance: none;
        background-image: url( 'data:image/svg+xml;charset=utf8,%3csvg fill="%23000000" fill-opacity="0.54" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"%3e%3cpath d="M7 10l5 5 5-5z"/%3e%3cpath d="M0 0h24v24H0z" fill="none"/%3e%3c/svg%3e' );
        background-position: 100% 50%;
        background-repeat: no-repeat;
        background-size: 24px 24px;
        border: none;
        border-radius: 0;
        box-sizing: border-box;
        color: inherit;
        cursor: pointer;
        font-family: inherit;
        font-size: 90%;
        font-weight: 300;
        height: auto;
        line-height: 120%;
        margin: -1px 0 0 0;
        outline: none;
        padding: 4px 28px 4px 4px;
        position: relative;
        vertical-align: initial;
        width: auto;

        &:focus,
        &:active {
            outline: none;
        }

        .flatpickr-monthDropdown-month {
            background-color: $monthBackground;
            outline: none;
            padding: 0;
        }
    }
}

.flatpickr-weekdays {
    align-items: center;
    background: $weekdaysBackground;
    display: flex;
    height: $weekdaysHeight;
    overflow: hidden;
    text-align: center;
    width: 100%;

    .flatpickr-weekdaycontainer {
        display: flex;
        flex: 1;
    }
}

span.flatpickr-weekday {
    background: $monthBackground;
    color: $weekdaysForeground;
    cursor: default;
    display: block;
    flex: 1;
    font-size: 90%;
    font-weight: bolder;
    line-height: 1;
    margin: 0;
    text-align: center;
}

.dayContainer,
.flatpickr-weeks {
    padding: 1px 0 0 0;
}

.flatpickr-days {
    align-items: flex-start;
    display: flex;
    overflow: hidden;
    position: relative;
    width: $daysWidth;

    &:focus {
        outline: 0;
    }

    @if variable-exists( "noCalendarBorder" ) {
        border-left: 1px solid $calendarBorderColor;
        border-right: 1px solid $calendarBorderColor;
    }
}

.dayContainer {
    box-sizing: border-box;
    display: inline-block;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    max-width: $daysWidth;
    min-width: $daysWidth;
    opacity: 1;
    outline: 0;
    padding: 0;
    text-align: left;
    transform: translate3d( 0, 0, 0 );
    width: $daysWidth;

    & + .dayContainer {
        box-shadow: -1px 0 0 $calendarBorderColor;
    }
}

.flatpickr-day {
    background: none;
    border: 1px solid transparent;
    border-radius: 0;
    box-sizing: border-box;
    color: $dayForeground;
    cursor: pointer;
    display: inline-block;
    flex-basis: 14.2857%;
    font-weight: 400;
    height: $daySize;
    justify-content: center;
    line-height: $daySize;
    margin: 0;
    max-width: $daySize;
    position: relative;
    text-align: center;
    width: 14.2857%;

    &,
    &.prevMonthDay,
    &.nextMonthDay {
        &.inRange,
        &.today.inRange,
        &:hover,
        &:focus {
            background: $dayHoverBackground;
            border-color: $dayHoverBackground;
            cursor: pointer;
            outline: 0;
        }
    }

    &.today {
        border-color: $todayColor;

        &:hover,
        &:focus {
            background: $todayColor;
            border-color: $todayColor;

            @if variable-exists( "today_fg_color" ) {
                color: $today_fg_color;
            } @else {
                color: #FFF;
            }
        }
    }

    &.selected,
    &.startRange,
    &.endRange {
        &,
        &.inRange,
        &:focus,
        &:hover,
        &.prevMonthDay,
        &.nextMonthDay {
            background: $selectedDayBackground;
            border-color: $selectedDayBackground;
            box-shadow: none;

            @if variable-exists( "selectedDayForeground" ) {
                color: $selectedDayForeground;
            } @else {
                color: #FFF;
            }
        }

        &.startRange {
            border-radius: 50px 0 0 50px;
        }

        &.endRange {
            border-radius: 0 50px 50px 0;
        }

        &.startRange + .endRange:not( :nth-child( 7n+1 ) ) {
            box-shadow: -5 * $dayMargin 0 0 $selectedDayBackground;
        }

        &.startRange.endRange {
            border-radius: 50px;
        }
    }

    &.inRange {
        border-radius: 0;
        box-shadow: -2.5 * $dayMargin 0 0 $dayHoverBackground, 2.5 * $dayMargin 0 0 $dayHoverBackground;
    }

    &.flatpickr-disabled,
    &.flatpickr-disabled:hover,
    &.prevMonthDay,
    &.nextMonthDay,
    &.notAllowed,
    &.notAllowed.prevMonthDay,
    &.notAllowed.nextMonthDay {
        background: transparent;
        color: rgba( $dayForeground, .3 );
        cursor: default;

        @if variable-exists( "disabled_border_color" ) {
            border-color: $disabled_border_color;
        } @else {
            border-color: transparent;
        }
    }

    &.flatpickr-disabled,
    &.flatpickr-disabled:hover {
        color: rgba( $dayForeground, .1 );
        cursor: not-allowed;
    }

    &.week.selected {
        border-radius: 0;
        box-shadow: -2.5 * $dayMargin 0 0 $selectedDayBackground, 2.5 * $dayMargin 0 0 $selectedDayBackground;
    }

    &.hidden {
        visibility: hidden;
    }
}

.rangeMode .flatpickr-day {
    margin-top: 1px;
}

.flatpickr-weekwrapper {
    float: left;

    .flatpickr-weeks {
        padding: 0 12px;

        @if variable-exists( "noCalendarBorder" ) {
            border-left: 1px solid $calendarBorderColor;
        } @else {
            box-shadow: 1px 0 0 $calendarBorderColor;
        }
    }

    .flatpickr-weekday {
        float: none;
        line-height: $weekdaysHeight;
        width: 100%;
    }

    span.flatpickr-day {
        &,
        &:hover {
            background: transparent;
            border: none;
            color: rgba( $dayForeground, .3 );
            cursor: default;
            display: block;
            max-width: none;
            width: 100%;
        }
    }
}

.flatpickr-innerContainer {
    box-sizing: border-box;
    display: block;
    display: flex;
    overflow: hidden;

    @if variable-exists( "noCalendarBorder" ) {
        background: $calendarBackground;
        border-bottom: 1px solid $calendarBorderColor;
    }
}

.flatpickr-rContainer {
    box-sizing: border-box;
    display: inline-block;
    padding: 0;
}

.flatpickr-time {
    box-sizing: border-box;
    display: block;
    display: flex;
    height: 0;
    line-height: $timeHeight;
    max-height: $timeHeight;
    outline: 0;
    overflow: hidden;
    text-align: center;

    @if variable-exists( "noCalendarBorder" ) {
        background: $calendarBackground;
        border-radius: 0 0 5px 5px;
    }

    &::after {
        clear: both;
        content: "";
        display: table;
    }

    .numInputWrapper {
        flex: 1;
        float: left;
        height: $timeHeight;
        width: 40%;

        span.arrowUp::after {
            border-bottom-color: $dayForeground;
        }

        span.arrowDown::after {
            border-top-color: $dayForeground;
        }
    }

    &.hasSeconds .numInputWrapper {
        width: 26%;
    }

    &.time24hr .numInputWrapper {
        width: 49%;
    }

    input {
        appearance: textfield;
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        box-sizing: border-box;
        color: $dayForeground;
        font-size: 14px;
        height: inherit;
        line-height: inherit;
        margin: 0;
        padding: 0;
        position: relative;
        text-align: center;

        &.flatpickr-hour {
            font-weight: bold;
        }

        &.flatpickr-minute,
        &.flatpickr-second {
            font-weight: 400;
        }

        &:focus {
            border: 0;
            outline: 0;
        }
    }

    .flatpickr-time-separator,
    .flatpickr-am-pm {
        align-self: center;
        color: $dayForeground;
        float: left;
        font-weight: bold;
        height: inherit;
        line-height: inherit;
        user-select: none;
        width: 2%;
    }

    .flatpickr-am-pm {
        cursor: pointer;
        font-weight: 400;
        outline: 0;
        text-align: center;
        width: 18%;
    }

    input,
    .flatpickr-am-pm {
        &:hover,
        &:focus {
            background: lighten( $dayHoverBackground, 3 );
        }
    }
}

.flatpickr-input {
    background-image: url( "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23369' class='bi bi-calendar3'%3E%3Cg stroke-width='1.333'%3E%3Cpath d='M10.5 0h-9A1.5 1.5 0 0 0 0 1.5v9A1.5 1.5 0 0 0 1.5 12h9a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 10.5 0zM.75 2.893c0-.355.336-.643.75-.643h9c.414 0 .75.288.75.643v7.714c0 .355-.336.643-.75.643h-9c-.414 0-.75-.288-.75-.643z'/%3E%3Cpath d='M4.875 5.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zM2.625 7.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm-6.75 2.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5zm2.25 0a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5z'/%3E%3C/g%3E%3C/svg%3E" );
    background-position: 3px;
    background-repeat: no-repeat;
    border-style: inset;
    border-width: 1px;
    padding: 3px 3px 3px 20px;

    &.flatpickr-mobile {
        height: 2rem;
        width: 11rem;
    }

    &:focus {
        border-radius: 0;
    }

    &[readonly] {
        cursor: pointer;
    }
}

.flatpickr_wrapper {
    white-space: nowrap;
}
