/* ============================================================================
   TikZ Inline Preview
   Floating preview widget for live TikZ compilation in Monaco Editor
   Purple/violet accent to match TikZ editor theme
   ========================================================================== */

.tikz-inline-preview {
	position: fixed;
	display: flex;
	flex-direction: column;
	background: rgba(18, 18, 18, 0.94);
	backdrop-filter: blur(20px) saturate(1.4);
	-webkit-backdrop-filter: blur(20px) saturate(1.4);
	border: 1px solid rgba(124, 111, 224, 0.18);
	border-radius: 12px;
	padding: 10px 14px 10px 14px;
	box-shadow:
		0 8px 40px rgba(0, 0, 0, 0.5),
		0 2px 12px rgba(0, 0, 0, 0.3),
		0 0 0 1px rgba(124, 111, 224, 0.06),
		inset 0 1px 0 rgba(255, 255, 255, 0.04);
	max-width: calc(100vw - 16px);
	min-width: 200px;
	max-height: calc(100vh - 16px);
	max-height: calc(100dvh - 16px);
	overflow: visible;
	z-index: 31000;
	opacity: 0;
	transform: translateY(6px) scale(0.96);
	transition:
		opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1),
		transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
	pointer-events: none;
	will-change: opacity, transform;
}

.tikz-inline-preview.visible {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Violet gradient accent line */
.tikz-inline-preview::before {
	content: '';
	position: absolute;
	top: 0;
	left: 16px;
	right: 16px;
	height: 1.5px;
	background: linear-gradient(90deg,
		transparent,
		rgba(124, 111, 224, 0.5) 20%,
		rgba(124, 111, 224, 0.7) 50%,
		rgba(124, 111, 224, 0.5) 80%,
		transparent);
	border-radius: 1px;
}

.tikz-inline-preview::after {
	content: '';
	position: absolute;
	bottom: -1px;
	left: 20%;
	right: 20%;
	height: 1px;
	background: linear-gradient(90deg,
		transparent,
		rgba(124, 111, 224, 0.12),
		transparent);
}

/* ── Header ── */

.tikz-inline-preview-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 6px;
	cursor: grab;
	user-select: none;
}

.tikz-inline-preview-header:active {
	cursor: grabbing;
}

.tikz-inline-preview-label {
	font-size: 0.65rem;
	font-weight: 600;
	color: rgba(124, 111, 224, 0.6);
	text-transform: uppercase;
	letter-spacing: 0.8px;
	line-height: 1;
	user-select: none;
}

.tikz-inline-preview-status {
	font-size: 0.6rem;
	color: rgba(255, 255, 255, 0.3);
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(255, 255, 255, 0.06);
	border-radius: 4px;
	padding: 1px 5px;
	letter-spacing: 0.3px;
	user-select: none;
}

/* ── Action buttons ── */

.tikz-inline-preview-actions {
	display: flex;
	gap: 4px;
	margin-left: auto;
}

.tikz-inline-preview-btn {
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 4px;
	color: rgba(124, 111, 224, 0.7);
	font-size: 0.72rem;
	padding: 2px 6px;
	cursor: pointer;
	transition: background 0.15s, color 0.15s, border-color 0.15s;
	line-height: 1.2;
}

.tikz-inline-preview-btn:hover {
	background: rgba(124, 111, 224, 0.15);
	color: rgba(124, 111, 224, 1);
	border-color: rgba(124, 111, 224, 0.25);
}

.tikz-inline-preview-btn.active {
	background: rgba(124, 111, 224, 0.2);
	border-color: rgba(124, 111, 224, 0.35);
	color: rgba(124, 111, 224, 1);
}

/* ── Settings dropdown ── */

.tikz-inline-preview-settings {
	position: absolute;
	bottom: 100%;
	right: 0;
	margin-bottom: 4px;
	background: rgba(22, 22, 22, 0.97);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	border: 1px solid rgba(124, 111, 224, 0.15);
	border-radius: 8px;
	padding: 10px 12px;
	min-width: 210px;
	z-index: 32000;
	opacity: 0;
	visibility: hidden;
	transform: translateY(-4px) scale(0.97);
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

.tikz-inline-preview-settings.visible {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

.tikz-inline-preview-settings-title {
	font-size: 0.62rem;
	font-weight: 600;
	color: rgba(124, 111, 224, 0.55);
	text-transform: uppercase;
	letter-spacing: 0.7px;
	margin-bottom: 8px;
	user-select: none;
}

.tikz-inline-preview-settings-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 4px 0;
	font-size: 0.72rem;
	color: rgba(255, 255, 255, 0.7);
}

.tikz-inline-preview-settings-row + .tikz-inline-preview-settings-row {
	border-top: 1px solid rgba(255, 255, 255, 0.04);
}

/* Mini toggle switch */
.tikz-inline-preview-toggle {
	position: relative;
	display: inline-block;
	width: 30px;
	height: 16px;
	flex-shrink: 0;
}

.tikz-inline-preview-toggle input {
	opacity: 0;
	width: 0;
	height: 0;
}

.tikz-inline-preview-toggle-slider {
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.1);
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.2s;
}

