/* Календарь в хедере. Фон сайта снаружи; сам календарь — в рамочке. Не sticky. */

.calendar-bar {
    display: none;
    position: sticky;
    top: var(--calendar-sticky-top, 52px);
    z-index: 8500;
    flex: 0 0 auto;
    height: auto;
    min-height: 52px;
    width: auto;
    max-width: none;
    align-items: flex-end;
    gap: 6px;
    /* боковые отступы снаружи рамочки */
    margin: 0 clamp(100px, 8vw, 150px);
    padding: 8px 8px;
    background: var(--calendar-bg, transparent);
    border: none;
    border-radius: 8px;
    box-sizing: border-box;
}

.calendar-bar__days {
    flex: 1 1 auto;
    display: flex;
    align-self: flex-end;
    align-items: stretch;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    min-width: 0;
    gap: 6px;
    overflow: hidden;
    position: relative;
}

.calendar-bar__days-track {
    display: flex;
    flex-wrap: nowrap;
    height: 100%;
}

.calendar-bar__days-page {
    display: flex;
    align-items: stretch;
    gap: 6px;
    min-width: 0;
    height: 100%;
    box-sizing: border-box;
}

.calendar-bar__days-page > .calendar-bar__day {
    flex: 1 1 0;
}

.calendar-bar__today,
.calendar-bar__day,
.calendar-bar__arrow {
    border: none;
    background: transparent;
    color: var(--title-text, #1a6b6d);
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    min-width: 0;
}

.calendar-bar__today {
    flex: 0 0 auto;
    min-width: 118px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 4px;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    box-sizing: border-box;
    line-height: 1;
    position: relative;
    border-radius: 6px;
    border: 1.5px solid rgba(26, 107, 109, 0.7);
    background-color: rgba(255, 255, 255, 0.62);
}

.calendar-bar__today-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    line-height: 1;
}

.calendar-bar__today-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
    color: #1a6b6d;
}

.calendar-bar__today-num {
    font-size: calc(var(--calendar-font-size, 10px) + 2px);
    font-weight: 600;
    line-height: 1;
    margin: 0;
    color: #929191;
}

.calendar-bar__today-wd {
    font-size: 11px;
    font-weight: 600;
    margin-top: 0;
    padding-left: 2px;
    opacity: 1;
    color: #7a7a7a;
}

.calendar-bar__arrow {
    flex: 0 0 22px;
    height: 36px;
    font-size: 18px;
    line-height: 1;
    border-radius: 6px;
    color: var(--title-text, #1a6b6d);
}

.calendar-bar__arrow:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.45);
}

.calendar-bar__arrow:disabled {
    opacity: 0.28;
    cursor: default;
}

.calendar-bar__arrow[hidden] {
    display: none;
}

.calendar-bar__day {
    flex: 1 1 0;
    align-self: stretch;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border-radius: 5px;
    position: relative;
    padding: 0;
    background-color: transparent;
}

.calendar-bar__day-num {
    font-size: var(--calendar-font-size, 10px);
    font-weight: 700;
    color: #929191;
}

.calendar-bar__day--weekend .calendar-bar__day-num,
.calendar-bar__today--weekend .calendar-bar__today-num {
    color: #d48a8a;
}

.calendar-bar__cell--dark.calendar-bar__day--weekend .calendar-bar__day-num,
.calendar-bar__cell--dark.calendar-bar__today--weekend .calendar-bar__today-num {
    color: #f4bdbd;
}

.calendar-bar__day-wd {
    font-size: 8px;
    font-weight: 600;
    margin-top: 3px;
    color: #929191;
    opacity: 1;
}

.calendar-bar__day:hover,
.calendar-bar__today:hover {
    filter: brightness(0.96);
}

.calendar-bar__day--note,
.calendar-bar__today--note {
    background-color: #ffffff;
    border-radius: 5px;
}

.calendar-bar__important-dot {
    position: absolute;
    left: 2px;
    bottom: 2px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #e53935;
    box-shadow: 0 0 0 1px #fff;
    pointer-events: none;
}

.calendar-note__heading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Строка «Заголовок»: −5px сверху и снизу (−10px суммарно) */
#calendarNoteForm .add-text-form__head .add-text-form__input,
#calendarNoteForm .add-text-form__head .add-text-form__file-btn {
    padding-top: 10px;
    padding-bottom: 10px;
}

