@use "styles/variables";

/**
 * Settings Styles
 *
 * DataViews-inspired table layout with extensible column architecture.
 * Used across all settings pages (Core Blocks, Editor Validation, External Plugins).
 */

// Admin page background
// Applied to all settings pages (core blocks, editor validation, external plugins)
body.toplevel_page_block-a11y-checks,
body.accessibility-validation_page_block-a11y-checks-post-page,
body[class*='accessibility-validation_page_block-a11y-checks-'] {
	#wpcontent {
		padding-left: 0;
	}

	.wrap {
		margin: 0;
	}
}

// Header section (React)
.ba11y-settings-header {
	padding: var(--a11y-settings-space);
	border-bottom: 1px solid var(--a11y-light-grey);
	background: #fff;

	h1 {
		margin: 0;
        padding: 0;
		font-size: 1.4rem;
		font-weight: 500;
		line-height: 1.3;
		color: #1d2327;
	}

	p {
		font-size: 0.85rem;
		color: var(--a11y-black);
		margin: 5px 0 0 0;
	}
}

// Save notifications
.ba11y-settings-content .components-notice {
    margin: calc(var(--a11y-settings-space) / 1.5) var(--a11y-settings-space);
    background-color: var(--a11y-lightest-green);
    border: 1px solid var(--a11y-green);
    border-left: 5px solid var(--a11y-dark-green);
    border-radius: 4px;
}

// DataView container
.ba11y-dataview {
	background: #fff;
    margin: 32px 24px;
    padding: 0;
    border-radius: 4px;
	overflow-x: auto;
}

// Table container - using standard HTML table
.ba11y-dataview-table {
	width: 100%;
	border-collapse: collapse;
	border-spacing: 0;

	&.widefat {
		border: none;
	}

	// Override WordPress widefat striped default styles
	tbody tr,
	tbody tr:nth-child(odd),
	tbody tr:nth-child(even) {
		background-color: #fff;
	}

	tbody tr:hover {
		background-color: var(--a11y-lightest-grey) !important;
	}
}

.ba11y-dataview-thead th,
.ba11y-dataview-table td {
    padding: calc(var(--a11y-settings-space) / 2);
    vertical-align: middle;

    &.ba11y-dataview-td-level {
        padding-top: calc(calc(var(--a11y-settings-space) / 2) - 8px);
    }
}

// Table header
.ba11y-dataview-thead {
	th {
		font-size: var(--a11y-font-small);
		font-weight: 500;
		color: var(--a11y-black);
		border-bottom: 1px solid var(--a11y-grey);
		background: #fff;
		text-align: left;
		vertical-align: middle;
	}

	// Set fixed widths for consistent column sizing across all tables
	.ba11y-dataview-th-block {
		min-width: 90px;
        width: 10%;
	}

	.ba11y-dataview-th-category {
		min-width: 90px;
        width: 10%;
	}

	.ba11y-dataview-th-level {
		min-width: 220px;
        width: 220px;
	}

	.ba11y-dataview-th-siteEditor {
		width: 90px;
	}

	// First column (check) will auto-fill remaining space
	.ba11y-dataview-th-check {
		min-width: 180px;
		width: auto;
	}
}

.ba11y-dataview-th-content {
	display: flex;
	align-items: center;
	gap: 2px;
}

// Table cells
.ba11y-dataview-cell {
	font-size: var(--a11y-font-small);
	color: var(--a11y-black);
	padding: calc(var(--a11y-settings-space) / 2);
	border-bottom: 1px solid var(--a11y-light-grey);
	vertical-align: middle;
	text-align: left !important;

    &.ba11y-dataview-cell-level {
        padding-top: calc(var(--a11y-settings-space) / 4);
    }
}

// Check description
.ba11y-check-description {
	color: var(--a11y-black);
}

// Block badge
.ba11y-block-badge,
.ba11y-category-badge {
	display: inline-flex;
	padding: 2px 8px;
	background: var(--a11y-lightest-grey);
    border: 1px solid var(--a11y-light-grey);
	border-radius: 2px;
	font-size: 0.65rem;
	color: var(--a11y-black);
	font-weight: 500;
	white-space: nowrap;
}

