/*
 * A timeline (0.91.0, Ui::timeline(); CONTRACT §8.6, the offers' calendar): a row per item and a column per day, the
 * bars of the times each row runs, the marks of the days that need a look, the legend in words. A real table that
 * scrolls inside its own box, the rows' heads sticky at its start; the page never scrolls sideways. Compiled on its own
 * (assets/timeline.css) and loaded by the first timeline a screen prints, or in the head by Ui::timeline_assets(), so
 * the common path pays nothing (the owner's rule). The legend reuses the chart's list (kit/charts.css).
 */

@reference "./chrome.css";

.rooster-admin-timeline {
	@apply grid min-w-0 gap-3;
	container-type: inline-size;
}

/* The weeks shown and their pager, above the grid. */
.rooster-admin-timeline__head {
	@apply flex flex-wrap items-center gap-x-4 gap-y-2;
}

.rooster-admin-timeline__range {
	@apply m-0 text-sm font-semibold text-foreground;
}

.rooster-admin-timeline__head > .rooster-admin-pager {
	@apply ms-auto;
}

/* The grid: its own scroll region (named by the caption, focusable), its hairlines, a stronger line where a week starts
   (the cells' own rules at no weight, so each part's class sets its padding). */
.rooster-admin-timeline__scroll {
	@apply max-w-full overflow-x-auto rounded-md border border-border bg-card;

	@variant focus-visible {
		@apply outline-2 -outline-offset-2 outline-link;
	}
}

.rooster-admin-timeline__table {
	@apply m-0 w-full border-separate border-spacing-0 text-xs;
}

:where(.rooster-admin-timeline__table) :is(th, td) {
	@apply p-0 align-middle font-normal;
	border-inline-start: 1px solid color-mix(in srgb, var(--ra-border) 60%, transparent);
}

:where(.rooster-admin-timeline__table tbody) :is(th, td) {
	@apply border-t border-t-border;
}

:where(.rooster-admin-timeline__table) :is(th, td).is-week-start {
	border-inline-start-color: var(--ra-control-border);
}

/* The rows' heads and the corner: sticky at the start, on the card's surface, a line at their end. */
.rooster-admin-timeline__corner,
.rooster-admin-timeline__name {
	@apply sticky start-0 z-2 bg-card text-start;
	border-inline-end: 1px solid var(--ra-border);
}

.rooster-admin-timeline__corner {
	@apply px-3 py-1.5 font-semibold text-secondary-foreground;
}

.rooster-admin-timeline__who {
	@apply box-border block w-56 overflow-hidden px-3 py-1.5;
}

.rooster-admin-timeline__link,
.rooster-admin-timeline__label {
	@apply text-sm font-medium text-foreground;
}

.rooster-admin-timeline__link {
	@apply text-link;

	@variant focus-visible {
		@apply ra-ring;
	}
}

.rooster-admin-timeline__note {
	@apply block truncate text-secondary-foreground;
}

/* A week's head names it by its first day; a day's head its weekday over its number, today's number on the accent. */
.rooster-admin-timeline__week {
	@apply truncate px-1.5 py-1 text-start text-2xs text-secondary-foreground;
}

.rooster-admin-timeline__day {
	@apply py-1 text-center text-2xs text-secondary-foreground;
}

.rooster-admin-timeline__dow,
.rooster-admin-timeline__num {
	@apply mx-auto block min-w-7;
}

.rooster-admin-timeline__num {
	@apply size-5 rounded-full text-xs leading-5 font-semibold text-foreground;
}

.rooster-admin-timeline__day.is-today .rooster-admin-timeline__num {
	@apply min-w-5 bg-accent text-accent-on;
}

.rooster-admin-timeline__cell.is-today {
	background: color-mix(in srgb, var(--ra-accent) 7%, transparent);
}

/* A day: its bars across its width (from or to the quarter of a part day), rounded where the bar really starts or
   ends; a draft is an outline; the marks in its top corner. */
.rooster-admin-timeline__cell {
	@apply relative h-10;
}

.rooster-admin-timeline__bar {
	@apply absolute inset-x-0 top-1/2 -mt-2 h-4;
	background: var(--ra-tone);
}

.rooster-admin-timeline__bar.is-draft {
	@apply border border-dashed bg-card;
	border-color: var(--ra-tone);
}

.rooster-admin-timeline__bar.is-start {
	@apply ms-0.5 rounded-s-full;
}

.rooster-admin-timeline__bar.is-end {
	@apply me-0.5 rounded-e-full;
}

.rooster-admin-timeline__bar.is-from-1 {
	@apply start-1/4;
}

.rooster-admin-timeline__bar.is-from-2 {
	@apply start-1/2;
}

.rooster-admin-timeline__bar.is-from-3 {
	@apply start-3/4;
}

.rooster-admin-timeline__bar.is-to-1 {
	@apply end-3/4;
}

.rooster-admin-timeline__bar.is-to-2 {
	@apply end-1/2;
}

.rooster-admin-timeline__bar.is-to-3 {
	@apply end-1/4;
}

.rooster-admin-timeline__marks {
	@apply absolute end-0.5 top-0.5 z-1 flex gap-0.5;
}

.rooster-admin-timeline__mark {
	@apply inline-flex rounded-sm leading-[0];
	color: var(--ra-tone-fg);

	@variant focus-visible {
		@apply ra-ring;
	}
}

/* The legend's swatches: a state's bar, a part of a day, today's column. */
.rooster-admin-timeline__legend {
	@apply mt-0;
}

.rooster-admin-timeline__swatch {
	@apply inline-block h-2.5 w-4 rounded-full;
	background: var(--ra-tone, var(--ra-muted-foreground));
}

.rooster-admin-timeline__swatch.is-draft {
	@apply border border-dashed bg-card;
	border-color: var(--ra-tone);
}

.rooster-admin-timeline__swatch.is-part {
	background: linear-gradient(to right, transparent 50%, var(--ra-muted-foreground) 50%);
}

.rooster-admin-timeline__swatch.is-part:dir(rtl) {
	background: linear-gradient(to left, transparent 50%, var(--ra-muted-foreground) 50%);
}

.rooster-admin-timeline__swatch.is-today {
	@apply rounded-sm;
	background: color-mix(in srgb, var(--ra-accent) 18%, transparent);
}

/* Forced colours: the bars keep their shape in the system's ink. */
@media (forced-colors: active) {
	.rooster-admin-timeline__bar,
	.rooster-admin-timeline__swatch {
		forced-color-adjust: none;
		background: CanvasText;
	}

	.rooster-admin-timeline__bar.is-draft,
	.rooster-admin-timeline__swatch.is-draft {
		background: Canvas;
		border-color: CanvasText;
	}
}

/* A narrow box (a phone, a narrow column): the rows' heads narrow, the grid scrolls inside its box. */
@container (width < 40rem) {
	.rooster-admin-timeline__who {
		@apply w-36;
	}
}
