/**
 * GO4TASTE Editorial – shared look of the tables in posts (#17).
 *
 * Replaces the <style> blocks pasted into posts ("Własny HTML"), removed by
 * `wp go4taste-editorial clean-content`. The base is their most common variant. All rules are scoped to the
 * go4taste-* classes, so they do not touch the rest of the page. Inline styles of the tables still win.
 *
 * Loaded on single posts whose content uses the classes ({@see G4T_Editorial\Front\Tables}).
 */

/* Horizontal scroll of a wide table on narrow screens. */
.go4taste-table-wrapper {
	width: 100%;
	margin: 20px 0;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.go4taste-table {
	width: 100%;
	border-collapse: collapse;
	font-family: Arial, sans-serif;
	font-size: 14px;
}

.go4taste-table-wrapper > .go4taste-table {
	margin: 0;
}

.go4taste-table th {
	padding: 10px;
	background-color: #003d18;
	color: #fff;
	text-align: left;
}

.go4taste-table td {
	padding: 10px;
	border: 1px solid #e3ecc8;
}

/*
 * Stripes from the second data row on (the first one borders the header). Set on the cells, so they win over
 * the inline `background` of the rows pasted with the tables (e.g. `tr style="background:#fafafa"`). Rows with
 * the dark header color stay as they are. A header row inside tbody (th cells, no thead) shifts the count.
 * The row conditions sit in :where(), so the hover and the section rows below outrank every stripe rule.
 */
.go4taste-table :where(tbody tr:nth-child(even):not([style*="003d18" i])) > td {
	background-color: #f3f7ea;
}

.go4taste-table :where(tbody:has(> tr:first-child > th) tr:nth-child(even)) > td {
	background-color: transparent;
}

.go4taste-table :where(tbody:has(> tr:first-child > th) tr:nth-child(odd):not(:first-child):not([style*="003d18" i])) > td {
	background-color: #f3f7ea;
}

.go4taste-table tbody tr:not([style*="003d18" i]):hover > td {
	background-color: #e5edcf;
}

.go4taste-table td:first-child {
	color: #003d18;
	font-weight: 700;
}

/*
 * Cards on phones: a table whose cells name their column (`td data-label="…"`) shows each row as a card,
 * label next to the value (about 20 posts had this layout in their own <style>).
 */
@media (max-width: 600px) {

	.go4taste-table:has(td[data-label]),
	.go4taste-table:has(td[data-label]) tbody,
	.go4taste-table:has(td[data-label]) tr {
		display: block;
		width: 100%;
	}

	/* The header row is replaced by the labels; hidden visually only, screen readers keep it. */
	.go4taste-table:has(td[data-label]) thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.go4taste-table:has(td[data-label]) tr {
		margin-bottom: 12px;
		border: 1px solid #e3ecc8;
	}

	/* Block, not grid or flex: a cell with text and inline tags (<strong>, <br>) stays one flow. */
	.go4taste-table td[data-label] {
		display: block;
		position: relative;
		min-height: 2.5em;
		padding-left: 50%;
		border: 0;
		border-bottom: 1px solid #e3ecc8;
	}

	.go4taste-table td[data-label]:last-child {
		border-bottom: 0;
	}

	.go4taste-table td[data-label]::before {
		content: attr(data-label);
		position: absolute;
		top: 10px;
		left: 10px;
		width: calc(50% - 20px);
		color: #003d18;
		font-weight: 700;
	}
}

/* Section rows inside a table; the doubled class outranks the stripes and the hover. */
.go4taste-table.go4taste-table tbody tr.section > td,
.go4taste-table.go4taste-table tbody tr.section-row > td {
	background-color: #b1c903;
	color: #003d18;
	font-weight: 700;
}

/* Table "card": a title bar above the table and a note below it. */
.go4taste-wrapper {
	margin-bottom: 45px;
	font-family: Arial, sans-serif;
}

.go4taste-title {
	padding: 18px;
	background-color: #003d18;
	color: #fff;
	font-size: 22px;
}

.go4taste-title span,
.go4taste-highlight {
	color: #b1c903;
	font-weight: 700;
}

/* A highlighted first cell keeps the brand lime only on the title bar; in the table it stays readable. */
.go4taste-table td.go4taste-highlight {
	color: #003d18;
}

.go4taste-note {
	margin-top: 18px;
	padding: 16px;
	border-left: 4px solid #b1c903;
	background-color: #f4f8e6;
	font-size: 14px;
}
