/*
 * The calendar (plan §9 /calendar, the trip's Calendar tab): our toolbar and type filters, and FullCalendar restyled
 * to the UI spec. FullCalendar draws only the grid or the list (its own toolbar is off); everything here maps it onto
 * the tokens: hairline borders, no shadows, sentence case, tabular times, Inter, and event colours as accents (a tinted
 * fill and a coloured edge with the type's icon) over normal text, so the text keeps its contrast in both themes.
 */

/* Event colours (plan §8 item 13). Dark mode uses lighter tones of the same hues. */
:root {
  --tl-cal-visit: #3B82F6;
  --tl-cal-transport: #F97316;
  --tl-cal-stay: #8B5CF6;
  --tl-cal-trip: #10B981;
  --tl-cal-note: #6366F1;
  --tl-cal-checklist: #14B8A6;
  --tl-cal-deadline: #E11D48;
  --tl-cal-holiday: #78716C;
  --tl-cal-tint: 14%;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tl-cal-visit: #60A5FA;
    --tl-cal-transport: #FB923C;
    --tl-cal-stay: #A78BFA;
    --tl-cal-trip: #34D399;
    --tl-cal-note: #818CF8;
    --tl-cal-checklist: #2DD4BF;
    --tl-cal-deadline: #FB7185;
    --tl-cal-holiday: #A8A29E;
    --tl-cal-tint: 22%;
  }
}

:root[data-theme="dark"] {
  --tl-cal-visit: #60A5FA;
  --tl-cal-transport: #FB923C;
  --tl-cal-stay: #A78BFA;
  --tl-cal-trip: #34D399;
  --tl-cal-note: #818CF8;
  --tl-cal-checklist: #2DD4BF;
  --tl-cal-deadline: #FB7185;
  --tl-cal-holiday: #A8A29E;
  --tl-cal-tint: 22%;
}

.tl-cal-ev--visit, .tl-cal-filter--visit { --ev: var(--tl-cal-visit); }
.tl-cal-ev--transport, .tl-cal-filter--transport { --ev: var(--tl-cal-transport); }
.tl-cal-ev--stay, .tl-cal-filter--stay { --ev: var(--tl-cal-stay); }
.tl-cal-ev--trip, .tl-cal-filter--trip { --ev: var(--tl-cal-trip); }
.tl-cal-ev--note, .tl-cal-filter--note { --ev: var(--tl-cal-note); }
.tl-cal-ev--checklist, .tl-cal-filter--checklist { --ev: var(--tl-cal-checklist); }
.tl-cal-ev--deadline, .tl-cal-filter--deadline { --ev: var(--tl-cal-deadline); }
.tl-cal-ev--holiday, .tl-cal-filter--holiday { --ev: var(--tl-cal-holiday); }

/* Phase 6c: a public holiday is a quiet band: a faint fill, muted text and the country's flag. */
.tl-cal .fc .tl-cal-ev--holiday {
  background: color-mix(in srgb, var(--ev) 8%, var(--tl-surface));
}

.tl-cal .fc .tl-cal-ev--holiday .tl-cal-ev__title {
  color: var(--tl-text-muted);
}

.tl-cal-ev__flag {
  display: block;
  width: 16px;
  height: 12px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--tl-border);
  background-size: cover;
}

/* ------------------------------------------------------------------ page: type filters */

.tl-cal-page__subscribe {
  flex: none;
}

.tl-cal-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -8px 0 -8px;
}

.tl-cal-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--tl-border-strong);
  border-radius: var(--tl-radius-pill);
  background: var(--tl-surface);
  color: var(--tl-text-muted);
  font: 500 13px/18px var(--tl-font);
  cursor: pointer;
  transition: background-color var(--tl-fast) var(--tl-ease), border-color var(--tl-fast) var(--tl-ease);
}

.tl-cal-filter:hover {
  border-color: var(--tl-text-muted);
}

.tl-cal-filter:focus-visible {
  outline: none;
  border-color: var(--tl-primary);
  box-shadow: var(--tl-focus-shadow);
}

.tl-cal-filter__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--ev);
  box-sizing: border-box;
}

.tl-cal-filter[aria-pressed="true"] {
  border-color: var(--ev);
  background: color-mix(in srgb, var(--ev) var(--tl-cal-tint), var(--tl-surface));
  color: var(--tl-text);
}

.tl-cal-filter[aria-pressed="true"] .tl-cal-filter__dot {
  background: var(--ev);
}

