/* ==========================================================================
   Date picker — paired with js/datepicker.js

   Colours are derived from --primary so the admin palette in api/theme.php
   still drives the picker. Each color-mix() is preceded by a flat fallback for
   engines that don't support it (pre-16.2 iOS Safari, older Android WebViews).
   ========================================================================== */

.rdp-field {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 15px 14px;
    border: 1.5px solid var(--border, #e2e8f0);
    border-radius: var(--radius-lg, 16px);
    background: var(--bg-card, #fff);
    cursor: pointer;
    /* Explicit: a drag that starts on the field scrolls the form. The picker only
       opens if the finger lifts without travelling (see TAP_SLOP in the JS). */
    touch-action: pan-y;
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.rdp-field:hover {
    border-color: var(--border-hover, #cbd5e1);
}

.rdp-field.is-open {
    border-color: var(--primary, #7c3aed);
    box-shadow: 0 0 0 4px var(--primary-glow, rgba(124, 58, 237, 0.14));
    background: #fff;
}

.rdp-lead {
    flex-shrink: 0;
    font-size: 1.05rem;
    line-height: 1;
    color: var(--text-muted, #94a3b8);
    transition: color 160ms ease;
}

.rdp-field.is-open .rdp-lead,
.rdp-field.has-value .rdp-lead {
    color: var(--primary, #7c3aed);
}

.rdp-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    padding: 0;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-heading, #0f172a);
    cursor: pointer;
    /* The field is readonly and pointer focus is cancelled in JS; killing the
       appearance keeps iOS from painting its own inset shadow on top. */
    appearance: none;
    -webkit-appearance: none;
}

.rdp-input:focus {
    outline: none;
}

.rdp-input::placeholder {
    color: var(--text-muted, #94a3b8);
    font-weight: 400;
    opacity: 1;
}

/* Clear button only earns its space once there is something to clear. */
.rdp-clear {
    display: none;
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted, #94a3b8);
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
}

.rdp-field.has-value .rdp-clear {
    display: inline-flex;
}

.rdp-clear:hover {
    background: #f1f5f9;
    color: var(--text-body, #334155);
}

.rdp-trail {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-muted, #94a3b8);
    transition: color 160ms ease;
}

.rdp-field.is-open .rdp-trail,
.rdp-field.has-value .rdp-trail {
    color: var(--primary, #7c3aed);
}

/* ---------- floating panel ---------- */

.rdp-scrim {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    z-index: 1080;
    background: rgba(15, 23, 42, 0.45);
    /* Swallows background drags on iOS, where body overflow alone doesn't hold. */
    touch-action: none;
    animation: rdp-fade 180ms ease;
}

.rdp-scrim[hidden] {
    display: none;
}

.rdp-panel {
    position: fixed;
    z-index: 1090;
    width: min(340px, calc(100vw - 24px));
    /* Column layout with a scrolling body so the Clear/Today footer stays
       reachable no matter how little vertical room is left. */
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: var(--radius-xl, 20px);
    background: #fff;
    box-shadow: 0 24px 48px -12px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(15, 23, 42, 0.04);
    overflow: hidden;
    animation: rdp-pop 160ms cubic-bezier(0.16, 1, 0.3, 1);
    /* No panning or zooming from the panel chrome; the day grid opts back in
       below. Taps are unaffected by touch-action. */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.rdp-panel[hidden] {
    display: none;
}

.rdp-grabber {
    flex: 0 0 auto;
    display: none;
}

.rdp-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 16px 16px 8px;
}

.rdp-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    border-radius: 10px;
    padding: 4px 8px;
    margin-left: -8px;
    background: transparent;
    font-family: inherit;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text-heading, #0f172a);
    cursor: pointer;
    transition: background 140ms ease;
}

.rdp-title:hover {
    background: #f5f3ff;
    background: color-mix(in srgb, var(--primary, #7c3aed) 7%, #fff);
}

.rdp-title i {
    font-size: 0.72rem;
    color: var(--text-secondary, #64748b);
}

.rdp-nav {
    display: flex;
    gap: 6px;
}

.rdp-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: #f3eefe;
    background: color-mix(in srgb, var(--primary, #7c3aed) 9%, #fff);
    color: var(--primary, #7c3aed);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 140ms ease, transform 140ms ease;
}

.rdp-nav-btn:hover {
    background: #e7dcfd;
    background: color-mix(in srgb, var(--primary, #7c3aed) 16%, #fff);
}

.rdp-nav-btn:active {
    transform: scale(0.94);
}

.rdp-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Scrollable when the grid overflows, but never chains to the page behind. */
    touch-action: pan-y;
    overscroll-behavior: contain;
    padding: 4px 12px 12px;
}

.rdp-weekdays,
.rdp-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.rdp-weekdays span {
    padding: 6px 0 10px;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
}

.rdp-days {
    gap: 2px;
}

.rdp-day {
    position: relative;
    /* min-height carries pre-15 iOS Safari, where aspect-ratio is ignored and the
       cells would otherwise collapse to the text height. */
    min-height: 40px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-heading, #0f172a);
    cursor: pointer;
    transition: background 130ms ease, color 130ms ease;
}

.rdp-day:hover:not(.is-disabled):not(.is-selected) {
    background: #f5f3ff;
    background: color-mix(in srgb, var(--primary, #7c3aed) 8%, #fff);
}

.rdp-day.is-outside {
    color: var(--text-muted, #cbd5e1);
    font-weight: 400;
}

.rdp-day.is-today {
    background: #ede9fe;
    background: color-mix(in srgb, var(--primary, #7c3aed) 13%, #fff);
    color: var(--primary, #7c3aed);
    font-weight: 700;
}

.rdp-day.is-selected {
    background: var(--primary, #7c3aed);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 4px 10px -2px var(--primary-glow, rgba(124, 58, 237, 0.45));
}

.rdp-day.is-disabled {
    color: #cbd5e1;
    font-weight: 400;
    cursor: not-allowed;
    opacity: 0.55;
}

/* Month / year pickers reuse the panel body. */
.rdp-cells {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 6px 0;
}

.rdp-cell {
    padding: 14px 4px;
    border: 0;
    border-radius: 12px;
    background: #f8fafc;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-body, #334155);
    cursor: pointer;
    transition: background 130ms ease, color 130ms ease;
}

.rdp-cell:hover {
    background: #f1ebfe;
    background: color-mix(in srgb, var(--primary, #7c3aed) 11%, #fff);
    color: var(--primary, #7c3aed);
}

.rdp-cell.is-selected {
    background: var(--primary, #7c3aed);
    color: #fff;
}

.rdp-foot {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
}

.rdp-foot-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 0;
    border-radius: 8px;
    padding: 6px 10px;
    background: transparent;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--primary, #7c3aed);
    cursor: pointer;
    transition: background 140ms ease;
}

.rdp-foot-btn:hover {
    background: #f3eefe;
    background: color-mix(in srgb, var(--primary, #7c3aed) 9%, #fff);
}

.rdp-foot-btn i {
    font-size: 0.95rem;
}

.rdp-foot-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rdp-apply {
    border: 0;
    border-radius: 10px;
    padding: 9px 20px;
    background: var(--primary, #7c3aed);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: filter 140ms ease, opacity 140ms ease, transform 140ms ease;
}

.rdp-apply:hover:not(:disabled) {
    filter: brightness(1.08);
}

.rdp-apply:active:not(:disabled) {
    transform: scale(0.97);
}

.rdp-apply:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---------- phone: dock to the bottom as a sheet ---------- */

.rdp-panel.is-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: rdp-rise 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.rdp-panel.is-sheet .rdp-grabber {
    display: block;
    width: 40px;
    height: 4px;
    margin: 10px auto 2px;
    border-radius: 99px;
    background: #e2e8f0;
}

.rdp-panel.is-sheet .rdp-head {
    padding: 12px 20px 8px;
}

.rdp-panel.is-sheet .rdp-body {
    padding: 4px 14px 14px;
}

/* 44px is the minimum comfortable touch target on both iOS and Android. */
.rdp-panel.is-sheet .rdp-day {
    font-size: 1rem;
    min-height: 44px;
}

.rdp-panel.is-sheet .rdp-nav-btn {
    width: 40px;
    height: 40px;
}

.rdp-panel.is-sheet .rdp-cell {
    padding: 18px 4px;
}

.rdp-panel.is-sheet .rdp-foot {
    padding: 14px 20px;
}

.rdp-panel.is-sheet .rdp-foot-btn {
    padding: 8px 12px;
    font-size: 0.98rem;
}

.rdp-panel.is-sheet .rdp-apply {
    padding: 12px 26px;
    font-size: 1rem;
}

/* Set by JS while a sheet is open. Deliberately NOT position:fixed — that zeroes
   the real scroll offset and makes the page flash to the top when released. This
   holds the page still without ever moving it; iOS, which ignores overflow on
   body for touch, is covered by touch-action on the scrim and panel. */
body.rdp-locked {
    overflow: hidden;
    overscroll-behavior: contain;
}

@keyframes rdp-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes rdp-pop {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes rdp-rise {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .rdp-panel,
    .rdp-scrim {
        animation: none;
    }
}
