/**
 * Flexa viewer styling. Loaded by assets/viewer.html. Uses CSS custom
 * properties for the two menu themes (dark default / light) so the admin's
 * "Menus theme" setting only has to toggle a body class.
 */

:root {
	--flexa-panel-bg: #1b212c;
	--flexa-panel-fg: #eef1f6;
	--flexa-panel-border: rgba(255, 255, 255, .08);
	--flexa-accent: #2f6bff;
	--flexa-toolbar-bg: rgba(20, 24, 32, .92);
}
body.flexa-theme-light {
	--flexa-panel-bg: #ffffff;
	--flexa-panel-fg: #1d2327;
	--flexa-panel-border: rgba(0, 0, 0, .08);
	--flexa-toolbar-bg: rgba(255, 255, 255, .96);
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	height: 100%;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	overflow: hidden;
}

/* ===== Loading overlay ===== */
.flexa-loading {
	position: fixed;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	color: #cfd6e4;
	background: transparent;
}
.flexa-loading[hidden] { display: none; }
.flexa-spinner {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	border: 3px solid rgba(255, 255, 255, .18);
	border-top-color: var(--flexa-accent);
	animation: flexa-spin 0.9s linear infinite;
}
@keyframes flexa-spin { to { transform: rotate(360deg); } }
.flexa-loading-text { font-size: 14px; }
.flexa-loading-text.flexa-error-text { color: #ff6b6b; }
.flexa-loading-track {
	width: 200px;
	height: 4px;
	border-radius: 2px;
	background: rgba(255, 255, 255, .12);
	overflow: hidden;
}
.flexa-loading-bar {
	height: 100%;
	width: 0;
	background: var(--flexa-accent);
	transition: width .2s ease;
}

.flexa-btn-primary {
	width: 100%;
	padding: 10px 12px;
	border: 0;
	border-radius: 6px;
	background: var(--flexa-accent);
	color: #fff;
	font-size: 14px;
	cursor: pointer;
}
.flexa-btn-primary:hover { filter: brightness(1.08); }

/* ===== App shell ===== */
.flexa-app {
	position: fixed;
	inset: 0;
	display: flex;
	flex-direction: column;
}
.flexa-app[hidden] { display: none; }
.flexa-app.flexa-fullscreen { background: inherit; }

/* ===== Toolbar ===== */
.flexa-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 10px;
	background: var(--flexa-toolbar-bg);
	color: var(--flexa-panel-fg);
	backdrop-filter: blur(6px);
	z-index: 5;
	flex-wrap: wrap;
}
.flexa-tb-group { display: flex; align-items: center; gap: 4px; }
.flexa-tb-center { flex: 1; justify-content: center; }

.flexa-icon-btn {
	width: 34px;
	height: 34px;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: var(--flexa-panel-fg);
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
}
.flexa-icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.flexa-icon-btn:hover { background: rgba(127, 127, 127, .16); }
.flexa-icon-btn.flexa-active { background: var(--flexa-accent); color: #fff; }
.flexa-icon-btn[hidden] { display: none; }

.flexa-btn-text { width: auto; padding: 0 10px; font-size: 12px; }

.flexa-page-indicator { font-size: 12px; opacity: .85; white-space: nowrap; }

.flexa-title {
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 220px;
	margin-inline-end: 6px;
}
.flexa-jump-input {
	width: 52px;
	padding: 4px 6px;
	border-radius: 5px;
	border: 1px solid var(--flexa-panel-border);
	background: rgba(127, 127, 127, .08);
	color: inherit;
	font-size: 12px;
	text-align: center;
}

.flexa-more-wrap { position: relative; }
.flexa-more-menu {
	position: absolute;
	top: 40px;
	right: 0;
	background: var(--flexa-panel-bg);
	color: var(--flexa-panel-fg);
	border: 1px solid var(--flexa-panel-border);
	border-radius: 8px;
	padding: 6px;
	min-width: 160px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, .35);
	z-index: 6;
}
.flexa-menu-item {
	display: block;
	width: 100%;
	text-align: start;
	padding: 8px 10px;
	background: transparent;
	border: 0;
	border-radius: 6px;
	color: inherit;
	font-size: 13px;
	cursor: pointer;
}
.flexa-menu-item[hidden] { display: none; }
.flexa-menu-item:hover { background: rgba(127, 127, 127, .16); }