@media (max-width: 639.98px) {
  /* One scrolling row on phones, so the calendar starts high on the screen. */
  .tl-cal-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: -8px calc(-1 * var(--tl-page-padding)) -8px;
    padding: 2px var(--tl-page-padding) 4px;
    scrollbar-width: none;
  }

  .tl-cal-filters::-webkit-scrollbar {
    display: none;
  }

  .tl-cal-filter {
    flex: none;
    min-height: 44px;
  }

  .tl-cal-page__subscribe {
    display: none !important;
  }
}

@media (min-width: 640px) {
  .tl-cal-page__subscribe + .tl-menu-host {
    display: none;
  }
}

/* ------------------------------------------------------------------ the component: toolbar */

.tl-cal {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.tl-cal__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tl-cal__nav {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tl-cal__title {
  margin: 0 0 0 4px;
  font: var(--tl-text-heading);
  font-size: 18px;
  line-height: 24px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-cal__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tl-cal__note {
  margin: 0;
  font: var(--tl-text-meta);
  color: var(--tl-text-muted);
}

/* A link inside the sentence ("Plan a trip") is told apart by more than its colour (WCAG 1.4.1; axe
   link-in-text-block caught it on an empty month in the 1.2.1 release run). */
.tl-cal__note a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 639.98px) {
  .tl-cal__toolbar {
    gap: 8px;
  }

  .tl-cal__nav {
    flex: 1 1 100%;
  }

  .tl-cal__actions {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .tl-cal__title {
    font-size: 17px;
  }
}

/* ------------------------------------------------------------------ FullCalendar, restyled */

.tl-cal .fc {
  --fc-border-color: var(--tl-border);
  --fc-page-bg-color: var(--tl-surface);
  --fc-neutral-bg-color: var(--tl-surface-muted);
  --fc-neutral-text-color: var(--tl-text-muted);
  --fc-today-bg-color: color-mix(in srgb, var(--tl-primary) 7%, transparent);
  --fc-event-bg-color: var(--tl-surface-muted);
  --fc-event-border-color: var(--tl-border-strong);
  --fc-event-text-color: var(--tl-text);
  --fc-event-selected-overlay-color: transparent;
  --fc-more-link-bg-color: transparent;
  --fc-more-link-text-color: var(--tl-text-muted);
  --fc-list-event-hover-bg-color: var(--tl-surface-muted);
  --fc-highlight-color: transparent;
  --fc-small-font-size: 12px;
  font-family: var(--tl-font);
  color: var(--tl-text);
}

.tl-cal__grid {
  min-width: 0;
  border: 1px solid var(--tl-border);
  border-radius: var(--tl-radius-card);
  background: var(--tl-surface);
  overflow: hidden;
}

/* The grid's own outer border is ours (rounded). */
.tl-cal .fc .fc-scrollgrid,
.tl-cal .fc-theme-standard .fc-scrollgrid {
  border: 0;
}

.tl-cal .fc-theme-standard td,
.tl-cal .fc-theme-standard th {
  border-color: var(--tl-border);
}

.tl-cal .fc .fc-scrollgrid-section > td,
.tl-cal .fc .fc-scrollgrid-section > th {
  border-right: 0;
}

.tl-cal .fc .fc-scrollgrid-section-header > th,
.tl-cal .fc .fc-col-header {
  background: var(--tl-surface);
}

.tl-cal .fc .fc-col-header-cell {
  border-left: 0;
  border-right: 0;
}

.tl-cal .fc .fc-col-header-cell-cushion {
  display: block;
  padding: 10px 6px;
  color: var(--tl-text-muted);
  font: 500 12px/16px var(--tl-font);
  text-decoration: none;
}

.tl-cal .fc a {
  color: inherit;
  text-decoration: none;
}

/* Month: day numbers top left, today as a teal disc. */
.tl-cal .fc .fc-daygrid-day-top {
  flex-direction: row;
}

.tl-cal .fc .fc-daygrid-day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  margin: 4px;
  padding: 0 4px;
  border-radius: var(--tl-radius-pill);
  font: 500 13px/1 var(--tl-font);
  font-variant-numeric: tabular-nums;
  color: var(--tl-text);
}

/* Days of the next and previous month: muted, but still readable (4.5:1; FullCalendar fades the whole cell top). */
.tl-cal .fc .fc-day-other .fc-daygrid-day-top {
  opacity: 1;
}

.tl-cal .fc .fc-day-other .fc-daygrid-day-number {
  color: var(--tl-text-muted);
  font-weight: 400;
}

.tl-cal .fc .fc-daygrid-day.fc-day-today {
  background: var(--fc-today-bg-color);
}

.tl-cal .fc .fc-day-today .fc-daygrid-day-number {
  background: var(--tl-primary);
  color: var(--tl-on-primary);
}

.tl-cal .fc .fc-daygrid-day-frame {
  min-height: 96px;
}

.tl-cal .fc .fc-daygrid-more-link {
  margin: 2px 4px;
  padding: 0 4px;
  font: 500 12px/18px var(--tl-font);
  color: var(--tl-text-muted);
}

.tl-cal .fc .fc-daygrid-more-link:hover {
  color: var(--tl-text);
  background: var(--tl-surface-muted);
}

/* Events (every view): a tinted fill, a 3px edge in the type's colour, the type's icon, normal text. */
.tl-cal .fc .tl-cal-ev {
  border: 0;
  border-left: 3px solid var(--ev);
  border-radius: 6px;
  background: color-mix(in srgb, var(--ev) var(--tl-cal-tint), var(--tl-surface));
  color: var(--tl-text);
  box-shadow: none;
  cursor: pointer;
  transition: background-color var(--tl-fast) var(--tl-ease);
}

.tl-cal .fc .tl-cal-ev:hover {
  background: color-mix(in srgb, var(--ev) calc(var(--tl-cal-tint) + 10%), var(--tl-surface));
}

.tl-cal .fc .tl-cal-ev:focus-visible {
  outline: 2px solid var(--tl-primary);
  outline-offset: 1px;
}

.tl-cal .fc .tl-cal-ev .fc-event-main,
.tl-cal .fc .tl-cal-ev .fc-event-main-frame {
  color: var(--tl-text);
}

.tl-cal .fc .fc-h-event.tl-cal-ev,
.tl-cal .fc .fc-daygrid-event.tl-cal-ev {
  margin: 1px 4px 2px;
  /* 24px tall: a tap target that meets WCAG 2.5.8 (Phase 8). */
  padding: 3px 6px 3px 5px;
}

/* A span that continues from or into another week has no edge on that side. */
.tl-cal .fc .fc-h-event.tl-cal-ev:not(.fc-event-start) {
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  margin-left: 0;
  padding-left: 8px;
}

.tl-cal .fc .fc-h-event.tl-cal-ev:not(.fc-event-end) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  margin-right: 0;
}

.tl-cal .fc .tl-cal-ev .fc-event-main {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 0;
  font: 500 12px/18px var(--tl-font);
}

.tl-cal-ev__icon {
  flex: none;
  display: inline-flex;
  color: var(--ev);
}

.tl-cal-ev__icon svg {
  display: block;
}

.tl-cal-ev__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tl-cal-ev__line {
  display: flex;
  gap: 5px;
  min-width: 0;
}

.tl-cal-ev__time {
  flex: none;
  color: var(--tl-text-muted);
  font-variant-numeric: tabular-nums;
}

.tl-cal-ev__title {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tl-cal-ev__detail {
  color: var(--tl-text-muted);
  font: 400 13px/18px var(--tl-font);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Week: time slots. */
.tl-cal .fc .fc-timegrid-slot {
  height: 32px;
}

.tl-cal .fc .fc-v-event .tl-cal-ev__line {
  flex-wrap: wrap;
  column-gap: 5px;
}

.tl-cal .fc .fc-v-event .tl-cal-ev__title {
  white-space: normal;
  overflow-wrap: anywhere;
}

.tl-cal .fc .fc-timegrid-slot-label-cushion,
.tl-cal .fc .fc-timegrid-axis-cushion {
  color: var(--tl-text-muted);
  font: 400 12px/16px var(--tl-font);
  font-variant-numeric: tabular-nums;
}

.tl-cal .fc .fc-timegrid-slot-minor {
  border-top-style: none;
}

.tl-cal .fc .fc-timegrid-col.fc-day-today {
  background: var(--fc-today-bg-color);
}

.tl-cal .fc .fc-v-event.tl-cal-ev {
  padding: 2px 4px 2px 5px;
}

.tl-cal .fc .fc-v-event.tl-cal-ev .fc-event-main {
  align-items: flex-start;
}

.tl-cal .fc .fc-timegrid-event-harness-inset .fc-timegrid-event {
  box-shadow: 0 0 0 1px var(--tl-surface);
}

/* List: day headings as quiet rows, events as list rows with their detail line. */
.tl-cal .fc .fc-list {
  border: 0;
}

/* No events in the list: a quiet line with the card's own padding, not FullCalendar's grey block. */
.tl-cal .fc .fc-list-empty {
  background: transparent;
}

.tl-cal .fc .fc-list-empty-cushion {
  margin: 0;
  padding: 32px 16px;
  font: 400 14px/20px var(--tl-font);
  color: var(--tl-text-muted);
  text-align: center;
}

.tl-cal .fc .fc-list-day-cushion {
  padding: 10px 16px;
  background: var(--tl-surface-muted);
  font: 600 13px/18px var(--tl-font);
  color: var(--tl-text);
}

.tl-cal .fc .fc-list-day-cushion a {
  text-decoration: none;
}

.tl-cal .fc .fc-list-event.tl-cal-ev {
  border-left: 0;
  border-radius: 0;
  background: transparent;
}

.tl-cal .fc .fc-list-event.tl-cal-ev:hover,
.tl-cal .fc .fc-list-event.tl-cal-ev:hover td {
  background: var(--tl-surface-muted);
}

.tl-cal .fc .fc-list-event td {
  padding: 10px 16px;
  border-color: var(--tl-border);
  vertical-align: top;
}

.tl-cal .fc .fc-list-event-graphic {
  display: none;
}

.tl-cal .fc .fc-list-event-time {
  width: 1%;
  padding-right: 0;
  color: var(--tl-text-muted);
  font: 400 13px/22px var(--tl-font);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tl-cal .fc .fc-list-event-title {
  font: 500 15px/22px var(--tl-font);
}

.tl-cal .fc .fc-list-event-title .tl-cal-ev__icon {
  margin-top: 4px;
}

.tl-cal .fc .fc-list-event-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.tl-cal .fc .fc-list-event-title .tl-cal-ev__title {
  white-space: normal;
  overflow-wrap: anywhere;
}

.tl-cal .fc .fc-list-empty {
  min-height: 160px;
  background: var(--tl-surface);
}

.tl-cal .fc .fc-list-empty-cushion {
  margin: 32px 16px;
  color: var(--tl-text-muted);
  font: var(--tl-text-body);
}

/* The "+3 more" popover: a floating layer (the only shadow). */
.tl-cal .fc .fc-popover {
  border: 1px solid var(--tl-border);
  border-radius: 12px;
  background: var(--tl-surface);
  box-shadow: var(--tl-shadow-float);
  overflow: hidden;
  z-index: 20;
}

.tl-cal .fc .fc-popover-header {
  padding: 8px 10px 8px 12px;
  background: var(--tl-surface);
  font: 600 13px/18px var(--tl-font);
  color: var(--tl-text);
}

.tl-cal .fc .fc-popover-close {
  opacity: 1;
  color: var(--tl-text-muted);
  font-size: 18px;
}

.tl-cal .fc .fc-popover-body {
  padding: 0 0 6px;
}

/* Phones: a compact month. */
@media (max-width: 639.98px) {
  .tl-cal__grid {
    margin: 0 calc(-1 * var(--tl-page-padding));
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .tl-cal .fc .fc-daygrid-day-frame {
    min-height: 64px;
  }

  .tl-cal .fc .fc-daygrid-day-number {
    min-width: 22px;
    height: 22px;
    margin: 2px;
    font-size: 12px;
  }

  .tl-cal .fc .fc-h-event.tl-cal-ev,
  .tl-cal .fc .fc-daygrid-event.tl-cal-ev {
    margin: 1px 2px;
    padding: 0 3px 0 3px;
  }

  .tl-cal .fc .tl-cal-ev .fc-event-main {
    font-size: 11px;
    line-height: 16px;
    gap: 3px;
  }

  .tl-cal .fc .fc-daygrid .tl-cal-ev__icon,
  .tl-cal .fc .fc-daygrid .tl-cal-ev__time {
    display: none;
  }

  .tl-cal .fc .fc-list-event td {
    padding: 12px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tl-cal-filter,
  .tl-cal .fc .tl-cal-ev {
    transition: none;
  }
}

/* Timed events in the week: the text stays inside the block; a short one (a 30-minute ferry) is one ellipsised line. */
.tl-cal .fc .fc-v-event.tl-cal-ev {
  overflow: hidden;
}

.tl-cal .fc .fc-v-event.tl-cal-ev .fc-event-main {
  overflow: hidden;
  height: 100%;
}

.tl-cal .fc .fc-timegrid-event-short.tl-cal-ev .tl-cal-ev__line {
  flex-wrap: nowrap;
}

.tl-cal .fc .fc-timegrid-event-short.tl-cal-ev .tl-cal-ev__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
