/* ============================================================================
   TikZ Editor Modal
   Extends latex-equations.css via dual-class approach:
   overlay has class="latex-equations-overlay latex-tikz-overlay"
   All shared structural styles are inherited from latex-equations.css.
   Only TikZ-specific overrides live here.
   ========================================================================== */

/* Wider modal for TikZ (visual editor needs space) */
.latex-tikz-overlay .latex-equations-modal {
	width: min(1900px, 98vw);
}

/* ─── Tab Bar ─────────────────────────────────────────────────────────── */

.latex-tikz-tab-bar {
	display: flex;
	gap: 4px;
	padding: 0 16px 8px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
	margin-bottom: 0;
}

.latex-tikz-tab {
	padding: 8px 20px;
	border: none;
	border-bottom: 2px solid transparent;
	background: transparent;
	color: rgba(255, 255, 255, 0.5);
	font-size: 0.9rem;
	font-weight: 500;
	cursor: pointer;
	transition: color 0.15s, border-color 0.15s;
	border-radius: 6px 6px 0 0;
}

.latex-tikz-tab:hover {
	color: rgba(255, 255, 255, 0.8);
	background: rgba(255, 255, 255, 0.04);
}

.latex-tikz-tab.active {
	color: #fff;
	border-bottom-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.08);
}

/* ─── Monaco Editor Container ────────────────────────────────────────── */

.latex-tikz-monaco-container {
	width: 100%;
	height: 350px;
	border: 1px solid #2c2c2c;
	border-radius: 8px;
	overflow: hidden;
}

/* ─── Library Pills ──────────────────────────────────────────────────── */

.latex-tikz-library-bar {
	display: flex;
	gap: 4px;
	overflow-x: auto;
	padding: 2px 0;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
	flex-wrap: wrap;
}

.latex-tikz-library-bar::-webkit-scrollbar {
	height: 4px;
}

.latex-tikz-library-bar::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.1);
	border-radius: 2px;
}

.latex-tikz-library-pill {
	padding: 4px 10px;
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 12px;
	background: transparent;
	color: rgba(255, 255, 255, 0.45);
	font-size: 0.72rem;
	cursor: pointer;
	white-space: nowrap;
	transition: all 0.15s;
	flex-shrink: 0;
}

.latex-tikz-library-pill:hover {
	color: rgba(255, 255, 255, 0.7);
	border-color: rgba(255, 255, 255, 0.15);
	background: rgba(255, 255, 255, 0.04);
}

.latex-tikz-library-pill.active {
	color: #fff;
	border-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.15);
}

/* ─── Preview Container ──────────────────────────────────────────────── */

.latex-tikz-preview {
	flex: 1;
	min-height: 300px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #0f0f0f;
	border-radius: 8px;
	border: 1px dashed #333;
	padding: 12px;
}

.latex-tikz-preview embed {
	background: white;
	border-radius: 4px;
}

/* ─── Status Indicator ───────────────────────────────────────────────── */

.latex-tikz-status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 0.85rem;
	color: #9d9d9d;
	padding: 4px 0;
}

.latex-tikz-status .status-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #666;
	transition: background 0.2s;
}

.latex-tikz-status.compiling .status-dot {
	background: #f0ad4e;
	animation: latex-tikz-pulse 1s infinite;
}

.latex-tikz-status.ready .status-dot {
	background: #4ec9b0;
}

.latex-tikz-status.error .status-dot {
	background: #ff6b6b;
}

@keyframes latex-tikz-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.4; }
}

/* ─── Error Display ──────────────────────────────────────────────────── */

.latex-tikz-error {
	background: rgba(255, 107, 107, 0.08);
	border: 1px solid rgba(255, 107, 107, 0.2);
	border-radius: 8px;
	padding: 10px 12px;
	font-family: 'Fira Code', 'JetBrains Mono', monospace;
	font-size: 0.78rem;
	color: #ff9999;
	max-height: 150px;
	overflow-y: auto;
	display: none;
	white-space: pre-wrap;
	word-break: break-all;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 107, 107, 0.2) transparent;
}

.latex-tikz-error.visible {
	display: block;
}

/* ─── Quick Snippet Buttons ──────────────────────────────────────────── */

.latex-tikz-quick-row {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
}

.latex-tikz-quick-btn {
	padding: 4px 10px;
	border: 1px solid #3a3a3a;
	border-radius: 6px;
	background: #262626;
	color: #dcdcdc;
	font-size: 0.78rem;
	cursor: pointer;
	transition: all 0.15s;
	white-space: nowrap;
}

.latex-tikz-quick-btn:hover {
	border-color: #7c6fe0;
	color: #7c6fe0;
	background: rgba(124, 111, 224, 0.08);
}

