.custom-date {
    position: relative;
    width: 100%;
    min-width: 0;
}

.custom-date-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-width: 1px !important;
    min-height: 1px !important;
    margin: 0 !important;
    padding: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
}

.custom-date-trigger {
    position: relative;
    width: 100%;
    min-width: 0;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 38px 9px 11px;
    border: 1px solid var(--control-line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    line-height: 1.45;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.custom-date-trigger:hover { border-color: var(--focus); }
.custom-date.is-open .custom-date-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-shadow);
}
.custom-date-trigger:disabled { cursor: default; opacity: .6; }

.custom-date-value {
    display: block;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.custom-date-value.is-placeholder { color: var(--muted); }

.custom-date-icon {
    position: absolute;
    right: 13px;
    top: 50%;
    width: 15px;
    height: 14px;
    margin-top: -7px;
    border: 1.5px solid var(--muted);
    border-radius: 3px;
    pointer-events: none;
}
.custom-date-icon::before {
    content: "";
    position: absolute;
    left: 2px;
    right: 2px;
    top: 4px;
    border-top: 1.5px solid var(--muted);
}
.custom-date-icon::after {
    content: "";
    position: absolute;
    left: 3px;
    top: -3px;
    width: 7px;
    height: 4px;
    border-left: 1.5px solid var(--muted);
    border-right: 1.5px solid var(--muted);
}
.custom-date.is-open .custom-date-icon,
.custom-date.is-open .custom-date-icon::before,
.custom-date.is-open .custom-date-icon::after { border-color: var(--accent-dark); }

.custom-date-panel {
    position: absolute;
    z-index: 130;
    top: calc(100% + 8px);
    left: 0;
    width: 320px;
    max-width: min(320px, calc(100vw - 32px));
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 18px 44px rgba(12, 24, 38, .18);
}
.custom-date.opens-up .custom-date-panel { top: auto; bottom: calc(100% + 8px); }
.custom-date.align-right .custom-date-panel { left: auto; right: 0; }

.custom-date-header {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 36px;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.custom-date-title {
    min-width: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 800;
    text-align: center;
    text-transform: capitalize;
}
.custom-date-nav {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.custom-date-nav span { font-size: 26px; line-height: 1; transform: translateY(-1px); }
.custom-date-nav:hover {
    border-color: var(--line);
    background: var(--surface-alt);
    color: var(--accent-dark);
}
.custom-date-nav:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.custom-date-weekdays,
.custom-date-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 3px;
}
.custom-date-weekdays { margin-bottom: 4px; }
.custom-date-weekdays span {
    display: grid;
    place-items: center;
    min-height: 28px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.custom-date-day {
    aspect-ratio: 1 / 1;
    min-width: 0;
    min-height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.custom-date-day:hover:not(:disabled),
.custom-date-day:focus-visible:not(:disabled) {
    background: var(--surface-alt);
    border-color: var(--line);
    outline: 0;
}
.custom-date-day.is-outside { color: var(--muted); opacity: .55; }
.custom-date-day.is-today:not(.is-selected) {
    border-color: var(--focus);
    color: var(--accent-dark);
}
.custom-date-day.is-selected,
.custom-date-day.is-selected:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 800;
}
.custom-date-day:disabled {
    color: var(--muted);
    opacity: .28;
    cursor: default;
}

.custom-date-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}
.custom-date-footer-action {
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--accent-dark);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 750;
    transition: background .12s ease, border-color .12s ease;
}
.custom-date-footer-action:hover:not(:disabled) {
    border-color: var(--line);
    background: var(--accent-soft);
}
.custom-date-footer-action:disabled { color: var(--muted); opacity: .45; cursor: default; }
.custom-date-footer-action:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* В карточках редактирования календарь становится частью самого поля. */
.card-form .field .custom-date-trigger {
    min-height: 26px;
    padding: 2px 30px 0 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}
.card-form .field .custom-date-trigger:hover,
.card-form .field .custom-date.is-open .custom-date-trigger {
    border: 0;
    background: transparent;
    box-shadow: none;
}
.card-form .field .custom-date-trigger:focus-visible { outline: 0; }
.card-form .field .custom-date-icon { right: 4px; }

@media (max-width: 620px) {
    .custom-date-panel {
        width: min(320px, calc(100vw - 28px));
        max-width: calc(100vw - 28px);
        padding: 10px;
    }
    .custom-date-trigger,
    .custom-date-day { font-size: 16px; }
    .custom-date-weekdays span,
    .custom-date-footer-action { font-size: 13px; }
    .card-form .field .custom-date-trigger { font-size: 16px; }
}
