﻿/* ============================================================
   Custom Datepicker — haverkamp design system
   Dark default + :root[data-theme='light'] overrides
   Brand vars: --brand-500 (indigo dark / blue light)
   ============================================================ */

/* ── Wrapper ──────────────────────────────────────────────── */
.dp-wrapper {
    position: relative;
}

/* ── Input row ────────────────────────────────────────────── */
.dp-input-wrap {
    position: relative;
}

.dp-display {
    cursor: pointer;
    padding-right: 2.75rem !important;
    caret-color: transparent;
    user-select: none;
}

.dp-trigger {
    position: absolute;
    right: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(148, 163, 184, 0.6);
    padding: 0.2rem;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    transition: color 0.2s ease;
}

.dp-trigger:hover {
    color: var(--brand-500);
}

:root[data-theme='light'] .dp-trigger {
    color: #94a3b8;
}

:root[data-theme='light'] .dp-trigger:hover {
    color: var(--brand-500);
}

/* ── Popup ────────────────────────────────────────────────── */
.dp-popup {
    /* position:fixed escapes any backdrop-filter stacking context */
    position: fixed;
    top: 0;   /* overridden by JS _reposition() */
    left: 0;  /* overridden by JS _reposition() */
    z-index: 9999;
    width: 320px;
    padding: 0.9rem;
    background: rgba(13, 18, 32, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    box-shadow:
        0 28px 64px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    animation: dpSlideIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.dp-popup--up {
    /* positioning handled by JS; keep slide-up animation */
    animation: dpSlideUp 0.18s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes dpSlideIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.972); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

@keyframes dpSlideUp {
    from { opacity: 0; transform: translateY(8px)  scale(0.972); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

:root[data-theme='light'] .dp-popup {
    background: rgba(255, 255, 255, 0.99);
    border-color: rgba(148, 163, 184, 0.2);
    box-shadow:
        0 12px 40px rgba(15, 23, 42, 0.14),
        0 0 0 1px rgba(148, 163, 184, 0.06);
    backdrop-filter: blur(8px);
}

/* ── Header ───────────────────────────────────────────────── */
.dp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.55rem;
    margin-bottom: 0.35rem;
}

.dp-period-controls {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 6rem;
    gap: 0.45rem;
    align-items: stretch;
}

.dp-period-menu-wrap {
    position: relative;
}

.dp-select {
    appearance: none;
    min-width: 0;
    min-height: 2.25rem;
    padding: 0.42rem 2.2rem 0.42rem 0.9rem;
    border: 1px solid rgba(129, 140, 248, 0.14);
    border-radius: 0.7rem;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.04) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%23cbd5e1' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.72rem center / 0.9rem,
        rgba(15, 23, 42, 0.82);
    color: #f1f5f9;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 10px 22px -16px rgba(15, 23, 42, 0.95);
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.dp-period-trigger {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
}

.dp-period-trigger-label {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dp-period-trigger.is-open {
    border-color: rgba(129, 140, 248, 0.38);
    background:
        linear-gradient(180deg, rgba(129, 140, 248, 0.22) 0%, rgba(99, 102, 241, 0.12) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 12.5L10 7.5L15 12.5' stroke='%23e0e7ff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.72rem center / 0.9rem,
        rgba(30, 41, 59, 0.96);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 16px 32px -22px rgba(99, 102, 241, 0.65);
}

.dp-period-menu {
    position: absolute;
    top: calc(100% + 0.45rem);
    left: 0;
    z-index: 20;
    width: 100%;
    max-height: 15.5rem;
    padding: 0.35rem;
    overflow-y: auto;
    border: 1px solid rgba(129, 140, 248, 0.18);
    border-radius: 0.9rem;
    background: rgba(7, 12, 24, 0.98);
    box-shadow:
        0 22px 44px -24px rgba(2, 6, 23, 0.9),
        0 0 0 1px rgba(255, 255, 255, 0.04);
}

.dp-period-option {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 2.2rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid transparent;
    border-radius: 0.7rem;
    background: transparent;
    color: #cbd5e1;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.dp-period-option:hover,
.dp-period-option:focus-visible {
    outline: none;
    border-color: rgba(129, 140, 248, 0.22);
    background: rgba(99, 102, 241, 0.14);
    color: #f8fafc;
}

.dp-period-option--selected {
    border-color: rgba(129, 140, 248, 0.3);
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.34) 0%, rgba(79, 70, 229, 0.22) 100%);
    color: #ffffff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.dp-period-option:disabled {
    opacity: 0.34;
    cursor: not-allowed;
}

.dp-select:hover {
    border-color: rgba(129, 140, 248, 0.3);
    background:
        linear-gradient(180deg, rgba(129, 140, 248, 0.18) 0%, rgba(99, 102, 241, 0.1) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%23e0e7ff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.72rem center / 0.9rem,
        rgba(30, 41, 59, 0.92);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 14px 28px -20px rgba(99, 102, 241, 0.65);
}

.dp-select:focus-visible,
.dp-nav:focus-visible,
.dp-day:focus-visible,
.dp-clear:focus-visible,
.dp-today:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.26);
}

.dp-helper {
    margin: 0 0 0.75rem;
    color: rgba(148, 163, 184, 0.84);
    font-size: 0.72rem;
    line-height: 1.45;
}

.dp-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.dp-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    font-size: 0.68rem;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.dp-nav:hover {
    background: rgba(129, 140, 248, 0.15);
    border-color: rgba(129, 140, 248, 0.28);
    color: #a5b4fc;
}

.dp-nav:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.05);
    color: rgba(148, 163, 184, 0.5);
}

:root[data-theme='light'] .dp-nav {
    background: rgba(248, 250, 252, 0.9);
    border-color: rgba(148, 163, 184, 0.2);
    color: #64748b;
}

:root[data-theme='light'] .dp-nav:hover {
    background: rgba(37, 99, 235, 0.07);
    border-color: rgba(37, 99, 235, 0.2);
    color: #2563eb;
}

:root[data-theme='light'] .dp-nav:disabled {
    background: rgba(248, 250, 252, 0.72);
    border-color: rgba(148, 163, 184, 0.12);
    color: rgba(100, 116, 139, 0.56);
}

:root[data-theme='light'] .dp-select {
    border-color: rgba(37, 99, 235, 0.14);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.96) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%23475569' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.72rem center / 0.9rem,
        rgba(248, 250, 252, 0.94);
    color: #0f172a;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.92),
        0 10px 24px -18px rgba(15, 23, 42, 0.18);
}

