/* Календарь в стиле Google Calendar */
#view-calendar { --cal-hour: 48px; --cal-gutter: 54px; --cal-default: #1a73e8; --cal-red: #ea4335; --cal-grid: #edf1f8; --cal-cell: #fff; --cal-weekend: #f8fafd; position: relative; }
:root[data-theme="dark"] #view-calendar { --cal-grid: #131314; --cal-cell: #222326; --cal-weekend: #1c1d20; }
#calendar-pager { background: var(--cal-grid); }
#calendar-views { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; margin: 0 6px; }
.cal-view-button { background: none; border: 0; padding: 4px 12px; font-size: 13px; }
.cal-view-button.active { background: #1a73e822; color: var(--accent); font-weight: 600; }
#calendar-new { width: 32px; height: 32px; }
#calendar-fab { display: none; position: absolute; right: 16px; bottom: 18px; width: 54px; height: 54px; border-radius: 17px; background: var(--card); color: var(--accent); box-shadow: 0 3px 14px #0005; z-index: 8; }
#view-calendar.creating #calendar-fab { display: none; }
/* isolation: слои внутри календаря (колонка часов, события) не вылезают поверх меню. */
#calendar-pager { isolation: isolate; position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#calendar-track { position: absolute; inset: 0; --swipe: 0px; --cal-fixed: 0px; }
#calendar-track.timed { --cal-fixed: var(--cal-gutter); }
.cal-page { position: absolute; inset: 0; display: flex; flex-direction: column; }
/* При листании соседние периоды выезжают из-под неподвижной колонки часов. */
.cal-page-prev, .cal-page-next { left: var(--cal-fixed); }
.cal-page-prev { transform: translateX(calc(-100% + var(--swipe))); }
.cal-page-next { transform: translateX(calc(100% + var(--swipe))); }
.swiping .cal-page-current :is(.cal-day, .cal-allday-cell, .cal-col, .cal-month) { transform: translateX(var(--swipe)); }
.cal-page-current .cal-gutter { position: relative; z-index: 20; background: var(--cal-grid); }
.animating .cal-page-prev, .animating .cal-page-next, .animating .cal-page-current :is(.cal-day, .cal-allday-cell, .cal-col, .cal-month) { transition: transform .26s cubic-bezier(.2, 0, .2, 1); }
.cal-gutter { min-width: 0; overflow: hidden; }
.cal-time .cal-gutter { padding-top: 0; }

.cal-days, .cal-allday, .cal-time { display: grid; flex: none; }
.cal-days, .cal-allday { scrollbar-gutter: stable; overflow: hidden auto; }
.cal-day { background: none; border: 0; padding: 6px 0 2px; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.cal-weekday { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.cal-number { font-size: 22px; width: 40px; height: 40px; line-height: 40px; border-radius: 50%; }
.cal-day:hover .cal-number { background: var(--hover); }
.cal-day.selected .cal-number { background: #1a73e822; }
.cal-day.today .cal-weekday { color: var(--accent); font-weight: 600; }
.cal-day.today .cal-number { background: var(--cal-default); color: #fff; }
.cal-day.journal .cal-number, .cal-cell.journal .cal-dnum { text-decoration: underline 2px var(--accent); text-underline-offset: 4px; }
.cal-days { background: var(--cal-grid); cursor: grab; touch-action: pan-y; }
.cal-allday { max-height: 26%; padding-bottom: 2px; }
.cal-allday-cell { position: relative; min-width: 0; min-height: 28px; margin: 0 1.5px; padding: 3px 3px 4px; border-radius: 10px; background: var(--cal-cell); }

.cal-scroll { flex: 1; min-height: 0; overflow: hidden auto; scrollbar-gutter: stable; touch-action: pan-y; border-top: 1px solid transparent; }
.cal-hour-label { height: var(--cal-hour); font-size: 10px; color: var(--muted); text-align: right; padding-right: 7px; transform: translateY(-8px); white-space: nowrap; }
/* Клетки часов — отдельные прямоугольники со скруглёнными углами, как в Google Календаре. */
.cal-col { position: relative; min-width: 0; touch-action: pan-y; }
.cal-col.weekend .cal-hour-line::before { background: var(--cal-weekend); }
.cal-hour-line { position: relative; height: var(--cal-hour); }
.cal-hour-line::before { content: ""; position: absolute; inset: 1.5px; border-radius: min(10px, calc(var(--cal-hour) / 4)); background: var(--cal-cell); }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; margin-top: -1px; background: var(--cal-red); z-index: 5; pointer-events: none; }
.cal-now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--cal-red); }

.cal-event { position: absolute; z-index: 3; overflow: hidden; border-radius: 9px; margin-top: 1.5px; padding: 2px 6px; color: #fff; font-size: 12px; line-height: 1.3; cursor: pointer; box-shadow: inset 0 0 0 1px #ffffff4d; touch-action: pan-y; }
.cal-event { container-type: inline-size; }
.cal-event:hover { filter: brightness(1.07); }
@container (max-width: 52px) { .cal-event-time { display: none; } }
.cal-event-title { font-weight: 600; overflow-wrap: anywhere; }
.cal-event-time { font-size: 11px; opacity: .92; }
.cal-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 9px; cursor: ns-resize; }
.cal-resize::after { content: ""; position: absolute; left: calc(50% - 10px); width: 20px; bottom: 2px; height: 2px; border-radius: 2px; background: #ffffffa0; }
.cal-event.dragging { z-index: 9; opacity: .9; box-shadow: 0 4px 14px #0006; }
.cal-chip { display: flex; gap: 4px; align-items: center; background: var(--cal-color); color: #fff; border-radius: 5px; padding: 0 5px; margin-bottom: 2px; font-size: 12px; line-height: 17px; white-space: nowrap; overflow: hidden; cursor: pointer; touch-action: pan-y; }
.cal-chip-title { overflow: hidden; text-overflow: ellipsis; }
.cal-chip.timed { background: none; color: inherit; }
.cal-chip.timed::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--cal-color); }
.cal-chip-time { color: var(--muted); font-size: 11px; }
.cal-chip.dragging { position: relative; z-index: 9; opacity: .9; background: var(--cal-color); color: #fff; pointer-events: none; }

.cal-selection { position: absolute; left: 1px; right: 3px; z-index: 7; background: #1a73e830; border: 2px solid var(--cal-default); border-radius: 10px; touch-action: none; cursor: grab; }
.cal-selection-label { font-size: 11px; font-weight: 600; color: var(--accent); padding: 1px 5px; white-space: nowrap; overflow: hidden; }
.cal-selection.whole { position: static; height: 19px; }
.cal-handle { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 2px solid var(--cal-default); touch-action: none; cursor: ns-resize; }
.cal-handle::after { content: ""; position: absolute; inset: -12px; }
.cal-handle.top { left: 6px; top: -8px; }
.cal-handle.bottom { right: 6px; bottom: -8px; }

.cal-month { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.cal-month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); height: 24px; flex: none; }
.cal-month-head div { text-align: center; font-size: 11px; line-height: 24px; color: var(--muted); text-transform: uppercase; }
.cal-month-body { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(6, minmax(0, 1fr)); gap: 3px; padding: 0 3px 3px; min-height: 0; }
.cal-cell { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 2px 3px; overflow: hidden; border-radius: 10px; background: var(--cal-cell); }
.cal-cell > * { flex: none; }
.cal-cell.other { background: var(--cal-weekend); }
.cal-cell.other .cal-dnum { color: var(--muted); }
.cal-dnum { align-self: center; width: 24px; height: 24px; margin-bottom: 1px; padding: 0; border: 0; border-radius: 50%; background: none; font-size: 12px; }
.cal-cell.today .cal-dnum { background: var(--cal-default); color: #fff; }
.cal-more { background: none; border: 0; padding: 0 5px; text-align: left; font-size: 11px; color: var(--muted); }
.cal-cell.drop, .cal-allday-cell.drop { background: #1a73e830; outline: 2px solid var(--cal-default); outline-offset: -2px; }

.cal-bar { display: flex; align-items: center; gap: 2px; }
.cal-popup, #calendar-quick { position: fixed; z-index: 14; background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 28px #0005; }
.cal-popup { width: min(360px, calc(100vw - 16px)); max-height: 70vh; overflow-y: auto; padding: 8px 8px 16px; }
.cal-popup .cal-bar { justify-content: flex-end; }
.cal-popup h2 { display: flex; gap: 10px; align-items: baseline; font-size: 20px; font-weight: 500; margin: 4px 10px; overflow-wrap: anywhere; }
.cal-swatch { width: 13px; height: 13px; border-radius: 4px; flex: none; }
.cal-popup-when, .cal-popup-repeat, #calendar-popup-text { margin: 4px 10px 0 33px; font-size: 14px; color: var(--muted); }
.cal-popup-repeat { display: flex; gap: 6px; align-items: center; }
.cal-popup-repeat .icon { width: 15px; height: 15px; }
#calendar-popup-text { color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
#calendar-quick { width: 360px; max-width: 100vw; padding: 8px 14px 16px; }
#calendar-quick-title, #calendar-title-input { width: 100%; background: none; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; outline: none; font-size: 20px; padding: 6px 2px; }
#calendar-quick-title:focus, #calendar-title-input:focus { border-color: var(--accent); }
#calendar-quick-when { color: var(--muted); font-size: 14px; margin-top: 8px; }

.cal-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: #0008; padding: 16px; }
.cal-modal { display: flex; flex-direction: column; gap: 12px; width: min(520px, 100%); max-height: 100%; overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 10px 16px 18px; }
.cal-line { display: flex; gap: 12px; align-items: flex-start; }
.cal-line > .icon { margin-top: 8px; color: var(--muted); }
.cal-fields { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cal-when-row { display: flex; gap: 8px; }
.cal-when-row input[type="date"] { flex: 1; }
.cal-check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
#calendar-colors { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 6px; }
.cal-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.cal-dot.active { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--card); }
#calendar-text { min-height: 96px; resize: vertical; }

@media (max-width: 760px) {
  #view-calendar { --cal-gutter: 38px; }
  #calendar-header { flex-wrap: wrap; padding: 5px 6px; gap: 2px; }
  #calendar-views { order: 1; width: 100%; margin: 2px 0 0; }
  .cal-view-button { flex: 1; padding: 5px 0; }
  #calendar-new { display: none; }
  #calendar-fab { display: inline-grid; }
  .cal-number { font-size: 18px; width: 32px; height: 32px; line-height: 32px; }
  .cal-hour-label { padding-right: 4px; }
  .cal-event { padding: 1px 3px; font-size: 11px; }
  .cal-chip { padding: 0 3px; font-size: 10.5px; }
  .cal-chip.timed { background: var(--cal-color); color: #fff; }
  .cal-chip.timed::before, .cal-chip-time { display: none; }
  .cal-chip-title { text-overflow: clip; }
  #calendar-quick { left: 0; right: 0; bottom: var(--cal-kb, 0px); width: auto; border-radius: 22px 22px 0 0; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .cal-popup { left: 0; right: 0; bottom: 0; width: auto; border-radius: 22px 22px 0 0; padding-bottom: 22px; }
  .cal-overlay { padding: 0; }
  .cal-modal { width: 100%; height: 100%; border: 0; border-radius: 0; align-content: start; }
}
