/* ============================================================================
   MAIN STYLES - LaTeX Split-View Editor
   ============================================================================ */

/* Import main file selector styles */
@import url('main-file-selector.css');

/* Theme variables of the editor. The colour values live in css/palette.css;
   this block only gives them the names the editor styles use. The light
   theme is switched on by applyUITheme() in settings-manager.js, which sets
   data-ui-theme on <html>; data-ui-palette picks the colours (palette.css). */
:root {
	--theme-bg-sunken: var(--pal-dark-sunken);
	--theme-bg-primary: rgb(var(--pal-dark-bg-rgb));
	--theme-bg-tertiary: var(--pal-dark-surface);
	--theme-bg-secondary: var(--pal-dark-surface-alt);
	--theme-bg-accent: var(--pal-dark-surface);
	--theme-bg-hover: var(--pal-dark-hover);
	--theme-bg-active: var(--pal-dark-active);
	--theme-bg-primary-rgb: var(--pal-dark-bg-rgb);
	--theme-overlay-rgb: var(--pal-dark-overlay-rgb);

	--theme-border-primary: var(--pal-dark-border);
	--theme-border-secondary: var(--pal-dark-border-subtle);
	--theme-border-accent: rgba(var(--pal-dark-accent-rgb), 0.6);

	--theme-text-primary: var(--pal-dark-text);
	--theme-text-secondary: var(--pal-dark-text-secondary);
	--theme-text-accent: var(--pal-dark-accent-text);
	--theme-text-muted: var(--pal-dark-text-muted);
	--theme-text-error: var(--pal-dark-error);
	--theme-text-warning: var(--pal-dark-warn);
	--theme-text-success: var(--pal-dark-success);

	--theme-primary: rgb(var(--pal-dark-accent-rgb));
	--theme-primary-hover: rgb(var(--pal-dark-accent-hover-rgb));
	--theme-primary-rgb: var(--pal-dark-accent-rgb);
	--theme-on-primary: var(--pal-dark-on-accent);
	--theme-accent: rgb(var(--pal-dark-accent-rgb));
	--theme-secondary: var(--pal-dark-hover);
	--theme-secondary-hover: var(--pal-dark-active);

	--theme-shadow-accent: 0 0 0 3px rgba(var(--pal-dark-accent-rgb), 0.22);

	--theme-shadow-primary: 0 8px 32px rgba(0, 0, 0, 0.5);
	--theme-shadow-secondary: 0 12px 30px rgba(0, 0, 0, 0.4);
	--theme-font-brand: var(--pal-font-brand);
}

:root[data-ui-theme="light"] {
	--theme-bg-sunken: var(--pal-light-sunken);
	--theme-bg-primary: rgb(var(--pal-light-bg-rgb));
	--theme-bg-tertiary: var(--pal-light-surface);
	--theme-bg-secondary: var(--pal-light-surface-alt);
	--theme-bg-accent: var(--pal-light-surface);
	--theme-bg-hover: var(--pal-light-hover);
	--theme-bg-active: var(--pal-light-active);
	--theme-bg-primary-rgb: var(--pal-light-bg-rgb);
	--theme-overlay-rgb: var(--pal-light-overlay-rgb);

	--theme-border-primary: var(--pal-light-border);
	--theme-border-secondary: var(--pal-light-border-subtle);
	--theme-border-accent: rgba(var(--pal-light-accent-rgb), 0.6);

	--theme-text-primary: var(--pal-light-text);
	--theme-text-secondary: var(--pal-light-text-secondary);
	--theme-text-accent: var(--pal-light-accent-text);
	--theme-text-muted: var(--pal-light-text-muted);
	--theme-text-error: var(--pal-light-error);
	--theme-text-warning: var(--pal-light-warn);
	--theme-text-success: var(--pal-light-success);

	--theme-primary: rgb(var(--pal-light-accent-rgb));
	--theme-primary-hover: rgb(var(--pal-light-accent-hover-rgb));
	--theme-primary-rgb: var(--pal-light-accent-rgb);
	--theme-on-primary: var(--pal-light-on-accent);
	--theme-accent: rgb(var(--pal-light-accent-rgb));
	--theme-secondary: var(--pal-light-hover);
	--theme-secondary-hover: var(--pal-light-active);

	--theme-shadow-accent: 0 0 0 3px rgba(var(--pal-light-accent-rgb), 0.22);

	--theme-shadow-primary: 0 8px 32px rgba(26, 29, 33, 0.16);
	--theme-shadow-secondary: 0 12px 30px rgba(26, 29, 33, 0.12);
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html {
	position: relative;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	accent-color: var(--theme-primary);
	position: relative;
	top: 0;
	left: 0;
	width: 100%;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	background: var(--theme-bg-primary);
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
	position: sticky;
	top: 0;
	left: 0;
	right: 0;
	background: var(--theme-bg-secondary);
	color: var(--theme-text-primary);
	padding: 0.75rem 1.5rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid var(--theme-border-primary);
	height: 50px;
	min-height: 50px;
	z-index: 21000;
	flex-shrink: 0;
}

.header-left {
	display: flex;
	align-items: center;
	gap: 1rem;
}

.logo {
	display: flex;
	align-items: center;
	gap: 0.55rem;
	color: var(--theme-text-primary);
	text-decoration: none;
	border-radius: 6px;
}

.logo:focus-visible {
	outline: 2px solid var(--theme-primary);
	outline-offset: 4px;
}

.logo-icon {
	width: 26px;
	height: 26px;
	flex-shrink: 0;
}

/* The logo exists as two files, one per background. Its two colours are the
   same in all palettes, so only the mode (data-ui-theme) decides. */
:root[data-ui-theme="light"] .logo-on-dark,
:root:not([data-ui-theme="light"]) .logo-on-light {
	display: none;
}

.logo-text {
	font-family: var(--theme-font-brand);
	font-size: 1.2rem;
	font-weight: 700;
	letter-spacing: -0.01em;
	color: var(--theme-text-primary);
}

.project-name-wrapper {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	padding-left: 1rem;
	border-left: 1px solid var(--theme-border-primary);
	min-width: 0;
}

/* The project name opens the start screen, where another project can be chosen. */
.project-switch {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	max-width: 22rem;
	padding: 0.3rem 0.5rem;
	border: none;
	border-radius: 6px;
	background: transparent;
	color: var(--theme-text-secondary);
	font: inherit;
	font-size: 0.9rem;
	cursor: pointer;
}

.project-switch:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.project-switch:focus-visible {
	outline: 2px solid var(--theme-primary);
	outline-offset: 2px;
}

.project-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.project-switch-caret {
	flex-shrink: 0;
	opacity: 0.7;
}

.project-select-btn {
	background: transparent;
	border: none;
	color: var(--theme-text-muted);
	cursor: pointer;
	padding: 0.25rem;
	border-radius: 4px;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0.7;
}

.project-select-btn:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-accent);
	opacity: 1;
}