:root[data-theme='light'] .dp-period-trigger.is-open {
    border-color: rgba(37, 99, 235, 0.26);
    background:
        linear-gradient(180deg, rgba(219, 234, 254, 0.98) 0%, rgba(239, 246, 255, 0.98) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 12.5L10 7.5L15 12.5' stroke='%231d4ed8' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.72rem center / 0.9rem,
        rgba(255, 255, 255, 0.98);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.96),
        0 16px 32px -24px rgba(37, 99, 235, 0.28);
}

:root[data-theme='light'] .dp-select:hover {
    border-color: rgba(37, 99, 235, 0.24);
    background:
        linear-gradient(180deg, rgba(219, 234, 254, 0.96) 0%, rgba(239, 246, 255, 0.98) 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%231d4ed8' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.72rem center / 0.9rem,
        rgba(37, 99, 235, 0.07);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.96),
        0 14px 28px -22px rgba(37, 99, 235, 0.28);
}

:root[data-theme='light'] .dp-period-menu {
    border-color: rgba(37, 99, 235, 0.16);
    background: rgba(255, 255, 255, 0.99);
    box-shadow:
        0 22px 44px -26px rgba(15, 23, 42, 0.2),
        0 0 0 1px rgba(148, 163, 184, 0.06);
}

:root[data-theme='light'] .dp-period-option {
    color: #334155;
}

:root[data-theme='light'] .dp-period-option:hover,
:root[data-theme='light'] .dp-period-option:focus-visible {
    border-color: rgba(37, 99, 235, 0.16);
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
}

:root[data-theme='light'] .dp-period-option--selected {
    border-color: rgba(37, 99, 235, 0.22);
    background: linear-gradient(180deg, rgba(219, 234, 254, 0.98) 0%, rgba(191, 219, 254, 0.88) 100%);
    color: #1d4ed8;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

:root[data-theme='light'] .dp-select:focus-visible,
:root[data-theme='light'] .dp-nav:focus-visible,
:root[data-theme='light'] .dp-day:focus-visible,
:root[data-theme='light'] .dp-clear:focus-visible,
:root[data-theme='light'] .dp-today:focus-visible {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

:root[data-theme='light'] .dp-helper {
    color: rgba(100, 116, 139, 0.88);
}

/* ── Weekday labels ───────────────────────────────────────── */
.dp-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    margin-bottom: 0.15rem;
}

.dp-weekdays span {
    text-align: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: #475569;
    padding: 0.12rem 0;
    letter-spacing: 0.02em;
}

:root[data-theme='light'] .dp-weekdays span {
    color: #94a3b8;
}

/* ── Day grid ─────────────────────────────────────────────── */
.dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
}

.dp-day {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 0.4rem;
    background: none;
    color: #cbd5e1;
    font-size: 0.79rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
    line-height: 1;
}

