﻿/* =========================================
   Variables & Base Table Shell
========================================= */
:root {
	--tbl-text-main: #111827;
	--tbl-text-muted: #6b7280;
	--tbl-bg-body: #ffffff;
	--tbl-bg-table-head: #f4f5f7;
	--tbl-border-color: #e5e7eb;
	--tbl-border-strong: #d1d5db;
	--tbl-primary: #3276b1;
	--tbl-hover: #f9fafb;
	--tbl-hover-strong: #e4edff;
}

.tbl-wrapper *:focus:not(:focus-visible) {
	outline: none !important;
}

.tbl-wrapper {
	background: var(--tbl-bg-body);
	color: var(--tbl-text-main);
	border: 1px solid var(--tbl-border-strong);
	border-radius: 8px;
	box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
	height: calc(100vh - 200px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	margin-top: 20px;
}

/* =========================================
   Toolbar & Inputs
========================================= */
.tbl-toolbar {
	flex: 0 0 auto;
	padding: 15px 30px;
	border-bottom: 1px solid var(--tbl-border-strong);
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: #fff;
}

.tbl-filter-bar {
	display: flex;
	gap: 15px;
	align-items: center;
}

.tbl-filter-input {
	padding: 8px 12px;
	border: 1px solid var(--tbl-border-strong);
	border-radius: 6px;
	font-size: 0.9em;
	height: 38px;
	width: 100%;
	background: #fff;
	color: var(--tbl-text-main);
}

.tbl-filter-input:focus {
	border-color: var(--tbl-primary);
	outline: none;
}

.tbl-btn-outline {
	height: 38px;
	padding: 0 16px;
	background: #fff;
	border: 1px solid var(--tbl-border-strong);
	border-radius: 6px;
	cursor: pointer;
	font-weight: 600;
	transition:
		background 0.2s,
		opacity 0.2s;
	color: var(--tbl-text-main);
	display: flex;
	align-items: center;
	white-space: nowrap;
}

.tbl-btn-outline:hover:not(:disabled) {
	background: #f9fafb;
}

.tbl-btn-outline.active {
	background: var(--tbl-hover-strong);
	border-color: var(--tbl-primary);
	color: var(--tbl-primary);
}

.tbl-btn-icon {
	width: 38px;
	padding: 0;
	justify-content: center;
	font-size: 1.1em;
}

.tbl-btn-action {
	background: transparent;
	border: none;
	font-size: 1.1em;
	cursor: pointer;
	padding: 4px 8px;
	color: var(--tbl-primary);
}

.tbl-btn-action:hover {
	color: #1a4971;
}

.tbl-btn-action.tbl-delete {
	color: #d9363e;
}

.tbl-btn-action.tbl-delete:hover {
	color: #a00;
}

.tbl-btn-reset {
	height: 38px;
	padding: 0 16px;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 6px;
	cursor: pointer;
	color: var(--tbl-text-muted);
	font-weight: 600;
	display: flex;
	align-items: center;
	gap: 6px;
}

.tbl-btn-reset:hover {
	color: #d9363e;
	background: #fef2f2;
}

/* =========================================
   Data Table Core
========================================= */
.tbl-table-container {
	flex: 1;
	overflow-y: auto;
	overflow-x: auto;
}

.tbl-table {
	width: 100%;
	border-collapse: collapse;
	text-align: left;
	margin: 0;
	table-layout: auto;
}

.tbl-table > thead {
	position: sticky;
	top: 0;
	z-index: 3;
}

.tbl-table thead th {
	background-color: var(--tbl-bg-table-head);
	padding: 14px 20px;
	font-size: 0.75em;
	text-transform: uppercase;
	color: var(--tbl-primary);
	font-weight: 700;
	cursor: pointer;
	border-bottom: 2px solid var(--tbl-border-strong);
	vertical-align: middle;
}

.tbl-table th:hover {
	background-color: #e5e7eb;
}

.tbl-table td {
	padding: 14px 20px;
	font-size: 0.85em;
	border-bottom: 1px solid var(--tbl-border-color);
	background-color: #ffffff;
}

.tbl-table tbody tr.tbl-main-row:hover td {
	background-color: var(--tbl-hover-strong);
}

/* =========================================
   Reusable Column Sizing Utilities
========================================= */
.tbl-col-actions {
	width: 100px;
	white-space: nowrap;
	text-align: center;
}

/* =========================================
   Movable Filter Modal Panel
========================================= */
.tbl-floating-filter-panel {
	position: fixed;
	top: 100px;
	right: 30px;
	width: 320px;
	resize: both;
	min-width: 250px;
	min-height: 200px;
	max-height: 90vh;
	background: #ffffff;
	border: 1px solid var(--tbl-border-strong);
	border-radius: 8px;
	box-shadow:
		0 15px 35px rgba(0, 0, 0, 0.2),
		0 5px 15px rgba(0, 0, 0, 0.1);
	z-index: 10000;
	display: none;
	flex-direction: column;
	overflow: hidden;
}

.tbl-floating-filter-panel.open {
	display: flex;
}

.tbl-filter-panel-header {
	background: var(--tbl-bg-table-head);
	padding: 12px 20px;
	border-bottom: 1px solid var(--tbl-border-strong);
	display: flex;
	justify-content: flex-end; /* <--- Changed to push buttons to the right */
	align-items: center;
	cursor: grab;
	user-select: none;
	color: var(--tbl-primary);
	font-weight: 700;
	font-size: 0.9em;
	text-transform: uppercase;
}

.tbl-filter-panel-header:active {
	cursor: grabbing;
}

/* Header Reset Button Style */
.tbl-filter-panel-header .tbl-btn-reset {
	height: auto;
	padding: 4px 8px;
	font-size: 0.85em;
	color: var(--tbl-primary);
}

.tbl-filter-panel-header .tbl-btn-reset:hover {
	color: #d9363e;
	background: transparent;
}

.tbl-close-panel-btn {
	background: transparent;
	border: none;
	font-size: 1.5em;
	line-height: 1;
	cursor: pointer;
	color: var(--tbl-text-muted);
	padding: 0;
}

.tbl-close-panel-btn:hover {
	color: #d9363e;
}

.tbl-filter-panel-body {
	padding: 20px;
	flex: 1;
	overflow-y: auto;
}

.tbl-filter-grid {
	display: flex;
	flex-direction: column;
	gap: 15px;
}

.tbl-filter-group {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.tbl-filter-label {
	font-size: 0.75em;
	font-weight: 700;
	color: var(--tbl-primary);
	text-transform: uppercase;
	margin: 0;
}

.tbl-column-filter.active-filter {
	background-color: var(--tbl-hover-strong);
}

/* =========================================
   Inline Filter Match Menus
========================================= */
.tbl-input-with-menu {
	position: relative;
	display: flex;
	align-items: center;
	width: 100%;
}

.tbl-input-with-menu .tbl-filter-input {
	padding-right: 32px;
}

.tbl-filter-menu-btn {
	position: absolute;
	right: 4px;
	background: transparent;
	border: none;
	color: var(--tbl-text-muted);
	cursor: pointer;
	padding: 6px;
	border-radius: 4px;
	font-size: 0.9em;
}

.tbl-filter-menu-btn:hover,
.tbl-filter-menu-btn.active {
	color: var(--tbl-primary);
	background: var(--tbl-hover-strong);
}

.tbl-match-menu {
	position: absolute;
	top: calc(100% + 5px);
	left: 0;
	right: 0;
	width: 100%;
	box-sizing: border-box;
	background: #fff;
	border: 1px solid var(--tbl-border-strong);
	border-radius: 6px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	z-index: 9999 !important;
	padding: 5px 0;
	display: none;
}

.tbl-match-menu.open {
	display: block;
}

.tbl-match-option {
	padding: 8px 15px;
	font-size: 0.85em;
	cursor: pointer;
	color: var(--tbl-text-main);
	text-transform: none;
	font-weight: 500;
}

.tbl-match-option:hover {
	background: var(--tbl-hover);
}

.tbl-match-option.selected {
	background: var(--tbl-hover-strong);
	color: var(--tbl-primary);
	font-weight: 700;
}

/* =========================================
   Pagination
========================================= */
.tbl-pagination {
	flex: 0 0 auto;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 15px;
	gap: 15px;
	background: #fff;
	border-top: 1px solid var(--tbl-border-strong);
}

@media (max-width: 600px) {
	.tbl-toolbar {
		flex-direction: column;
		align-items: stretch;
	}

	.tbl-filter-bar {
		justify-content: space-between;
	}
}