.project-select-btn:active {
	background: var(--theme-bg-secondary);
}

.header-center {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

.header-right {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

/* Header actions share one quiet icon-button look. Their own stylesheets
   (comments, GitHub, collaboration, login) keep the active states. */
.header-right > .comment-panel-toggle,
.header-right > .github-sync-trigger,
.header-right > .feedback-trigger,
.header-right > .collab-trigger,
.header-right > .login-trigger,
.header-right > .settings-btn,
.header-right > .btn-bridge-connected {
	width: 34px;
	height: 34px;
	padding: 0;
	align-items: center;
	justify-content: center;
	border: 1px solid transparent;
	border-radius: 6px;
	background: transparent;
	color: var(--theme-text-secondary);
	box-shadow: none;
	transition: background 0.12s ease, color 0.12s ease;
}

.header-right > .comment-panel-toggle:hover,
.header-right > .github-sync-trigger:hover,
.header-right > .feedback-trigger:hover,
.header-right > .collab-trigger:hover,
.header-right > .login-trigger:hover,
.header-right > .settings-btn:hover,
.header-right > .btn-bridge-connected:hover {
	background: var(--theme-bg-hover);
	border-color: transparent;
	color: var(--theme-text-primary);
	transform: none;
	box-shadow: none;
}

.header-right > .btn-secondary {
	height: 34px;
	border: 1px solid var(--theme-border-primary);
	background: transparent;
	color: var(--theme-text-primary);
	font-weight: 500;
}

.header-right > .btn-secondary:hover {
	background: var(--theme-bg-hover);
}

.settings-btn {
	background: transparent;
	border: none;
	color: var(--theme-text-primary);
	font-size: 1.3rem;
	cursor: pointer;
	padding: 0.5rem;
	border-radius: 4px;
	transition: all 0.2s;
	display: flex;
	align-items: center;
}

.settings-btn:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-accent);
}