/* ─── Compile Button ─────────────────────────────────────────────────── */

.latex-tikz-compile-btn {
	padding: 6px 14px;
	border: 1px solid #7c6fe0;
	border-radius: 8px;
	background: rgba(124, 111, 224, 0.12);
	color: #b8b0f0;
	font-size: 0.82rem;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.15s;
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.latex-tikz-compile-btn:hover {
	background: rgba(124, 111, 224, 0.22);
	color: #fff;
}

.latex-tikz-compile-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ─── Template Grid ──────────────────────────────────────────────────── */

.latex-tikz-template-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 8px;
	overflow-y: auto;
	max-height: calc(100vh - 380px);
	padding: 2px;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.latex-tikz-template-grid::-webkit-scrollbar {
	width: 4px;
}

.latex-tikz-template-grid::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.1);
	border-radius: 2px;
}

.latex-tikz-template-card {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px;
	border: 1px solid rgba(255, 255, 255, 0.06);
	border-radius: 10px;
	background: rgba(255, 255, 255, 0.02);
	cursor: pointer;
	transition: all 0.15s;
}

.latex-tikz-template-card:hover {
	border-color: rgba(124, 111, 224, 0.3);
	background: rgba(124, 111, 224, 0.06);
	transform: translateY(-1px);
}

.latex-tikz-template-card.selected {
	border-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.12);
	box-shadow: 0 0 8px rgba(124, 111, 224, 0.2);
}

.latex-tikz-template-icon {
	font-size: 1.8rem;
	text-align: center;
	padding: 8px 0;
	opacity: 0.7;
}

.latex-tikz-template-name {
	font-size: 0.82rem;
	font-weight: 600;
	color: rgba(255, 255, 255, 0.85);
	text-align: center;
}

.latex-tikz-template-desc {
	font-size: 0.7rem;
	color: rgba(255, 255, 255, 0.4);
	text-align: center;
}

/* ─── Category Bar (for templates) ───────────────────────────────────── */

.latex-tikz-category-bar {
	display: flex;
	gap: 4px;
	overflow-x: auto;
	padding: 2px 0;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
	flex-wrap: wrap;
}

.latex-tikz-category-pill {
	padding: 4px 10px;
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 12px;
	background: transparent;
	color: rgba(255, 255, 255, 0.45);
	font-size: 0.72rem;
	cursor: pointer;
	white-space: nowrap;
	transition: all 0.15s;
	flex-shrink: 0;
}

.latex-tikz-category-pill:hover {
	color: rgba(255, 255, 255, 0.7);
	border-color: rgba(255, 255, 255, 0.15);
	background: rgba(255, 255, 255, 0.04);
}

.latex-tikz-category-pill.active {
	color: #fff;
	border-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.15);
}

/* ─── Visual Editor ──────────────────────────────────────────────────── */

.latex-tikz-visual-container {
	display: grid;
	grid-template-columns: 48px 1fr 220px;
	gap: 8px;
	height: calc(100vh - 320px);
	min-height: 400px;
}

.latex-tikz-tool-palette {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 4px;
	background: #171717;
	border: 1px solid #2c2c2c;
	border-radius: 8px;
}

.latex-tikz-tool-btn {
	width: 40px;
	height: 40px;
	border: 1px solid transparent;
	border-radius: 6px;
	background: transparent;
	color: rgba(255, 255, 255, 0.6);
	font-size: 1.1rem;
	cursor: pointer;
	display: grid;
	place-items: center;
	transition: all 0.15s;
}

.latex-tikz-tool-btn:hover {
	background: rgba(255, 255, 255, 0.06);
	color: rgba(255, 255, 255, 0.9);
}

.latex-tikz-tool-btn.active {
	border-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.15);
	color: #b8b0f0;
}

.latex-tikz-canvas-wrap {
	position: relative;
	border: 1px solid #2c2c2c;
	border-radius: 8px;
	overflow: hidden;
	background: #0a0a0a;
}

.latex-tikz-canvas-wrap canvas {
	display: block;
	width: 100%;
	height: 100%;
}

.latex-tikz-canvas-coords {
	position: absolute;
	bottom: 6px;
	right: 8px;
	font-size: 0.72rem;
	color: rgba(255, 255, 255, 0.35);
	font-family: 'Fira Code', monospace;
	pointer-events: none;
}

