/*
 * Hinnasto- ja toimitusaikataulukko (template-hinnasto-taulukko.php).
 * Enqueued only on that page (see the is_page_template() check in
 * functions.php). Uses the theme's design tokens (:root, style.css) and the
 * design system classes in the markup.
 *
 * Sticky header: thead th is position: sticky within
 * .hinnasto-taulukko__table-wrap, which has a max-height and its own
 * vertical scrollbar at every breakpoint. The bounded height is required:
 * the wrapper needs overflow-x: auto (wide table scrolls sideways), which
 * per the CSS Overflow spec also computes overflow-y as auto, making the
 * wrapper the scroll container sticky positions against. Without a bounded
 * height it never scrolls internally and the header never sticks.
 */

/* Page width, side margins and top/bottom space come from DS .pagelayout
   .pt-xl .pb-xl in the markup. Title area: DS .title-page -- heading, the
   disclaimer as its description, the filter as its action; heading left and
   description/filter right from the DS md breakpoint up. Only the gap down
   to the table is set here. */
.hinnasto-taulukko__title {
	margin-bottom: var(--v-space-l);
	row-gap: var(--v-space-16);
}

.hinnasto-taulukko__disclaimer a {
	color: inherit;
}

/* Filter dropdown: styled by the design system's default <select> (48px,
   DS border/focus ring, chevron icon). Only the width is set here; a
   `background` shorthand would wipe out the DS chevron (a background-image). */
.hinnasto-taulukko__filter-label select {
	width: 100%;
	max-width: 320px;
}

.hinnasto-taulukko__table-wrap {
	margin-top: 24px;
	overflow-x: auto;
	overflow-y: auto;
	max-height: 70vh;
	/* Containing block for the visually hidden (.sr-only, position: absolute)
	   spans inside the cells. Without it they are positioned against the page,
	   escape this scroll box and stretch the whole document (empty space below
	   the footer, and sideways on narrow screens). */
	position: relative;
}

/* Always-visible scrollbars. macOS/iOS overlay scrollbars hide until the
   user scrolls, so there is no cue that the table has more content to the
   right or below (WCAG 1.4.11: black thumb, about 18:1 against the track). Chromium and
   Safari use the ::-webkit-scrollbar rules, which force a classic scrollbar;
   Firefox uses scrollbar-color. The standard properties are applied only
   where ::-webkit-scrollbar is unsupported, because in Chrome 121+ they
   would override the webkit styling and bring the overlay behavior back. */
.hinnasto-taulukko__table-wrap::-webkit-scrollbar {
	width: 14px;
	height: 14px;
}

.hinnasto-taulukko__table-wrap::-webkit-scrollbar-track {
	background: #f2f2f2;
}

.hinnasto-taulukko__table-wrap::-webkit-scrollbar-thumb {
	background: var(--color-text-muted, #5e5e5e);
	border: 3px solid #f2f2f2;
	border-radius: 7px;
}

.hinnasto-taulukko__table-wrap::-webkit-scrollbar-thumb:hover {
	background: #4a4a4a;
}

.hinnasto-taulukko__table-wrap::-webkit-scrollbar-corner {
	background: #f2f2f2;
}

@supports not selector(::-webkit-scrollbar) {
	.hinnasto-taulukko__table-wrap {
		scrollbar-width: auto;
		scrollbar-color: #5e5e5e #f2f2f2;
	}
}

/* The DS .table class in the markup gives the cell padding (12px / 8px),
   1px row lines, semibold start-aligned headers and the white background.
   Set here: full width, 14px DS text size (keeps the nine-column table
   from scrolling sideways on laptops), numbers on one line, and the sticky,
   clickable, wrapping headers. */
.hinnasto-taulukko__table {
	width: 100%;
	font-size: var(--v-font-14-size);
	line-height: var(--v-font-14-lineheight);
	white-space: nowrap;
}

.hinnasto-taulukko__table thead th {
	position: sticky;
	top: 0;
	z-index: 2;
	cursor: pointer;
	user-select: none;
	/* The DS header cells don't wrap; these long Finnish labels have to,
	   or the table becomes several screens wide. */
	white-space: normal;
	text-wrap: balance;
	vertical-align: bottom;
	background-color: var(--v-color-background-primary);
	/* Row line that stays under the header while it is pinned. */
	box-shadow: 0 1px 0 var(--color-border);
}

/* The header label is a real <button> (keyboard and screen reader sorting):
   reset to look like the plain header text, with the focus ring kept. */
.hinnasto-taulukko__sort {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	text-align: inherit;
	text-wrap: inherit;
	cursor: pointer;
}

.hinnasto-taulukko__sort:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* Model names are row headers (<th scope="row">) but look like the other
   body cells. */
.hinnasto-taulukko__table tbody th {
	background: transparent;
	font-weight: inherit;
	text-align: start;
	white-space: nowrap;
}

/* Sort-direction arrow: the DS chevron icon as a mask, so it takes the text
   colour. The DS icon files are sprites (four 16px variants stacked), so
   only the top 16px is shown. Rendered only on the active sort column
   (.dir-d / .dir-u, set by sortByColumn() in assets/js/hinnasto-taulukko.js),
   so unsorted headers reserve no extra space. */
.hinnasto-taulukko__table th.dir-d::after,
.hinnasto-taulukko__table th.dir-u::after {
	content: '';
	display: inline-block;
	width: 16px;
	height: 16px;
	margin-inline-start: 4px;
	vertical-align: -3px;
	background-color: currentColor;
	-webkit-mask: var(--sort-icon) 0 0 / 16px 64px no-repeat;
	mask: var(--sort-icon) 0 0 / 16px 64px no-repeat;
}

.hinnasto-taulukko__table th.dir-d::after {
	--sort-icon: url('https://www.volvocars.com/static/shared/icons/v5/chevron-up-16.svg');
}

.hinnasto-taulukko__table th.dir-u::after {
	--sort-icon: url('https://www.volvocars.com/static/shared/icons/v5/chevron-down-16.svg');
}

/* All columns are start-aligned (left), header included, same as the DS
   table. Number columns keep tabular figures so digits are even-width. */
.hinnasto-taulukko__table th.col-num,
.hinnasto-taulukko__table td.num {
	text-align: start;
}

/* Extra space before the Toimitusaika-arvio column so its text doesn't
   run into the Käyttö value next to it. */
.hinnasto-taulukko__table .col-toimitus {
	padding-inline-start: var(--v-space-32, 32px);
}

.hinnasto-taulukko__table td.num {
	font-variant-numeric: tabular-nums;
}

/* Alternating row background, driven by JS (applyZebraStriping() in
   assets/js/hinnasto-taulukko.js) rather than :nth-child(even), which would
   count rows hidden by the filter. .is-even-row is recomputed after every
   filter change and sort, so it always matches the visible rows. */
.hinnasto-taulukko__table tbody tr.is-even-row {
	/* DS secondary background (same token the DS odd:bg-secondary uses). */
	background-color: var(--v-color-background-secondary);
}

.hinnasto-taulukko__row.is-hidden {
	display: none;
}

.hinnasto-taulukko__footnote {
	/* DS disclaimer (.micro .text-secondary in the markup). No border line
	   above: the table's last row line already sits right above it. */
	margin-top: 20px;
}

.hinnasto-taulukko__footnote p + p {
	margin-top: 4px;
}


