/*
 * MAOL timetable
 *
 * Narrow (default): a chronological list. Each start time is a heading followed by its sessions.
 * Wide: the same elements placed on a grid. Each session's inline style sets its grid-row and
 * grid-column, plus its colors (--maoltt-bg, --maoltt-fg, --maoltt-accent).
 */

.maoltt {
  --maoltt-gap: 6px;
  --maoltt-radius: 6px;
  --maoltt-line: #e2e4e6;
  --maoltt-muted: #5b6670;
  --maoltt-text: #232d37;

  container: maoltt / inline-size;
  margin: 1.5rem 0 2rem;
  color: var(--maoltt-text);
  font-size: 0.9375rem;
  line-height: 1.35;
}

.maoltt *,
.maoltt *::before,
.maoltt *::after {
  box-sizing: border-box;
}

/* ---------- Print button ---------- */

.maoltt__tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.maoltt__print {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid #c5ccd2;
  border-radius: 999px;
  background: #fff;
  color: var(--maoltt-text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.maoltt__print[hidden] {
  display: none;
}

.maoltt__print:hover,
.maoltt__print:focus-visible {
  border-color: var(--maoltt-text);
}

.maoltt__print-title {
  display: none;
}

/* ---------- Narrow: chronological list ---------- */

.maoltt__track-head {
  display: none;
}

.maoltt__slot-time {
  margin: 1.25rem 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--maoltt-line);
  font-size: 1.0625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.maoltt__slot-time:first-child,
.maoltt__track-head + .maoltt__slot-time {
  margin-top: 0;
}

.maoltt__session {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  margin: 0 0 var(--maoltt-gap);
  padding: 0.65rem 0.8rem;
  border: 0;
  border-left: 4px solid var(--maoltt-accent);
  border-radius: var(--maoltt-radius);
  background: var(--maoltt-bg);
  color: var(--maoltt-fg);
  font: inherit;
  text-align: left;
  overflow-wrap: break-word;
  hyphens: auto;
}

.maoltt__session--link {
  scroll-margin-top: 90px; /* below the theme's fixed header when opened from a shared link */
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.maoltt__session--link:hover {
  box-shadow: 0 2px 10px rgba(35, 45, 55, 0.15);
}

.maoltt__session--link:focus-visible {
  outline: 3px solid var(--maoltt-accent);
  outline-offset: 2px;
}

.maoltt__time {
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.maoltt__title {
  font-weight: 700;
}

.maoltt__subtitle {
  font-size: 0.875rem;
}

.maoltt__track {
  font-size: 0.8125rem;
}

.maoltt__badge {
  align-self: flex-start;
  margin-top: 0.15rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #c0392b;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- Wide: grid ---------- */

/*
 * A track needs roughly 120px, so timetables with many tracks switch to the grid later.
 * Renderer adds maoltt--fit-s (up to 5 tracks) or maoltt--fit-l (6–10 tracks).
 * The two blocks below are identical apart from the breakpoint and the class; keep them in sync.
 */
@container maoltt (min-width: 640px) {
  .maoltt--fit-s {
    & .maoltt__grid {
      display: grid;
      grid-template-columns: var(--maoltt-columns, 3.25rem repeat(var(--maoltt-cols), minmax(0, 1fr)));
      gap: var(--maoltt-gap);
  }

  & .maoltt__track-head {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    grid-row: 1;
    padding: 0 0.25rem 0.4rem;
    border-bottom: 2px solid var(--maoltt-text);
    font-size: 0.8125rem;
    line-height: 1.25;
  }

  & .maoltt__track-name {
    font-weight: 700;
  }

  & .maoltt__track-room {
    color: var(--maoltt-muted);
  }

  & .maoltt__slot-time {
    grid-column: 1;
    margin: 0;
    padding: 0.55rem 0 0;
    border: 0;
    color: var(--maoltt-muted);
    font-size: 0.8125rem;
  }

  & .maoltt__session {
    margin: 0;
    padding: 0.5rem 0.6rem;
    border-left-width: 3px;
    font-size: 0.875rem;
  }

  & .maoltt__session--all {
    align-items: center;
    border-left: 0;
    text-align: center;
  }

  & .maoltt__session--all .maoltt__badge {
    align-self: center;
  }

  /* Simultaneous sessions sharing a track (see Renderer::columns) have half the room or less. */
  & .maoltt__session--lane {
    padding: 0.4rem;
    font-size: 0.8125rem;
  }

  & .maoltt__subtitle {
    font-size: 0.8125rem;
  }

  /* The column heading already names the track; keep the label for screen readers only. */
  & .maoltt__track {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  & .maoltt__session--link:hover {
    transform: translateY(-1px);
  }
  }
}

@container maoltt (min-width: 900px) {
  .maoltt--fit-l {
    & .maoltt__grid {
      display: grid;
      grid-template-columns: var(--maoltt-columns, 3.25rem repeat(var(--maoltt-cols), minmax(0, 1fr)));
      gap: var(--maoltt-gap);
  }

  & .maoltt__track-head {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    grid-row: 1;
    padding: 0 0.25rem 0.4rem;
    border-bottom: 2px solid var(--maoltt-text);
    font-size: 0.8125rem;
    line-height: 1.25;
  }

  & .maoltt__track-name {
    font-weight: 700;
  }

  & .maoltt__track-room {
    color: var(--maoltt-muted);
  }

  & .maoltt__slot-time {
    grid-column: 1;
    margin: 0;
    padding: 0.55rem 0 0;
    border: 0;
    color: var(--maoltt-muted);
    font-size: 0.8125rem;
  }

  & .maoltt__session {
    margin: 0;
    padding: 0.5rem 0.6rem;
    border-left-width: 3px;
    font-size: 0.875rem;
  }

  & .maoltt__session--all {
    align-items: center;
    border-left: 0;
    text-align: center;
  }

  & .maoltt__session--all .maoltt__badge {
    align-self: center;
  }

  /* Simultaneous sessions sharing a track (see Renderer::columns) have half the room or less. */
  & .maoltt__session--lane {
    padding: 0.4rem;
    font-size: 0.8125rem;
  }

  & .maoltt__subtitle {
    font-size: 0.8125rem;
  }

  /* The column heading already names the track; keep the label for screen readers only. */
  & .maoltt__track {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  & .maoltt__session--link:hover {
    transform: translateY(-1px);
  }
  }
}

@media (prefers-reduced-motion: reduce) {
  .maoltt__session--link {
    transition: none;
  }

  .maoltt__session--link:hover {
    transform: none;
  }
}

/* ---------- Popup (created by timetable.js, outside .maoltt) ---------- */

.maoltt-dialog {
  width: min(560px, calc(100% - 24px));
  max-height: min(85vh, 800px);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 48px rgba(35, 45, 55, 0.35);
  color: #232d37;
  font-size: 1rem;
  line-height: 1.5;
  overflow: hidden;
}

.maoltt-dialog::backdrop {
  background: rgba(35, 45, 55, 0.6);
}

.maoltt-dialog__inner {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  border-top: 6px solid var(--maoltt-accent, #0574a5);
}

.maoltt-dialog__content {
  padding: 1.25rem 1.5rem 1rem;
  outline: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.maoltt-dialog__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #5b6670;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.maoltt-dialog__close:hover,
.maoltt-dialog__close:focus-visible {
  background: #f1f2f3;
  color: #232d37;
}

.maoltt-dialog__meta {
  margin: 0 2.5rem 0.35rem 0;
  color: #5b6670;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.maoltt-dialog .maoltt-dialog__title {
  margin: 0 2rem 0.5rem 0;
  color: #232d37;
  font-size: 1.375rem;
  line-height: 1.25;
  text-transform: none;
}

.maoltt-dialog__subtitle {
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.maoltt-dialog__description > :first-child {
  margin-top: 0.75rem;
}

.maoltt-dialog__description > :last-child {
  margin-bottom: 0;
}

.maoltt-dialog__footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid #e2e4e6;
  text-align: right;
}

.maoltt-dialog__copy {
  padding: 0.35rem 0.75rem;
  border: 1px solid #c5ccd2;
  border-radius: 999px;
  background: #fff;
  color: #232d37;
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.maoltt-dialog__copy:hover,
.maoltt-dialog__copy:focus-visible {
  border-color: #232d37;
}

/* On phones the popup opens as a sheet from the bottom of the screen. */
@media (max-width: 599px) {
  .maoltt-dialog {
    width: 100%;
    max-width: none;
    max-height: 88vh;
    margin: auto 0 0;
    border-radius: 14px 14px 0 0;
  }
}

/* ---------- Print ---------- */

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  .maoltt .maoltt__grid {
    overflow: visible;
  }

  .maoltt .maoltt__grid > * {
    font-size: 8pt;
  }

  .maoltt .maoltt__grid .maoltt__time,
  .maoltt .maoltt__grid .maoltt__subtitle,
  .maoltt .maoltt__grid .maoltt__track-room {
    font-size: 0.9em;
  }

  .maoltt .maoltt__grid .maoltt__session {
    padding: 0.3rem 0.4rem;
    box-shadow: none;
    transform: none;
    break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .maoltt .maoltt__slot-time {
    break-after: avoid;
  }

  .maoltt-dialog,
  .maoltt__tools {
    display: none;
  }

  /* The print button hides everything around its timetable (timetable.js) and shows the timetable's name. */
  .maoltt-print-hide {
    display: none !important;
  }

  .maoltt-print-path {
    margin: 0 !important;
    padding: 0 !important;
  }

  .maoltt-printing .maoltt {
    margin: 0;
  }

  .maoltt-printing .maoltt__print-title {
    display: block;
    margin: 0 0 0.75rem;
    font-size: 14pt;
    font-weight: 700;
  }
}
