/**
 * weekly-schedule.css — the "Full Weekly Schedule" card.
 *
 * @version 1.0.0
 *
 * The markup is generated by scripts/gen-schedule-html.mjs into index.html,
 * campbell-river.html, cortes-island.html and tomorrow.html. Change it in the
 * generator, never in the pages. The card is a native <details>, so it opens
 * with no script and does not go through toggleCollapse().
 *
 * Filtering is pure CSS: the direction and day controls are radio buttons, and
 * :has() hides every section and day group that does not match the checked
 * ones. The HTML always carries the whole week, which is the point of the card
 * (crawlers read it). Where :has() is unsupported the controls stay hidden and
 * the whole week shows. The inline script under the card only preselects today.
 *
 * tomorrow.html loads none of the shared CSS and defines only a few tokens, so
 * every var() below carries a literal fallback. Dark mode arrives two ways on
 * this site ([data-theme="dark"] and body.dark-mode), so every hard-coded
 * colour is a --ws-* token redefined under both.
 *
 * Linked non-blocking (the media="print" swap): the card starts collapsed and
 * sits at the foot of the page.
 */

/* ---- tokens ---- */
.weekly-schedule {
  --ws-ink: var(--text-primary, #1a1a1a);
  --ws-muted: var(--text-secondary, #4a4a4a);
  --ws-accent: var(--primary-blue, #1a73e8);
  --ws-link: var(--primary-blue, #1a73e8);
  --ws-chip-bg: #f1f5f9;
  --ws-chip-line: #dbe3ec;
  --ws-opt-bg: #ffffff;
  --ws-opt-line: #c3cfdd;
  --ws-sel-bg: #1a73e8;          /* white on this is 4.5:1 */
  --ws-sel-ink: #ffffff;
  --ws-dg-bg: #fff3cd;
  --ws-dg-ink: #856404;
}

/* The site's dark --primary-blue (#4a9eff) is 4.35:1 on the dark card, just
   under the 4.5:1 body-text floor, so links here get a lighter blue (5.8:1).
   The selected filter flips to dark text on that lighter blue (8.7:1): white
   on #4a9eff would be 2.6:1. */
[data-theme="dark"] .weekly-schedule,
body.dark-mode .weekly-schedule {
  --ws-link: #7cb8ff;
  --ws-chip-bg: #1a202c;
  --ws-chip-line: #4a5568;
  --ws-opt-bg: #1a202c;
  --ws-opt-line: #5a6a80;
  --ws-sel-bg: #7cb8ff;
  --ws-sel-ink: #0f172a;
  --ws-dg-bg: #3d3200;
  --ws-dg-ink: #ffd54f;
}

/* ---- header: the <summary> ---- */
.weekly-schedule > .ws-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 44px;              /* the whole strip is the toggle */
  cursor: pointer;
  list-style: none;              /* hides the Firefox/Chrome marker */
  user-select: none;
  border-radius: 4px;
}

.weekly-schedule > .ws-summary::-webkit-details-marker {
  display: none;                 /* Safari's marker */
}

.weekly-schedule > .ws-summary:focus-visible {
  outline: 3px solid var(--ws-accent);
  outline-offset: 3px;
}

.weekly-schedule .ws-title {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ws-ink);
  flex-shrink: 0;
}

.weekly-schedule .ws-hint {
  flex: 1;
  text-align: center;
  font-size: 0.82rem;
  color: var(--ws-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weekly-schedule[open] .ws-hint {
  visibility: hidden;
}

.weekly-schedule .ws-icon {
  font-size: 0.8rem;
  color: var(--ws-ink);
  flex-shrink: 0;
  /* Pins the chevron to the right edge, like the other cards', even on phones
     where .ws-hint is hidden and nothing else fills the strip. */
  margin-left: auto;
  transition: transform 0.3s ease;
}

.weekly-schedule[open] .ws-icon {
  transform: rotate(180deg);
}

/* ---- body ---- */
.weekly-schedule .ws-body {
  padding-top: 0.75rem;
  color: var(--ws-ink);
  container-type: inline-size;   /* the filter and time layouts follow the card, not the viewport */
}

.weekly-schedule .ws-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- filters: direction + day ---- */
.weekly-schedule .ws-filters {
  display: none;                 /* shown only where :has() can act on them */
}

.weekly-schedule .ws-filter {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  margin: 0 0 0.5rem;
  padding: 0;
  border: 0;
}

.weekly-schedule .ws-filter--dir {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Seven joined segments: at 375px the card leaves ~309px, which fits 7 x 44px
   only with no gaps between them. */
.weekly-schedule .ws-filter--day {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0;
}

.weekly-schedule .ws-opt {
  position: relative;
  display: block;
  margin: 0;
  cursor: pointer;
}

/* The radio itself stays in the accessibility tree and takes keyboard focus;
   the <span> after it is what shows. */
.weekly-schedule .ws-opt input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.weekly-schedule .ws-opt span {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--ws-opt-line);
  border-radius: 8px;
  background: var(--ws-opt-bg);
  color: var(--ws-ink);
  font-size: 0.85rem;
  line-height: 1.25;
  text-align: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* A tint, not a border colour: the joined day segments share their borders. */
.weekly-schedule .ws-opt:hover input:not(:checked) + span {
  background: var(--ws-chip-bg);
}

.weekly-schedule .ws-opt input:checked + span {
  background: var(--ws-sel-bg);
  border-color: var(--ws-sel-bg);
  color: var(--ws-sel-ink);
  font-weight: 600;
}

.weekly-schedule .ws-opt input:focus-visible + span {
  z-index: 1;                    /* keeps the ring above the joined neighbours */
  outline: 3px solid var(--ws-accent);
  outline-offset: 2px;
}

.weekly-schedule .ws-filter--day .ws-opt span {
  padding: 0.3rem 0;
  border-left-width: 0;
  border-radius: 0;
}

.weekly-schedule .ws-filter--day .ws-opt:first-of-type span {
  border-left-width: 1px;
  border-radius: 8px 0 0 8px;
}

.weekly-schedule .ws-filter--day .ws-opt:last-of-type span {
  border-radius: 0 8px 8px 0;
}

/* Today: a dot under the day name (the script adds the class). */
.weekly-schedule .ws-opt.ws-is-today span::after {
  content: '';
  position: absolute;
  bottom: 5px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: currentColor;
}

/* Narrower than 7 x 44px: split the days into rows of four so every button
   keeps a 44px target. */
@container (max-width: 305px) {
  .weekly-schedule .ws-filter--day {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
  }

  .weekly-schedule .ws-filter--day .ws-opt span,
  .weekly-schedule .ws-filter--day .ws-opt:first-of-type span,
  .weekly-schedule .ws-filter--day .ws-opt:last-of-type span {
    border-width: 1px;
    border-radius: 8px;
  }
}

@supports selector(:has(*)) {
  .weekly-schedule .ws-filters {
    display: block;
    max-width: 36rem;              /* on desktop, stretched full-width buttons read as a banner */
    margin-bottom: 0.5rem;
  }

  /* Show only the checked direction... */
  .weekly-schedule:has(input[name="ws-dir"][value="quadraToC"]:checked) .ws-direction:not([data-direction="quadraToC"]),
  .weekly-schedule:has(input[name="ws-dir"][value="campbellToQ"]:checked) .ws-direction:not([data-direction="campbellToQ"]),
  .weekly-schedule:has(input[name="ws-dir"][value="quadraToCortes"]:checked) .ws-direction:not([data-direction="quadraToCortes"]),
  .weekly-schedule:has(input[name="ws-dir"][value="cortesToQ"]:checked) .ws-direction:not([data-direction="cortesToQ"]),
  /* ...and the one group of days that includes the checked day. */
  .weekly-schedule:has(input[name="ws-day"][value="mon"]:checked) .ws-day:not([data-days~="mon"]),
  .weekly-schedule:has(input[name="ws-day"][value="tue"]:checked) .ws-day:not([data-days~="tue"]),
  .weekly-schedule:has(input[name="ws-day"][value="wed"]:checked) .ws-day:not([data-days~="wed"]),
  .weekly-schedule:has(input[name="ws-day"][value="thu"]:checked) .ws-day:not([data-days~="thu"]),
  .weekly-schedule:has(input[name="ws-day"][value="fri"]:checked) .ws-day:not([data-days~="fri"]),
  .weekly-schedule:has(input[name="ws-day"][value="sat"]:checked) .ws-day:not([data-days~="sat"]),
  .weekly-schedule:has(input[name="ws-day"][value="sun"]:checked) .ws-day:not([data-days~="sun"]) {
    display: none;
  }
}

/* ---- timetable ---- */
.weekly-schedule .ws-note,
.weekly-schedule .ws-firstlast,
.weekly-schedule .ws-related {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ws-muted);
  margin: 0 0 0.75rem;
}

.weekly-schedule .ws-firstlast strong {
  color: var(--ws-ink);
}

.weekly-schedule .ws-direction {
  margin-top: 1.25rem;
}

.weekly-schedule .ws-direction h3 {
  font-size: 1rem;
  margin: 0 0 0.35rem;
  color: var(--ws-ink);
}

.weekly-schedule .ws-day h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.9rem 0 0.4rem;
  color: var(--ws-ink);
}

.weekly-schedule .ws-count {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ws-muted);
}

/* Morning / afternoon / evening: label beside the times, or above them when
   the card is narrow. */
.weekly-schedule .ws-part {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  align-items: start;
  gap: 0.25rem 0.5rem;
  margin-top: 0.45rem;
}

.weekly-schedule .ws-part-label {
  padding-top: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ws-muted);
}

@container (max-width: 480px) {
  .weekly-schedule .ws-part {
    grid-template-columns: minmax(0, 1fr);
  }

  .weekly-schedule .ws-part-label {
    padding-top: 0;
  }
}

.weekly-schedule .ws-times {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.weekly-schedule .ws-times li {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--ws-chip-line);
  border-radius: 6px;
  background: var(--ws-chip-bg);
  color: var(--ws-ink);
  white-space: nowrap;
}

.weekly-schedule .ws-none {
  font-size: 0.85rem;
  color: var(--ws-muted);
  margin: 0;
}

.weekly-schedule .ws-dg {
  font-size: 0.82rem;
  line-height: 1.4;
  margin: 0.5rem 0 0;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: var(--ws-dg-bg);
  color: var(--ws-dg-ink);
}

.weekly-schedule .ws-note {
  margin-top: 1.5rem;
}

.weekly-schedule .ws-related {
  margin: 0;
}

.weekly-schedule .ws-related a {
  color: var(--ws-link);
}

@media (max-width: 480px) {
  .weekly-schedule .ws-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .weekly-schedule .ws-icon,
  .weekly-schedule .ws-opt span {
    transition: none;
  }
}