.tikz-inline-preview-toggle-slider::before {
	content: '';
	position: absolute;
	width: 12px;
	height: 12px;
	left: 2px;
	bottom: 2px;
	background: rgba(255, 255, 255, 0.5);
	border-radius: 50%;
	transition: transform 0.2s, background 0.2s;
}

.tikz-inline-preview-toggle input:checked + .tikz-inline-preview-toggle-slider {
	background: rgba(124, 111, 224, 0.4);
}

.tikz-inline-preview-toggle input:checked + .tikz-inline-preview-toggle-slider::before {
	transform: translateX(14px);
	background: rgba(124, 111, 224, 1);
}

/* Mini select */
.tikz-inline-preview-select {
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 4px;
	color: rgba(255, 255, 255, 0.7);
	font-size: 0.68rem;
	padding: 2px 4px;
	outline: none;
	cursor: pointer;
	min-width: 65px;
}

.tikz-inline-preview-select:focus {
	border-color: rgba(124, 111, 224, 0.35);
}

.tikz-inline-preview-select option {
	background: #1e1e1e;
	color: #ccc;
}

/* ── Snippet toolbar ── */

.tikz-inline-preview-toolbar {
	border-top: 1px solid rgba(255, 255, 255, 0.06);
	margin: 2px 0 6px 0;
	padding-top: 6px;
}

.tikz-inline-preview-toolbar-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 3px;
	margin-bottom: 5px;
}

.tikz-inline-preview-toolbar-tab {
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(255, 255, 255, 0.06);
	border-radius: 4px;
	color: rgba(255, 255, 255, 0.5);
	font-size: 0.62rem;
	padding: 2px 6px;
	cursor: pointer;
	transition: all 0.12s ease;
	line-height: 1.2;
}

.tikz-inline-preview-toolbar-tab:hover {
	background: rgba(124, 111, 224, 0.1);
	color: rgba(255, 255, 255, 0.8);
	border-color: rgba(124, 111, 224, 0.15);
}

.tikz-inline-preview-toolbar-tab.active {
	background: rgba(124, 111, 224, 0.15);
	color: rgba(124, 111, 224, 0.95);
	border-color: rgba(124, 111, 224, 0.3);
}

.tikz-inline-preview-toolbar-grid {
	display: flex;
	flex-wrap: wrap;
	gap: 3px;
	max-height: 90px;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: rgba(124, 111, 224, 0.2) transparent;
}

.tikz-inline-preview-toolbar-grid::-webkit-scrollbar {
	width: 4px;
}

.tikz-inline-preview-toolbar-grid::-webkit-scrollbar-thumb {
	background: rgba(124, 111, 224, 0.2);
	border-radius: 2px;
}

.tikz-inline-preview-toolbar-grid::-webkit-scrollbar-track {
	background: transparent;
}

.tikz-inline-preview-snippet-btn {
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(255, 255, 255, 0.06);
	border-radius: 4px;
	color: #ccc;
	font-size: 0.68rem;
	padding: 3px 7px;
	cursor: pointer;
	text-align: center;
	transition: background 0.12s, color 0.12s, border-color 0.12s;
	line-height: 1;
	white-space: nowrap;
}

.tikz-inline-preview-snippet-btn:hover {
	background: rgba(124, 111, 224, 0.15);
	color: #fff;
	border-color: rgba(124, 111, 224, 0.25);
}

.tikz-inline-preview-snippet-btn:active {
	background: rgba(124, 111, 224, 0.25);
	transform: scale(0.95);
}

/* ── PDF output area ── */

.tikz-inline-preview-output {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 1;
	min-height: 80px;
	overflow: auto;
	border-radius: 6px;
}

.tikz-inline-preview-output embed {
	width: 100%;
	height: 100%;
	min-height: 80px;
	background: #fff;
}

/* ── Error state ── */

.tikz-inline-preview.has-error {
	border-color: rgba(241, 158, 158, 0.2);
}

.tikz-inline-preview.has-error::before {
	background: linear-gradient(90deg,
		transparent,
		rgba(241, 158, 158, 0.4) 20%,
		rgba(241, 158, 158, 0.6) 50%,
		rgba(241, 158, 158, 0.4) 80%,
		transparent);
}

/* ── Resize handle ── */

.tikz-inline-preview-resize-handle {
	position: absolute;
	bottom: 0;
	right: 0;
	width: 16px;
	height: 16px;
	cursor: nwse-resize;
	z-index: 2;
}

.tikz-inline-preview-resize-handle::before {
	content: '';
	position: absolute;
	bottom: 3px;
	right: 3px;
	width: 8px;
	height: 8px;
	border-right: 2px solid rgba(124, 111, 224, 0.3);
	border-bottom: 2px solid rgba(124, 111, 224, 0.3);
}

.tikz-inline-preview-resize-handle:hover::before {
	border-color: rgba(124, 111, 224, 0.6);
}

.tikz-inline-preview-error {
	color: rgba(241, 158, 158, 0.7);
	font-size: 0.7rem;
	font-family: 'JetBrains Mono', 'Fira Code', monospace;
	text-align: center;
	padding: 2px 0;
	max-height: 40px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