/* Строка почты: −5px сверху и снизу (−10px суммарно) */
#calendarNoteForm .calendar-note__notify .add-text-form__input {
    padding-top: 10px;
    padding-bottom: 10px;
}

.calendar-note__emails {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.calendar-note__email-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.calendar-note__email-row .calendar-note__email-input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.calendar-note__email-add {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: #ffffff;
    color: #1a6b6d;
    font-size: 22px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.calendar-note__email-add:hover {
    background: #f5f5f5;
    border-color: #1a6b6d;
    color: #155859;
}

.calendar-note__email-add:disabled,
.calendar-note__email-add[hidden] {
    display: none;
}

/* Поле «Введите текст»: +20px по высоте по умолчанию */
#calendarNoteForm #calendarNoteContent.add-text-form__textarea {
    min-height: 180px;
    height: 180px;
}

/* +6px от почты до «Сохранить» */
#calendarNoteForm .calendar-note__notify {
    margin-bottom: 6px;
}

#calendarNoteForm .add-text-form__submit {
    margin-top: 0;
}

.calendar-note__date {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid rgba(0, 0, 0, 0.28);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    background: rgba(255, 255, 255, 0.55);
}

.calendar-bar__day--note {
    box-shadow: none;
}

/* Сегодня есть дело — статичный фон, без бесконечной анимации (она держала GPU). */
.calendar-bar__today--due {
    background-color: rgba(255, 255, 255, 0.88);
}

.calendar-bar__day--note .calendar-bar__day-num,
.calendar-bar__today--note .calendar-bar__today-num,
.calendar-bar__day--note .calendar-bar__day-wd,
.calendar-bar__today--note .calendar-bar__today-wd {
    text-shadow: none;
}

.calendar-bar__cell--dark .calendar-bar__day-wd,
.calendar-bar__cell--dark .calendar-bar__today-wd {
    color: rgba(255, 255, 255, 0.75);
}

.calendar-bar__tip {
    position: absolute;
    z-index: 2;
    width: max-content;
    max-width: 300px;
    max-height: 500px;
    overflow: auto;
    padding: 8px 10px;
    border-radius: 8px;
    background: #fffef8;
    color: #333;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    font-size: 12px;
    line-height: 1.35;
    text-align: left;
    pointer-events: auto;
    white-space: pre-wrap;
    word-break: break-word;
    cursor: pointer;
}

.calendar-bar__tip:hover {
    background: #fff8e8;
}

/* Подсказка без заметки — чуть прозрачнее (~80%) */
.calendar-bar__tip--hint {
    opacity: 0.8;
}

/* Подсказка с заметкой — полностью непрозрачная */
.calendar-bar__tip--note {
    min-width: 250px;
    opacity: 1;
}

/* Невидимый мост: по нему мышь доезжает от дня до подсказки */
.calendar-bar__tip::before {
    content: '';
    position: absolute;
    left: -12px;
    right: -12px;
    top: -18px;
    height: 18px;
    pointer-events: auto;
}

.calendar-bar__tip[hidden] {
    display: none;
}

.calendar-bar__tip-date {
    font-weight: 700;
    margin-bottom: 2px;
}

.calendar-bar__tip-hint {
    font-weight: 600;
    color: #1a6b6d;
}

.calendar-bar__tip-title {
    font-weight: 700;
    margin-top: 6px;
    margin-bottom: 4px;
}

/* Цвет заметки в модалке: пульсирующая точка вместо иконки */
.calendar-note__color {
    position: relative;
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    min-width: 0;
}

.calendar-note__dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8);
    animation: calendar-dot-pulse 1.6s ease-out infinite;
    flex-shrink: 0;
    margin-right: auto;
}

@keyframes calendar-dot-pulse {
    0% { box-shadow: 0 0 0 0 rgba(26, 107, 109, 0.45); }
    70% { box-shadow: 0 0 0 12px rgba(26, 107, 109, 0); }
    100% { box-shadow: 0 0 0 0 rgba(26, 107, 109, 0); }
}

