﻿/* Preserve the original input for form values, validation and existing scripts. */
input.mx-date-source {
    position: absolute !important;
    width: 1px !important;
    min-width: 0 !important;
    height: 1px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    pointer-events: none !important;
}

.mx-date-field {
    display: inline-flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    box-sizing: border-box;
    background: #fff;
    color: #181d27;
    border: 1px solid #d5d7da;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(10, 13, 18, .05);
}

    .mx-date-field[hidden] {
        display: none !important;
    }

    .mx-date-field input.mx-date-editor {
        flex: 1 1 auto;
        width: 0 !important;
        min-width: 0 !important;
        height: 42px !important;
        padding: 8px 12px !important;
        border: 0 !important;
        border-radius: 8px !important;
        background: transparent !important;
        color: inherit !important;
        box-shadow: none !important;
        outline: none !important;
        font-family: inherit;
        font-size: 16px;
        line-height: 24px;
        box-sizing: border-box;
    }

    .mx-date-field .mx-date-editor::placeholder {
        color: #9ca3af;
        opacity: 1;
    }

    .mx-date-field .mx-date-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 32px;
        width: 32px;
        height: 40px;
        padding: 0;
        border: 0;
        border-radius: 6px;
        background: transparent;
        color: #717680;
        cursor: pointer;
    }

.mx-date-button:last-child {
    margin-right: 4px;
}

.mx-date-button:hover:not(:disabled) {
    background: #f3f6f5;
    color: #344654;
}

.mx-date-field:focus-within {
    border-color: #63c0a2;
    box-shadow: 0 0 0 3px rgba(99, 192, 162, .18);
}

.mx-date-button:focus-visible {
    outline: 2px solid #344654;
    outline-offset: -3px;
}

.mx-date-disabled,
.mx-date-readonly {
    background: #f5f5f5;
}

.mx-date-button:disabled {
    opacity: .45;
    cursor: default;
}

.mx-date-invalid,
.mx-date-field.input-validation-error {
    border-color: #d92d20;
}

.mx-date-calendar.flatpickr-calendar {
    z-index: 2147483000;
    border: 1px solid #d5d7da;
    border-radius: 8px;
    font-family: inherit;
    box-shadow: 0 8px 24px rgba(10, 13, 18, .15);
}

.mx-date-calendar .flatpickr-day.selected,
.mx-date-calendar .flatpickr-day.selected:hover,
.mx-date-calendar .flatpickr-day.selected:focus {
    background: #63c0a2;
    border-color: #63c0a2;
    color: #181d27;
}

.mx-date-calendar .flatpickr-day.today {
    border-color: #63c0a2;
}

.mx-date-calendar .flatpickr-time input {
    color: #181d27;
    font-size: 16px;
}


/* Consistent spacing between the text and action buttons. */
.mx-date-field {
    gap: 4px;
    padding: 4px 6px;
}

    .mx-date-field input.mx-date-editor {
        height: 34px !important;
        margin: 0 !important;
        padding: 5px 6px !important;
    }

    .mx-date-field .mx-date-button {
        flex: 0 0 32px;
        width: 32px;
        height: 32px;
        margin: 0;
        padding: 0;
        line-height: 1;
        box-sizing: border-box;
    }

        .mx-date-field .mx-date-button i {
            display: block;
            margin: 0;
            font-size: 16px;
            line-height: 1;
        }

/* Let the popup accommodate padding without squeezing the date grid. */
.mx-date-calendar.flatpickr-calendar:not(.noCalendar) {
    width: max-content !important;
    padding: 12px;
    box-sizing: border-box;
}

/* Align navigation, month and year within one header row. */
.mx-date-calendar .flatpickr-months {
    position: relative;
    align-items: center;
    margin-bottom: 8px;
}

    .mx-date-calendar .flatpickr-months .flatpickr-month {
        height: 36px;
    }

.mx-date-calendar .flatpickr-current-month {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    left: 32px;
    width: calc(100% - 64px);
    height: 36px;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    box-sizing: border-box;
}

    .mx-date-calendar .flatpickr-current-month .flatpickr-monthDropdown-months {
        width: auto;
        min-width: 0;
        height: 32px;
        margin: 0;
        padding: 0 4px;
        border: 0;
        border-radius: 4px;
        background: transparent;
        color: inherit;
        font: inherit;
        line-height: normal;
        box-shadow: none;
        appearance: auto;
    }

    .mx-date-calendar .flatpickr-current-month .numInputWrapper {
        flex: 0 0 66px;
        width: 66px;
        height: 32px;
        margin: 0;
        border-radius: 4px;
    }

    .mx-date-calendar .flatpickr-current-month input.cur-year {
        width: 100% !important;
        min-width: 0 !important;
        height: 32px !important;
        margin: 0 !important;
        padding: 0 18px 0 4px !important;
        border: 0 !important;
        border-radius: 4px !important;
        background: transparent !important;
        color: inherit;
        font: inherit;
        line-height: 32px;
        box-shadow: none !important;
        box-sizing: border-box;
    }

