/* ============================================================================
   LaTeX Equations Modal
   Large, professional equation builder with live preview
   ========================================================================== */

.latex-equations-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.7);
	backdrop-filter: blur(8px);
	display: none;
	align-items: flex-start;
	justify-content: center;
	z-index: 32000;
	padding: 0.5rem;
}

body.latex-equations-open {
	overflow: hidden;
}

.latex-equations-overlay.active {
	display: flex;
}

.latex-equations-modal {
	background: #1e1e1e;
	border: 1px solid #343434;
	border-radius: 14px;
	width: min(1800px, 98vw);
	min-height: 94vh;
	max-height: 98vh;
	zoom: 0.88;
	color: #f4f4f4;
	box-shadow:
		0 20px 50px rgba(0, 0, 0, 0.55),
		0 0 0 1px rgba(78, 201, 176, 0.14);
	display: flex;
	flex-direction: column;
	gap: 1rem;
	padding: 1.25rem;
	overflow: auto;
	position: relative;
	z-index: 32100;
}

.latex-equations-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.latex-equations-title {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.latex-equations-title h2 {
	margin: 0;
	font-size: 1.4rem;
	letter-spacing: 0.4px;
}

.latex-equations-title p {
	margin: 0;
	color: #c0c0c0;
	font-size: 0.95rem;
}

.latex-equations-actions {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex-wrap: wrap;
	justify-content: flex-end;
}

.latex-equations-chip {
	background: rgba(78, 201, 176, 0.12);
	border: 1px solid rgba(78, 201, 176, 0.35);
	color: #b8f5e5;
	padding: 0.35rem 0.75rem;
	border-radius: 999px;
	font-size: 0.85rem;
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
}

.latex-equations-mode {
	display: inline-flex;
	border: 1px solid #343434;
	border-radius: 999px;
	overflow: hidden;
	background: #151515;
}

.latex-equations-mode button {
	background: transparent;
	color: #d0d0d0;
	border: none;
	padding: 0.45rem 0.75rem;
	cursor: pointer;
	font-size: 0.9rem;
	transition: background 0.2s ease, color 0.2s ease;
}

.latex-equations-mode button.active {
	background: #2f2f2f;
	color: #4ec9b0;
}

.latex-equations-btn {
	border-radius: 8px;
	border: 1px solid #3a3a3a;
	background: #262626;
	color: #f5f5f5;
	padding: 0.45rem 0.85rem;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	font-weight: 600;
	transition: all 0.2s ease;
}

.latex-equations-btn:hover {
	background: #303030;
	border-color: #4ec9b0;
	color: #4ec9b0;
}

.latex-equations-btn.primary {
	background: linear-gradient(135deg, #4ec9b0, #3ea490);
	border-color: #4ec9b0;
	color: #0b0b0b;
}

.latex-equations-btn.primary:hover {
	filter: brightness(1.05);
}

.latex-equations-close {
	background: transparent;
	color: #bbb;
	border: none;
	font-size: 1.4rem;
	cursor: pointer;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	transition: background 0.2s ease, color 0.2s ease;
}

.latex-equations-close:hover {
	background: rgba(255, 255, 255, 0.06);
	color: #fff;
}

.latex-equations-body {
	display: grid;
	grid-template-columns: 1fr 0.95fr;
	gap: 0.9rem;
	height: 100%;
	min-height: 0;
	align-items: start;
}

.latex-equations-column {
	display: flex;
	flex-direction: column;
	gap: 0.9rem;
	min-height: 0;
	overflow: visible;
	padding-right: 0.25rem;
}

.latex-equations-card {
	background: #171717;
	border: 1px solid #2c2c2c;
	border-radius: 12px;
	padding: 0.9rem;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	min-height: 0;
}

.latex-equations-card-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
}

.latex-equations-card-title {
	font-weight: 700;
	font-size: 1rem;
	letter-spacing: 0.2px;
}

.latex-equations-card-subtitle {
	color: #9d9d9d;
	font-size: 0.9rem;
}

.latex-equations-input {
	width: 100%;
	min-height: 160px;
	background: #0f0f0f;
	color: #f5f5f5;
	border: 1px solid #2c2c2c;
	border-radius: 10px;
	padding: 0.75rem;
	font-family: 'JetBrains Mono', 'Fira Code', monospace;
	font-size: 0.95rem;
	resize: vertical;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.latex-equations-input:focus {
	outline: 1px solid #4ec9b0;
}

.latex-equations-quick {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.latex-equations-pill-btn {
	background: #2b2b2b;
	border: 1px solid #3a3a3a;
	border-radius: 999px;
	padding: 0.35rem 0.75rem;
	color: #dcdcdc;
	cursor: pointer;
	font-size: 0.9rem;
	transition: all 0.2s ease;
}

.latex-equations-pill-btn:hover {
	border-color: #4ec9b0;
	color: #4ec9b0;
	background: #252525;
}

.latex-equations-symbol-groups {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 0.6rem;
}

.latex-equations-symbol-group {
	border: 1px solid #2c2c2c;
	border-radius: 10px;
	padding: 0.65rem;
	background: #121212;
	position: relative;
	overflow: visible;
}

.latex-equations-symbol-group-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	color: #cfcfcf;
	font-weight: 600;
	margin-bottom: 0.5rem;
	font-size: 0.95rem;
}

.latex-equations-symbol-toggle {
	background: #262626;
	border: 1px solid #3a3a3a;
	border-radius: 999px;
	padding: 0.2rem 0.75rem;
	color: #ddd;
	cursor: pointer;
	font-size: 0.85rem;
	transition: all 0.2s ease;
}

.latex-equations-symbol-toggle:hover {
	border-color: #4ec9b0;
	color: #4ec9b0;
}

.latex-equations-symbols {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(34px, 1fr));
	gap: 0.35rem;
}

.latex-equations-symbols.favorites {
	margin-bottom: 0.25rem;
}

.latex-equations-symbols.collapsible {
	position: absolute;
	top: calc(100% + 0.35rem);
	left: 0;
	min-width: 240px;
	max-width: min(420px, calc(100vw - 24px));
	background: #111;
	border: 1px solid #2f2f2f;
	border-radius: 10px;
	padding: 0.55rem;
	box-shadow:
		0 12px 30px rgba(0, 0, 0, 0.55),
		0 0 0 1px rgba(78, 201, 176, 0.12);
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(38px, 1fr));
	gap: 0.4rem;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateY(8px) scale(0.98);
	transition:
		opacity 0.12s ease,
		transform 0.12s ease,
		visibility 0.12s ease;
	z-index: 32500;
	max-height: min(260px, calc(100vh - 140px));
	overflow-y: auto;
	overflow-x: auto;
}

