// Logs screen: the entry list, with one entry opening under its row. Built by `npm run build` into
// build/logs.css. The panel, row title, badges and shared table rules are in _components.scss.
@use "tokens" as *;
@use "components";

.cf7hs-ui.cf7hs-logs {
	// The Time column plus its padding: where the form title starts, so the details line up with it.
	--cf7hs-log-indent: 156px;


	// Toolbar (shared rules in _components.scss): the form filter sits just left of the search.
	.cf7hs-ui__filter {
		order: 2;
		display: flex;
		align-items: center;
		align-self: center;
		gap: $grid-unit-10;
		margin-inline-start: auto;

		select { min-height: $button-size-compact; max-width: 200px; font-size: 13px; }
		.button { min-height: $button-size-compact; }
	}
	.cf7hs-ui__filter + .cf7hs-ui__search { margin-inline-start: 0; }
	.cf7hs-ui__search { order: 3; }
	.cf7hs-ui__views-nav { order: 1; }
	// With JavaScript the select applies on change (logs.js), so its button is only the fallback.
	.cf7hs-logs__list.has-js .cf7hs-ui__filter-apply { display: none; }

	// Below the table: "N entries · Kept for N days" and, past one page, the pagination.
	.tablenav.bottom {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-between;
		gap: $grid-unit-10 $grid-unit-20;

		.tablenav-pages { margin: 0; float: none; }
		.displaying-num { display: none; }
	}

	.wp-list-table {
		// Top-aligned, so the time, the title and the result badge share their first line.
		tbody > tr > * { vertical-align: top; }
		.column-time { inline-size: 120px; }
		.column-result { inline-size: 220px; }

		// An entry opens under its row: the row and its details share one light background.
		tbody > tr.is-open > * { background: $row-tint; border-block-end: 0; }
		tbody > tr.cf7hs-log-expand > td {
			padding-block: $grid-unit-05 $grid-unit-20;
			padding-inline: var(--cf7hs-log-indent) $grid-unit-30;
			background: $row-tint;
			border-block-end: 1px solid $gray-200;
		}
		tbody > tr.cf7hs-log-expand > td:focus { outline: none; }
		tbody > tr.cf7hs-log-expand > td:focus-visible { outline: $focus-width solid $accent; outline-offset: calc(-1 * #{$focus-width}); }
	}

	// The title: a link without JavaScript, a disclosure button (with a chevron) with it.
	button.cf7hs-log-toggle {
		display: inline-flex;
		align-items: center;
		gap: $grid-unit-10;
		margin: 0;
		padding: 0;
		border: 0;
		background: none;
		font: inherit;
		font-weight: 500;
		color: $gray-900;
		text-align: start;
		cursor: pointer;
	}
	button.cf7hs-log-toggle:hover { color: $accent; }
	button.cf7hs-log-toggle:focus-visible { outline: $focus-width solid $accent; outline-offset: 2px; border-radius: $radius-small; }
	.cf7hs-log-chev {
		flex: none;
		width: 6px;
		height: 6px;
		margin-inline-start: -14px; // Hangs in the cell padding, so the title lines up with the line under it.
		border-inline-end: 1.5px solid currentColor;
		border-block-end: 1.5px solid currentColor;
		transform: rotate(-45deg);
		transition: transform 0.1s ease;
	}
	button.cf7hs-log-toggle[aria-expanded="true"] .cf7hs-log-chev { transform: rotate(45deg); }
	@media (prefers-reduced-motion: reduce) {
		.cf7hs-log-chev { transition: none; }
	}

	// One entry's details (admin/log-entry).
	.cf7hs-log-entry { display: flex; flex-direction: column; gap: $grid-unit-20; max-width: 820px; }
	.cf7hs-log-loading { display: flex; align-items: center; gap: $grid-unit-10; margin: $grid-unit-10 0 0; font-size: 13px; color: $text-muted; }
	.cf7hs-log-loading .spinner { float: none; margin: 0; }
	.cf7hs-log-expand .notice { margin: $grid-unit-10 0 0; }
	.cf7hs-log-outside { padding-block: $grid-unit-20; padding-inline: $grid-unit-30; }
	.cf7hs-log-outside-title { display: flex; flex-wrap: wrap; align-items: center; gap: $grid-unit-10; margin: 0 0 $grid-unit-20; font-size: 15px; font-weight: 600; }
	.cf7hs-log-kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: $grid-unit-10 $grid-unit-15; margin: 0; font-size: 13px; }
	.cf7hs-log-kv dt { color: $text-muted; }
	.cf7hs-log-kv dd { margin: 0; overflow-wrap: anywhere; }
	.cf7hs-log-request { background: $white; border: 1px solid $gray-200; border-radius: $radius-small; padding: 10px $grid-unit-15; font-size: 12px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
	.cf7hs-log-request:focus-visible { outline: $focus-width solid $accent; outline-offset: 1px; }
	// Long requests show 12 lines until "Show all N lines" (logs.js).
	.cf7hs-log-request.is-capped { max-block-size: calc(12 * 1.6em + 20px); overflow: hidden; }
	.cf7hs-log-more { align-self: flex-start; margin-block-start: -$grid-unit-10; font-size: 13px; }
	.cf7hs-log-rejected { background: #fcf0f1; color: #8a2424; }
	.cf7hs-log-actions { display: flex; flex-wrap: wrap; align-items: center; gap: $grid-unit-10; }
	.cf7hs-log-masked { margin-block: 0; margin-inline-start: auto; color: $text-muted; }
	.cf7hs-log-copy-fallback textarea { margin-block-start: $grid-unit-10; font-size: 12px; }

	.cf7hs-log-legacy { padding-inline: $grid-unit-20; }
	.cf7hs-log-legacy summary { cursor: pointer; padding-block: $grid-unit-05; font-weight: 500; }
	.cf7hs-log-legacy pre { max-block-size: 320px; overflow: auto; white-space: pre-wrap; }
	.cf7hs-log-footer { margin: 0; font-size: 13px; color: $text-muted; }
	.cf7hs-log-table-error form p { margin-block: 0 $grid-unit-10; }

	.cf7hs-ui__mobile-meta { display: none; }

	@media (max-width: 782px) {
		// Core keeps the first column on narrow screens and overlays its label; time lives in the form cell there.
		.wp-list-table .column-time { display: none !important; }
		.cf7hs-ui__mobile-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-block-start: 6px; font-size: 12px; color: $text-muted; }
		.wp-list-table .toggle-row { display: none; }
		.cf7hs-log-chev { margin-inline-start: 0; } // No room to hang it in the narrow cell padding.
		.cf7hs-log-kv { grid-template-columns: 1fr; gap: 2px; }
		.cf7hs-log-kv dd + dt { margin-block-start: $grid-unit-10; }
		// Core hides every cell but the primary one on phones; the details cell spans the row.
		.wp-list-table tbody > tr.cf7hs-log-expand > td { display: block; padding-block: 0 18px; padding-inline: $grid-unit-15; }
		.cf7hs-log-actions .button, .cf7hs-log-more { min-height: $button-size-next-default-40px; }
		.cf7hs-log-masked { margin: 0; flex-basis: 100%; }
		.cf7hs-log-outside { padding-block: $grid-unit-15 $grid-unit-20; padding-inline: $grid-unit-15; }
		.cf7hs-ui__filter {
			order: 1;
			align-self: stretch;
			margin-block: $grid-unit-10 $grid-unit-05;
			margin-inline: $grid-unit-15;

			select { width: 100%; max-width: none; min-height: $button-size-next-default-40px; font-size: 16px; }
			.button { min-height: $button-size-next-default-40px; }
		}
		.cf7hs-ui__search { order: 0; }
		.cf7hs-ui__views-nav { order: 3; }
	}

	@media (forced-colors: active) {
		.cf7hs-log-rejected { forced-color-adjust: none; outline: 1px solid CanvasText; }
		.wp-list-table tbody > tr.is-open > *, .wp-list-table tbody > tr.cf7hs-log-expand > td { border-block-end: 1px solid CanvasText; }
	}
}