.ba11y-dataview-td-level {
    .components-base-control {
        width: 100%;
    }

	.components-toggle-group-control {
		border: 1px solid var(--a11y-grey);
		background: #fff;

        &::before {
            display: none;
        }

		.components-toggle-group-control-option-base {
            color: var(--a11y-black);
			background: #fff;

			&:focus {
				box-shadow: inset 0 0 0 1px #fff, 0 0 0 1.5px #2271b1;
				z-index: 1;
				position: relative;
			}

			&:hover:not([aria-checked='true']) {
				background-color: var(--a11y-lightest-grey);
			}

			&[aria-checked='true'] {
				background: var(--wp-admin-theme-color);
				color: #fff;
			}
		}
	}
}

// // Heading levels checkboxes
.ba11y-heading-levels-checkboxes {
	display: flex;
	gap: 20px;
	justify-content: flex-end;

	.components-checkbox-control__label {
		font-size: var(--a11y-font-small);
		font-weight: 500;
		color: var(--a11y-black);
	}
}

// // Actions footer
.ba11y-settings-actions {
	display: flex;
	align-items: center;
	gap: 20px;
	padding: 0 var(--a11y-settings-space);

	.components-button.is-primary:not(:disabled) {
        background-color: #2271b1;
        border-color: #2271b1;

        &:hover {
            background-color: var(--wp-admin-theme-color);
            border-color: var(--wp-admin-theme-color);
        }
    }

	.ba11y-unsaved-notice {
		font-size: var(--a11y-font-small);
		color: var(--a11y-dark-red);
		font-style: italic;
	}
}

// ========================================
// Responsive Table Styles
// ========================================

// Tablet - reduce margins
@media screen and (max-width: 960px) {
	.ba11y-settings-header,
	.ba11y-settings-content .components-notice,
	.ba11y-settings-actions {
		margin-left: 24px;
		margin-right: 24px;
		padding-left: 24px;
		padding-right: 24px;
	}
}

// Mobile - WordPress responsive table pattern
@media screen and (max-width: 782px) {
	.ba11y-settings-header,
	.ba11y-dataview,
	.ba11y-settings-content .components-notice,
	.ba11y-settings-actions {
		margin-left: var(--a11y-settings-space-mobile);
		margin-right: var(--a11y-settings-space-mobile);
		padding-left: var(--a11y-settings-space-mobile);
		padding-right: var(--a11y-settings-space-mobile);
	}

	// Responsive table layout
	.ba11y-dataview-table {
		border: 0;

		thead {
			display: none;
		}

		tbody {
			display: block;
		}

		tr {
			display: block;
			margin-bottom: 16px;
			border: 1px solid var(--a11y-light-grey);
			border-radius: 4px;
			background: #fff !important;

			&:last-child {
				margin-bottom: 0;
			}
		}

		td {
			display: block;
			border: none;
			text-align: left !important;

			&::before {
				content: attr(data-colname) ": ";
				font-weight: 600;
				color: var(--a11y-dark-grey);
				display: block;
				margin-bottom: 4px;
				font-size: 0.7rem;
				text-transform: uppercase;
				letter-spacing: 0.5px;
			}

			&.ba11y-dataview-td-check {
				padding-bottom: 12px;
				margin-bottom: 12px;
				border-bottom: 1px solid var(--a11y-light-grey);

				&::before {
					margin-bottom: 6px;
				}
			}

			&.ba11y-dataview-td-level,
			&.ba11y-dataview-td-siteEditor {
				.components-toggle-group-control,
				.components-toggle-control {
					width: 100%;
				}
			}
		}
	}

	// Make heading levels checkboxes stack vertically
	.ba11y-heading-levels-checkboxes {
		flex-direction: column;
		gap: 12px;
		align-items: flex-start;
	}

	// Settings actions stack vertically
	.ba11y-settings-actions {
		flex-direction: column;
		align-items: stretch;

		.components-button {
			width: 100%;
			justify-content: center;
			margin-bottom: 12px;
		}

		.ba11y-unsaved-notice {
			text-align: center;
		}
	}
}