.settings-icon {
	width: 20px;
	height: 20px;
	flex-shrink: 0;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
	padding: 0.5rem 1rem;
	border: none;
	border-radius: 6px;
	cursor: pointer;
	font-size: 0.85rem;
	font-weight: 600;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.btn-icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

.btn-primary {
	background: var(--theme-primary);
	color: var(--theme-on-primary);
}

.btn-primary:hover {
	background: var(--theme-primary-hover);
	color: var(--theme-on-primary);
}

.btn-success {
	background: #28a745;
	color: var(--theme-text-primary);
}

.btn-success:hover {
	background: #34b350;
}

.btn-info {
	background: var(--theme-primary);
	color: var(--theme-on-primary);
}

.btn-info:hover {
	background: var(--theme-primary-hover);
	color: var(--theme-on-primary);
}

.btn-danger {
	background: #dc3545;
	color: var(--theme-text-primary);
}

.btn-secondary {
	background: var(--theme-secondary);
	color: var(--theme-text-primary);
}

.btn-secondary:hover {
	background: var(--theme-secondary-hover);
}

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

/* ============================================================================
   COMPILE SPLIT-BUTTON
   ============================================================================ */

.compile-split-btn {
	position: relative;
	display: inline-flex;
	align-items: center;
	--compile-split-height: 34px;
}

.compile-split-btn .compile-main {
	height: var(--compile-split-height);
	border-top-right-radius: 0;
	border-bottom-right-radius: 0;
	border-right: 1px solid rgba(var(--theme-bg-primary-rgb), 0.2);
}

.compile-split-btn .compile-dropdown-toggle {
	height: var(--compile-split-height);
	border-top-left-radius: 0;
	border-bottom-left-radius: 0;
	padding: 0 0.65rem;
	min-width: 34px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.compile-split-btn .compile-dropdown-toggle svg {
	width: 11px;
	height: 7px;
	display: block;
}

.compile-dropdown-menu {
	position: absolute;
	top: calc(100% + 4px);
	right: 0;
	width: 280px;
	background: var(--theme-bg-secondary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 8px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
	z-index: 10000;
	opacity: 0;
	visibility: hidden;
	transform: translateY(-4px);
	transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
	padding: 6px 0;
}

.compile-dropdown-menu.open {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.compile-dropdown-section {
	padding: 2px 0;
}

.compile-dropdown-item {
	display: grid;
	grid-template-columns: 20px 1fr auto;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding: 7px 12px;
	background: none;
	border: none;
	color: var(--theme-text-primary);
	font-size: 0.85rem;
	cursor: pointer;
	text-align: left;
	white-space: nowrap;
}

.compile-dropdown-item:hover {
	background: var(--theme-bg-hover);
}

.compile-dropdown-item.active {
	color: var(--theme-text-accent);
}

.compile-dropdown-check {
	width: 20px;
	text-align: center;
	color: var(--theme-text-accent);
	font-size: 0.9rem;
}

.compile-dropdown-hint {
	color: var(--theme-text-muted);
	font-size: 0.75rem;
}

.compile-dropdown-divider {
	height: 1px;
	background: var(--theme-border-primary);
	margin: 4px 0;
}

.compile-dropdown-item.toggle-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	cursor: default;
	padding: 7px 12px;
}

.compile-dropdown-item.delay-selector-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 4px 12px 7px 12px;
}

.compile-dropdown-divider {
	height: 1px;
	background: var(--theme-border-primary);
	margin: 4px 8px;
}

.delay-label {
	font-size: 0.8rem;
	color: var(--theme-text-secondary);
}

.compile-delay-select {
	background: var(--theme-bg-active);
	color: var(--theme-text-primary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 4px;
	padding: 2px 6px;
	font-size: 0.78rem;
	cursor: pointer;
	outline: none;
	transition: border-color 0.2s, box-shadow 0.2s;
}

.compile-delay-select:hover {
	border-color: var(--theme-primary);
}

.compile-delay-select:focus {
	border-color: var(--theme-primary);
	box-shadow: 0 0 0 2px rgba(var(--theme-primary-rgb), 0.2);
}

.compile-delay-select option {
	background: var(--theme-bg-secondary);
	color: var(--theme-text-primary);
}

/* ============================================================================
   TOGGLE SWITCH
   ============================================================================ */

.toggle-switch {
	position: relative;
	display: inline-block;
	width: 50px;
	height: 26px;
}

.toggle-switch input {
	opacity: 0;
	width: 0;
	height: 0;
}

.toggle-slider {
	position: absolute;
	cursor: pointer;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: var(--theme-bg-active);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	border-radius: 26px;
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-slider:hover {
	background-color: var(--theme-secondary-hover);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(var(--theme-primary-rgb), 0.1);
}

.toggle-slider:before {
	position: absolute;
	content: "";
	height: 20px;
	width: 20px;
	left: 3px;
	top: 50%;
	transform: translate(0, -50%);
	background: linear-gradient(180deg, var(--theme-text-primary) 0%, #f0f0f0 100%);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	border-radius: 50%;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
}

input:checked + .toggle-slider {
	background-color: var(--theme-primary);
	color: var(--theme-on-primary);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 2px rgba(var(--theme-primary-rgb), 0.2);
}

input:checked + .toggle-slider:hover {
	background-color: var(--theme-primary-hover);
	color: var(--theme-on-primary);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 2px rgba(var(--theme-primary-rgb), 0.3);
}

input:checked + .toggle-slider:before {
	transform: translate(24px, -50%);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.15);
}

input:focus + .toggle-slider {
	outline: 2px solid rgba(var(--theme-primary-rgb), 0.4);
	outline-offset: 2px;
}

.toggle-label {
	margin-left: 0.5rem;
	color: var(--theme-text-primary);
	font-size: 0.85rem;
}

/* Small toggle variant (for dropdown menus) */
.toggle-switch-sm {
	width: 36px;
	height: 20px;
	flex-shrink: 0;
}

.toggle-switch-sm .toggle-slider:before {
	height: 14px;
	width: 14px;
	left: 3px;
	top: 50%;
}

.toggle-switch-sm input:checked + .toggle-slider:before {
	transform: translate(16px, -50%);
}

/* ============================================================================
   STATUS INDICATOR
   ============================================================================ */

.status-indicator {
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	padding: 0.5rem;
}

.status-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	position: relative;
}

.status-icon {
	width: 20px;
	height: 20px;
	position: relative;
}

/* Idle: nothing to report, so nothing is shown. */
.status-badge.status-idle .status-icon {
	visibility: hidden;
}

/* Compiling Status - Spinner */
.status-badge.status-compiling .status-icon {
	color: #ffc107;
	animation: compiling-spin 1.5s linear infinite;
}

.status-badge.status-compiling .status-icon circle {
	stroke: currentColor;
	fill: none;
	stroke-width: 2;
	stroke-dasharray: 40 20;
	stroke-linecap: round;
	animation: compiling-dash 2s ease-in-out infinite;
}

/* Success Status - Checkmark */
.status-badge.status-success .status-icon {
	color: #28a745;
}

.status-badge.status-success .status-icon circle {
	stroke: currentColor;
	fill: rgba(40, 167, 69, 0.1);
	stroke-width: 2;
}

.status-badge.status-success .status-icon path {
	stroke: currentColor;
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
	fill: none;
	stroke-dasharray: 20;
	stroke-dashoffset: 20;
	animation: checkmark-draw 0.6s ease-out 0.2s forwards;
}

/* Error Status - X Mark */
.status-badge.status-error .status-icon {
	color: #dc3545;
}

.status-badge.status-error .status-icon circle {
	stroke: currentColor;
	fill: rgba(220, 53, 69, 0.1);
	stroke-width: 2;
}

.status-badge.status-error .status-icon path {
	stroke: currentColor;
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
	fill: none;
	stroke-dasharray: 20;
	stroke-dashoffset: 20;
	animation: xmark-draw 0.4s ease-out 0.1s forwards;
}

/* Animations */
@keyframes compiling-spin {
	0% {
		transform: rotate(0deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

@keyframes compiling-dash {
	0%, 100% {
		stroke-dashoffset: 0;
		opacity: 1;
	}
	50% {
		stroke-dashoffset: -30;
		opacity: 0.7;
	}
}

@keyframes checkmark-draw {
	to {
		stroke-dashoffset: 0;
	}
}

@keyframes xmark-draw {
	to {
		stroke-dashoffset: 0;
	}
}

/* The spinner turns while compiling; success and error just appear. */
.status-badge.status-compiling .status-icon {
	animation: compiling-spin 1.5s linear infinite;
}

/* ============================================================================
   MAIN CONTAINER
   ============================================================================ */

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

.project-tab-bar {
	display: flex;
	align-items: center;
	gap: 0;
	background: var(--theme-bg-secondary);
	border-bottom: 1px solid var(--theme-border-primary);
	height: 32px;
	min-height: 32px;
	padding: 0 0.5rem;
	overflow-x: auto;
	flex-shrink: 0;
}

.project-tab {
	display: flex;
	align-items: center;
	gap: 0.35rem;
	padding: 0 0.75rem;
	height: 100%;
	font-size: 0.8rem;
	color: var(--theme-text-muted);
	cursor: pointer;
	border-right: 1px solid var(--theme-border-primary);
	white-space: nowrap;
	max-width: 180px;
	transition: background 0.15s, color 0.15s;
	user-select: none;
}

.project-tab:hover {
	background: var(--theme-bg-tertiary);
	color: var(--theme-text-primary);
}

.project-tab-active {
	color: var(--theme-text-primary);
	background: var(--theme-bg-primary);
	border-bottom: 2px solid var(--theme-text-accent);
}

.project-tab-name {
	overflow: hidden;
	text-overflow: ellipsis;
}

.project-tab-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #f38ba8;
	flex-shrink: 0;
}

.project-tab-close {
	background: none;
	border: none;
	color: inherit;
	font-size: 1rem;
	line-height: 1;
	padding: 0 0.15rem;
	cursor: pointer;
	opacity: 0;
	transition: opacity 0.15s;
}

.project-tab:hover .project-tab-close {
	opacity: 0.7;
}

.project-tab-close:hover {
	opacity: 1;
	color: var(--theme-text-error);
}

/* Adjust main container height when tabs are visible */
body.tabs-visible .main-container {
	height: calc(100vh - 50px - 32px);
	height: calc(100dvh - 50px - 32px);
}

.main-container {
	display: flex;
	position: relative;
	top: 0;
	left: 0;
	height: calc(100vh - 50px);
	height: calc(100dvh - 50px);
	min-height: 0;
	min-width: 0;
	overflow: hidden;
	transition: padding-bottom 0.2s ease;
	padding-bottom: 0;
}

/* Adjust layout when AI chat is open - add padding to prevent overlap */
body.ai-chat-open .main-container {
	padding-bottom: 260px;
}

/* ============================================================================
   SIDEBAR
   ============================================================================ */

.sidebar {
	position: relative;
	top: 0;
	left: 0;
	flex: 0 0 250px;
	min-width: 150px;
	max-width: 600px;
	background: var(--theme-bg-tertiary);
	border-right: 1px solid var(--theme-border-primary);
	overflow-y: auto;
	transition: flex 0.2s ease;
	display: flex;
	flex-direction: column;
}

.sidebar.collapsed {
	flex: 0 0 0;
	min-width: 0;
	max-width: 0;
	overflow: hidden;
	border-right: none;
}

.sidebar-header {
	padding: 1rem;
	background: var(--theme-bg-secondary);
	border-bottom: 1px solid var(--theme-border-primary);
}

.sidebar-title-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 0.5rem;
}

.sidebar-title {
	color: var(--theme-text-primary);
	font-size: 0.9rem;
	font-weight: 600;
}

.sidebar-actions {
	display: flex;
	gap: 0.25rem;
}

.sidebar-action-btn {
	background: transparent;
	border: 1px solid var(--theme-border-primary);
	border-radius: 4px;
	padding: 0.25rem 0.5rem;
	cursor: pointer;
	color: var(--theme-text-primary);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s;
}

.sidebar-action-btn:hover {
	background: var(--theme-bg-hover);
	border-color: var(--theme-primary);
	color: var(--theme-text-accent);
}

.sidebar-action-btn:active {
	background: var(--theme-bg-secondary);
}

/* ============================================================================
   CREATE ITEM MODAL
   ============================================================================ */

.create-item-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 10000;
	display: flex;
	align-items: center;
	justify-content: center;
}

.create-item-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(var(--theme-bg-primary-rgb), 0.6);
	backdrop-filter: blur(4px);
}

.create-item-dialog {
	position: relative;
	background: var(--theme-bg-secondary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 8px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
	min-width: 400px;
	max-width: 500px;
	width: 90%;
	z-index: 1;
	animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
	from {
		opacity: 0;
		transform: scale(0.95) translateY(-10px);
	}
	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

.create-item-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 1.25rem 1.5rem;
	border-bottom: 1px solid var(--theme-border-primary);
}

.create-item-header h3 {
	margin: 0;
	color: var(--theme-text-primary);
	font-size: 1.1rem;
	font-weight: 600;
}

.create-item-close {
	background: transparent;
	border: none;
	color: var(--theme-text-secondary);
	font-size: 1.75rem;
	cursor: pointer;
	padding: 0;
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 4px;
	transition: all 0.2s;
	line-height: 1;
}

.create-item-close:hover {
	background: rgba(231, 76, 60, 0.1);
	color: var(--theme-text-error);
}

.create-item-body {
	padding: 1.5rem;
}

.create-item-path {
	margin-bottom: 1rem;
	color: var(--theme-text-secondary);
	font-size: 0.85rem;
}

.create-item-path span {
	color: var(--theme-text-accent);
	font-weight: 500;
}

.create-item-input {
	width: 100%;
	padding: 0.75rem 1rem;
	background: var(--theme-bg-primary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 6px;
	color: var(--theme-text-primary);
	font-size: 0.95rem;
	font-family: inherit;
	transition: all 0.2s;
}

.create-item-input:focus {
	outline: none;
	border-color: var(--theme-primary);
	box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.1);
}

.create-item-hint {
	margin-top: 0.75rem;
	color: var(--theme-text-secondary);
	font-size: 0.85rem;
}

.create-item-footer {
	display: flex;
	justify-content: flex-end;
	gap: 0.75rem;
	padding: 1rem 1.5rem;
	border-top: 1px solid var(--theme-border-primary);
}

.create-item-btn {
	padding: 0.6rem 1.25rem;
	border: none;
	border-radius: 6px;
	font-size: 0.9rem;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s;
	font-family: inherit;
}

.create-item-btn-secondary {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.create-item-btn-secondary:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.create-item-btn-primary {
	background: var(--theme-primary);
	color: var(--theme-on-primary);
}

.create-item-btn-primary:hover {
	background: var(--theme-primary-hover);
	color: var(--theme-on-primary);
}

.create-item-btn-primary:active {
	transform: scale(0.98);
}

/* ── Biber consent dialog (ui/biber-consent-dialog.js) ── */

.biber-consent-dialog {
	max-width: 560px;
	outline: none;
}

.biber-consent-dialog .create-item-body p {
	margin: 0 0 0.85rem;
	color: var(--theme-text-primary);
	font-size: 0.92rem;
	line-height: 1.5;
}

.biber-consent-files {
	margin: -0.35rem 0 0.85rem;
	padding: 0.5rem 0.75rem 0.5rem 1.75rem;
	max-height: 7.5rem;
	overflow-y: auto;
	background: var(--theme-bg-primary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 6px;
	color: var(--theme-text-accent);
	font-size: 0.88rem;
	overflow-wrap: anywhere;
}

.biber-consent-remember {
	display: flex;
	align-items: flex-start;
	gap: 0.6rem;
	margin-top: 1rem;
	color: var(--theme-text-primary);
	font-size: 0.9rem;
	line-height: 1.4;
	cursor: pointer;
}

.biber-consent-remember input {
	margin-top: 0.2rem;
	flex-shrink: 0;
}

/* ── Template Conflict Dialog ── */

.conflict-dialog {
	max-width: 520px;
}

.conflict-banner {
	display: flex;
	align-items: flex-start;
	gap: 0.65rem;
	padding: 0.75rem 1rem;
	background: rgba(231, 196, 60, 0.08);
	border: 1px solid rgba(231, 196, 60, 0.2);
	border-radius: 6px;
	color: var(--theme-text-warning);
	font-size: 0.9rem;
	line-height: 1.5;
	margin-bottom: 0.75rem;
}

.conflict-banner svg {
	flex-shrink: 0;
	margin-top: 2px;
}

.conflict-banner span {
	color: var(--theme-text-primary);
}

.conflict-banner strong {
	color: var(--theme-text-primary);
}

.conflict-file-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.conflict-file-list li {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.45rem 0.75rem;
	background: rgba(var(--theme-overlay-rgb), 0.04);
	border-radius: 5px;
	color: var(--theme-text-primary);
	font-size: 0.88rem;
	font-family: 'Consolas', 'Monaco', monospace;
}

.conflict-file-icon {
	font-size: 0.85rem;
	opacity: 0.7;
}

.conflict-footer {
	justify-content: space-between;
}

.conflict-actions-right {
	display: flex;
	gap: 0.5rem;
}

.conflict-btn-overwrite {
	background: rgba(231, 76, 60, 0.15);
	color: var(--theme-text-error);
	border: 1px solid rgba(231, 76, 60, 0.3);
}

.conflict-btn-overwrite:hover {
	background: rgba(231, 76, 60, 0.25);
	color: var(--theme-text-error);
	border-color: rgba(231, 76, 60, 0.5);
}

.conflict-btn-overwrite:active {
	transform: scale(0.98);
}

.conflict-new-project-row {
	padding: 0 1.5rem 1rem;
}

.conflict-btn-new-project {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	background: rgba(var(--theme-primary-rgb), 0.08);
	color: var(--theme-text-accent);
	border: 1px solid rgba(var(--theme-primary-rgb), 0.25);
	padding: 0.6rem 1rem;
}

.conflict-btn-new-project:hover {
	background: rgba(var(--theme-primary-rgb), 0.15);
	color: var(--theme-text-accent);
	border-color: rgba(var(--theme-primary-rgb), 0.4);
}

.conflict-btn-new-project:active {
	transform: scale(0.99);
}

/* ============================================================================
   CONTEXT MENU
   ============================================================================ */

.context-menu {
	background: var(--theme-bg-secondary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 6px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
	min-width: 180px;
	overflow: visible;
	animation: contextMenuSlideIn 0.15s ease-out;
}

@keyframes contextMenuSlideIn {
	from {
		opacity: 0;
		transform: scale(0.95) translateY(-5px);
	}
	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

.context-menu-item {
	padding: 0.6rem 1rem;
	color: var(--theme-text-primary);
	font-size: 0.9rem;
	cursor: pointer;
	transition: all 0.15s;
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.context-menu-item:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-accent);
}

.context-menu-item:active {
	background: var(--theme-bg-secondary);
}

.search-box {
	width: 100%;
	padding: 0.5rem;
	background: var(--theme-bg-hover);
	border: 1px solid var(--theme-border-primary);
	border-radius: 4px;
	color: var(--theme-text-primary);
	font-size: 0.85rem;
}

.search-box:focus {
	outline: none;
	border-color: var(--theme-primary);
}

.file-list {
	padding: 0.5rem;
	position: relative;
	z-index: 4;
	transition: outline 0.2s, background 0.2s;
	flex: 1;
	min-height: 0;
}

.file-list.drag-over {
	outline: 2px dashed var(--theme-primary);
	outline-offset: -4px;
	background: rgba(var(--theme-primary-rgb), 0.05);
}

.upload-context-menu {
	background: var(--theme-bg-secondary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 6px;
	padding: 4px 0;
	min-width: 160px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.upload-menu-item {
	padding: 8px 14px;
	cursor: pointer;
	font-size: 0.85rem;
	color: var(--theme-text-primary);
	white-space: nowrap;
}

.upload-menu-item:hover {
	background: var(--theme-bg-hover);
}

.file-item {
	padding: 0.6rem 0.75rem;
	margin: 0.25rem 0;
	background: transparent;
	border-radius: 4px;
	cursor: pointer;
	transition: all 0.2s;
	color: var(--theme-text-primary);
	font-size: 0.85rem;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	min-width: 0;
}

.file-item:hover {
	background: var(--theme-bg-secondary);
}

.file-item.active {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
	border-left: 2px solid var(--theme-primary);
}

.file-item.selected {
	background: rgba(var(--theme-primary-rgb), 0.12);
	border-left: 2px solid rgba(var(--theme-primary-rgb), 0.5);
	color: var(--theme-text-primary);
}

.file-item.selected.active {
	background: var(--theme-bg-hover);
	border-left: 2px solid var(--theme-primary);
}

.file-icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

/* Long file/folder names: single line with ellipsis, full name via title tooltip */
.file-item .file-name-text {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.folder-header .folder-name-text {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.file-item .main-file-badge,
.file-item .zotero-sync-badge {
	flex-shrink: 0;
}

/* ============================================================================
   FOLDER STYLES
   ============================================================================ */

.folder-item {
	margin-bottom: 4px;
}

.folder-header {
	padding: 0.6rem 0.75rem;
	margin: 0.25rem 0;
	background: transparent;
	border-radius: 4px;
	cursor: pointer;
	transition: all 0.2s;
	color: var(--theme-text-primary);
	font-size: 0.85rem;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	min-width: 0;
}

.folder-header:hover {
	background: var(--theme-bg-secondary);
}

.folder-icon {
	width: 16px;
	height: 16px;
}

.folder-arrow {
	margin-left: auto;
	font-size: 0.8em;
	transition: transform 0.2s ease;
}

.folder-content {
	margin-left: 20px;
	margin-top: 2px;
}

.folder-content .file-item,
.folder-content .folder-header {
	background: transparent;
}

.folder-content .file-item:hover,
.folder-content .folder-header:hover {
	background: var(--theme-bg-secondary);
}

.file-item.subfolder,
.folder-item.subfolder {
	font-size: 0.85em;
}

/* ============================================================================
   TOPIC BLOCKS AND FOLDER ORGANIZATION
   ============================================================================ */

.topic-block {
	margin-bottom: 0.75rem;
	border: 1px solid var(--theme-border-primary);
	border-radius: 4px;
	background: var(--theme-bg-secondary);
}

.topic-block-header {
	padding: 0.5rem 0.75rem;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	border-bottom: 1px solid var(--theme-border-primary);
	color: var(--theme-text-primary);
	font-size: 0.85rem;
	font-weight: 600;
}

.topic-block-icon {
	font-size: 1rem;
}

.topic-block-name {
	flex: 1;
}

.topic-block-actions {
	display: flex;
	gap: 0.25rem;
}

.topic-block-btn {
	background: transparent;
	border: none;
	color: var(--theme-text-secondary);
	cursor: pointer;
	padding: 0.25rem 0.5rem;
	border-radius: 3px;
	font-size: 1rem;
	line-height: 1;
	transition: all 0.2s;
}

.topic-block-btn:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.topic-block-content {
	padding: 0.25rem;
}

.folder-item.in-topic-block {
	margin-bottom: 2px;
}

.folder-drag-handle {
	cursor: grab;
	color: var(--theme-text-muted);
	font-size: 0.7rem;
	line-height: 1;
	margin-right: 0.25rem;
	user-select: none;
}

.folder-drag-handle:active {
	cursor: grabbing;
}

.folder-item.dragging {
	opacity: 0.5;
}

.folder-item.drag-over {
	background: rgba(var(--theme-primary-rgb), 0.1);
	border-left: 2px solid var(--theme-primary);
}

.folder-menu-btn {
	background: transparent;
	border: none;
	color: var(--theme-text-muted);
	cursor: pointer;
	padding: 0.25rem 0.5rem;
	border-radius: 3px;
	font-size: 1rem;
	line-height: 1;
	transition: all 0.2s;
	margin-left: auto;
	opacity: 0;
}

.folder-header:hover .folder-menu-btn {
	opacity: 1;
}

.folder-menu-btn:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.file-drag-handle {
	cursor: grab;
	color: var(--theme-text-muted);
	font-size: 0.7rem;
	line-height: 1;
	margin-right: 0.25rem;
	user-select: none;
}

.file-drag-handle:active {
	cursor: grabbing;
}

.file-item.dragging {
	opacity: 0.5;
}

.file-item.drag-over {
	background: rgba(var(--theme-primary-rgb), 0.1);
	border-left: 2px solid var(--theme-primary);
}

.file-menu-btn {
	background: transparent;
	border: none;
	color: var(--theme-text-muted);
	cursor: pointer;
	padding: 0.25rem 0.5rem;
	border-radius: 3px;
	font-size: 1rem;
	line-height: 1;
	transition: all 0.2s;
	margin-left: auto;
	opacity: 0;
}

.file-item:hover .file-menu-btn {
	opacity: 1;
}

.file-menu-btn:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.file-item.in-topic-block {
	margin-left: 0.5rem;
}

.topic-block-content {
	padding: 0.25rem;
}

.context-menu {
	position: fixed;
	background: var(--theme-bg-secondary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 6px;
	box-shadow: var(--theme-shadow-primary);
	z-index: 10001;
	padding: 0.35rem 0;
	min-width: 190px;
	max-width: 250px;
}

.context-menu-category {
	padding: 0.3rem 0.85rem;
	font-size: 0.7rem;
	font-weight: 600;
	color: var(--theme-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	background: var(--theme-bg-tertiary);
	border-bottom: 1px solid var(--theme-border-secondary);
	user-select: none;
}

.context-menu-separator {
	height: 1px;
	background: var(--theme-border-secondary);
	margin: 0.35rem 0;
}

/* ── Submenu (flyout) ── */

.context-submenu-trigger {
	position: relative;
	justify-content: space-between;
}

.context-submenu-arrow {
	margin-left: auto;
	opacity: 0.5;
	font-size: 0.75rem;
}

.context-submenu {
	display: none;
	position: absolute;
	top: 0;
	right: 100%;
	margin-right: 2px;
	background: var(--theme-bg-secondary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 6px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
	min-width: 160px;
	max-height: 260px;
	overflow-y: auto;
	z-index: 10002;
	padding: 0.25rem 0;
}

.context-submenu.visible {
	display: block;
	animation: contextMenuSlideIn 0.12s ease-out;
}

/* Fall back to right side when no space on left */
.context-submenu.context-submenu-right {
	right: auto;
	left: 100%;
	margin-right: 0;
	margin-left: 2px;
}

.context-menu-item {
	padding: 0.4rem 0.85rem;
	cursor: pointer;
	color: var(--theme-text-primary);
	font-size: 0.8rem;
	transition: all 0.12s ease;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	user-select: none;
}

.context-menu-item:hover {
	background: var(--theme-bg-hover);
	color: var(--theme-text-primary);
}

.context-menu-item:active {
	background: var(--theme-bg-active);
}

/* Special item styles */
.context-menu-item-warning {
	color: var(--theme-text-warning);
}

.context-menu-item-warning:hover {
	background: color-mix(in srgb, var(--theme-text-warning) 14%, transparent);
	color: var(--theme-text-warning);
}

.context-menu-item-danger {
	color: var(--theme-text-error);
}

.context-menu-item-danger:hover {
	background: color-mix(in srgb, var(--theme-text-error) 14%, transparent);
	color: var(--theme-text-error);
}

/* ============================================================================
   SPLIT PANEL
   ============================================================================ */

.split-panel {
	display: flex;
	flex: 1;
	position: relative;
	top: 0;
	left: 0;
	min-height: 0;
	min-width: 0;
	overflow: visible;
}

.editor-pane, .preview-pane {
	position: relative;
	top: 0;
	left: 0;
	height: 100%;
	min-height: 0;
	min-width: 0;
	overflow: visible;
}

.editor-pane {
	flex: 1;
	display: flex;
	flex-direction: column;
	background: var(--theme-bg-primary);
	transition: flex 0.2s ease;
}

.editor-pane.collapsed {
	flex: 0 0 0;
	min-width: 0;
	max-width: 0;
	overflow: hidden;
}

.preview-pane {
	flex: 1;
	background: var(--theme-bg-secondary);
	border-left: 1px solid var(--theme-border-primary);
	display: flex;
	flex-direction: column;
	transition: flex 0.2s ease;
	position: relative;
	top: 0;
	left: 0;
	z-index: 5;
}

.preview-pane.collapsed {
	flex: 0 0 0;
	min-width: 0;
	max-width: 0;
	overflow: hidden;
	border-left: none;
}

.preview-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	height: 100%;
	min-height: 0;
	position: relative;
}

.preview-panel {
	flex: 1;
	display: none;
	min-height: 0;
	width: 100%;
}

.preview-panel.active {
	display: flex;
}

.pdf-panel {
	flex-direction: column;
}

.log-panel {
	flex-direction: column;
	align-items: stretch;
	padding: 1rem 1.25rem;
	gap: 0.75rem;
	overflow: auto;
}

.pane-title-group {
	display: flex !important;
	align-items: center;
	gap: 0.75rem;
	flex-shrink: 0;
}

.pane-tabs {
	display: inline-flex !important;
	align-items: center;
	gap: 0.25rem;
	background: var(--theme-bg-primary);
	border: 1px solid var(--theme-border-primary);
	border-radius: 8px;
	padding: 2px;
	flex-shrink: 0;
}

.pane-tab {
	border: none;
	background: transparent;
	color: var(--theme-text-primary);
	padding: 0.35rem 0.7rem;
	border-radius: 6px;
	cursor: pointer;
	font-size: 0.85rem;
	transition: background 0.15s ease, color 0.15s ease;
}

.pane-tab:hover {
	background: var(--theme-bg-hover);
}

.pane-tab.active {
	background: var(--theme-primary);
	color: var(--theme-on-primary);
}

.pane-actions {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.pane-actions-tools {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	margin-right: 0.35rem;
}

.pane-tool-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border-radius: 7px;
	border: 1px solid var(--theme-border-primary);
	background: var(--theme-bg-tertiary);
	color: var(--theme-text-primary);
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.pane-tool-btn:hover {
	background: var(--theme-bg-hover);
	border-color: var(--theme-primary);
	color: var(--theme-text-accent);
}

.pane-tool-btn:active {
	transform: translateY(1px) scale(0.98);
}

.pane-tool-icon {
	width: 18px;
	height: 18px;
	display: block;
}

.pane-tool-icon.spin-once {
	animation: paneToolSpin 0.6s ease;
	transform-origin: 50% 50%;
}

.pane-tool-btn.press-once {
	animation: paneToolPress 0.32s ease;
}

@keyframes paneToolSpin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

@keyframes paneToolPress {
	0% { transform: translateY(0) scale(1); }
	40% { transform: translateY(2px) scale(0.97); }
	100% { transform: translateY(0) scale(1); }
}

.pane-header {
	padding: 0.75rem 1rem;
	background: var(--theme-bg-secondary);
	border-bottom: 1px solid var(--theme-border-primary);
	color: var(--theme-text-primary);
	font-size: 0.85rem;
	display: flex !important;
	justify-content: space-between;
	align-items: center;
	position: relative;
	z-index: 5;
	min-height: 50px;
	flex-shrink: 0;
}

.pane-header h3 {
	font-size: 0.9rem;
	font-weight: 600;
}

.pane-actions {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.pane-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 8px;
	border: 1px solid var(--theme-border-primary);
	background: var(--theme-bg-secondary);
	color: var(--theme-text-primary);
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.pane-icon-btn:hover,
.pane-icon-btn.active {
	background: var(--theme-bg-hover);
	border-color: var(--theme-primary);
	color: var(--theme-text-accent);
}

.pane-icon-btn svg {
	width: 18px;
	height: 18px;
}

/* ============================================================================
   CODE EDITOR
   ============================================================================ */

.code-editor {
	flex: 1;
	min-height: 0;
	overflow: visible;
	background: var(--theme-bg-primary);
	position: relative;
}

#monaco-editor {
	width: 100%;
	height: 100%;
}

.monaco-editor,
.monaco-editor .overflow-guard {
	overflow: visible !important;
}

/* ============================================================================
   PDF VIEWER
   ============================================================================ */

.pdf-viewer {
	flex: 1;
	background: var(--theme-bg-active);
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	overflow: hidden;
	pointer-events: auto;
	z-index: 1;
}

.pdf-frame {
	width: 100%;
	height: 100%;
	border: none;
	position: absolute;
	top: 0;
	left: 0;
}

.pdf-frame.fade-in {
	transition: opacity 1.5s ease-in-out;
}

.pdf-placeholder {
	text-align: center;
	color: var(--theme-text-secondary);
	padding: 3rem;
}

.pdf-placeholder svg {
	width: 80px;
	height: 80px;
	margin-bottom: 1rem;
	opacity: 0.5;
}

/* ============================================================================
   LOADING OVERLAY
   ============================================================================ */

.loading-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(var(--theme-bg-primary-rgb), 0.95);
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 10;
	pointer-events: none;
}

.loading-overlay.active {
	display: flex;
}

.loading-content {
	text-align: center;
	color: var(--theme-text-primary);
}

.spinner {
	border: 4px solid var(--theme-border-primary);
	border-top: 4px solid var(--theme-primary);
	border-radius: 50%;
	width: 50px;
	height: 50px;
	animation: spin 1s linear infinite;
	margin: 0 auto 1rem;
}

@keyframes spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

/* ============================================================================
   NOTIFICATIONS
   ============================================================================ */

.notification {
	position: fixed;
	top: 65px;
	right: 20px;
	padding: 0.5rem 0.75rem;
	background: rgba(var(--theme-bg-primary-rgb), 0.9);
	backdrop-filter: blur(10px);
	border-radius: 20px;
	box-shadow: 0 2px 8px rgba(0,0,0,0.3);
	color: var(--theme-text-primary);
	z-index: 2000;
	display: none;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.8rem;
	border: 1px solid rgba(var(--theme-overlay-rgb), 0.1);
}

.notification.active {
	display: flex;
	animation: subtleFadeIn 0.4s ease;
}

.notification.success {
	border-color: rgba(40, 167, 69, 0.3);
}

.notification.error {
	border-color: rgba(220, 53, 69, 0.3);
}

@keyframes subtleFadeIn {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ============================================================================
   RESIZER
   ============================================================================ */

/* The handle is 5px wide to be easy to grab and shows as a hairline. */
.resizer {
	width: 5px;
	background: linear-gradient(to right, transparent 2px, var(--theme-border-primary) 2px, var(--theme-border-primary) 3px, transparent 3px);
	cursor: col-resize;
	position: relative;
	flex-shrink: 0;
	z-index: 5;
}

.resizer:hover {
	background: var(--theme-primary);
}

.sidebar.collapsed ~ .sidebar-resizer:not(.force-visible) {
	display: none;
}

.editor-pane.collapsed ~ .resizer:not(.force-visible),
.preview-pane.collapsed ~ .resizer:not(.force-visible) {
	display: none;
}

.split-panel:has(.editor-pane.collapsed) .resizer:not(.force-visible),
.split-panel:has(.preview-pane.collapsed) .resizer:not(.force-visible) {
	display: none;
}

.resizer.force-visible {
	display: block !important;
	width: 16px !important;
	background: var(--theme-primary) !important;
	color: var(--theme-on-primary) !important;
	opacity: 0.9;
	transition: width 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.resizer.force-visible:hover {
	background: var(--theme-primary) !important;
	color: var(--theme-on-primary) !important;
	opacity: 1;
	width: 15px !important;
}

/* ============================================================================
   SYNTAX HIGHLIGHTING
   ============================================================================ */

.latex-command { color: var(--theme-text-accent); }
.latex-comment { color: #6a9955; font-style: italic; }
.latex-bracket { color: #e06c75; }
.latex-string { color: #ce9178; }

/* ============================================================================
   GLOBAL SCROLLBAR STYLES
   Neutral and quiet: the thumb is a tint of the text colour.
   ============================================================================ */

*::-webkit-scrollbar {
	width: 10px;
	height: 10px;
}

*::-webkit-scrollbar-track {
	background: transparent;
}

*::-webkit-scrollbar-thumb {
	background: rgba(var(--theme-overlay-rgb), 0.16);
	border-radius: 10px;
	border: 2px solid transparent;
	background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
	background: rgba(var(--theme-overlay-rgb), 0.28);
	background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:active {
	background: rgba(var(--theme-overlay-rgb), 0.38);
	background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
	background: transparent;
}

/* Firefox */
* {
	scrollbar-width: thin;
	scrollbar-color: rgba(var(--theme-overlay-rgb), 0.22) transparent;
}

/* Monaco Editor scrollbar */
.monaco-scrollable-element > .scrollbar > .slider {
	background: rgba(var(--theme-overlay-rgb), 0.16) !important;
	border-radius: 10px !important;
}

.monaco-scrollable-element > .scrollbar > .slider:hover {
	background: rgba(var(--theme-overlay-rgb), 0.28) !important;
}

.monaco-scrollable-element > .scrollbar > .slider:active {
	background: rgba(var(--theme-overlay-rgb), 0.38) !important;
}

/* ============================================================================
   SYNCTEX HIGHLIGHT
   ============================================================================ */

.synctex-highlight-line {
	background-color: rgba(var(--theme-primary-rgb), 0.3) !important;
	animation: synctexPulse 2s ease-out;
}

/* Citation key with a saved evidence link — color configurable via
   --linked-cite-color (settings). Overrides the theme token foreground. */
.linked-cite-key {
	color: var(--linked-cite-color, #3FB950) !important;
	font-weight: 600;
	text-decoration-line: underline;
	text-decoration-style: dotted;
	text-decoration-color: var(--linked-cite-color, #3FB950);
	text-underline-offset: 2px;
	cursor: pointer;
}

.synctex-highlight-glyph {
	background-color: rgba(var(--theme-primary-rgb), 0.6);
	width: 5px !important;
	margin-left: 3px;
}

@keyframes synctexPulse {
	0% {
		background-color: rgba(var(--theme-primary-rgb), 0.6);
	}
	50% {
		background-color: rgba(var(--theme-primary-rgb), 0.4);
	}
	100% {
		background-color: rgba(var(--theme-primary-rgb), 0.3);
	}
}

/* ============================================================================
   PDF.JS TEXT LAYER (for text selection)
   ============================================================================ */

.textLayer {
	position: absolute;
	text-align: initial;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	overflow: hidden;
	opacity: 1;
	line-height: 1;
	-webkit-text-size-adjust: none;
	-moz-text-size-adjust: none;
	text-size-adjust: none;
	forced-color-adjust: none;
	z-index: 2;
	pointer-events: none;
}

.textLayer span,
.textLayer br {
	color: transparent;
	position: absolute;
	white-space: pre;
	cursor: text;
	transform-origin: 0% 0%;
}

.textLayer span.markedContent {
	top: 0;
	height: 0;
}

.textLayer .highlight {
	margin: -1px;
	padding: 1px;
	background-color: rgba(var(--theme-primary-rgb), 0.3);
	border-radius: 4px;
}

.textLayer .highlight.appended {
	position: initial;
}

.textLayer .highlight.begin {
	border-radius: 4px 0 0 4px;
}

.textLayer .highlight.end {
	border-radius: 0 4px 4px 0;
}

.textLayer .highlight.middle {
	border-radius: 0;
}

.textLayer .highlight.selected {
	background-color: rgba(0, 100, 0, 0.2);
}

/* Text selection styling */
.textLayer ::selection {
	background: rgba(var(--theme-primary-rgb), 0.3);
}

.textLayer ::-moz-selection {
	background: rgba(var(--theme-primary-rgb), 0.3);
}

/* Keep the annotation layer on top of the text to allow clickable links */
.pdf-page-canvas {
	pointer-events: none;
	z-index: 1;
}

/* PDF paper (Settings). A CSS filter leaves the canvas pixels untouched,
   so snips and exports stay white. */
:root[data-pdf-paper="dimmed"] .pdf-page-canvas {
	filter: brightness(0.94) sepia(0.12);
}

:root[data-pdf-paper="inverted"] .pdf-page-canvas {
	filter: invert(0.9) hue-rotate(180deg);
}

.annotationLayer {
	pointer-events: none;  /* Let text selection pass through to textLayer below */
	z-index: 5;
}

/* Only link elements within annotation layer intercept clicks */
.annotationLayer a,
.annotationLayer .linkAnnotation {
	pointer-events: auto;
}

/* ============================================================================
   PDF.JS ANNOTATION LAYER (for hyperlinks)
   ============================================================================ */

.annotationLayer section {
	position: absolute;
	text-align: initial;
	pointer-events: auto;
}

.annotationLayer a,
.annotationLayer .linkAnnotation {
	position: absolute;
	font-size: 1em;
}

.annotationLayer a:hover,
.annotationLayer .linkAnnotation:hover {
	background: rgba(255, 255, 0, 0.3);
	box-shadow: 0 2px 10px rgba(255, 255, 0, 0.3);
	cursor: pointer;
}

.annotationLayer .textAnnotation img {
	position: absolute;
	cursor: pointer;
	width: 100%;
	height: 100%;
}

.annotationLayer .textWidgetAnnotation input,
.annotationLayer .textWidgetAnnotation textarea,
.annotationLayer .choiceWidgetAnnotation select,
.annotationLayer .buttonWidgetAnnotation.checkBox input,
.annotationLayer .buttonWidgetAnnotation.radioButton input {
	background-image: none;
	border: 1px solid transparent;
	box-sizing: border-box;
	font: calc(9px * var(--scale-factor)) sans-serif;
	height: 100%;
	margin: 0;
	vertical-align: top;
	width: 100%;
}

.annotationLayer .choiceWidgetAnnotation select option {
	padding: 0;
}

.annotationLayer .buttonWidgetAnnotation.radioButton input {
	border-radius: 50%;
}

.annotationLayer .textWidgetAnnotation textarea {
	resize: none;
}

.annotationLayer .textWidgetAnnotation input[disabled],
.annotationLayer .textWidgetAnnotation textarea[disabled],
.annotationLayer .choiceWidgetAnnotation select[disabled],
.annotationLayer .buttonWidgetAnnotation.checkBox input[disabled],
.annotationLayer .buttonWidgetAnnotation.radioButton input[disabled] {
	background: none;
	border: 1px solid transparent;
	cursor: not-allowed;
}

/* ============================================================================
   ACCESS GATE – Login hint banners
   ============================================================================ */

.access-gate-login-hint {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 4px;
	font-size: 13px;
	line-height: 1.4;
}

.access-gate-login-link {
	color: var(--theme-text-accent);
	text-decoration: underline;
	cursor: pointer;
	font-weight: 500;
	font-size: 13px;
}

.access-gate-login-link:hover {
	color: var(--theme-text-accent);
}

/* Bridge modal login hint */
.bridge-login-hint {
	background: rgba(224, 108, 117, 0.1);
	border: 1px solid rgba(224, 108, 117, 0.3);
	border-radius: 8px;
	padding: 10px 14px;
	margin-bottom: 12px;
	color: var(--theme-text-error);
	font-weight: 500;
}

.bridge-login-hint .access-gate-login-link {
	color: var(--theme-text-accent);
}

/* PDF toolbar login hint */
.pane-login-hint {
	font-size: 11px;
	padding: 2px 8px;
	flex-direction: row;
	gap: 4px;
	align-items: center;
	color: var(--theme-text-error);
}

.pane-login-hint .access-gate-login-link {
	font-size: 11px;
}
