/**
 * NIDA Past Works (ผลงานที่ผ่านมา) - Search & Table Styles
 * Matches Figma mockup 100%:
 * - Inherits Elementor default fonts & sizes (no hardcoded px typography)
 * - Support section background image configured from backend
 * - Clean floating white card (border-radius: 20px, soft shadow)
 * - Labels on top of input fields
 * - Pill inputs (border 1.5px solid #CBD5E1, border-radius 9999px)
 * - Deep red search button ("สืบค้น")
 * - Dashed divider line
 * - Popular tags: First tag enclosed with "คำค้นหายอดนิยม :", tags "อบรม", "ที่ปรึกษา", "ประเมินผล"
 * - Red outline clear button ("ล้างเงื่อนไข") aligned right
 * - Slate purple table header (#3F3A55)
 */

:root {
	--nida-pw-primary: #8E1B38;
	--nida-pw-primary-hover: #73132B;
	--nida-pw-th-bg: #3F3A55;
	--nida-pw-title: #1E2540;
	--nida-pw-text: #1E293B;
	--nida-pw-text-muted: #64748B;
	--nida-pw-border: #CBD5E1;
	--nida-pw-border-light: #E2E8F0;
	--nida-pw-card-bg: #FFFFFF;
	--nida-pw-radius-card: 20px;
	--nida-pw-radius-pill: 9999px;
	--nida-pw-radius-table: 12px;
	--nida-pw-shadow: 0 12px 36px rgba(0, 0, 0, 0.08);
}

/* Search Wrap & Section Wrapper (Supports Background Image from Backend) */
.nida-pw-search-wrap,
.nida-pw-section-wrap {
	width: 100%;
	box-sizing: border-box;
	font-family: "FC Vision", sans-serif;
	color: var(--nida-pw-text);
	position: relative;
	margin-bottom: 28px;
}

.nida-pw-search-wrap.has-bg,
.nida-pw-section-wrap.has-bg {
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	padding: 42px 24px;
	border-radius: 16px;
	margin-bottom: 36px;
}

.nida-pw-container {
	width: 100%;
	margin: 0 auto;
	box-sizing: border-box;
	font-family: "FC Vision", sans-serif;
	animation: nida-pw-fade-in 0.25s ease-out;
}

@keyframes nida-pw-fade-in {
	from {
		opacity: 0.4;
	}
	to {
		opacity: 1;
	}
}

.nida-pw-container *,
.nida-pw-container *::before,
.nida-pw-container *::after {
	box-sizing: border-box;
}

/* ==========================================================================
   1. Search Card Section
   ========================================================================== */

.nida-pw-card {
	background: var(--nida-pw-card-bg);
	border-radius: var(--nida-pw-radius-card);
	box-shadow: var(--nida-pw-shadow);
	padding: 34px 40px 30px 40px;
	position: relative;
	box-sizing: border-box;
	border: none;
	overflow: hidden;
}

/* Watermark/Illustration Background Icon on Top-Right Corner */
.nida-pw-card::after {
	content: '';
	position: absolute;
	top: -6px;
	right: -6px;
	width: var(--nida-pw-card-icon-w-desk, 240px);
	height: calc(var(--nida-pw-card-icon-w-desk, 240px) * 0.625);
	background-image: var(--nida-pw-card-icon-url, none);
	background-repeat: no-repeat;
	background-position: top right;
	background-size: contain;
	opacity: var(--nida-pw-card-icon-opacity, 0.85);
	pointer-events: none;
	user-select: none;
	z-index: 0;
	transition: opacity 0.25s ease, width 0.25s ease;
}

/* Ensure all interactive card contents sit on top of the bg icon */
.nida-pw-card-header,
.nida-pw-form,
.nida-pw-tags-row {
	position: relative;
	z-index: 1;
}

/* Card Header */
.nida-pw-card-header {
	margin-bottom: 22px;
}

