/* DateField / TimeField (Pages/MyComponents) — a text box with a calendar/clock button, and the
   popup it opens. The popup lives in the top layer (Popover API), so it is styled here, globally.
   Colours are Bootstrap variables only: dark mode swaps the stylesheet that defines them, and
   --bs-white is the dark theme's surface. The input is dir="ltr" (digits and separators read the
   same in every language), so its own padding is physical and flipped under [dir="rtl"]. */

.df {
    position: relative;
    display: block;
    min-width: 0;
}

/* The icon side's padding is !important: pages restyle their filter inputs' padding, and text
   under the button would be unreadable. */
.df > .df-input {
    width: 100%;
    padding-right: 2.1rem !important;
    font-variant-numeric: tabular-nums;
    background-image: none;
}

[dir="rtl"] .df > .df-input {
    text-align: right;
    padding-right: .75rem !important;
    padding-left: 2.1rem !important;
}

[dir="rtl"] .df > .df-input.form-control-sm {
    padding-right: .5rem !important;
}

[dir="rtl"] .df > .df-input.form-control-lg {
    padding-right: 1rem !important;
}

.df > .df-input::placeholder {
    letter-spacing: .02em;
}

.df-toggle {
    position: absolute;
    top: 1px;
    bottom: 1px;
    inset-inline-end: 1px;
    width: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: var(--bs-border-radius);
    background: transparent;
    color: var(--bs-secondary-color);
    cursor: pointer;
}

.df-toggle:hover:not(:disabled),
.df.df-open .df-toggle {
    color: var(--bs-primary);
}

.df-toggle:disabled {
    cursor: default;
    opacity: .5;
}

/* Inside an .input-group the wrapper takes the input's place in the row. */
.input-group > .df {
    flex: 1 1 auto;
    width: 1%;
}

.input-group > .df:not(:last-child) > .df-input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group > .df:not(:first-child) > .df-input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

