/*
 * Structure of [bach_timetable]: fixed columns, sticky location column,
 * scrolling, row heights, arrows. The look is the theme's; without it a basic
 * one in :where(), so a theme wins. Needs Bootstrap.
 */

/* Sizes in :where(), so a theme can set them */
:where(.bach-timetables) {
    --bach-location-width: 11rem; /* Number beside the title */
    --bach-slot-min-width: 2rem; /* An hour at least 8rem */
    --bach-location-line: 3px; /* Line right of the locations */
}

/* Wide tables scroll inside the content column */
.bach-timetable-frame {
    position: relative; /* For the arrows */
    margin-bottom: 1.5rem;
}

/* contain: inline-size, so the table scrolls instead of widening the column */
.bach-timetable-scroll {
    overflow-x: auto;
    contain: inline-size;
}

/* Arrows at the edges of the time columns */
.bach-timetable-arrow {
    position: absolute;
    top: 50%;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 0;
    transform: translateY(-50%);
    cursor: pointer;
}

.bach-timetable-arrow[hidden] {
    display: none;
}

.bach-timetable-arrow-earlier {
    left: calc(var(--bach-location-width) + .25rem);
}

.bach-timetable-arrow-later {
    right: .25rem;
}

/* Fixed layout. Separate borders (top and left per cell): collapsed ones don't
   move with the sticky column */
.bach-timetable {
    table-layout: fixed;
    width: max(100%, calc(var(--bach-location-width) + var(--bach-slots) * var(--bach-slot-min-width)));
    border-collapse: separate;
    border-spacing: 0;
    /* No shorthand: it would set the text color */
    border-width: 0 1px 1px 0;
    border-style: solid;
}

/* Slot columns share the rest */
.bach-timetable-location-col {
    width: var(--bach-location-width);
}

.bach-timetable th,
.bach-timetable td {
    position: relative; /* For the stretched links */
    overflow: hidden;
    border-width: 1px 0 0 1px;
    border-style: solid solid solid dotted;
    padding: .25rem;
    vertical-align: top;
}

/* Lines at full hours (solid), half hours (dotted) and beside events */
.bach-timetable td {
    border-left-width: 0;
}

.bach-timetable td.bach-timetable-hour,
.bach-timetable td.bach-timetable-half,
.bach-timetable .bach-timetable-event,
.bach-timetable .bach-timetable-event + td {
    border-left-width: 1px;
}

.bach-timetable .bach-timetable-hour,
.bach-timetable .bach-timetable-event,
.bach-timetable .bach-timetable-event + td {
    border-left-style: solid;
}

/* Rows as high as an event with three lines of artist and the times */
.bach-timetable tbody td {
    height: calc(3 * 1.2em + .75rem * 1.5 + 2 * .25rem + 1px);
}

/* The hours above and below */
.bach-timetable thead th,
.bach-timetable tfoot th {
    text-align: left;
    white-space: nowrap;
}

/* Space before the hours and the locations */
.bach-timetable thead th,
.bach-timetable tfoot th,
.bach-timetable .bach-timetable-location {
    padding-left: .5rem;
}

/* Sticky location column, opaque, bordered on both sides. Shadows: a wider
   line on its right, and 2px more on its left, as the column snaps to whole
   pixels and the scrolled slots don't */
.bach-timetable .bach-timetable-location {
    position: sticky;
    left: 0;
    z-index: 2;
    border-right-width: 1px;
    border-style: solid;
    text-align: left;
    overflow-wrap: break-word;
    background-color: var(--bach-location-bg);
    box-shadow: calc(var(--bach-location-line) - 1px) 0 0 var(--bach-location-border-color),
        -2px 0 0 var(--bach-location-border-color);
}

.bach-timetable tr > .bach-timetable-location + *,
.bach-timetable tbody tr > td:first-child {
    border-left-width: 0;
}

/* Phones: narrower location column, the number above the title */
@media (max-width: 575.98px) {
    :where(.bach-timetables) {
        --bach-location-width: 8rem;
    }

    .bach-timetable-location-content {
        flex-direction: column;
        gap: .25rem;
    }
}

