/* The deadline calendar, themed.
 *
 * Flatpickr ships a serviceable blue-grey default that belongs to no product. These rules put
 * it in the module's own palette and tighten it: the stock calendar is sized for a marketing
 * page, with a wide body and generous day cells, and this one sits inside a three-column
 * record form where that reads as a balloon.
 *
 * Scoped to `.ce-cal`, the class `flatpickr_init.js` stamps on its own instances, so nothing
 * here can reach another picker elsewhere in the platform.
 */

.flatpickr-calendar.ce-cal {
  width: 17.5rem; /* allow-length: seven day columns at the module's density */
  padding: .35rem; /* allow-length: the calendar's own inset, one step tighter than stock */
  border: var(--bs-border-width) solid var(--bs-border-color);
  border-radius: .6rem; /* allow-length: matches the record form's cards */
  box-shadow: 0 .5rem 1.5rem rgba(16, 24, 40, .14); /* allow-length: n/a, elevation for a popover */
  font-size: .82rem; /* allow-length: one step under body, matching the form's controls */
}

/* Stock draws a little triangle pointing at the field. It lands on the input's border and
   reads as a rendering artefact at this size. */
.flatpickr-calendar.ce-cal::before,
.flatpickr-calendar.ce-cal::after { display: none; }

.flatpickr-calendar.ce-cal .flatpickr-months {
  align-items: center;
  padding-bottom: .25rem; /* allow-length: separates the month from the weekday row */
}

.flatpickr-calendar.ce-cal .flatpickr-month,
.flatpickr-calendar.ce-cal .flatpickr-current-month {
  color: var(--bs-emphasis-color);
  font-weight: 600;
}

.flatpickr-calendar.ce-cal .flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-calendar.ce-cal .flatpickr-current-month input.cur-year {
  font-weight: 600;
  font-size: .85rem; /* allow-length: the calendar's own heading size */
}

/* The arrows are controls, so they get a hit area and a visible focus state rather than being
   bare glyphs that move on hover. */
.flatpickr-calendar.ce-cal .flatpickr-prev-month,
.flatpickr-calendar.ce-cal .flatpickr-next-month {
  padding: .3rem; /* allow-length: a comfortable target for a small glyph */
  border-radius: .35rem; /* allow-length: matches the day cells */
  fill: var(--bs-secondary-color);
}
.flatpickr-calendar.ce-cal .flatpickr-prev-month:hover,
.flatpickr-calendar.ce-cal .flatpickr-next-month:hover {
  background: var(--bs-tertiary-bg);
}
.flatpickr-calendar.ce-cal .flatpickr-prev-month:hover svg,
.flatpickr-calendar.ce-cal .flatpickr-next-month:hover svg {
  fill: var(--bs-emphasis-color);
}
.flatpickr-calendar.ce-cal .flatpickr-prev-month:focus-visible,
.flatpickr-calendar.ce-cal .flatpickr-next-month:focus-visible {
  outline: 2px solid var(--bs-primary); /* allow-length: a visible keyboard focus ring */
  outline-offset: 1px; /* allow-length: keeps the ring off the glyph */
}

.flatpickr-calendar.ce-cal span.flatpickr-weekday {
  color: var(--bs-secondary-color);
  font-weight: 500;
  font-size: .72rem; /* allow-length: a column label under the day numbers */
}

/* Flatpickr sizes its day grid in fixed pixels and lets the calendar shell inherit that
   width. Narrowing only the shell therefore clips the seventh column: the month rendered six
   days per week and Sunday fell off the edge, which is a calendar that cannot be trusted.
   The grid is told to fill the shell instead, and each day takes a seventh of it, so the
   week stays whole at whatever width the shell is given. */
.flatpickr-calendar.ce-cal .flatpickr-days,
.flatpickr-calendar.ce-cal .dayContainer {
  width: 100%;
  min-width: 0;
  max-width: none;
}

.flatpickr-calendar.ce-cal .flatpickr-day {
  border-radius: .35rem; /* allow-length: a soft square, not a circle */
  border: 0;
  flex-basis: calc(100% / 7);
  max-width: calc(100% / 7);
  height: 2rem; /* allow-length: the day cell, sized to the calendar's own width */
  line-height: 2rem; /* allow-length: pairs with the height above */
  color: var(--bs-body-color);
}

.flatpickr-calendar.ce-cal span.flatpickr-weekday {
  flex-basis: calc(100% / 7);
  max-width: calc(100% / 7);
}

.flatpickr-calendar.ce-cal .flatpickr-day:hover {
  background: var(--bs-tertiary-bg);
}

/* Today is a marker, not a selection: an outline rather than a fill, so it cannot be mistaken
   for the chosen date. */
.flatpickr-calendar.ce-cal .flatpickr-day.today {
  box-shadow: inset 0 0 0 1px var(--bs-border-color); /* allow-length: a hairline ring */
  font-weight: 600;
}

.flatpickr-calendar.ce-cal .flatpickr-day.selected,
.flatpickr-calendar.ce-cal .flatpickr-day.selected:hover {
  background: var(--c-navy, var(--bs-primary));
  border-color: transparent;
  color: #fff; /* allow-length: n/a, colour token: text on the filled selection */
  font-weight: 600;
}

.flatpickr-calendar.ce-cal .flatpickr-day.prevMonthDay,
.flatpickr-calendar.ce-cal .flatpickr-day.nextMonthDay {
  color: var(--bs-secondary-color);
  opacity: .55; /* allow-length: n/a, the neighbouring month reads as context */
}

.flatpickr-calendar.ce-cal .flatpickr-day.flatpickr-disabled {
  color: var(--bs-border-color);
}

.flatpickr-calendar.ce-cal .flatpickr-day:focus-visible {
  outline: 2px solid var(--bs-primary); /* allow-length: a visible keyboard focus ring */
  outline-offset: -2px; /* allow-length: keeps the ring inside the cell */
}

/* The field Flatpickr shows the reader. It replaces the real input in the layout, so it keeps
   the same classes and therefore the same height as every other control on the form. */
.ce-date-alt { background: var(--bs-body-bg); }

@media (prefers-reduced-motion: reduce) {
  .flatpickr-calendar.ce-cal { animation: none !important; }
}