button.dp-day:hover {
    background: rgba(129, 140, 248, 0.15);
    border-color: rgba(129, 140, 248, 0.18);
    color: #e0e7ff;
}

.dp-day--outside {
    color: rgba(100, 116, 139, 0.38);
}

button.dp-day--outside:hover {
    color: #64748b;
}

.dp-day--today {
    border-color: rgba(129, 140, 248, 0.55) !important;
    color: #a5b4fc;
    font-weight: 700;
}

.dp-day--selected {
    background: rgba(99, 102, 241, 0.88) !important;
    color: #ffffff !important;
    border-color: transparent !important;
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.38);
}

.dp-day--focused:not(.dp-day--selected) {
    border-color: rgba(129, 140, 248, 0.45);
    background: rgba(129, 140, 248, 0.12);
    color: #e2e8f0;
}

.dp-day--disabled {
    color: rgba(100, 116, 139, 0.22);
    cursor: not-allowed;
    pointer-events: none;
}

/* Light theme day grid */
:root[data-theme='light'] .dp-day {
    color: #334155;
}

:root[data-theme='light'] button.dp-day:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.14);
    color: #1d4ed8;
}

:root[data-theme='light'] .dp-day--outside {
    color: rgba(148, 163, 184, 0.48);
}

:root[data-theme='light'] button.dp-day--outside:hover {
    color: #94a3b8;
}

:root[data-theme='light'] .dp-day--today {
    border-color: rgba(37, 99, 235, 0.5) !important;
    color: #2563eb;
}

:root[data-theme='light'] .dp-day--selected {
    background: rgba(37, 99, 235, 0.88) !important;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.25);
}

:root[data-theme='light'] .dp-day--focused:not(.dp-day--selected) {
    border-color: rgba(37, 99, 235, 0.28);
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
}

:root[data-theme='light'] .dp-day--disabled {
    color: rgba(148, 163, 184, 0.32);
}

/* ── Year grid ────────────────────────────────────────────── */
.dp-grid--years {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.dp-year {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.42rem 0.2rem;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.04);
    color: #94a3b8;
    font-size: 0.76rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}

.dp-year:hover {
    background: rgba(129, 140, 248, 0.14);
    border-color: rgba(129, 140, 248, 0.22);
    color: #e0e7ff;
}

.dp-year--current {
    border-color: rgba(129, 140, 248, 0.42);
    color: #a5b4fc;
}

.dp-year--selected {
    background: rgba(99, 102, 241, 0.82) !important;
    color: #fff !important;
    border-color: transparent !important;
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.3);
}

:root[data-theme='light'] .dp-year {
    background: rgba(248, 250, 252, 0.9);
    border-color: rgba(148, 163, 184, 0.18);
    color: #475569;
}

:root[data-theme='light'] .dp-year:hover {
    background: rgba(37, 99, 235, 0.07);
    border-color: rgba(37, 99, 235, 0.18);
    color: #1d4ed8;
}

:root[data-theme='light'] .dp-year--current {
    border-color: rgba(37, 99, 235, 0.36);
    color: #2563eb;
}

:root[data-theme='light'] .dp-year--selected {
    background: rgba(37, 99, 235, 0.84) !important;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.22);
}

/* ── Footer ───────────────────────────────────────────────── */
.dp-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.65rem;
    padding-top: 0.6rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

:root[data-theme='light'] .dp-footer {
    border-top-color: rgba(148, 163, 184, 0.15);
}

.dp-clear,
.dp-today {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.28rem 0.5rem;
    border-radius: 0.35rem;
    cursor: pointer;
    transition: background 0.13s ease, color 0.13s ease;
}

.dp-clear {
    color: #64748b;
}

.dp-clear:hover {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.1);
}

.dp-today {
    color: #818cf8;
}

.dp-today:hover {
    color: #e0e7ff;
    background: rgba(129, 140, 248, 0.13);
}

:root[data-theme='light'] .dp-clear {
    color: #94a3b8;
}

:root[data-theme='light'] .dp-clear:hover {
    color: #dc2626;
    background: rgba(239, 68, 68, 0.08);
}

:root[data-theme='light'] .dp-today {
    color: #2563eb;
}

:root[data-theme='light'] .dp-today:hover {
    color: #1d4ed8;
    background: rgba(37, 99, 235, 0.08);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 360px) {
    .dp-popup {
        width: calc(100vw - 2rem);
        left: 50%;
        transform: translateX(-50%);
    }

    .dp-period-controls {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dp-popup {
        animation: none !important;
    }

    .dp-day,
    .dp-year,
    .dp-nav,
    .dp-select,
    .dp-trigger {
        transition: none !important;
    }
}