.calendar-note__palette {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 168px;
    padding: 8px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.calendar-note__palette[hidden] {
    display: none;
}

.calendar-note__swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    padding: 0;
    cursor: pointer;
}

.calendar-note__swatch.is-active {
    outline: 2px solid #1a6b6d;
    outline-offset: 2px;
}

#calendarNoteForm .add-text-form__head,
#calendarNoteForm .calendar-note__notify,
#calendarNoteForm .add-text-form__tools,
#calendarNoteForm .text-note-editor,
#calendarNoteForm .add-text-form__meta,
#calendarNoteForm .add-text-form__submit,
#calendarNoteForm .edit-text-form__delete {
    grid-row: auto;
    grid-column: 1 / -1;
}

.calendar-note__notify {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: start;
    min-width: 0;
}

.calendar-note__notify-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.calendar-note__notify-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    user-select: none;
    min-width: 0;
}

.calendar-note__notify-check input {
    width: 24px;
    height: 24px;
    margin: 0;
    accent-color: #1a6b6d;
    cursor: pointer;
    flex-shrink: 0;
}

.calendar-note__notify-label {
    line-height: 1.25;
}

.calendar-note__notify-time-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.calendar-note__notify-time {
    width: auto;
    min-width: 5.6em;
    height: 34px;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-dark);
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    line-height: 1;
    box-sizing: border-box;
    cursor: pointer;
    appearance: auto;
}

.calendar-note__notify-time:focus {
    outline: none;
    border-color: #1a6b6d;
    box-shadow: 0 0 0 2px rgba(26, 107, 109, 0.18);
}

/* Дата рядом со временем — только десктоп (≥881px) */
.calendar-note__notify-when {
    display: none;
    font-weight: 400;
    color: #6a6a6a;
    white-space: nowrap;
    font-size: 13px;
}

.calendar-note__notify-info-wrap {
    display: none;
    position: relative;
    flex-shrink: 0;
}

.calendar-note__notify-info {
    display: inline-flex;
    position: relative;
    z-index: 1;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid #1a6b6d;
    border-radius: 50%;
    background: #1a6b6d;
    color: #fff;
    cursor: help;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.calendar-note__notify-info-mark {
    font-size: 13px;
    font-weight: 800;
    font-style: italic;
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1;
    transform: translateY(-0.5px);
    pointer-events: none;
}

.calendar-note__notify-tip {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 30;
    width: min(320px, 70vw);
    padding: 10px 12px;
    border-radius: 8px;
    background: #1a2a2b;
    color: #f5f7f7;
    font-size: 12px;
    font-weight: 400;
    font-style: normal;
    line-height: 1.4;
    text-align: left;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    user-select: text;
    cursor: text;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
}

/* Мост между кнопкой i и подсказкой — мышь не «проваливается» в зазор */
.calendar-note__notify-tip::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 12px;
}

.calendar-note__notify-tip::after {
    content: '';
    position: absolute;
    bottom: 100%;
    right: 8px;
    border: 6px solid transparent;
    border-bottom-color: #1a2a2b;
}

.calendar-note__notify-email {
    display: inline;
    padding: 1px 4px;
    border-radius: 3px;
    background: #ffe566;
    color: #1a1a1a;
    font-weight: 700;
    user-select: text;
}

