/* Advanced Datagrid — resize handles, drag indicators, context menu, frozen columns */

/* ── Resize handle ─────────────────────────────────────────── */
ot-datagrid th {
	position: relative;
}

.resize-handle {
	position: absolute;
	right: 0;
	top: 25%;
	bottom: 25%;
	width: 4px;
	cursor: col-resize;
	background: var(--border, #e2e8f0);
	border-radius: 2px;
	transition: background 150ms;
	z-index: 1;
}

.resize-handle:hover,
.resize-handle.resizing {
	top: 0;
	bottom: 0;
	background: var(--primary);
}

/* ── Drag indicators ───────────────────────────────────────── */
ot-datagrid th[draggable="true"] {
	cursor: grab;
}

ot-datagrid th[draggable="true"]:active {
	cursor: grabbing;
}

ot-datagrid th.drag-over {
	border-left: 3px solid var(--primary);
}

ot-datagrid th.dragging {
	opacity: 0.4;
}

/* ── Context menu ──────────────────────────────────────────── */
[data-context-menu] {
	position: fixed;
	z-index: 200;
	background: var(--card-background, #fff);
	border: 1px solid var(--border, #e2e8f0);
	border-radius: 0.375rem;
	padding: 0.25rem 0;
	min-width: 8rem;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

[data-context-menu] button {
	display: block;
	width: 100%;
	text-align: left;
	padding: 0.375rem 0.75rem;
	border: none;
	background: none;
	font-size: 0.875rem;
	cursor: pointer;
	color: var(--foreground, #1e293b);
	border-radius: 0;
}

[data-context-menu] button:hover {
	background: var(--muted, #f1f5f9);
}

/* ── Wide metrics datagrid — frozen columns + horizontal scroll ── */

/* Scroll container */
.datagrid-scroll-container {
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	flex: 1;
	min-height: 0;
}

/* Custom scrollbar */
.datagrid-scroll-container::-webkit-scrollbar {
	height: 10px;
}

.datagrid-scroll-container::-webkit-scrollbar-track {
	background: var(--muted, #f1f5f9);
	border-radius: 5px;
}

.datagrid-scroll-container::-webkit-scrollbar-thumb {
	background: var(--border, #cbd5e1);
	border-radius: 5px;
}

.datagrid-scroll-container::-webkit-scrollbar-thumb:hover {
	background: var(--muted-foreground, #94a3b8);
}

/* Table inside scroll container */
.datagrid-scroll-container table {
	width: 100%;
}

/* Frozen (sticky) columns */
th[data-frozen],
td[data-frozen] {
	position: sticky;
	z-index: 2;
	background: var(--card-background, #fff);
}

/* Frozen headers above scrolled headers */
th[data-frozen] {
	z-index: 3;
}

/* Shadow on the last frozen column — only when the container is scrollable */
.datagrid-scroll-container[data-scrollable] th[data-frozen-last]::after,
.datagrid-scroll-container[data-scrollable] td[data-frozen-last]::after {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	right: -6px;
	width: 6px;
	pointer-events: none;
	background: linear-gradient(to right, rgba(0, 0, 0, 0.08), transparent);
}

/* Wide grid element */
ot-datagrid {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	position: relative;
	flex: 1;
	min-height: 0;
}

ot-datagrid th {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

ot-datagrid td {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

ot-datagrid table {
	table-layout: auto;
}

/* Loading state */
ot-datagrid.loading table,
ot-datagrid.loading [data-datagrid-pagination] {
	opacity: 0.5;
	transition: opacity 200ms;
	pointer-events: none;
}

/* Prevent text selection during drag/resize */
ot-datagrid.resizing,
ot-datagrid.dragging {
	user-select: none;
}