.latex-equations-symbols.collapsible.drop-above {
	top: auto;
	bottom: calc(100% + 0.35rem);
	transform-origin: center bottom;
}

.latex-equations-symbol-group:hover .latex-equations-symbols.collapsible,
.latex-equations-symbol-group.expanded .latex-equations-symbols.collapsible {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translateY(0);
}

.latex-equations-symbol-btn {
	background: #242424;
	border: 1px solid #303030;
	border-radius: 8px;
	color: #f1f1f1;
	min-height: 36px;
	display: grid;
	place-items: center;
	font-size: 0.9rem;
	padding: 0.15rem;
	cursor: pointer;
	transition: all 0.15s ease;
}

.latex-symbol-align-mini {
	display: block;
	text-align: center;
	line-height: 1.1;
	font-size: 0.85rem;
}

.latex-equations-symbols.collapsible.drop-above {
	transform: translateY(-8px) scale(0.98);
}

.latex-equations-input-card {
	position: static;
	top: auto;
	z-index: auto;
}

.latex-equations-symbol-btn:hover {
	border-color: #4ec9b0;
	color: #4ec9b0;
	transform: translateY(-1px);
}

.latex-equations-preview {
	background: #0f0f0f;
	border: 1px dashed #333;
	border-radius: 10px;
	min-height: 200px;
	display: grid;
	place-items: center;
	padding: 1rem;
	position: relative;
}

.latex-equations-preview-output {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-wrap: wrap;
	gap: 0.5rem;
	text-align: center;
}

.latex-equations-preview-output .katex-display > .katex > .katex-html {
	padding-right: 3em;
}

.latex-equations-preview-output .katex-display > .katex > .katex-html > .tag {
	right: 0;
}

.latex-equations-load-status {
	position: absolute;
	top: 8px;
	left: 12px;
	color: #9d9d9d;
	font-size: 0.85rem;
	pointer-events: none;
}

.latex-equations-preview .katex {
	font-size: 1.2rem;
}