[dir="rtl"] .input-group > .df:not(:last-child) > .df-input {
    border-top-right-radius: var(--bs-border-radius);
    border-bottom-right-radius: var(--bs-border-radius);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

[dir="rtl"] .input-group > .df:not(:first-child) > .df-input {
    border-top-left-radius: var(--bs-border-radius);
    border-bottom-left-radius: var(--bs-border-radius);
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

[dir="rtl"] .input-group > .df:not(:first-child):not(:last-child) > .df-input {
    border-radius: 0;
}

.input-group-sm > .df > .df-input {
    padding-top: .25rem;
    padding-bottom: .25rem;
    font-size: .875rem;
    min-height: calc(1.5em + .5rem + calc(var(--bs-border-width) * 2));
}

/* ── popup ─────────────────────────────────────────────────────────────────────────────── */

.df-popover {
    position: fixed;
    inset: auto;
    margin: 0;
    padding: 0;
    width: 18.5rem;
    max-width: calc(100vw - 8px);
    overflow: visible;
    border: 1px solid var(--bs-border-color);
    border-radius: .75rem;
    background: var(--bs-white);
    color: var(--bs-body-color);
    box-shadow: 0 .75rem 2.25rem rgba(0, 0, 0, .18), 0 .125rem .375rem rgba(0, 0, 0, .08);
    z-index: 2147483000; /* only matters where the top layer is not available */
    font-size: .875rem;
}

.df-popover-time {
    width: 17rem;
}

.df-popover::backdrop {
    background: transparent;
}

.df-panel-body {
    padding: .625rem;
}

.df-head {
    display: flex;
    align-items: center;
    gap: .25rem;
    margin-bottom: .375rem;
}

.df-title {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    gap: .125rem;
    font-weight: 600;
}

.df-title-btn,
.df-nav {
    border: 0;
    background: transparent;
    color: inherit;
    border-radius: .5rem;
    line-height: 1.2;
}

.df-title-btn {
    padding: .3rem .5rem;
    font-weight: 600;
}

.df-title-static {
    padding: .3rem .5rem;
}

.df-nav {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bs-secondary-color);
}

.df-title-btn:hover,
.df-nav:hover {
    background: rgba(var(--bs-primary-rgb), .1);
    color: var(--bs-primary);
}

[dir="rtl"] .df-flip {
    display: inline-block;
    transform: scaleX(-1);
}

.df-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.df-weekdays {
    margin-bottom: 2px;
}

.df-weekdays > span {
    text-align: center;
    font-size: .7rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    padding: .25rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
}

.df-day,
.df-cell {
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: inherit;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background-color .1s ease-in-out;
}

.df-day {
    height: 2.25rem;
    padding: 0;
}

.df-day.df-out {
    color: var(--bs-secondary-color);
    opacity: .55;
}

.df-day:hover:not(:disabled),
.df-cell:hover:not(:disabled) {
    background: rgba(var(--bs-primary-rgb), .1);
}

.df-day.df-today,
.df-cell.df-today {
    box-shadow: inset 0 0 0 1px rgba(var(--bs-primary-rgb), .6);
    font-weight: 600;
}

.df-day.df-cursor {
    outline: 2px solid rgba(var(--bs-primary-rgb), .45);
    outline-offset: -2px;
}

.df-day.df-selected,
.df-cell.df-selected,
.df-day.df-selected:hover,
.df-cell.df-selected:hover {
    background: var(--bs-primary);
    color: #fff;
    font-weight: 600;
    opacity: 1;
}

.df-day:disabled,
.df-cell:disabled {
    cursor: not-allowed;
    opacity: .3;
    text-decoration: line-through;
}

.df-months,
.df-years {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.df-years {
    grid-template-columns: repeat(4, 1fr);
}

.df-cell {
    min-height: 2.5rem;
    padding: .25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.15;
}

.df-cell-number {
    font-size: .7rem;
    opacity: .6;
}

.df-cell.df-selected .df-cell-number {
    opacity: .85;
}

.df-foot {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px solid var(--bs-border-color);
}

.df-foot .df-close {
    display: none;
    margin-inline-start: auto;
}

/* ── time ──────────────────────────────────────────────────────────────────────────────── */

.df-time-preview {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: .125rem;
    font-size: 1.5rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--bs-secondary-color);
    margin-bottom: .25rem;
}

.df-time-preview .df-time-part-set {
    color: var(--bs-body-color);
}

.df-section-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--bs-secondary-color);
    margin: .375rem 0 .25rem;
}

.df-hours {
    grid-template-columns: repeat(6, 1fr);
}

.df-minutes {
    grid-template-columns: repeat(6, 1fr);
}

.df-minutes-fine {
    grid-template-columns: repeat(10, 1fr);
    max-height: 11rem;
    overflow-y: auto;
}

.df-hours .df-cell,
.df-minutes .df-cell {
    min-height: 2rem;
}

/* ── phone: a bottom sheet with larger targets ─────────────────────────────────────────── */

.df-popover.df-sheet {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100%;
    max-width: 100%;
    border-radius: 1rem 1rem 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    font-size: 1rem;
    max-height: 92vh;
    max-height: 92dvh;
    overflow-y: auto;
}

.df-popover.df-sheet::backdrop {
    background: rgba(0, 0, 0, .35);
}

.df-sheet .df-panel-body {
    padding: .875rem 1rem 1rem;
    max-width: 30rem;
    margin: 0 auto;
}

.df-sheet .df-day {
    height: 2.75rem;
}

.df-sheet .df-cell {
    min-height: 2.75rem;
}

.df-sheet .df-hours .df-cell,
.df-sheet .df-minutes .df-cell {
    min-height: 2.5rem;
}

.df-sheet .df-weekdays > span {
    font-size: .8rem;
}

.df-sheet .df-foot .df-close {
    display: inline-block;
}

/* Without the Popover API the popup is laid out where it is rendered, under the field;
   date-field.js still makes it fixed and places it. */
@supports not selector(:popover-open) {
    .df-popover {
        position: absolute;
        top: calc(100% + 4px);
        inset-inline-start: 0;
    }
}
