/* ============================================
   CUSTOM DATE PICKER
   ============================================ */

.cdp-wrapper {
    position: relative;
    display: flex;
    align-items: stretch;
    width: 100%;
}

/* Native input kept for form submission, hidden visually */
.cdp-hidden-input {
    position: absolute !important;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    pointer-events: none;
    clip: rect(0 0 0 0);
    margin: 0;
    padding: 0;
    border: 0;
}

/* Visible text input replaces native */
.cdp-text {
    flex: 1;
    min-width: 0;
    padding-right: 2.5rem; /* space for calendar button */
}

.cdp-wrapper .cdp-button {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: inherit;
    opacity: 0.65;
    cursor: pointer;
    padding: 0;
    z-index: 2;
}

.cdp-wrapper .cdp-button:hover,
.cdp-wrapper .cdp-button:focus {
    opacity: 1;
    outline: none;
}

/* Popup calendar — rendered as a portal on document.body, positioned via JS (fixed).
   Colors are set dynamically via CSS variables so the popup inherits the active
   form-control background/foreground from the current theme (light, dark, custom). */
.cdp-popup {
    --cdp-bg: #fff;
    --cdp-fg: #212529;
    --cdp-border: rgba(0, 0, 0, 0.15);
    --cdp-hover-bg: color-mix(in srgb, var(--cdp-fg) 10%, transparent);
    --cdp-accent: #0d6efd;
    --cdp-accent-fg: #fff;

    position: fixed;
    top: 0;
    left: 0;
    z-index: 2000;
    background: var(--cdp-bg);
    color: var(--cdp-fg);
    border: 1px solid var(--cdp-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    padding: 0.75rem;
    min-width: 280px;
    max-width: 320px;
    font-size: 0.9rem;
    user-select: none;
}

.cdp-header {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.cdp-header .cdp-nav {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--cdp-border);
    background: transparent;
    color: inherit;
    border-radius: 4px;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.cdp-header .cdp-nav:hover {
    background: var(--cdp-hover-bg);
}

.cdp-header .cdp-month,
.cdp-header .cdp-year {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--cdp-border);
    border-radius: 4px;
    background: var(--cdp-bg);
    color: inherit;
    font-size: 0.9rem;
}

.cdp-header .cdp-year {
    flex: 0 0 5rem;
}

.cdp-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 2px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.7;
}

.cdp-weekdays > div {
    padding: 0.25rem 0;
}

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

.cdp-day {
    aspect-ratio: 1 / 1;
    border: none;
    background: transparent;
    color: inherit;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.cdp-day:hover {
    background: var(--cdp-hover-bg);
}

.cdp-day-other {
    opacity: 0.35;
}

.cdp-today {
    font-weight: 700;
    outline: 1px solid currentColor;
    outline-offset: -2px;
    opacity: 0.9;
}

.cdp-selected {
    background: var(--cdp-accent);
    color: var(--cdp-accent-fg);
}

.cdp-selected:hover {
    background: var(--cdp-accent);
    color: var(--cdp-accent-fg);
    filter: brightness(1.1);
}

.cdp-footer {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--cdp-border);
}

.cdp-footer .cdp-clear,
.cdp-footer .cdp-today-btn {
    background: transparent;
    border: 1px solid var(--cdp-border);
    color: inherit;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
}

.cdp-footer .cdp-clear:hover,
.cdp-footer .cdp-today-btn:hover {
    background: var(--cdp-hover-bg);
}

/* ============================================
   FLOATING LABEL COMPATIBILITY
   The existing .responsive-form-floating .floating-label uses `~` sibling selectors
   targeting the input. Wrapping our inputs in a <div> breaks that chain, so we
   re-apply the floating behavior by matching the wrapper.
   ============================================ */

@media (max-width: 767px) {
    .responsive-form-floating .cdp-wrapper {
        position: relative;
    }

    .responsive-form-floating .cdp-wrapper .cdp-text {
        padding-top: 1.625rem;
    }

    /* Animate label when visible text input is focused */
    .responsive-form-floating .cdp-wrapper:focus-within ~ .floating-label,
    /* Or when it has a value (placeholder not shown) */
    .responsive-form-floating .cdp-wrapper:has(.cdp-text:not(:placeholder-shown)) ~ .floating-label {
        opacity: 0.65;
        transform: scale(0.85) translateY(-0.5rem) translateX(0.15rem);
    }

    /* Hide the text input's placeholder so it doesn't overlap the floating label at rest */
    .responsive-form-floating .cdp-wrapper .cdp-text::placeholder {
        color: transparent !important;
    }
}

/* Mobile: full-width popup, slightly larger tap targets */
@media (max-width: 480px) {
    .cdp-popup {
        min-width: 260px;
        max-width: 100vw;
        font-size: 0.95rem;
    }
    .cdp-day {
        font-size: 0.9rem;
    }
    .cdp-header .cdp-nav {
        width: 2.25rem;
        height: 2.25rem;
    }
}
