/* Schedule widget (Tabler branch) – a day laid out as columns over a time axis.

   The markup is built by static/js/schedule.js; everything here only positions it. The
   geometry lives in two custom properties the script sets on the grid:

       --schedule-minute-height   how tall one minute is (px)
       --schedule-columns         how many columns the day has

   Colours come from the theme, so light and dark mode follow without a second palette. */

.schedule {
    --schedule-minute-height: 1px;
    --schedule-axis-width: 3.5rem;
    --schedule-column-min: 9rem;
    --schedule-line: var(--tblr-border-color);
    /* The half hour is a hint, not a division – clearly fainter than the full hour, or the
       eye reads two lines of equal weight per hour. */
    --schedule-line-half: color-mix(in srgb, var(--tblr-border-color) 45%, transparent);
}

/* The scroll box: the axis and the column heads stay put inside it, so a day with many
   tracks scrolls sideways without losing its labels. */
.schedule-scroll {
    overflow: auto;
    max-height: 70vh;
}

.schedule-grid {
    display: grid;
    grid-template-columns: var(--schedule-axis-width) repeat(var(--schedule-columns), minmax(var(--schedule-column-min), 1fr));
    grid-template-rows: auto 1fr;
    min-width: min-content;
}

/* Head row -------------------------------------------------------------------------- */

.schedule-corner,
.schedule-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--tblr-bg-surface);
    border-bottom: 1px solid var(--schedule-line);
}

.schedule-corner {
    grid-row: 1;
    grid-column: 1;
    left: 0;
    z-index: 3;
    border-right: 1px solid var(--schedule-line);
}

/* Rows are named rather than left to auto placement: the head belongs in the first row,
   everything else in the second, whatever order the script appends them in. */
.schedule-head {
    grid-row: 1;
    padding: 0.25rem 0.5rem;
    border-left: 1px solid var(--schedule-line);
    min-width: 0;
}

.schedule-head-title {
    font-weight: var(--tblr-font-weight-medium);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schedule-head-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.125rem;
}

/* Time axis ------------------------------------------------------------------------- */

.schedule-axis {
    grid-row: 2;
    grid-column: 1;
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--tblr-bg-surface);
    border-right: 1px solid var(--schedule-line);
}

/* The label sits above its line, right-aligned against the axis edge – the same way a
   ruler is read. */
.schedule-axis-label {
    position: absolute;
    right: 0.375rem;
    transform: translateY(-0.6em);
    font-size: 0.75rem;
    line-height: 1;
    color: var(--tblr-secondary);
}

.schedule-axis-label-first {
    transform: translateY(0.1em);
}

.schedule-axis-label-last {
    transform: translateY(-1.2em);
}

/* Columns --------------------------------------------------------------------------- */

.schedule-column {
    grid-row: 2;
    position: relative;
    border-left: 1px solid var(--schedule-line);
    min-width: 0;
    /* Full hours draw a line, half hours a fainter one. Both gradients repeat once per
       hour – with a half-hour period the second one would put a line on every full hour as
       well and each hour would show a double stroke. --schedule-line-offset shifts them to
       the first full hour, because the window may start on a half hour (08:30), and the
       lines would otherwise sit half an hour off from the labels of the axis. */
    background-position: 0 var(--schedule-line-offset, 0);
    background-image:
        repeating-linear-gradient(
            to bottom,
            var(--schedule-line) 0,
            var(--schedule-line) 1px,
            transparent 1px,
            transparent calc(60 * var(--schedule-minute-height))
        ),
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent calc(30 * var(--schedule-minute-height)),
            var(--schedule-line-half) calc(30 * var(--schedule-minute-height)),
            var(--schedule-line-half) calc(30 * var(--schedule-minute-height) + 1px),
            transparent calc(30 * var(--schedule-minute-height) + 1px),
            transparent calc(60 * var(--schedule-minute-height))
        );
}

/* Slots ----------------------------------------------------------------------------- */

.schedule-slot {
    position: absolute;
    display: block;
    overflow: hidden;
    padding: 0.125rem 0.375rem;
    text-align: left;
    font-size: 0.75rem;
    line-height: 1.25;
    color: var(--tblr-body-color);
    /* Opaque, so a slot covers the grid lines behind it: Tabler's -lt tints are
       translucent, which would let the hour lines run straight through the slot. Surface
       colour underneath, the tint painted over it. */
    background-color: var(--tblr-bg-surface);
    background-image: linear-gradient(var(--tblr-primary-lt), var(--tblr-primary-lt));
    border: 1px solid transparent;
    border-left: 3px solid var(--tblr-primary);
    border-radius: var(--tblr-border-radius);
    cursor: pointer;
}

.schedule-slot:hover {
    border-color: var(--tblr-primary);
    z-index: 4;
}

.schedule-slot:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: 1px;
    z-index: 4;
}

/* A slot that says something is off – a missing second examiner, a room that is not
   booked. Orange is the same warning tone the room selects use. */
.schedule-slot[data-variant="warning"] {
    background-image: linear-gradient(var(--tblr-orange-lt), var(--tblr-orange-lt));
    border-left-color: var(--tblr-orange);
}

.schedule-slot[data-variant="warning"]:hover {
    border-color: var(--tblr-orange);
}

.schedule-slot[data-editable="false"] {
    cursor: default;
}

.schedule-slot-title {
    font-weight: var(--tblr-font-weight-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-slot-time {
    font-weight: var(--tblr-font-weight-normal);
    color: var(--tblr-secondary);
}

.schedule-slot-line {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--tblr-secondary);
}

/* Short slots have room for the first line only; hiding the rest beats cutting a line in
   half. 2.25rem is about 30 minutes at the default height. */
.schedule-slot[data-compact="true"] .schedule-slot-line {
    display: none;
}

.schedule-slot-warning {
    color: var(--tblr-orange);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The grip for changing the end. Invisible until the pointer is on the slot – a handle on
   every slot at all times would clutter the day. */
.schedule-slot-handle {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 0.375rem;
    cursor: ns-resize;
}

.schedule-slot:hover .schedule-slot-handle::after,
.schedule-slot.is-active .schedule-slot-handle::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 2px;
    width: 1.25rem;
    height: 2px;
    transform: translateX(-50%);
    border-radius: 1px;
    background: var(--tblr-primary);
    opacity: 0.6;
}

.schedule-slot.is-active {
    z-index: 5;
    box-shadow: var(--tblr-box-shadow-sm);
}

/* While a slot is moved, the pointer owns it – no text selection, no tooltips. */
.schedule.is-dragging {
    cursor: ns-resize;
    user-select: none;
}

/* Now marker ------------------------------------------------------------------------ */

/* Drawn per column instead of as one band across the grid: a band would have to claim its
   own grid cell and would push the columns out of their row. */
.schedule-now {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--tblr-red);
    pointer-events: none;
    z-index: 3;
}

.schedule-column:first-of-type .schedule-now::before {
    content: "";
    position: absolute;
    left: 0;
    top: -3px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tblr-red);
}

.schedule-empty {
    grid-column: 1 / -1;
    padding: 1rem;
    color: var(--tblr-secondary);
}
