/**
 * Styles for the [svg_calendar] shortcode.
 *
 * FullCalendar 6's global bundle injects its own CSS from JavaScript. Because the script is
 * deferred, that CSS arrives after first paint — hence the min-height below, which reserves
 * the space and stops the page jumping once the calendar renders.
 */

.svg-ics-calendar-wrap {
  position: relative;
  margin: 1.5rem 0;
}

.svg-ics-calendar {
  min-height: 32rem;
}

.svg-ics-calendar__loading {
  color: #666;
  font-style: italic;
  padding: 1rem 0;
}

/* -------------------------------------------------------------- Toolbar
 *
 * The toolbar title is an <h2>, so a theme's heading styles land on it and can easily push it
 * into the buttons — themes often constrain content to ~650px, which is narrow for three
 * toolbar groups. These rules keep the toolbar readable whatever the theme does.
 */

.svg-ics-calendar .fc-header-toolbar {
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.svg-ics-calendar .fc-toolbar-chunk {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.svg-ics-calendar .fc-toolbar-title {
  margin: 0;
  padding: 0;
  /* The date range is what orients the reader; it was the quietest thing in the toolbar. */
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  letter-spacing: normal;
}

.svg-ics-calendar .fc-button {
  /* Paging arrows were about 20px tall — below any sensible touch target. */
  min-height: 2.5rem;
  padding: 0.35em 0.85em;
  font-size: 0.95rem;
  line-height: 1.4;
  text-transform: none;
  letter-spacing: normal;
}

.svg-ics-calendar .fc-prev-button,
.svg-ics-calendar .fc-next-button {
  min-width: 2.75rem;
}

/* Themes commonly style buttons with their own colours; FullCalendar's own state colours
   must win so the active view is still recognisable. */
.svg-ics-calendar .fc-button:focus {
  box-shadow: 0 0 0 2px rgba(44, 62, 80, 0.3);
}

/* ---------------------------------------------------------------- Legend */

.svg-ics-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  font-size: 0.9em;
}

.svg-ics-legend__item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
}

.svg-ics-legend__swatch {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border-radius: 3px;
  flex: 0 0 auto;
  /* A pale colour — a light grey, say — is otherwise invisible on a white background. */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

/* ------------------------------------------------- Legend as a filter
 *
 * Styled as chips rather than bare text: a plain colour square with a word next to it reads
 * as a caption, not as something to press. The border and background say "control".
 */

.svg-ics-legend--filterable {
  gap: 0.4rem 0.5rem;
}

.svg-ics-legend__button {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0.25em 0.7em;
  font: inherit;
  line-height: 1.4;
  color: inherit;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 999px;
  cursor: pointer;
  transition: opacity 0.12s ease, background-color 0.12s ease;
}

.svg-ics-legend__button:hover {
  background: rgba(0, 0, 0, 0.09);
}

.svg-ics-legend__button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Deselected: drained of colour rather than hidden, so it still reads as a thing you can
   switch back on. */
.svg-ics-legend__button.is-muted {
  opacity: 0.45;
  background: transparent;
}

.svg-ics-legend__button.is-muted .svg-ics-legend__swatch {
  filter: grayscale(1);
}


/* ----------------------------------------------------------- Event popup */

/* Fixed rather than absolute: in a long list view the container is several screens tall, so
   a popup centred inside it would open below the fold. Centring on the viewport keeps it
   visible wherever the reader happens to be scrolled to. */
.svg-ics-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1000;
  transform: translate(-50%, -50%);
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(80vh, 40rem);
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  background: #fff;
  border: 1px solid #ddd;
  border-left: 5px solid #666;
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
}

/* Dims the page behind the dialog and catches a click anywhere outside it. */
.svg-ics-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.35);
}

.svg-ics-popup__close {
  position: absolute;
  top: 0.25rem;
  right: 0.35rem;
  /* 44px: the smallest target most guidance considers reliably tappable. */
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: #666;
  background: none;
  border: 0;
  cursor: pointer;
}

.svg-ics-popup__close:hover,
.svg-ics-popup__close:focus {
  color: #000;
}

.svg-ics-popup__title {
  margin: 0 1.5rem 0.4rem 0;
  font-size: 1.15em;
  line-height: 1.3;
}

