/*
 * Powerhut Tides
 * Loaded only on pages that use [phut_tides]. All classes start phut-tides-.
 * Colours inherit from the theme where possible; override in the theme's CSS
 * or Elementor > Site Settings > Custom CSS.
 */

.phut-tides {
	margin: 0 0 1.5em;
}

.phut-tides-title {
	margin: 0 0 0.5em;
}

.phut-tides-table {
	width: 100%;
	max-width: 420px;
	border-collapse: collapse;
	font-variant-numeric: tabular-nums; /* times and heights line up */
}

.phut-tides-caption {
	caption-side: top;
	text-align: left;
	font-size: 0.85em;
	padding-bottom: 0.4em;
	opacity: 0.8;
}

.phut-tides-table th,
.phut-tides-table td {
	padding: 0.3em 0.6em;
	text-align: left;
	border-bottom: 1px solid rgba( 0, 0, 0, 0.1 );
}

.phut-tides-table thead th {
	font-size: 0.85em;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.phut-tides-day-row th {
	background: rgba( 0, 0, 0, 0.04 );
	font-weight: 600;
}

.phut-tides-height {
	text-align: right;
	white-space: nowrap;
}

.phut-tides-high .phut-tides-type {
	font-weight: 600;
}

/* Tides earlier today: still shown, but faded */
.phut-tides-past {
	opacity: 0.55;
}

.phut-tides-approx {
	cursor: help;
}

.phut-tides-note,
.phut-tides-stale,
.phut-tides-empty {
	font-size: 0.85em;
	margin: 0.5em 0 0;
}

.phut-tides-admin-error {
	font-size: 0.85em;
	margin: 0.5em 0 0;
	padding: 0.4em 0.6em;
	border-left: 3px solid #d63638;
	background: #fcf0f1;
	color: #1d2327;
}

/* ------------------------------------------------------------------------
 * Side by side: [phut_tides stations="..."]  (0.2.0)
 *
 * Markup: .phut-tides-group > [h2] + .phut-tides-columns > .phut-tides (x 1-3) + attribution
 *
 * Each station takes exactly a third of the width, even with only 1 or 2
 * stations, so a page with two stations lines up with a page with three.
 * minmax( 0, 1fr ) rather than plain 1fr: 1fr won't shrink below a column's
 * content, so a long title or table could make one column wider than the others.
 *
 * Why a container query (@container) rather than a screen-width @media query:
 * the shortcode often sits in an Elementor column or sidebar much narrower than
 * the screen. @media sees a 1400px screen and squeezes three tables into a 400px
 * column; @container looks at the width of the group itself, so it stacks there.
 * container-type goes on the group wrapper; the grid is on .phut-tides-columns
 * inside it, because a container query can only style the container's children.
 *
 * Below 768px the columns stack in one column. DOM order = sort order, so the
 * earliest tide is on top. 768px gives each table about 240px, about the least
 * a Tide | Time | Height table needs.
 * ---------------------------------------------------------------------- */

.phut-tides-group {
	container-type: inline-size;      /* measure this box's width for @container below */
	container-name: phut-tides-group;
	margin: 0 0 1.5em;
}

/* Narrow (and the starting point): one column, stacked */
.phut-tides-columns {
	display: grid;
	grid-template-columns: minmax( 0, 1fr );
	gap: 1.5em;
	align-items: start;
}

/* Wide: three equal thirds */
@container phut-tides-group ( min-width: 768px ) {
	.phut-tides-columns {
		grid-template-columns: repeat( 3, minmax( 0, 1fr ) );
	}
}

/* Group title and the single acknowledgement sit outside the grid, full width */
.phut-tides-group-title {
	margin: 0 0 0.75em;
}

.phut-tides-group > .phut-tides-attribution {
	margin: 0.75em 0 0;
}

/* Columns: no bottom margin of their own, tables fill the column */
.phut-tides-columns > .phut-tides {
	margin: 0;
	min-width: 0; /* lets a grid item shrink below its content width */
}

.phut-tides-columns .phut-tides-table {
	max-width: none;
}

/* Fallback (commented out): a screen-width @media query.
 * Container queries work in Chrome/Edge 105+, Safari 16+ and Firefox 110+ (all
 * since early 2023). Older browsers ignore the @container block and just show one
 * stacked column, which is still readable. If that ever matters, uncomment this:
 * @supports only applies it where container queries are missing. Note it goes by
 * the screen width, so it won't stack inside a narrow Elementor column. */
/*
@supports not ( container-type: inline-size ) {
	@media ( min-width: 768px ) {
		.phut-tides-columns {
			grid-template-columns: repeat( 3, minmax( 0, 1fr ) );
		}
	}
}
*/

/* Alternative (commented out): the earlier auto-fit version.
 * Fits as many columns of at least 240px as there is room for, and needs no
 * breakpoint, but 1 or 2 stations stretch to fill the whole width instead of
 * taking a third each, which is why it was swapped for the above. */
/*
.phut-tides-columns {
	grid-template-columns: repeat( auto-fit, minmax( min( 240px, 100% ), 1fr ) );
}
*/

/* UKHO branding requirement: Arial, at least 12px, on two lines, black, white or ADMIRALTY blue */
.phut-tides-attribution {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 1.4;
	color: #000;
	margin: 0.75em 0 0;
}

/* Example (commented out): white attribution on a dark section */
/*
.dark-section .phut-tides-attribution {
	color: #fff;
}
*/
