/**
 * Webhook Table - Front-end styles
 * Uses design system variables and .sma-table.
 * Version: 1.0.0
 */

.webhook-table-wrapper {
	--wt-padding: var(--sma-space-6);
	margin: var(--sma-space-6) 0 var(--sma-space-4);
	padding: var(--wt-padding);
	box-sizing: border-box;
	max-width: 100%;
	overflow-x: hidden;
}

.webhook-table-card {
	/* sma-card already adds background, radius, and inner padding; this keeps the table from touching the edges. */
}

.webhook-table-title {
	font-size: var(--sma-font-size-xl);
	margin-bottom: var(--sma-space-1);
}

.webhook-table-description {
	font-size: var(--sma-font-size-base);
	margin-top: var(--sma-space-1);
}

.webhook-table-toolbar {
	flex-wrap: nowrap;
	align-items: center;
	gap: var(--sma-space-4);
}

.webhook-table-search {
	flex: 1;
	min-width: 0;
}

.webhook-table-toolbar-right {
	display: flex;
	align-items: center;
	gap: var(--sma-space-4);
	flex-shrink: 0;
	white-space: nowrap;
}

.webhook-table-refreshed {
	flex-shrink: 0;
}

.webhook-table-search {
	gap: var(--sma-space-2);
	justify-content: flex-start;
}

.webhook-table-search-input {
	max-width: 260px;
}

.webhook-table-error,
.webhook-table-message {
	color: var(--sma-gray-600);
	margin: var(--sma-space-4) 0;
}

.webhook-table-error {
	color: var(--sma-error-dark);
}

/* Service unavailable (no data, no cache) — centered vertically in viewport */
.webhook-table-unavailable {
	text-align: center;
	min-height: 50vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	margin: 2rem 0;
}

.webhook-table-unavailable-message {
	font-size: var(--sma-font-size-base);
	margin: 0;
}

