/* ============================================================================
   Chemistry Inline Preview
   Floating preview widget for live chemistry rendering in Monaco Editor
   Green/emerald accent to match Chemistry editor theme
   ========================================================================== */

.chem-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(46, 160, 67, 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(46, 160, 67, 0.06),
		inset 0 1px 0 rgba(255, 255, 255, 0.04);
	max-width: calc(100vw - 16px);
	min-width: 80px;
	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;
}

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

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

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

/* ── Header ── */

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

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

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

.chem-inline-preview-mode {
	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 ── */

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

.chem-inline-preview-btn {
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 4px;
	color: rgba(46, 160, 67, 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;
}

.chem-inline-preview-btn:hover {
	background: rgba(46, 160, 67, 0.15);
	color: rgba(46, 160, 67, 1);
	border-color: rgba(46, 160, 67, 0.25);
}

.chem-inline-preview-btn.active {
	background: rgba(46, 160, 67, 0.2);
	border-color: rgba(46, 160, 67, 0.35);
	color: rgba(46, 160, 67, 1);
}

/* ── Settings dropdown ── */

.chem-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(46, 160, 67, 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);
}

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

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

.chem-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);
}

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

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

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

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

.chem-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;
}

.chem-inline-preview-toggle input:checked + .chem-inline-preview-toggle-slider {
	background: rgba(46, 160, 67, 0.4);
}

.chem-inline-preview-toggle input:checked + .chem-inline-preview-toggle-slider::before {
	transform: translateX(14px);
	background: rgba(46, 160, 67, 1);
}

/* Mini select */
.chem-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;
}

.chem-inline-preview-select:focus {
	border-color: rgba(46, 160, 67, 0.35);
}

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

/* ── Symbol toolbar ── */

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

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

.chem-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.72rem;
	padding: 2px 6px;
	cursor: pointer;
	transition: all 0.12s ease;
	line-height: 1.2;
}

.chem-inline-preview-toolbar-tab:hover {
	background: rgba(46, 160, 67, 0.1);
	color: rgba(255, 255, 255, 0.8);
	border-color: rgba(46, 160, 67, 0.15);
}

.chem-inline-preview-toolbar-tab.active {
	background: rgba(46, 160, 67, 0.15);
	color: rgba(46, 160, 67, 0.95);
	border-color: rgba(46, 160, 67, 0.3);
}

.chem-inline-preview-toolbar-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
	gap: 3px;
	max-height: 90px;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: rgba(46, 160, 67, 0.2) transparent;
}

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

.chem-inline-preview-toolbar-grid::-webkit-scrollbar-thumb {
	background: rgba(46, 160, 67, 0.2);
	border-radius: 2px;
}

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

.chem-inline-preview-symbol-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.75rem;
	padding: 4px 2px;
	cursor: pointer;
	text-align: center;
	transition: background 0.12s, color 0.12s, border-color 0.12s;
	line-height: 1;
}

.chem-inline-preview-symbol-btn:hover {
	background: rgba(46, 160, 67, 0.15);
	color: #fff;
	border-color: rgba(46, 160, 67, 0.25);
}

.chem-inline-preview-symbol-btn:active {
	background: rgba(46, 160, 67, 0.25);
	transform: scale(0.92);
}

/* ── KaTeX / PDF output area ── */

.chem-inline-preview-output {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 1;
	min-height: 24px;
	overflow: auto;
	scrollbar-width: thin;
	scrollbar-color: rgba(46, 160, 67, 0.2) transparent;
}

.chem-inline-preview-output::-webkit-scrollbar {
	width: 4px;
	height: 4px;
}

.chem-inline-preview-output::-webkit-scrollbar-thumb {
	background: rgba(46, 160, 67, 0.2);
	border-radius: 2px;
}

.chem-inline-preview-output::-webkit-scrollbar-track {
	background: transparent;
}

.chem-inline-preview-output embed {
	background: #fff;
}

/* KaTeX styling inside preview */
.chem-inline-preview .katex {
	color: #e8e8e8;
	font-size: 1.15rem;
}

.chem-inline-preview .katex-display {
	margin: 0;
	padding: 0;
}

/* Empty state */
.chem-inline-preview-empty {
	color: rgba(255, 255, 255, 0.2);
	font-size: 0.75rem;
	font-style: italic;
	text-align: center;
	padding: 4px 0;
	user-select: none;
}

/* ── Error state ── */

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

.chem-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 ── */

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

.chem-inline-preview-resize-handle::before {
	content: '';
	position: absolute;
	bottom: 3px;
	right: 3px;
	width: 8px;
	height: 8px;
	border-right: 2px solid rgba(46, 160, 67, 0.3);
	border-bottom: 2px solid rgba(46, 160, 67, 0.3);
}

.chem-inline-preview-resize-handle:hover::before {
	border-color: rgba(46, 160, 67, 0.6);
}

.chem-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;
}

/* ── Loading spinner ── */

.chem-inline-preview-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	color: rgba(46, 160, 67, 0.5);
	font-size: 0.7rem;
	padding: 4px 0;
}

.chem-inline-preview-spinner {
	width: 10px;
	height: 10px;
	border: 1.5px solid rgba(46, 160, 67, 0.15);
	border-top-color: rgba(46, 160, 67, 0.6);
	border-radius: 50%;
	animation: chem-inline-spin 0.6s linear infinite;
}

@keyframes chem-inline-spin {
	to { transform: rotate(360deg); }
}