/* Location header: number (a circle) beside the wrapping title */
.bach-timetable-location-content {
    display: flex;
    align-items: flex-start;
    gap: .375rem;
}

.bach-timetable-location-number {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid;
    border-radius: 50%;
    font-size: .6875rem;
    font-weight: bold;
    line-height: 1;
}

.bach-timetable-location-title {
    min-width: 0;
    hyphens: auto; /* Long German names */
}

/* Sort switch in the corner cell, small enough for the column */
.bach-timetable-sort .btn-group {
    flex-wrap: nowrap;
}

.bach-timetable-sort .btn {
    padding: .125rem .375rem;
    font-size: .75rem;
    white-space: nowrap;
}

/* Event cell: the artist image beside times and name when there's room
   (container query on the cell's content); as high as the content. Hidden
   images don't load */
.bach-timetable-event-content {
    container: bach-timetable-event / inline-size;
    display: flex;
    gap: .375rem;
}

.bach-timetable-event-text {
    flex: 1;
    min-width: 0;
}

.bach-timetable-event-image {
    display: none;
    flex: none;
    width: calc(3 * 1.2em + .75rem * 1.5);
    height: calc(3 * 1.2em + .75rem * 1.5);
    object-fit: cover;
}

@container bach-timetable-event (min-width: 10rem) {
    .bach-timetable-event-image {
        display: block;
    }
}

/* Artist: at most three lines */
.bach-timetable-artist {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    overflow-wrap: anywhere;
    line-height: 1.2;
}

.bach-timetable-times {
    display: block;
    overflow: hidden;
    font-size: .75rem;
    line-height: 1.5;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Tooltip: compact, the image beside times, name and details. As wide as its
   content, at most six half-hour cells (2 * 6 * 2rem), at least 2/3 of that,
   within narrow windows */
.bach-timetable-tooltip {
    --bs-tooltip-max-width: min(24rem, 100vw - 2rem);
    --bach-tooltip-image-size: 6rem;
}

.bach-timetable-tooltip .tooltip-inner {
    min-width: min(16rem, 100vw - 2rem);
    display: flex;
    align-items: center;
    gap: .5rem;
    text-align: left;
}

/* Square image box with a spinner; hidden until loaded */
.bach-timetable-tooltip-media {
    position: relative;
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: var(--bach-tooltip-image-size);
    height: var(--bach-tooltip-image-size);
}

.bach-timetable-tooltip-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bach-timetable-js .bach-timetable-tooltip-media:not(.bach-loaded) .bach-timetable-tooltip-image {
    opacity: 0;
}

.bach-timetable-tooltip-media.bach-loaded .spinner-border,
.bach-timetable-tooltip-media.bach-failed {
    display: none;
}

.bach-timetable-tooltip-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    overflow-wrap: break-word;
}

/* Beside the image: times at the top, details at the bottom, the name between */
.bach-timetable-tooltip-media + .bach-timetable-tooltip-text {
    min-height: var(--bach-tooltip-image-size);
}

.bach-timetable-tooltip-media + .bach-timetable-tooltip-text strong {
    margin-block: auto;
}

.bach-timetable-tooltip-text > *,
.bach-timetable-tooltip-details > * {
    display: block;
}

/* Times small above the name, details a bit below */
.bach-timetable-tooltip-times {
    font-size: .75rem;
}

.bach-timetable-tooltip-details {
    margin-top: .25rem;
}

/* Basic look without a theme: Bootstrap's colors */
:where(.bach-timetables) {
    --bach-location-border-color: var(--bs-secondary-color);
    --bach-location-bg: var(--bs-body-bg);
}

:where(.bach-timetable),
:where(.bach-timetable) :where(th, td) {
    border-color: var(--bs-border-color-translucent);
}

:where(.bach-timetable .bach-timetable-event) {
    color: var(--bs-primary-text-emphasis);
    background-color: var(--bs-primary-bg-subtle);
}

:where(.bach-timetable-arrow) {
    color: var(--bs-white);
    background-color: rgba(var(--bs-black-rgb), .6);
}