/* Cached data notice (live service down but showing last good data) */
.webhook-table-cached-notice {
	background: var(--sma-info-light, #e8f4fc);
	border-radius: var(--sma-radius-md, 6px);
	padding: var(--sma-space-4);
	border-left: 4px solid var(--sma-info, #0d6efd);
}

.webhook-table-empty {
	color: var(--sma-gray-500);
	font-style: italic;
	text-align: center;
}

/* Group header rows */
.webhook-table-group-header {
	background-color: #111c4e;
}
.webhook-table-group-header-cell {
	padding: var(--sma-space-3) var(--sma-space-4);
	font-weight: var(--sma-font-weight-bold, 700);
	font-size: var(--sma-font-size-base);
	color: #ffffff;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

/* Scroll wrapper: only the table scrolls horizontally; card and page stay within viewport. */
.webhook-table-scroll {
	width: 100%;
	max-width: 100%;
	min-width: 0;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	overflow-y: visible;
}

.webhook-table-scroll .sma-table,
.webhook-table-scroll .webhook-table {
	min-width: max-content;
	width: 100%;
}

/* Column header: label + filter/sort trigger */
.webhook-table-th {
	white-space: nowrap;
	vertical-align: middle;
	position: relative;
}
/* Remove hover effect on table headers */
.sma-table th:hover,
.webhook-table-wrapper .webhook-table th:hover,
.webhook-table-wrapper .sma-table.webhook-table th:hover,
.webhook-table-wrapper .webhook-table-th:hover,
.webhook-table th.webhook-table-th:hover,
.sma-table.webhook-table th.webhook-table-th:hover {
	background-color: var(--sma-gray-50) !important;
	color: var(--sma-gray-600) !important;
}
tr.webhook-table-group-header:hover {
	background-color: #111c4e !important;
	color: #ffffff !important;
}

.webhook-table-th-label {
	margin-right: var(--sma-space-1);
}
.webhook-table-th.has-filter .webhook-table-th-label {
	font-weight: var(--sma-font-weight-bold, 700);
}
.webhook-table-th-trigger {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: var(--sma-space-1);
	margin: 0;
	border: none;
	background: transparent;
	border-radius: var(--sma-radius-sm);
	cursor: pointer;
	color: var(--sma-gray-500);
	transition: color var(--sma-transition-fast), background var(--sma-transition-fast);
	vertical-align: middle;
	line-height: 1;
	position: relative;
}

.webhook-table-th-trigger:focus {
	outline: 2px solid var(--sma-primary);
	outline-offset: 2px;
}
.webhook-table-th-trigger-icon {
	display: inline-block;
	width: 16px;
	height: 16px;
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3'/%3E%3C/svg%3E") no-repeat center;
	background-size: contain;
	vertical-align: middle;
	transition: all var(--sma-transition-fast);
}
/* Active filter indicator - filled icon without background */
.webhook-table-th.has-filter .webhook-table-th-trigger {
	color: var(--sma-primary, #0066cc);
	background: transparent;
}

.webhook-table-th.has-filter .webhook-table-th-trigger-icon {
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='%230066cc' stroke='%230066cc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3'/%3E%3C/svg%3E") no-repeat center;
	background-size: contain;
}

/* Popover: filter and sort menu */
.webhook-table-popover[hidden],
.webhook-table-popover:not(.webhook-table-popover-open) {
	display: none !important;
}
.webhook-table-popover {
	position: fixed;
	z-index: 1000;
	min-width: 220px;
	max-width: 320px;
	max-height: 80vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	background: var(--sma-white);
	border: 1px solid var(--sma-gray-200);
	border-radius: var(--sma-radius-md);
	box-shadow: var(--sma-shadow-lg);
	font-family: var(--sma-font-family-base, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
}
.webhook-table-popover-content {
	padding: var(--sma-space-2);
	overflow-y: auto;
	font-family: inherit;
}
.webhook-table-popover-section {
	margin-bottom: var(--sma-space-2);
}
.webhook-table-popover-section:last-child {
	margin-bottom: 0;
}
.webhook-table-popover-btn {
	display: block;
	width: 100%;
	padding: var(--sma-space-2) var(--sma-space-3);
	margin: 0 0 var(--sma-space-1);
	border: none;
	background: transparent;
	border-radius: var(--sma-radius-sm);
	font-size: var(--sma-font-size-sm);
	text-align: left;
	cursor: pointer;
	color: var(--sma-gray-800);
	transition: background var(--sma-transition-fast);
}

.webhook-table-popover-btn:last-child {
	margin-bottom: 0;
}
.webhook-table-popover-filter {
	border-top: 1px solid var(--sma-gray-200);
	padding-top: var(--sma-space-2);
}
.webhook-table-popover-search {
	width: 100%;
	margin-bottom: var(--sma-space-2);
	padding: var(--sma-space-2);
	border: 1px solid var(--sma-gray-300);
	border-radius: var(--sma-radius-sm);
	font-size: var(--sma-font-size-sm);
	box-sizing: border-box;
}
.webhook-table-popover-search:focus {
	outline: none;
	border-color: var(--sma-primary);
}
.webhook-table-popover-list {
	max-height: 200px;
	overflow-y: auto;
	margin-bottom: var(--sma-space-2);
}
.webhook-table-popover-option {
	display: flex;
	align-items: center;
	gap: var(--sma-space-2);
	padding: var(--sma-space-1) 0;
	font-size: var(--sma-font-size-sm);
	font-family: inherit;
	cursor: pointer;
}
.webhook-table-popover-option input[type="checkbox"] {
	flex-shrink: 0;
}
.webhook-table-popover-select-all {
	font-weight: var(--sma-font-weight-medium);
	margin-bottom: var(--sma-space-1);
}
.webhook-table-popover-actions {
	display: flex;
	gap: var(--sma-space-2);
	margin-top: var(--sma-space-2);
}
.webhook-table-popover-apply,
.webhook-table-popover-clear {
	flex: 1;
}

/* Mobile: reduce padding, stack toolbar, full-width search */
@media (max-width: 768px) {
	.webhook-table-wrapper {
		--wt-padding: var(--sma-space-4);
		margin: var(--sma-space-4) 0 var(--sma-space-3);
		padding-left: var(--sma-space-3);
		padding-right: var(--sma-space-3);
	}

	.webhook-table-toolbar {
		flex-wrap: wrap;
		gap: var(--sma-space-2);
	}
	
	.webhook-table-toolbar-right {
		flex-wrap: wrap;
		width: 100%;
		justify-content: space-between;
	}

	.webhook-table-search {
		width: 100%;
	}

	.webhook-table-search-input {
		max-width: none;
		width: 100%;
		box-sizing: border-box;
	}

	.webhook-table-refreshed {
		text-align: left;
		font-size: var(--sma-font-size-xs);
	}

	.webhook-table-title {
		font-size: var(--sma-font-size-lg);
	}

	.webhook-table-card {
		margin-left: calc(-1 * var(--sma-space-3));
		margin-right: calc(-1 * var(--sma-space-3));
		padding-left: var(--sma-space-3);
		padding-right: var(--sma-space-3);
		border-radius: 0;
	}

	.webhook-table-scroll {
		margin-left: calc(-1 * var(--sma-space-3));
		margin-right: calc(-1 * var(--sma-space-3));
		padding-left: var(--sma-space-3);
		padding-right: var(--sma-space-3);
	}

	.webhook-table-scroll .sma-table {
		font-size: var(--sma-font-size-sm);
	}

	.webhook-table-scroll .sma-table th,
	.webhook-table-scroll .sma-table td {
		padding: var(--sma-space-2);
		white-space: nowrap;
	}

	.webhook-table-scroll .sma-table td:nth-child(4) {
		white-space: normal;
		max-width: 140px;
		overflow: hidden;
		text-overflow: ellipsis;
	}
}

@media (max-width: 480px) {
	.webhook-table-wrapper {
		padding-left: var(--sma-space-2);
		padding-right: var(--sma-space-2);
	}

	.webhook-table-card {
		margin-left: calc(-1 * var(--sma-space-2));
		margin-right: calc(-1 * var(--sma-space-2));
		padding-left: var(--sma-space-2);
		padding-right: var(--sma-space-2);
	}

	.webhook-table-scroll {
		margin-left: calc(-1 * var(--sma-space-2));
		margin-right: calc(-1 * var(--sma-space-2));
		padding-left: var(--sma-space-2);
		padding-right: var(--sma-space-2);
	}
}
