input[type="date"].custom-datepicker,
input[type="datetime-local"].custom-datepicker {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.custom-datepicker-wrapper {
    position: relative;
    width: 100%;
    max-width: 240px;
}

.input-with-lock .custom-datepicker-wrapper {
    max-width: none;
}

.auth-form .custom-datepicker-wrapper {
    max-width: none;
}

.custom-datepicker-trigger {
    display: flex;
    align-items: center;
    width: 100%;
    height: 48px;
    padding: 12px 40px 12px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 1rem;
    line-height: 1;
    color: var(--text-main);
    background: var(--white);
    cursor: text;
    text-align: left;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
}

.custom-datepicker-trigger:hover {
    border-color: var(--text-muted);
}

.custom-datepicker-trigger:focus-within {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background: var(--card-bg);
}

.custom-datepicker-trigger.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-datepicker-trigger.is-invalid {
    border-color: var(--error);
}

.custom-datepicker-trigger.is-invalid:focus-within {
    border-color: var(--error);
}

.custom-datepicker-error {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 5;
    font-size: 0.75rem;
    color: var(--error);
    pointer-events: none;
}

.custom-datepicker-trigger.is-disabled .custom-datepicker-arrow-btn,
.custom-datepicker-trigger.is-disabled .custom-datepicker-input {
    pointer-events: none;
    cursor: not-allowed;
}

.custom-datepicker-trigger .custom-datepicker-input,
.custom-datepicker-trigger .custom-datepicker-input:focus,
.custom-datepicker-trigger .custom-datepicker-input:focus-visible {
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 0;
    background-color: transparent !important;
    box-shadow: none;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    color: var(--text-main);
    caret-color: var(--text-main);
    -webkit-text-fill-color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] .custom-datepicker-trigger .custom-datepicker-input,
[data-theme="dark"] .custom-datepicker-trigger .custom-datepicker-input:focus,
[data-theme="dark"] .custom-datepicker-trigger .custom-datepicker-input:focus-visible {
    color: var(--text-main);
    caret-color: var(--text-main);
    -webkit-text-fill-color: var(--text-main);
}

.custom-datepicker-trigger .custom-datepicker-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.custom-datepicker-trigger .custom-datepicker-input::selection,
.custom-datepicker-trigger .custom-datepicker-input::-moz-selection {
    background: rgba(59, 130, 246, 0.18);
    color: var(--text-main);
}

.custom-datepicker-trigger .custom-datepicker-input:-webkit-autofill,
.custom-datepicker-trigger .custom-datepicker-input:-webkit-autofill:hover,
.custom-datepicker-trigger .custom-datepicker-input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--white) inset;
    -webkit-text-fill-color: var(--text-main);
    caret-color: var(--text-main);
    transition: background-color 9999s ease-out;
}

[data-theme="dark"] .custom-datepicker-trigger .custom-datepicker-input:-webkit-autofill,
[data-theme="dark"] .custom-datepicker-trigger .custom-datepicker-input:-webkit-autofill:hover,
[data-theme="dark"] .custom-datepicker-trigger .custom-datepicker-input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #0f0f0f inset;
}

.custom-datepicker-time {
    flex-shrink: 0;
    margin-left: 8px;
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.custom-datepicker-arrow-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.custom-datepicker-arrow-btn:focus,
.custom-datepicker-arrow-btn:focus-visible {
    outline: none;
}

.custom-datepicker-arrow-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-main);
}

.custom-datepicker-arrow {
    width: 16px;
    height: 16px;
    pointer-events: none;
    transition: transform 0.2s ease;
}

.custom-datepicker-trigger[aria-expanded="true"] .custom-datepicker-arrow {
    transform: rotate(180deg);
}

.custom-datepicker-panel {
    position: fixed;
    z-index: var(--z-picker, 20000);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 14px;
    display: none;
    box-sizing: border-box;
}

.custom-datepicker-panel:focus {
    outline: none;
}

@keyframes csReveal {
    0% {
        opacity: 0;
        transform: scaleY(0.85);
    }

    100% {
        opacity: 1;
        transform: scaleY(1);
    }
}

@keyframes csHide {
    0% {
        opacity: 1;
        transform: scaleY(1);
    }

    100% {
        opacity: 0;
        transform: scaleY(0.85);
    }
}

.custom-datepicker-panel.visible {
    animation: csReveal 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.custom-datepicker-panel.closing {
    animation: csHide 0.13s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.cal-nav {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: background 0.15s, color 0.15s;
}

.cal-nav:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-main);
}

.cal-nav:active {
    background: rgba(0, 0, 0, 0.08);
}