.latex-tikz-properties-panel {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 10px;
	background: #171717;
	border: 1px solid #2c2c2c;
	border-radius: 8px;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.latex-tikz-prop-title {
	font-size: 0.82rem;
	font-weight: 600;
	color: rgba(255, 255, 255, 0.7);
	padding-bottom: 4px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.latex-tikz-prop-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.latex-tikz-prop-label {
	font-size: 0.75rem;
	color: rgba(255, 255, 255, 0.5);
	white-space: nowrap;
}

.latex-tikz-prop-input {
	width: 70px;
	padding: 3px 6px;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 4px;
	background: rgba(255, 255, 255, 0.04);
	color: #e0e0e0;
	font-size: 0.75rem;
	font-family: 'Fira Code', monospace;
	text-align: right;
}

.latex-tikz-prop-input:focus {
	outline: none;
	border-color: rgba(124, 111, 224, 0.5);
}

.latex-tikz-prop-select {
	padding: 3px 6px;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 4px;
	background: rgba(255, 255, 255, 0.04);
	color: #e0e0e0;
	font-size: 0.75rem;
}

.latex-tikz-prop-color {
	width: 28px;
	height: 22px;
	border: 1px solid rgba(255, 255, 255, 0.15);
	border-radius: 4px;
	cursor: pointer;
	background: transparent;
	padding: 1px;
}

/* ─── Image Drop Zone ────────────────────────────────────────────────── */

.latex-tikz-image-drop {
	border: 2px dashed rgba(124, 111, 224, 0.3);
	border-radius: 8px;
	padding: 16px;
	text-align: center;
	color: rgba(255, 255, 255, 0.35);
	font-size: 0.8rem;
	transition: all 0.2s;
	cursor: pointer;
}

.latex-tikz-image-drop:hover,
.latex-tikz-image-drop.dragover {
	border-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.06);
	color: rgba(255, 255, 255, 0.6);
}

/* ─── Package Groups (collapsible) ───────────────────────────────────── */

.latex-tikz-package-group {
	border: 1px solid rgba(255, 255, 255, 0.06);
	border-radius: 8px;
	overflow: hidden;
	margin-bottom: 4px;
}

.latex-tikz-package-group-header {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 10px;
	background: rgba(255, 255, 255, 0.02);
	cursor: pointer;
	user-select: none;
	transition: background 0.15s;
}

.latex-tikz-package-group-header:hover {
	background: rgba(255, 255, 255, 0.05);
}

.latex-tikz-package-group-header .group-icon {
	font-size: 1rem;
}

.latex-tikz-package-group-header .group-name {
	font-size: 0.78rem;
	font-weight: 600;
	color: rgba(255, 255, 255, 0.7);
	flex: 1;
}

.latex-tikz-package-group-header .group-arrow {
	font-size: 0.65rem;
	color: rgba(255, 255, 255, 0.3);
	transition: transform 0.2s;
}

.latex-tikz-package-group.expanded .group-arrow {
	transform: rotate(90deg);
}

.latex-tikz-package-group-body {
	display: none;
	padding: 6px 10px 8px;
	gap: 4px;
	flex-wrap: wrap;
}

.latex-tikz-package-group.expanded .latex-tikz-package-group-body {
	display: flex;
}

.latex-tikz-package-pill {
	padding: 4px 10px;
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 12px;
	background: transparent;
	color: rgba(255, 255, 255, 0.45);
	font-size: 0.72rem;
	cursor: pointer;
	white-space: nowrap;
	transition: all 0.15s;
	position: relative;
}

.latex-tikz-package-pill:hover {
	color: rgba(255, 255, 255, 0.7);
	border-color: rgba(255, 255, 255, 0.15);
	background: rgba(255, 255, 255, 0.04);
}

.latex-tikz-package-pill.active {
	color: #fff;
	border-color: #7c6fe0;
	background: rgba(124, 111, 224, 0.15);
}

/* ─── Auto-Detect Notification Bar ──────────────────────────────────── */

.latex-tikz-autodetect-bar {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 12px;
	background: rgba(78, 201, 176, 0.08);
	border: 1px solid rgba(78, 201, 176, 0.2);
	border-radius: 8px;
	font-size: 0.78rem;
	color: #4ec9b0;
	animation: latex-tikz-slidein 0.2s ease-out;
}

.latex-tikz-autodetect-bar button {
	padding: 2px 10px;
	border: 1px solid rgba(78, 201, 176, 0.3);
	border-radius: 6px;
	background: rgba(78, 201, 176, 0.1);
	color: #4ec9b0;
	font-size: 0.72rem;
	cursor: pointer;
	transition: all 0.15s;
}

.latex-tikz-autodetect-bar button:hover {
	background: rgba(78, 201, 176, 0.2);
	color: #fff;
}

.latex-tikz-autodetect-bar .dismiss {
	margin-left: auto;
	background: none;
	border: none;
	color: rgba(78, 201, 176, 0.5);
	cursor: pointer;
	font-size: 0.9rem;
	padding: 0 4px;
}

@keyframes latex-tikz-slidein {
	from { opacity: 0; transform: translateY(-4px); }
	to { opacity: 1; transform: translateY(0); }
}

/* ─── Snippet Groups (collapsible) ──────────────────────────────────── */

.latex-tikz-snippet-groups {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.latex-tikz-snippet-group-header {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 4px 8px;
	cursor: pointer;
	user-select: none;
	font-size: 0.75rem;
	font-weight: 600;
	color: rgba(255, 255, 255, 0.55);
	transition: color 0.15s;
}

.latex-tikz-snippet-group-header:hover {
	color: rgba(255, 255, 255, 0.8);
}

.latex-tikz-snippet-group-header .snippet-arrow {
	font-size: 0.6rem;
	color: rgba(255, 255, 255, 0.3);
	transition: transform 0.2s;
}

.latex-tikz-snippet-group-header.expanded .snippet-arrow {
	transform: rotate(90deg);
}

.latex-tikz-snippet-group-body {
	display: none;
	flex-wrap: wrap;
	gap: 4px;
	padding: 2px 0 4px 16px;
}

.latex-tikz-snippet-group-body.expanded {
	display: flex;
}

/* ─── Template Preview Popup ─────────────────────────────────────────── */

.latex-tikz-template-preview-popup {
	position: fixed;
	z-index: 100000;
	background: #1a1a1a;
	border: 1px solid #444;
	border-radius: 10px;
	padding: 8px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
	max-width: 420px;
	max-height: 400px;
}

.latex-tikz-template-preview-popup embed {
	background: white;
	border-radius: 6px;
	width: 400px;
	height: 300px;
}

.latex-tikz-template-preview-popup .preview-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 400px;
	height: 300px;
	color: rgba(255, 255, 255, 0.4);
	font-size: 0.85rem;
}

.latex-tikz-template-preview-popup .preview-close {
	position: absolute;
	top: 4px;
	right: 8px;
	background: none;
	border: none;
	color: rgba(255, 255, 255, 0.5);
	font-size: 1.1rem;
	cursor: pointer;
}

/* ─── Template Card Preview Button ───────────────────────────────────── */

.latex-tikz-template-card {
	position: relative;
}

.latex-tikz-template-preview-btn {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 24px;
	height: 24px;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 6px;
	background: rgba(0, 0, 0, 0.4);
	color: rgba(255, 255, 255, 0.4);
	font-size: 0.7rem;
	cursor: pointer;
	display: grid;
	place-items: center;
	opacity: 0;
	transition: all 0.15s;
}

.latex-tikz-template-card:hover .latex-tikz-template-preview-btn {
	opacity: 1;
}

.latex-tikz-template-preview-btn:hover {
	background: rgba(124, 111, 224, 0.3);
	color: #fff;
	border-color: #7c6fe0;
}

/* ─── Canvas Info Bar ────────────────────────────────────────────────── */

.latex-tikz-info-bar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 4px 10px;
	font-size: 0.7rem;
	color: rgba(255, 255, 255, 0.3);
	font-family: 'Fira Code', monospace;
}