.latex-equations-preview-error {
	color: #f19e9e;
	font-size: 0.9rem;
	text-align: center;
}

.latex-equations-status {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	font-size: 0.9rem;
	color: #9d9d9d;
}

.latex-equations-status.ok {
	color: #4ec9b0;
}

.latex-equations-examples {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: 0.75rem;
}

.latex-equations-example {
	background: #141414;
	border: 1px solid #242424;
	border-radius: 10px;
	padding: 0.75rem;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	transition: border-color 0.2s ease, transform 0.2s ease;
}

.latex-equations-example:hover {
	border-color: #4ec9b0;
	transform: translateY(-2px);
}

.latex-equations-example-label {
	font-weight: 600;
}

.latex-equations-example-preview {
	min-height: 48px;
	display: grid;
	place-items: center;
	background: #0f0f0f;
	border-radius: 8px;
	padding: 0.5rem;
	border: 1px dashed #2a2a2a;
}

.latex-equations-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	font-size: 0.8rem;
	color: #b0b0b0;
}

.latex-equations-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	flex-wrap: wrap;
}

.latex-equations-help {
	color: #9d9d9d;
	font-size: 0.9rem;
}

/* Search bar */
.latex-equations-search-row {
	margin-bottom: 0.4rem;
}

.latex-equations-search {
	width: 100%;
	background: #0f0f0f;
	color: #f5f5f5;
	border: 1px solid #2c2c2c;
	border-radius: 8px;
	padding: 0.5rem 0.75rem;
	font-size: 0.9rem;
	font-family: inherit;
	transition: border-color 0.2s ease;
}

.latex-equations-search:focus {
	outline: none;
	border-color: #4ec9b0;
}

.latex-equations-search::placeholder {
	color: #666;
}

/* Category tabs */
.latex-equations-category-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	margin-bottom: 0.5rem;
}

.latex-equations-category-tabs .latex-equations-pill-btn.active {
	background: rgba(78, 201, 176, 0.15);
	border-color: #4ec9b0;
	color: #4ec9b0;
}

/* History */
.latex-equations-history-list {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	max-height: 200px;
	overflow-y: auto;
	padding-right: 0.25rem;
}

.latex-equations-history-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	background: #0f0f0f;
	border: 1px solid #242424;
	border-radius: 8px;
	padding: 0.5rem 0.75rem;
	transition: border-color 0.2s ease;
}

.latex-equations-history-item:hover {
	border-color: #4ec9b0;
}

.latex-equations-history-preview {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	font-size: 0.85rem;
}

.latex-equations-history-preview .katex {
	font-size: 0.9rem;
}

.latex-equations-history-actions {
	display: flex;
	gap: 0.35rem;
	flex-shrink: 0;
}

/* Danger pill button */
.latex-equations-pill-btn.danger {
	color: #f19e9e;
	border-color: rgba(241, 158, 158, 0.3);
}

.latex-equations-pill-btn.danger:hover {
	color: #ff7070;
	border-color: #ff7070;
	background: rgba(255, 112, 112, 0.08);
}

/* Favorite active */
.latex-equations-pill-btn.active {
	color: #ffd700;
	border-color: rgba(255, 215, 0, 0.4);
}

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

@media (max-width: 900px) {
	.latex-equations-modal {
		width: 100vw;
		height: 100vh;
		max-height: 100vh;
		padding: 0.9rem;
		border-radius: 0;
	}
	.latex-equations-header {
		flex-direction: column;
		align-items: flex-start;
		gap: 0.6rem;
	}
	.latex-equations-actions {
		justify-content: flex-start;
	}
	.latex-equations-body {
		gap: 0.75rem;
	}
	.latex-equations-symbol-groups {
		grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	}
	.latex-equations-symbols.collapsible {
		max-width: calc(100vw - 32px);
		max-height: 50vh;
	}
	.latex-equations-input {
		min-height: 140px;
	}
}

@media (max-width: 640px) {
	.latex-equations-modal {
		padding: 0.75rem;
	}
	.latex-equations-card {
		padding: 0.75rem;
	}
	.latex-equations-symbols {
		grid-template-columns: repeat(auto-fit, minmax(30px, 1fr));
	}
	.latex-equations-symbol-btn {
		min-height: 32px;
	}
	.latex-equations-preview {
		min-height: 160px;
	}
}