.cal-month-year {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.cal-title-btn {
    border: none;
    background: transparent;
    padding: 2px 10px;
    border-radius: 6px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.15s;
}

.cal-title-btn:hover {
    background: rgba(0, 0, 0, 0.04);
}

.cal-title-btn:active {
    background: rgba(0, 0, 0, 0.08);
}

.cal-day-names {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 6px;
}

.cal-day-name {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 4px 0;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

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

.cal-day {
    text-align: center;
    padding: 6px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    transition: background 0.1s;
    user-select: none;
    -webkit-user-select: none;
}

.cal-day:hover {
    background: rgba(0, 0, 0, 0.04);
}

.cal-day:active {
    background: rgba(0, 0, 0, 0.08);
}

.cal-day.cal-day-weekend {
    color: rgba(220, 38, 38, 0.75);
}

.cal-day.cal-day-today {
    font-weight: 700;
    color: var(--primary);
    position: relative;
}

.cal-day.cal-day-today::after {
    content: '';
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 2px;
    border-radius: 1px;
    background: var(--primary);
}

.cal-day.cal-day-selected {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.cal-day.cal-day-selected:hover {
    background: var(--primary);
}

.cal-day.cal-day-selected::after {
    display: none;
}

.cal-day.cal-day-focused {
    box-shadow: inset 0 0 0 2px var(--primary);
}

.cal-day.cal-day-other {
    color: var(--text-muted);
    opacity: 0.45;
}

.cal-day.cal-day-other:hover {
    opacity: 0.75;
}

.cal-day.cal-day-other.cal-day-weekend {
    color: rgba(220, 38, 38, 0.4);
}

.cal-day.cal-day-disabled {
    color: var(--text-muted);
    opacity: 0.35;
    pointer-events: none;
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.cal-cell {
    text-align: center;
    padding: 10px 4px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.1s;
}

.cal-cell:hover {
    background: rgba(0, 0, 0, 0.04);
}

.cal-cell:active {
    background: rgba(0, 0, 0, 0.08);
}

.cal-cell.cal-cell-selected {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.cal-cell.cal-cell-selected:hover {
    background: var(--primary);
}

.cal-cell.cal-cell-focused {
    box-shadow: inset 0 0 0 2px var(--primary);
}

.cal-days-grid.slide-out-left {
    animation: slideOutLeft 0.15s ease both;
}

.cal-days-grid.slide-out-right {
    animation: slideOutRight 0.15s ease both;
}

.cal-days-grid.slide-in-left {
    animation: slideInLeft 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.cal-days-grid.slide-in-right {
    animation: slideInRight 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.cal-footer {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.cal-btn {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: var(--font-main);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-align: center;
}

.cal-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.cal-btn:active {
    background: rgba(0, 0, 0, 0.08);
}

.cal-time {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.cal-time select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--light);
    color: var(--text-main);
    font-size: 0.85rem;
    font-family: var(--font-main);
    cursor: pointer;
    text-align: center;
    -moz-appearance: textfield;
    transition: border-color 0.15s;
}

.cal-time select:hover {
    border-color: var(--text-muted);
}

.cal-time select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.cal-time-sep {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    flex-shrink: 0;
}

[data-theme="dark"] .custom-datepicker-trigger {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .custom-datepicker-trigger:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .custom-datepicker-trigger:focus-within {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

[data-theme="dark"] .custom-datepicker-arrow-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .custom-datepicker-time {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .cal-nav:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .cal-nav:active {
    background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .cal-title-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .cal-title-btn:active {
    background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .cal-day:hover {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .cal-day:active {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .cal-day.cal-day-weekend {
    color: rgba(248, 113, 113, 0.8);
}

[data-theme="dark"] .cal-day.cal-day-other.cal-day-weekend {
    color: rgba(248, 113, 113, 0.45);
}

[data-theme="dark"] .cal-day.cal-day-selected {
    background: var(--primary);
}

[data-theme="dark"] .cal-cell:hover {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .cal-cell:active {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .cal-cell.cal-cell-selected {
    background: var(--primary);
}

[data-theme="dark"] .cal-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .cal-btn:active {
    background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .cal-time select {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .cal-time select:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .cal-time select:focus {
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.input-with-lock .custom-datepicker-trigger {
    padding-right: 40px;
}

.custom-datepicker-trigger.is-disabled .custom-datepicker-arrow-btn {
    display: none;
}

.profile-field .custom-datepicker-wrapper {
    max-width: none;
}

#add-modal .custom-datepicker-wrapper,
#edit-modal .custom-datepicker-wrapper {
    max-width: none;
}

.auth-form .custom-datepicker-wrapper:has(.custom-datepicker-trigger.is-invalid) + .field-hint {
    margin-top: 22px;
}

@keyframes slideOutLeft {
    to { transform: translateX(-28px); opacity: 0; }
}

@keyframes slideOutRight {
    to { transform: translateX(28px); opacity: 0; }
}

@keyframes slideInLeft {
    from { transform: translateX(28px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(-28px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .custom-datepicker-panel.visible,
    .custom-datepicker-panel.closing,
    .cal-days-grid.slide-out-left,
    .cal-days-grid.slide-out-right,
    .cal-days-grid.slide-in-left,
    .cal-days-grid.slide-in-right {
        animation: none;
    }
}