.latex-tikz-info-bar span {
	display: inline-flex;
	align-items: center;
	gap: 4px;
}

/* ─── Color Picker Row ───────────────────────────────────────────────── */

.latex-tikz-color-row {
	display: flex;
	align-items: center;
	gap: 6px;
}

.latex-tikz-color-input {
	width: 28px;
	height: 22px;
	border: 1px solid rgba(255, 255, 255, 0.15);
	border-radius: 4px;
	cursor: pointer;
	background: transparent;
	padding: 1px;
}

/* ─── Code Preview Panel (Visual Tab) ────────────────────────────────── */

.latex-tikz-code-preview {
	background: #121212;
	border: 1px solid #2c2c2c;
	border-radius: 8px;
	overflow: hidden;
}

.latex-tikz-code-preview-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 10px;
	background: #171717;
	border-bottom: 1px solid #2c2c2c;
	font-size: 0.78rem;
	font-weight: 600;
	color: rgba(255, 255, 255, 0.6);
}

.latex-tikz-code-preview-content {
	margin: 0;
	padding: 8px 10px;
	font-family: 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
	font-size: 0.75rem;
	color: #b8b0f0;
	max-height: 160px;
	overflow-y: auto;
	white-space: pre-wrap;
	word-break: break-all;
	line-height: 1.5;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* ─── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 1200px) {
	.latex-tikz-visual-container {
		grid-template-columns: 48px 1fr;
	}
	.latex-tikz-properties-panel {
		display: none;
	}
}

@media (max-width: 1100px) {
	.latex-tikz-overlay .latex-equations-body {
		grid-template-columns: 1fr;
	}
}