.mx-date-calendar .flatpickr-months .flatpickr-prev-month,
.mx-date-calendar .flatpickr-months .flatpickr-next-month {
    display: flex;
    align-items: center;
    justify-content: center;
    top: 0;
    width: 32px;
    height: 36px;
    padding: 8px;
    border-radius: 6px;
    box-sizing: border-box;
}

.mx-date-calendar .flatpickr-months .flatpickr-prev-month {
    left: 0;
}

.mx-date-calendar .flatpickr-months .flatpickr-next-month {
    right: 0;
}

    .mx-date-calendar .flatpickr-months .flatpickr-prev-month:hover,
    .mx-date-calendar .flatpickr-months .flatpickr-next-month:hover {
        background: #f3f6f5;
    }

.mx-date-calendar .flatpickr-months svg {
    display: block;
    width: 14px;
    height: 14px;
}

/* Separate weekday headings from the month header and date rows. */
.mx-date-calendar .flatpickr-weekdays {
    height: 28px;
    margin-bottom: 4px;
}

.mx-date-calendar span.flatpickr-weekday {
    color: #717680;
    font-size: 12px;
    font-weight: 600;
}

/* Keep time controls aligned when date/time fields use the same popup. */
.mx-date-calendar .flatpickr-time {
    align-items: center;
    height: 40px;
    max-height: 40px;
    line-height: 40px;
}

.mx-date-calendar.hasTime:not(.noCalendar) .flatpickr-time {
    margin-top: 10px;
}

.mx-date-calendar .flatpickr-time .numInputWrapper {
    height: 40px;
}

.mx-date-calendar .flatpickr-time input {
    height: 40px !important;
    margin: 0 !important;
    padding: 0 16px 0 6px !important;
    border: 0 !important;
    border-radius: 4px;
    line-height: 40px;
    box-shadow: none !important;
    box-sizing: border-box;
}

.mx-date-calendar .flatpickr-time .flatpickr-time-separator {
    height: 40px;
    line-height: 40px;
}


input.mx-date-source {
    visibility: hidden !important;
}

input.mx-date-source::-webkit-calendar-picker-indicator {
    display: none !important;
    pointer-events: none !important;
}

/* Compact popup for time-only fields. */
.mx-date-calendar.flatpickr-calendar.noCalendar {
    width: 240px !important;
    max-width: calc(100vw - 16px);
    padding: 12px;
    box-sizing: border-box;
}

    .mx-date-calendar.flatpickr-calendar.noCalendar .flatpickr-time {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        width: 100%;
        height: 40px;
        max-height: none;
        margin: 0;
        padding: 0;
        border: 0;
        overflow: visible;
    }

/* Equal space for hours, minutes and optional seconds. */
.mx-date-calendar.noCalendar .flatpickr-time .numInputWrapper {
    position: relative;
    flex: 1 1 0;
    float: none;
    width: auto !important;
    min-width: 0;
    height: 40px;
    border: 1px solid #d5d7da;
    border-radius: 6px;
    background: #fff;
    box-sizing: border-box;
    overflow: hidden;
}

    .mx-date-calendar.noCalendar .flatpickr-time .numInputWrapper:focus-within {
        border-color: #63c0a2;
        box-shadow: 0 0 0 2px rgba(99, 192, 162, .18);
    }

.mx-date-calendar.noCalendar .flatpickr-time input {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    height: 38px !important;
    margin: 0 !important;
    padding: 0 20px 0 6px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #181d27;
    font-family: inherit;
    font-size: 16px;
    font-weight: 500;
    line-height: 38px;
    text-align: center;
    box-sizing: border-box;
}

.mx-date-calendar.noCalendar .flatpickr-time .flatpickr-time-separator {
    flex: 0 0 8px;
    float: none;
    width: 8px;
    height: 40px;
    line-height: 40px;
    color: #717680;
    text-align: center;
}

/* Keep increment/decrement controls visible on touch screens too. */
.mx-date-calendar.noCalendar .numInputWrapper > span {
    right: 0;
    width: 20px;
    padding: 0;
    border: 0;
    border-left: 1px solid #e9eaeb;
    opacity: 1;
}

    .mx-date-calendar.noCalendar .numInputWrapper > span:hover {
        background: #edf7f3;
    }

    .mx-date-calendar.noCalendar .numInputWrapper > span::after {
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }

/* Enhanced dates with an accompanying value, such as patient age. */
.customDate:has(> .mx-date-field) {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
    min-width: 0;
}

.customDate > .mx-date-field {
    flex: 1 1 240px;
    width: auto;
    min-width: min(100%, 240px);
    max-width: 100%;
}

    /* Remove the legacy padding reserved for the overlaid age. */
    .customDate > .mx-date-field > input.mx-date-editor {
        padding: 5px 6px !important;
    }

/* Give the age its own space instead of overlaying the date buttons. */
.customDate:has(> .mx-date-field) > .customDate--Value {
    position: static;
    flex: 0 0 auto;
    height: auto;
    min-height: 44px;
    max-width: 100%;
    padding: 8px 12px;
    box-sizing: border-box;
    border: 1px solid #d5d7da;
    border-radius: 8px;
    background: #f5f5f5;
}

    .customDate:has(> .mx-date-field) > .customDate--Value p {
        margin: 0;
        line-height: 24px;
        white-space: nowrap;
    }