/* RTL: mirror the toolbar's more-menu edge */
body.flexa-rtl .flexa-more-menu { right: auto; left: 0; }

/* ===== Stage (flip mode) ===== */
.flexa-stage {
	position: relative;
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: auto;
	padding: 16px;
}
.flexa-stage.flexa-zoomed { align-items: flex-start; }

.flexa-book-wrap {
	width: 100%;
	height: 100%;
	max-width: 1400px;
	transition: transform .18s ease;
	will-change: transform;
}
.flexa-book-wrap.flexa-tilt-active { will-change: transform; }
.flexa-book { width: 100%; height: 100%; }
.flexa-book.flexa-single-view { margin: 0 auto; }

/* page-flip mirrors for RTL: flip the whole book, then un-flip each page's content */
.flexa-book.flexa-mirror { transform: scaleX(-1); }
.flexa-book.flexa-mirror .flexa-page-inner { transform: scaleX(-1); }

.flexa-page { background: #fff; }
.flexa-page-inner { position: relative; width: 100%; height: 100%; background: #fff; }
.flexa-page-inner canvas { display: block; width: 100%; height: 100%; }

.flexa-page-placeholder {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: repeating-linear-gradient(
		135deg,
		#f2f2f2, #f2f2f2 10px,
		#e9e9e9 10px, #e9e9e9 20px
	);
}
.flexa-page-placeholder .flexa-spinner {
	width: 28px;
	height: 28px;
	border-color: rgba(0, 0, 0, .12);
	border-top-color: var(--flexa-accent);
}

/* ===== Clickable link overlay ===== */
.flexa-link-overlay { position: absolute; inset: 0; pointer-events: none; }
.flexa-link {
	position: absolute;
	display: block;
	pointer-events: auto;
	cursor: pointer;
}
.flexa-link:hover { background: rgba(47, 107, 255, .12); outline: 1px solid rgba(47, 107, 255, .4); }

/* ===== Search highlight ===== */
.flexa-search-highlight {
	position: absolute;
	background: rgba(255, 224, 82, .55);
	border-radius: 2px;
	pointer-events: none;
	animation: flexa-highlight-pulse 1.6s ease 2;
}
@keyframes flexa-highlight-pulse {
	0%, 100% { background: rgba(255, 224, 82, .55); }
	50% { background: rgba(255, 224, 82, .85); }
}

/* ===== Scroll mode ===== */
.flexa-scroll-container {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 16px 0;
	scroll-snap-type: y proximity;
}
.flexa-scroll-container.flexa-mirror { direction: rtl; }
.flexa-scroll-page {
	max-width: 900px;
	margin: 0 auto 16px;
	scroll-snap-align: start;
	background: #fff;
	box-shadow: 0 4px 18px rgba(0, 0, 0, .25);
}
.flexa-scroll-page .flexa-page-inner { position: relative; }

/* ===== Seek bar ===== */
.flexa-seek-row {
	padding: 4px 14px 8px;
	background: var(--flexa-toolbar-bg);
}
.flexa-seek-row input[type="range"] { width: 100%; }

/* ===== Side panels ===== */
.flexa-side-panel {
	position: absolute;
	top: 52px;
	bottom: 0;
	width: min(320px, 86vw);
	background: var(--flexa-panel-bg);
	color: var(--flexa-panel-fg);
	border-inline-end: 1px solid var(--flexa-panel-border);
	overflow-y: auto;
	padding: 14px;
	z-index: 4;
	inset-inline-start: 0;
	box-shadow: 6px 0 24px rgba(0, 0, 0, .25);
}
body.flexa-rtl .flexa-side-panel { border-inline-end: 0; border-inline-start: 1px solid var(--flexa-panel-border); }

.flexa-thumb-list {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 10px;
}
.flexa-thumb {
	width: 100%;
	aspect-ratio: 3 / 4;
	border-radius: 4px;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
	transition: transform .12s ease;
	background: #e9e9e9;
	object-fit: cover;
}
.flexa-thumb:hover { transform: translateY(-2px); }
.flexa-thumb.flexa-thumb-pending {
	background: repeating-linear-gradient(
		135deg,
		#f2f2f2, #f2f2f2 8px,
		#e9e9e9 8px, #e9e9e9 16px
	);
}

.flexa-toc-list { display: flex; flex-direction: column; gap: 2px; }
.flexa-toc-item {
	text-align: start;
	background: transparent;
	border: 0;
	color: inherit;
	padding: 9px 6px;
	border-radius: 6px;
	font-size: 14px;
	cursor: pointer;
}
.flexa-toc-item:hover { background: rgba(127, 127, 127, .14); }

.flexa-search-input {
	width: 100%;
	padding: 9px 10px;
	border-radius: 6px;
	border: 1px solid var(--flexa-panel-border);
	background: rgba(127, 127, 127, .08);
	color: inherit;
	font-size: 14px;
	margin-bottom: 12px;
}
.flexa-search-result {
	display: block;
	width: 100%;
	text-align: start;
	background: transparent;
	border: 0;
	border-bottom: 1px solid var(--flexa-panel-border);
	color: inherit;
	padding: 10px 4px;
	cursor: pointer;
}
.flexa-search-result:hover { background: rgba(127, 127, 127, .1); }
.flexa-search-result strong { display: block; font-size: 12px; color: var(--flexa-accent); margin-bottom: 2px; }
.flexa-search-result span { display: block; font-size: 13px; opacity: .85; line-height: 1.4; }

.flexa-share-input {
	width: 100%;
	padding: 9px 10px;
	border-radius: 6px;
	border: 1px solid var(--flexa-panel-border);
	background: rgba(127, 127, 127, .08);
	color: inherit;
	font-size: 13px;
	margin-bottom: 10px;
}
.flexa-share-qr { margin-top: 16px; text-align: center; }
.flexa-share-qr canvas { max-width: 100%; border-radius: 6px; background: #fff; padding: 8px; }
.flexa-hint { font-size: 12px; opacity: .7; margin: 6px 0 0; }

/* ===== Mail-app picker popover ===== */
.flexa-mail-picker {
	position: fixed;
	z-index: 30;
	background: var(--flexa-panel-bg);
	color: var(--flexa-panel-fg);
	border: 1px solid var(--flexa-panel-border);
	border-radius: 8px;
	padding: 6px;
	min-width: 190px;
	box-shadow: 0 14px 36px rgba(0, 0, 0, .4);
}
.flexa-mail-picker-title { font-size: 11px; opacity: .65; padding: 4px 8px; }
.flexa-mail-picker button {
	display: block;
	width: 100%;
	text-align: start;
	padding: 8px;
	background: transparent;
	border: 0;
	border-radius: 6px;
	color: inherit;
	font-size: 13px;
	cursor: pointer;
}
.flexa-mail-picker button:hover { background: rgba(127, 127, 127, .16); }

/* ===== Credit line ===== */
.flexa-credit {
	position: absolute;
	bottom: 6px;
	inset-inline-end: 10px;
	font-size: 11px;
	color: rgba(255, 255, 255, .55);
	pointer-events: none;
	z-index: 3;
}
body.flexa-theme-light .flexa-credit { color: rgba(0, 0, 0, .45); }

/* ===== Responsive ===== */
@media ( max-width: 640px ) {
	.flexa-toolbar {
		flex-wrap: nowrap;
		overflow-x: auto;
		justify-content: flex-start;
		-webkit-overflow-scrolling: touch;
	}
	.flexa-tb-center { order: 3; flex-basis: 100%; justify-content: flex-start; }
	.flexa-page-indicator { font-size: 11px; }
	.flexa-title { max-width: 120px; }
	.flexa-side-panel { width: 100%; border: 0; }
}