.calendar-note__notify-info-wrap:hover .calendar-note__notify-tip,
.calendar-note__notify-info:focus-visible + .calendar-note__notify-tip,
.calendar-note__notify-tip:hover {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

@media (min-width: 881px) {
    .calendar-note__notify {
        grid-template-columns: minmax(160px, 1fr) auto;
        align-items: start;
    }

    .calendar-note__notify-row {
        min-height: 42px;
        align-self: start;
    }

    .calendar-note__notify-when {
        display: inline;
    }

    .calendar-note__notify-info-wrap {
        display: inline-flex;
    }
}

body.theme-on-dark .calendar-bar__arrow {
    color: #eaf6f6;
}

/* Цвет текста из настроек темы: будние цифры и подписи одним цветом.
   Выходные и ячейки с заметкой сохраняют свои цвета. */
body.theme-calendar-text .calendar-bar__day:not(.calendar-bar__day--weekend):not(.calendar-bar__day--note) .calendar-bar__day-num,
body.theme-calendar-text .calendar-bar__day:not(.calendar-bar__day--weekend):not(.calendar-bar__day--note) .calendar-bar__day-wd,
body.theme-calendar-text .calendar-bar__today:not(.calendar-bar__today--weekend):not(.calendar-bar__today--note) .calendar-bar__today-num,
body.theme-calendar-text .calendar-bar__today:not(.calendar-bar__today--weekend):not(.calendar-bar__today--note) .calendar-bar__today-wd,
body.theme-calendar-text .calendar-bar__today:not(.calendar-bar__today--weekend):not(.calendar-bar__today--note) .calendar-bar__today-label {
    color: var(--calendar-text-color);
}

/* Отступы календаря по ширине экрана (снаружи рамочки) */
@media (max-width: 1599px) {
    .calendar-bar {
        margin-left: clamp(48px, 5vw, 100px);
        margin-right: clamp(48px, 5vw, 100px);
    }
}

@media (max-width: 1399px) {
    .calendar-bar {
        margin-left: 20px;
        margin-right: 20px;
    }
}

/* Около ширины хранилища (~1000–1200) */
@media (max-width: 1199px) {
    .calendar-bar {
        margin-left: 10px;
        margin-right: 10px;
    }
}

@media (min-width: 881px) {
    .header {
        position: relative;
        top: auto;
    }

    .calendar-bar {
        display: flex;
        min-height: 43px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .calendar-bar__today,
    .calendar-bar__days,
    .calendar-bar__day,
    .calendar-bar__arrow {
        height: 33px;
        min-height: 33px;
        max-height: 33px;
    }
}

@media (max-width: 880px) {
    .calendar-bar {
        display: flex;
        position: relative;
        top: auto;
        flex: 0 0 auto;
        height: auto;
        min-height: 0;
        margin: 0 5px;
        padding: 3px 5px;
        gap: 0;
        align-items: center;
    }

    .calendar-bar--mobile .calendar-bar__today,
    .calendar-bar--mobile .calendar-bar__arrow {
        display: none;
    }

    .calendar-bar--mobile .calendar-bar__days {
        height: 38px;
        min-height: 38px;
        max-height: 38px;
        align-self: center;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
        gap: 6px;
    }

    .calendar-bar--mobile .calendar-bar__days::-webkit-scrollbar {
        display: none;
    }

    .calendar-bar--mobile .calendar-bar__day {
        flex: 0 0 calc((100% - 36px) / 7);
        scroll-snap-align: start;
        height: 38px;
        min-height: 38px;
        max-height: 38px;
        justify-content: center;
    }

    .calendar-bar--mobile .calendar-bar__day-num {
        /* десктопный базовый размер + 2px (было +3 / 13px → сейчас 12px) */
        font-size: calc(var(--calendar-font-size, 10px) + 2px);
    }

    .calendar-bar--mobile .calendar-bar__day-wd {
        font-size: 8px;
    }

    .calendar-note__dot {
        width: 36px;
        height: 36px;
        margin-left: 18px;
        margin-right: 18px;
    }

    /* Почта забирает свободное место справа от двухстрочной подписи */
    .calendar-note__notify {
        grid-template-columns: minmax(0, 1fr) max-content;
        gap: 8px;
        align-items: start;
    }

    .calendar-note__notify-row {
        gap: 6px;
        min-height: 0;
        flex-direction: column;
        align-items: flex-start;
    }

    .calendar-note__notify-check {
        gap: 6px;
    }

    .calendar-note__notify-label {
        width: 7.4em;
        line-height: 1.15;
    }

    .calendar-note__notify-time-wrap {
        padding-left: 32px;
    }

    .calendar-note__notify-time {
        height: 32px;
        min-width: 5.2em;
        font-size: 13px;
    }

    .calendar-note__notify-when,
    .calendar-note__notify-info-wrap {
        display: none !important;
    }

    .calendar-note__email-row .calendar-note__email-input,
    #calendarNoteEmail {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .calendar-note__email-add {
        width: 32px;
        height: 32px;
        font-size: 20px;
    }

    .calendar-bar--mobile .calendar-bar__day--today {
        border: 1.5px solid rgba(26, 107, 109, 0.7);
        background-color: rgba(255, 255, 255, 0.62);
        border-radius: 6px;
    }
}