.svg-ics-popup__time {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.svg-ics-popup__location,
.svg-ics-popup__source,
.svg-ics-popup__description {
  margin: 0 0 0.5rem;
  font-size: 0.95em;
}

.svg-ics-popup__source {
  font-weight: 600;
}

.svg-ics-popup__description {
  /* Feed descriptions keep their line breaks; the text itself is inserted via textContent. */
  white-space: pre-wrap;
  color: #444;
}

.svg-ics-popup__link {
  display: inline-block;
  margin-top: 0.25rem;
  word-break: break-all;
}

/* -------------------------------------------- Interaction affordances
 *
 * FullCalendar signals clickability with a hover state and a pointer cursor. Neither exists
 * on a touchscreen, so on a phone an entry that opens a link or a detail panel looks exactly
 * like plain text. These rules make the difference visible without hovering.
 */

.svg-ics-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.svg-ics-indicator {
  display: inline-flex;
  align-items: center;
  /* Never squeezed out by a long title in the grid views. */
  flex: 0 0 auto;
  margin-left: 0.4em;
  /* Fallback for inline (non-flex) contexts, where align-items does not apply. */
  vertical-align: -0.15em;
}

/* Without this the SVG sits on the text baseline and rides visibly high; the icon should be
   centred on the text's x-height instead. */
.svg-ics-indicator svg {
  display: block;
}

.svg-ics-calendar .svg-ics-has-link,
.svg-ics-calendar .svg-ics-has-details {
  cursor: pointer;
}

/* In the grid views there is no room for an icon, so linked titles are underlined instead —
   the one link cue that costs no horizontal space. */
.svg-ics-calendar .fc-daygrid-event.svg-ics-has-link .fc-event-title,
.svg-ics-calendar .fc-timegrid-event.svg-ics-has-link .fc-event-title {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* The external-link mark carries real consequence — it leaves the site — so it stays at full
   strength, while the details mark is a quieter hint. */
.svg-ics-has-link .svg-ics-indicator {
  opacity: 0.95;
}

.svg-ics-has-details .svg-ics-indicator {
  opacity: 0.6;
}

.svg-ics-calendar .fc-list-event:hover .svg-ics-indicator,
.svg-ics-calendar .fc-event:hover .svg-ics-indicator {
  opacity: 1;
}

/* Touch devices get no hover, so the press itself has to be visible. */
.svg-ics-calendar .svg-ics-has-link:active,
.svg-ics-calendar .svg-ics-has-details:active {
  filter: brightness(0.92);
}

.svg-ics-calendar .fc-list-event.svg-ics-has-link:active td,
.svg-ics-calendar .fc-list-event.svg-ics-has-details:active td {
  background: rgba(0, 0, 0, 0.06);
}

/* Keyboard users need to see where they are; :focus-visible keeps the ring off mouse clicks. */
.svg-ics-calendar .svg-ics-has-details:focus-visible,
.svg-ics-calendar .svg-ics-has-link:focus-visible,
.svg-ics-today__link:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
  border-radius: 2px;
}

/* In list views the title cell is what the badge lives in; keep them on one line together. */
.svg-ics-calendar .fc-list-event-title {
  display: flex;
  align-items: center;
  gap: 0;
}

.svg-ics-today__link {
  display: inline-flex;
  align-items: center;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.svg-ics-hint {
  margin: 0 0 0.5rem;
  font-size: 0.85em;
  opacity: 0.7;
}

/* Shown when a grid view has nothing in its range — during the holidays that is the normal
   state for weeks at a time, and empty cells alone explain nothing. */
.svg-ics-empty {
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.95em;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 3px;
}

/* ------------------------------------------- Week and day as a listing
 *
 * dayGridWeek/dayGridDay show day columns with the events listed underneath, rather than
 * placed on an hourly axis. Seven columns in a theme's ~650px content area leave roughly
 * 85px each, where FullCalendar's default single line truncates "Training Masters" to
 * "Tra". These views exist to be read, and unlike a month cell they have vertical room to
 * spare, so titles wrap instead.
 */

/* The dot, the time and the title are flex siblings. Simply allowing the title to wrap makes
   it collapse to the narrowest possible box and break mid-word; giving it a full-width line
   of its own puts the time on top and the whole title underneath. */
.svg-ics-calendar .fc-dayGridWeek-view .fc-daygrid-dot-event,
.svg-ics-calendar .fc-dayGridDay-view .fc-daygrid-dot-event {
  flex-wrap: wrap;
  align-items: baseline;
  padding: 0.15em 0.25em;
}

.svg-ics-calendar .fc-dayGridWeek-view .fc-event-title,
.svg-ics-calendar .fc-dayGridDay-view .fc-event-title {
  flex: 1 0 100%;
  white-space: normal;
  overflow: visible;
  line-height: 1.25;
}

/* The time stays on one line — a wrapped "18:0" / "0" would be unreadable. */
.svg-ics-calendar .fc-dayGridWeek-view .fc-event-time,
.svg-ics-calendar .fc-dayGridDay-view .fc-event-time {
  white-space: nowrap;
}

.svg-ics-calendar .fc-dayGridWeek-view .fc-daygrid-day-events,
.svg-ics-calendar .fc-dayGridDay-view .fc-daygrid-day-events {
  padding-bottom: 0.25rem;
}

/* ------------------------------------------------------ Cancelled events
 *
 * A cancelled session keeps its place in the calendar — members need to see that it was
 * called off, not simply fail to find it — but is struck through and dimmed.
 */

.svg-ics-calendar .svg-ics-cancelled .fc-event-title,
.svg-ics-calendar .svg-ics-cancelled .fc-list-event-title,
.svg-ics-calendar .svg-ics-cancelled .fc-event-time,
.svg-ics-calendar .svg-ics-cancelled .fc-list-event-time,
.svg-ics-popup__title.is-cancelled,
.svg-ics-today__title.is-cancelled {
  text-decoration: line-through;
}

.svg-ics-calendar .svg-ics-cancelled {
  opacity: 0.65;
}

/* List views draw the dot from a border, so the source colour has to be dimmed there too. */
.svg-ics-calendar .fc-list-event.svg-ics-cancelled .fc-list-event-dot {
  opacity: 0.65;
}

/* -------------------------------------------------------------- Messages */

.svg-ics-error {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.9rem;
  color: #7a231d;
  background: #fdecea;
  border-left: 4px solid #d63638;
}

.svg-ics-notice {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.9rem;
  font-size: 0.9em;
  background: #fcf9e8;
  border-left: 4px solid #dba617;
}

.svg-ics-notice ul {
  margin: 0.35rem 0 0;
  padding-left: 1.2rem;
}

/* ---------------------------------------------------- Today widget
 *
 * Styled to sit in a sidebar or on a front page: no borders of its own, inherits the
 * theme's typography, and stays legible at narrow widths.
 */

.svg-ics-today {
  margin: 1rem 0;
}

.svg-ics-today__heading {
  margin: 0 0 0.5rem;
  font-size: 1.1em;
}

.svg-ics-today__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.svg-ics-today__day {
  margin: 0.9rem 0 0.35rem;
  font-weight: 600;
  font-size: 0.9em;
  opacity: 0.75;
}

.svg-ics-today__day:first-child {
  margin-top: 0;
}

.svg-ics-today__item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.svg-ics-today__item:last-child {
  border-bottom: 0;
}

.svg-ics-today__dot {
  flex: 0 0 auto;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  /* Baseline alignment would let the dot drift with the line height. */
  align-self: center;
}

.svg-ics-today__time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 0.9em;
  white-space: nowrap;
  opacity: 0.85;
}

.svg-ics-today__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.svg-ics-today__title {
  font-weight: 600;
}

.svg-ics-today__meta {
  font-size: 0.85em;
  opacity: 0.75;
}

.svg-ics-today__status {
  margin: 0;
  font-size: 0.95em;
  opacity: 0.8;
}

.svg-ics-today__status.is-error {
  color: #7a231d;
}

@media (max-width: 420px) {
  /* Time above the title rather than beside it, so long titles stop wrapping to one word
     per line in a narrow sidebar. */
  .svg-ics-today__item {
    flex-wrap: wrap;
  }

  .svg-ics-today__body {
    flex: 1 0 100%;
    padding-left: 1.1em;
  }
}

/* ------------------------------------------------------------- Small screens */

@media (max-width: 640px) {
  .svg-ics-calendar {
    min-height: 24rem;
    font-size: 0.85em;
  }

  /* The month grid is unusable at phone widths; stack the toolbar so at least the view
     switcher stays reachable. */
  .svg-ics-calendar .fc-header-toolbar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .svg-ics-calendar .fc-toolbar-title {
    font-size: 1.15em;
  }

  /* A centred dialog on a phone leaves slivers of dimmed page around it and puts the close
     button out of thumb reach. Anchored to the bottom edge instead. */
  .svg-ics-popup {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-height: 80vh;
    padding: 1.1rem 1rem 1.5rem;
    transform: none;
    border-radius: 10px 10px 0 0;
    border-left: 0;
    border-top: 4px solid #666;
  }
}

@media print {
  .svg-ics-popup,
  .svg-ics-calendar .fc-header-toolbar {
    display: none;
  }
}

/* ------------------------------------------------- Background feeds
 *
 * School holidays, public holidays, closures. In the grid views these are ordinary all-day
 * events, so FullCalendar lays them out as a bar spanning the days they cover — the shape
 * Outlook gives an all-day entry. The colour is whatever was configured, untouched.
 *
 * Only a *timed* period still falls back to a tint, and only there does the title need
 * handling: it renders inside the tinted area and would otherwise sit on top of the day's
 * appointments.
 */

.svg-ics-calendar .fc-bg-event {
  /* FullCalendar's default of .3 is barely visible against a white cell. */
  opacity: 0.25;
}

.svg-ics-calendar .fc-bg-event .fc-event-title {
  /* Hidden rather than restyled: in a grid it overlapped the first appointment of the day,
     and the period is already named in the legend and in the list-view line. */
  display: none;
}

/* The holiday bar itself: full width of the days it covers, quiet but legible. */
.svg-ics-calendar .fc-daygrid-block-event.svg-ics-period .fc-event-title {
  font-weight: 600;
  padding: 0.1em 0.4em;
}

.svg-ics-calendar .svg-ics-period {
  border-radius: 3px;
}

/* The list-view stand-in for the day tint, which list views do not render. */
.svg-ics-periods {
  margin: 0 0 0.6rem;
  padding: 0.4rem 0.7rem;
  font-size: 0.9em;
  background: rgba(188, 108, 37, 0.12);
  border-left: 3px solid rgba(188, 108, 37, 0.6);
  border-radius: 2px;
}