.nida-pw-subtitle {
	font-size: var(--nida-pw-subtitle-size, 0.95em);
	color: var(--nida-pw-primary);
	font-weight: 500;
	margin: 0 0 6px 0;
	line-height: 1.4;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-title {
	font-size: var(--nida-pw-title-size, 1.85em);
	font-weight: 500;
	color: var(--nida-pw-title);
	margin: 0 0 8px 0;
	line-height: 1.25;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-desc {
	font-size: var(--nida-pw-desc-size, 0.88em);
	color: var(--nida-pw-text-muted);
	line-height: 1.6;
	margin: 0;
	max-width: 620px;
	font-family: "FC Vision", sans-serif;
}

/* Search Form Row */
.nida-pw-form {
	margin: 0;
	padding: 0;
}

.nida-pw-form-row {
	display: flex;
	align-items: flex-end;
	gap: 12px;
	width: 100%;
}

/* Field Columns */
.nida-pw-field {
	display: flex;
	flex-direction: column;
}

.nida-pw-field-keyword {
	flex: 1 1 380px;
	min-width: 200px;
}

.nida-pw-field-year {
	width: 170px;
	flex-shrink: 0;
}

.nida-pw-field-btn {
	flex-shrink: 0;
	margin-left: 6px;
}

/* Field Labels */
.nida-pw-label {
	font-size: 0.84em;
	font-weight: 500;
	color: #334155;
	margin-bottom: 7px;
	display: block;
	line-height: 1.2;
	user-select: none;
	font-family: "FC Vision", sans-serif;
}

/* Text Input - Strict overrides against Elementor/Theme styles */
.nida-pw-container input.nida-pw-input-text,
.nida-pw-card input[type="text"].nida-pw-input-text {
	width: 100% !important;
	height: 44px !important;
	border-radius: var(--nida-pw-radius-pill) !important;
	border: 1.5px solid var(--nida-pw-border) !important;
	padding: 0 20px !important;
	font-size: 0.9em !important;
	font-family: "FC Vision", sans-serif !important;
	font-weight: 500 !important;
	color: var(--nida-pw-text) !important;
	background: #FFFFFF !important;
	box-shadow: none !important;
	outline: none !important;
	transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
	appearance: none !important;
	-webkit-appearance: none !important;
	-moz-appearance: none !important;
	box-sizing: border-box !important;
}

.nida-pw-container input.nida-pw-input-text::placeholder,
.nida-pw-card input[type="text"].nida-pw-input-text::placeholder {
	color: #94A3B8 !important;
	font-family: "FC Vision", sans-serif !important;
	font-weight: 400 !important;
	opacity: 1 !important;
}

.nida-pw-container input.nida-pw-input-text:focus,
.nida-pw-card input[type="text"].nida-pw-input-text:focus {
	border-color: var(--nida-pw-primary) !important;
	box-shadow: 0 0 0 3px rgba(142, 27, 56, 0.12) !important;
}

/* Select Dropdown Wrapper */
.nida-pw-select-wrap {
	position: relative;
	width: 100%;
}

.nida-pw-container select.nida-pw-select,
.nida-pw-card select.nida-pw-select {
	width: 100% !important;
	height: 44px !important;
	border-radius: var(--nida-pw-radius-pill) !important;
	border: 1.5px solid var(--nida-pw-border) !important;
	padding: 0 32px 0 16px !important;
	font-size: 0.9em !important;
	font-family: "FC Vision", sans-serif !important;
	font-weight: 500 !important;
	color: #475569 !important;
	background: #FFFFFF !important;
	cursor: pointer !important;
	outline: none !important;
	box-shadow: none !important;
	appearance: none !important;
	-webkit-appearance: none !important;
	-moz-appearance: none !important;
	transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
	box-sizing: border-box !important;
}

.nida-pw-container select.nida-pw-select:focus,
.nida-pw-card select.nida-pw-select:focus {
	border-color: var(--nida-pw-primary) !important;
	box-shadow: 0 0 0 3px rgba(142, 27, 56, 0.12) !important;
}

.nida-pw-select-arrow {
	position: absolute;
	right: 14px;
	top: 50%;
	transform: translateY(-50%);
	pointer-events: none;
	width: 9px;
	height: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.nida-pw-select-arrow svg {
	width: 9px;
	height: 6px;
	fill: #334155;
	display: block;
}

/* Search Button */
.nida-pw-container button.nida-pw-btn-search,
.nida-pw-card button[type="submit"].nida-pw-btn-search {
	height: 44px !important;
	border-radius: var(--nida-pw-radius-pill) !important;
	background: var(--nida-pw-primary) !important;
	color: #FFFFFF !important;
	font-size: 0.94em !important;
	font-weight: 500 !important;
	font-family: "FC Vision", sans-serif !important;
	padding: 0 24px !important;
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	border: none !important;
	cursor: pointer !important;
	transition: all 0.2s ease !important;
	box-shadow: 0 2px 6px rgba(142, 27, 56, 0.2) !important;
	box-sizing: border-box !important;
	text-decoration: none !important;
	line-height: 1 !important;
}

.nida-pw-container button.nida-pw-btn-search:hover,
.nida-pw-card button[type="submit"].nida-pw-btn-search:hover {
	background: var(--nida-pw-primary-hover) !important;
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(142, 27, 56, 0.3) !important;
}

.nida-pw-container button.nida-pw-btn-search:active,
.nida-pw-card button[type="submit"].nida-pw-btn-search:active {
	transform: translateY(0);
}

/* Search Button Loading State */
.nida-pw-container button.nida-pw-btn-search.is-loading,
.nida-pw-card button[type="submit"].nida-pw-btn-search.is-loading {
	color: transparent !important;
	pointer-events: none !important;
	position: relative !important;
	opacity: 0.9 !important;
}

.nida-pw-container button.nida-pw-btn-search.is-loading::after,
.nida-pw-card button[type="submit"].nida-pw-btn-search.is-loading::after {
	content: '' !important;
	position: absolute !important;
	top: 50% !important;
	left: 50% !important;
	width: 18px !important;
	height: 18px !important;
	margin: -9px 0 0 -9px !important;
	border: 2.5px solid rgba(255, 255, 255, 0.35) !important;
	border-top-color: #FFFFFF !important;
	border-radius: 50% !important;
	animation: nida-pw-spin 0.65s linear infinite !important;
}

.nida-pw-tag-pill.is-loading {
	opacity: 0.65;
	pointer-events: none;
}

/* Bottom Tags & Clear Row */
.nida-pw-tags-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 24px;
	padding-top: 20px;
	border-top: 1px dashed var(--nida-pw-border-light);
	flex-wrap: wrap;
	gap: 12px;
}

.nida-pw-tags-group {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.nida-pw-container a.nida-pw-tag-pill,
.nida-pw-tag-pill {
	background: #FFFFFF;
	color: #64748B;
	font-size: 0.88em;
	font-weight: 500;
	font-family: "FC Vision", sans-serif;
	padding: 5px 18px;
	border-radius: var(--nida-pw-radius-pill);
	cursor: pointer;
	transition: all 0.2s ease;
	border: 1px solid var(--nida-pw-border);
	text-decoration: none;
	user-select: none;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	line-height: 1.4;
}

.nida-pw-container a.nida-pw-tag-pill:hover,
.nida-pw-tag-pill:hover {
	border-color: var(--nida-pw-primary);
	color: var(--nida-pw-primary);
	background: #FFFFFF;
}

.nida-pw-container a.nida-pw-tag-pill.is-active,
.nida-pw-tag-pill.is-active {
	background: var(--nida-pw-primary);
	color: #FFFFFF;
	border-color: var(--nida-pw-primary);
	font-weight: 500;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-tag-prefix {
	color: #64748B;
	font-weight: 500;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-tag-pill:hover .nida-pw-tag-prefix {
	color: var(--nida-pw-primary);
}

.nida-pw-tag-pill.is-active .nida-pw-tag-prefix {
	color: #FFFFFF;
}

/* Clear Conditions Button (Aligned Right, Red Outline) */
.nida-pw-container button.nida-pw-btn-clear,
.nida-pw-btn-clear {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	padding: 6px 22px !important;
	border-radius: var(--nida-pw-radius-pill) !important;
	border: 1.5px solid var(--nida-pw-primary) !important;
	color: var(--nida-pw-primary) !important;
	background: transparent !important;
	font-size: 0.88em !important;
	font-weight: 500 !important;
	font-family: "FC Vision", sans-serif !important;
	cursor: pointer !important;
	transition: all 0.2s ease !important;
	text-decoration: none !important;
	user-select: none !important;
	line-height: 1.4 !important;
	box-shadow: none !important;
}

.nida-pw-container button.nida-pw-btn-clear:hover,
.nida-pw-btn-clear:hover {
	background: var(--nida-pw-primary) !important;
	color: #FFFFFF !important;
}

/* ==========================================================================
   2. Results Table Section
   ========================================================================== */

.nida-pw-table-section {
	margin-top: 36px;
	width: 100%;
}

.nida-pw-table-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 14px;
	flex-wrap: wrap;
	gap: 10px;
}

.nida-pw-table-title {
	font-size: var(--nida-pw-table-title-size, 1.5em);
	font-weight: 500;
	color: var(--nida-pw-title);
	margin: 0;
	line-height: 1.25;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-count-badge {
	font-size: 0.85em;
	font-weight: 500;
	color: #64748B;
	background: #F1F5F9;
	padding: 4px 12px;
	border-radius: var(--nida-pw-radius-pill);
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-count-badge strong {
	color: var(--nida-pw-primary);
	font-weight: 500;
	font-family: "FC Vision", sans-serif;
}

/* Table Wrapper */
.nida-pw-table-wrap {
	background: #FFFFFF;
	border-radius: var(--nida-pw-radius-table);
	border: 1px solid var(--nida-pw-border-light);
	overflow: hidden;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.03);
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	position: relative;
}

table.nida-pw-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	min-width: 860px;
	text-align: left;
	font-family: inherit;
}

table.nida-pw-table tbody {
	transition: opacity 0.18s ease;
}

table.nida-pw-table.is-loading tbody {
	opacity: 0.35;
	pointer-events: none;
}

/* Table Loading Overlay */
.nida-pw-loading-overlay {
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.88);
	backdrop-filter: blur(2px);
	-webkit-backdrop-filter: blur(2px);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	z-index: 20;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease, visibility 0.2s ease;
	border-radius: var(--nida-pw-radius-table);
	min-height: 220px;
}

.nida-pw-table-wrap.is-loading .nida-pw-loading-overlay {
	opacity: 1;
	visibility: visible;
}

.nida-pw-spinner {
	width: 38px;
	height: 38px;
	border: 3.5px solid rgba(142, 27, 56, 0.15);
	border-top-color: var(--nida-pw-primary);
	border-radius: 50%;
	animation: nida-pw-spin 0.75s linear infinite;
}

.nida-pw-loading-text {
	font-size: 14px;
	font-weight: 500;
	color: var(--nida-pw-primary);
	font-family: "FC Vision", sans-serif;
	letter-spacing: -0.01em;
}

table.nida-pw-table thead th {
	background: var(--nida-pw-th-bg);
	color: #FFFFFF;
	font-size: 0.9em;
	font-weight: 500;
	padding: 14px 16px;
	text-align: left;
	vertical-align: middle;
	border: none;
	white-space: nowrap;
	line-height: 1.4;
	font-family: "FC Vision", sans-serif;
}

table.nida-pw-table thead th.col-code {
	width: 105px;
	text-align: center;
}

table.nida-pw-table thead th.col-name {
	width: 33%;
}

table.nida-pw-table thead th.col-leader {
	width: 20%;
}

table.nida-pw-table thead th.col-dept {
	width: 22%;
}

table.nida-pw-table thead th.col-start,
table.nida-pw-table thead th.col-end {
	width: 110px;
	text-align: center;
}

/* Table Body */
table.nida-pw-table tbody tr {
	background: #FFFFFF;
	transition: background-color 0.15s ease;
}

table.nida-pw-table tbody tr:nth-child(even) {
	background: #FAFBFD;
}

table.nida-pw-table tbody tr:hover {
	background: #F1F5F9 !important;
}

table.nida-pw-table tbody td {
	padding: 13px 16px;
	font-size: 0.88em;
	color: #334155;
	line-height: 1.5;
	vertical-align: top;
	border-bottom: 1px solid #EDF2F7;
	font-family: inherit;
}

table.nida-pw-table tbody tr:last-child td {
	border-bottom: none;
}

table.nida-pw-table tbody td.col-code {
	text-align: center;
	font-weight: 500;
	color: var(--nida-pw-text);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
	font-family: "FC Vision", sans-serif;
}

table.nida-pw-table tbody td.col-name {
	font-weight: 500;
	color: var(--nida-pw-text);
	font-family: "FC Vision", sans-serif;
}

.nida-pw-project-title {
	font-size: var(--nida-pw-name-size, 15px);
	font-weight: 500;
	color: var(--nida-pw-text);
	line-height: 1.5;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-project-client {
	margin-top: 5px;
	font-size: var(--nida-pw-client-size, 13px);
	font-weight: 400;
	color: #64748B;
	line-height: 1.4;
	display: flex;
	align-items: baseline;
	flex-wrap: wrap;
	gap: 5px;
}

.nida-pw-project-client-label {
	color: #94A3B8;
	font-size: 12px;
	font-weight: 500;
	flex-shrink: 0;
}

.nida-pw-project-client-name {
	color: #64748B;
	font-weight: 400;
}

table.nida-pw-table tbody td.col-leader {
	color: #475569;
}

table.nida-pw-table tbody td.col-dept {
	color: #475569;
}

table.nida-pw-table tbody td.col-start,
table.nida-pw-table tbody td.col-end {
	text-align: center;
	color: #64748B;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

/* Empty State */
.nida-pw-empty {
	padding: 56px 24px;
	text-align: center;
	color: #64748B;
}

.nida-pw-empty-icon {
	width: 48px;
	height: 48px;
	margin: 0 auto 12px auto;
	color: #94A3B8;
}

.nida-pw-empty-icon svg {
	width: 100%;
	height: 100%;
	fill: currentColor;
}

.nida-pw-empty-title {
	font-size: 1.05em;
	font-weight: 500;
	color: #334155;
	margin-bottom: 4px;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-empty-sub {
	font-size: 0.85em;
	color: #94A3B8;
	font-family: "FC Vision", sans-serif;
}

/* Pagination Bar */
.nida-pw-pagination-bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 18px;
	flex-wrap: wrap;
	gap: 12px;
	font-size: 0.88em;
	color: #64748B;
	font-family: "FC Vision", sans-serif;
}

.nida-pw-pagination-info {
	user-select: none;
}

.nida-pw-page-controls {
	display: flex;
	align-items: center;
	gap: 5px;
}

.nida-pw-container button.nida-pw-page-btn,
.nida-pw-page-btn {
	min-width: 36px;
	height: 36px;
	padding: 0 10px;
	border-radius: 8px;
	border: 1px solid var(--nida-pw-border-light);
	background: #FFFFFF;
	color: #334155;
	font-size: 0.88em;
	font-weight: 500;
	font-family: "FC Vision", sans-serif;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
	text-decoration: none;
	user-select: none;
	box-shadow: none;
}

.nida-pw-container button.nida-pw-page-btn:hover:not(:disabled):not(.is-active),
.nida-pw-page-btn:hover:not(:disabled):not(.is-active) {
	border-color: #CBD5E1;
	background: #F8FAFC;
	color: #0F172A;
}

.nida-pw-container button.nida-pw-page-btn.is-active,
.nida-pw-page-btn.is-active {
	background: var(--nida-pw-primary);
	color: #FFFFFF;
	border-color: var(--nida-pw-primary);
	box-shadow: 0 2px 6px rgba(142, 27, 56, 0.25);
}

.nida-pw-container button.nida-pw-page-btn:disabled,
.nida-pw-page-btn:disabled {
	opacity: 0.35;
	cursor: not-allowed;
	pointer-events: none;
}

.nida-pw-page-ellipsis {
	padding: 0 4px;
	color: #94A3B8;
	user-select: none;
}

/* ==========================================================================
   3. Responsive Styles
   ========================================================================== */

@media (max-width: 900px) {
	.nida-pw-card {
		padding: 28px 26px 24px 26px;
	}

	.nida-pw-card::after {
		width: calc(var(--nida-pw-card-icon-w-desk, 240px) * 0.75);
		height: calc(var(--nida-pw-card-icon-w-desk, 240px) * 0.75 * 0.625);
		opacity: 0.65;
	}

	.nida-pw-form-row {
		flex-wrap: wrap;
		gap: 12px;
	}

	.nida-pw-field-keyword {
		flex: 1 1 100%;
		width: 100%;
	}

	.nida-pw-field-year {
		flex: 1 1 45%;
		width: auto;
	}

	.nida-pw-field-btn {
		width: 100%;
		margin-left: 0;
		margin-top: 6px;
	}

	.nida-pw-container button.nida-pw-btn-search,
	.nida-pw-card button[type="submit"].nida-pw-btn-search {
		width: 100% !important;
	}

	.nida-pw-tags-row {
		flex-direction: column;
		align-items: flex-start;
		gap: 14px;
	}

	.nida-pw-btn-clear {
		align-self: flex-start;
	}
}

@media (max-width: 767px) {
	.nida-pw-card::after {
		top: -4px;
		right: -4px;
		width: var(--nida-pw-card-icon-w-mob, 130px);
		height: calc(var(--nida-pw-card-icon-w-mob, 130px) * 0.625);
		opacity: 0.35; /* Soft subtle watermark on mobile: guarantees 100% readability of title & desc */
	}
}

@media (max-width: 540px) {
	.nida-pw-search-wrap.has-bg,
	.nida-pw-section-wrap.has-bg {
		padding: 20px 10px;
	}

	.nida-pw-card {
		padding: 22px 16px 18px 16px;
	}

	.nida-pw-field-year {
		flex: 1 1 100%;
		width: 100%;
	}

	.nida-pw-pagination-bar {
		flex-direction: column;
		align-items: center;
		gap: 14px;
	}
}
