/*
 * Digital ePaper Manager — reader.
 * Themes can restyle by overriding the custom properties on .depm-reader.
 */

.depm-reader,
.depm-clip-view,
.depm-dialog {
	--depm-accent: #0f6b5c;
	--depm-accent-ink: #ffffff;
	--depm-ink: #1c232b;
	--depm-muted: #5b6672;
	--depm-surface: #ffffff;
	--depm-desk: #e9ecef;
	--depm-line: #d5dbe1;
	--depm-radius: 10px;
	--depm-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 18px rgba(16, 24, 40, 0.08);
	--depm-rail-w: 132px;
	--depm-viewer-h: calc(100vh - 170px);
	color: var(--depm-ink);
}

.depm-main {
	max-width: 1400px;
	margin: 0 auto;
	padding: 16px;
	box-sizing: border-box;
}

.depm-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.depm-reader {
	position: relative;
	background: var(--depm-desk);
	border-radius: var(--depm-radius);
	padding: 12px;
	box-sizing: border-box;
}

.depm-reader *,
.depm-reader *::before,
.depm-reader *::after {
	box-sizing: border-box;
}

.depm-reader:fullscreen {
	--depm-viewer-h: calc(100vh - 120px);
	border-radius: 0;
	overflow: auto;
}

/* Header */
.depm-reader__head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 4px 16px;
	padding: 2px 4px 10px;
}

.depm-reader__title {
	margin: 0;
	font-size: clamp(1.15rem, 1rem + 0.8vw, 1.6rem);
	line-height: 1.25;
}

.depm-reader__date {
	margin: 0;
	color: var(--depm-muted);
	font-size: 0.95rem;
}

.depm-reader__empty {
	background: var(--depm-surface);
	padding: 32px;
	border-radius: var(--depm-radius);
	text-align: center;
}

/* Toolbar */
.depm-toolbar {
	position: sticky;
	top: 0;
	z-index: 5;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 8px;
	margin-bottom: 10px;
	background: var(--depm-surface);
	border-radius: var(--depm-radius);
	box-shadow: var(--depm-shadow);
}

.admin-bar .depm-toolbar {
	top: 32px;
}

.depm-toolbar__group {
	display: flex;
	align-items: center;
	gap: 6px;
}

.depm-toolbar__group[hidden] {
	display: none;
}

.depm-jump {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
}

.depm-page-select {
	min-width: 118px;
	height: 38px;
	padding: 0 32px 0 12px;
	border: 1px solid var(--depm-line);
	border-radius: 8px;
	background-color: var(--depm-surface);
	color: var(--depm-ink);
	font-size: 0.95rem;
	font-weight: 600;
}

.depm-toolbar__count {
	color: var(--depm-muted);
	font-size: 0.9rem;
	white-space: nowrap;
}

.depm-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-width: 38px;
	height: 38px;
	padding: 0 12px;
	border: 1px solid var(--depm-line);
	border-radius: 8px;
	background: var(--depm-surface);
	color: var(--depm-ink);
	font: inherit;
	font-size: 0.92rem;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.depm-btn:hover,
.depm-btn:focus-visible {
	border-color: var(--depm-accent);
	color: var(--depm-ink);
}

.depm-btn:focus-visible,
.depm-thumb:focus-visible,
.depm-stage:focus-visible,
.depm-page-select:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--depm-accent) 45%, transparent);
	outline-offset: 2px;
}

.depm-btn[aria-disabled="true"] {
	opacity: 0.4;
	pointer-events: none;
}

.depm-btn--accent,
.depm-btn[aria-pressed="true"] {
	background: var(--depm-accent);
	border-color: var(--depm-accent);
	color: var(--depm-accent-ink);
}

.depm-btn--accent:hover,
.depm-btn--accent:focus-visible {
	color: var(--depm-accent-ink);
	filter: brightness(1.08);
}

.depm-btn--text {
	font-weight: 600;
}

.depm-btn[hidden] {
	display: none;
}

.depm-zoom-level {
	min-width: 48px;
	text-align: center;
	font-variant-numeric: tabular-nums;
	font-size: 0.9rem;
	color: var(--depm-muted);
}

/* Dropdown menus (native <details>) */
.depm-menu {
	position: relative;
}

.depm-menu[hidden] {
	display: none;
}

.depm-menu > summary {
	list-style: none;
}

.depm-menu > summary::-webkit-details-marker {
	display: none;
}

.depm-menu__panel {
	position: absolute;
	right: 0;
	top: calc(100% + 6px);
	z-index: 20;
	min-width: 200px;
	padding: 6px;
	background: var(--depm-surface);
	border: 1px solid var(--depm-line);
	border-radius: var(--depm-radius);
	box-shadow: var(--depm-shadow);
}

.depm-menu__item {
	display: block;
	width: 100%;
	padding: 9px 10px;
	border: 0;
	border-radius: 6px;
	background: none;
	color: var(--depm-ink);
	font: inherit;
	font-size: 0.92rem;
	text-align: left;
	text-decoration: none;
	cursor: pointer;
}

.depm-menu__item:hover,
.depm-menu__item:focus-visible {
	background: var(--depm-desk);
	color: var(--depm-ink);
}

/* Share list */
.depm-share {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 4px;
}

.depm-share li {
	margin: 0;
}

.depm-share__link {
	display: block;
	width: 100%;
	padding: 9px 10px 9px 30px;
	position: relative;
	border: 0;
	border-radius: 6px;
	background: none;
	color: var(--depm-ink);
	font: inherit;
	font-size: 0.92rem;
	text-align: left;
	text-decoration: none;
	cursor: pointer;
}

.depm-share__link::before {
	content: "";
	position: absolute;
	left: 10px;
	top: 50%;
	width: 10px;
	height: 10px;
	margin-top: -5px;
	border-radius: 50%;
	background: var(--depm-muted);
}

.depm-share__link--facebook::before { background: #3b5fa8; }
.depm-share__link--whatsapp::before { background: #2f9e57; }
.depm-share__link--x::before { background: #20262d; }
.depm-share__link--copy::before { background: var(--depm-accent); border-radius: 2px; }

.depm-share__link:hover,
.depm-share__link:focus-visible {
	background: var(--depm-desk);
	color: var(--depm-ink);
}

.depm-share__link.is-done::after {
	content: " ✓";
	color: var(--depm-accent);
}

/* In-edition find */
.depm-find {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0 0 10px;
}

.depm-find[hidden] {
	display: none;
}

.depm-find__input {
	flex: 1 1 220px;
	height: 38px;
	padding: 0 12px;
	border: 1px solid var(--depm-line);
	border-radius: 8px;
	font: inherit;
}

.depm-find__results {
	flex-basis: 100%;
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 4px;
	max-height: 220px;
	overflow: auto;
}

.depm-find__results:empty {
	display: none;
}

.depm-find__hit {
	display: flex;
	gap: 10px;
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--depm-line);
	border-radius: 8px;
	background: var(--depm-surface);
	font: inherit;
	font-size: 0.9rem;
	text-align: left;
	cursor: pointer;
}

.depm-find__hit span {
	color: var(--depm-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Body: rail + stage */
.depm-reader__body {
	display: grid;
	grid-template-columns: var(--depm-rail-w) minmax(0, 1fr);
	gap: 12px;
}

.depm-rail {
	max-height: var(--depm-viewer-h);
	overflow: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	padding: 2px;
}

.depm-rail__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 10px;
}

.depm-rail__list li {
	margin: 0;
}

.depm-thumb {
	display: block;
	padding: 5px;
	border: 2px solid transparent;
	border-radius: 8px;
	background: var(--depm-surface);
	color: var(--depm-muted);
	text-align: center;
	text-decoration: none;
	transition: border-color 0.15s ease;
}

.depm-thumb:hover {
	border-color: var(--depm-line);
}

.depm-thumb.is-active {
	border-color: var(--depm-accent);
	color: var(--depm-accent);
}

.depm-thumb__img {
	display: block;
	background: var(--depm-desk);
	border-radius: 4px;
	overflow: hidden;
}

.depm-thumb__img img {
	display: block;
	width: 100%;
	height: auto;
}

.depm-thumb__num {
	display: block;
	padding-top: 4px;
	font-size: 0.8rem;
	font-weight: 600;
}

.depm-stage {
	position: relative;
	max-height: var(--depm-viewer-h);
	overflow: auto;
	overscroll-behavior: contain;
	background: var(--depm-surface);
	border-radius: var(--depm-radius);
	box-shadow: var(--depm-shadow);
	touch-action: pan-x pan-y pinch-zoom;
}

.depm-stage.is-zoomed {
	cursor: grab;
}

.depm-stage.is-dragging {
	cursor: grabbing;
	user-select: none;
}

/* Zoom = frame width in % of the stage; the overflow makes the stage scroll. */
.depm-stage__inner {
	width: 100%;
}

.depm-stage__frame {
	position: relative;
	width: 100%;
}

.depm-stage__img {
	display: block;
	width: 100%;
	height: auto;
	transition: opacity 0.15s ease;
}

.depm-reader.is-loading .depm-stage__img {
	opacity: 0.55;
}

/* Clip tool */
.depm-clip-canvas {
	position: absolute;
	inset: 0;
	cursor: crosshair;
	touch-action: none;
}

.depm-clip-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	margin: 0 0 10px;
	background: #fff8e6;
	border: 1px solid #f0d58c;
	border-radius: var(--depm-radius);
}

.depm-clip-bar__hint {
	flex: 1 1 200px;
	font-size: 0.92rem;
}

.depm-reader.is-locked .depm-rail {
	opacity: 0.5;
	pointer-events: none;
}

/* Clip result dialog */
.depm-dialog {
	width: min(560px, calc(100vw - 32px));
	max-height: calc(100vh - 48px);
	padding: 0;
	border: 0;
	border-radius: 14px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
	background: var(--depm-surface);
}

.depm-dialog:not(dialog) {
	position: fixed;
	z-index: 100000;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	overflow: auto;
}

.depm-dialog::backdrop {
	background: rgba(15, 23, 32, 0.6);
}

.depm-dialog__inner {
	position: relative;
	padding: 22px;
}

.depm-dialog__title {
	margin: 0 0 12px;
	font-size: 1.2rem;
}

.depm-dialog__preview {
	background: var(--depm-desk);
	border-radius: 8px;
	padding: 8px;
	text-align: center;
}

.depm-dialog__preview img {
	max-width: 100%;
	max-height: 50vh;
	height: auto;
}

.depm-dialog__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 14px 0 10px;
}

.depm-dialog .depm-share {
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.depm-dialog__close {
	position: absolute;
	top: 10px;
	right: 12px;
	width: 34px;
	height: 34px;
	border: 0;
	border-radius: 50%;
	background: var(--depm-desk);
	color: var(--depm-ink);
	font-size: 1.3rem;
	line-height: 1;
	cursor: pointer;
}

/* Clip permalink page */
.depm-clip-view {
	max-width: 900px;
	margin: 0 auto;
}

.depm-clip-view__figure {
	margin: 0 0 16px;
	padding: 12px;
	background: var(--depm-desk);
	border-radius: var(--depm-radius);
	text-align: center;
}

.depm-clip-view__figure img {
	max-width: 100%;
	height: auto;
	box-shadow: var(--depm-shadow);
}

.depm-clip-view__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 16px;
}

.depm-clip-view .depm-share {
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.depm-edition-summary,
.depm-back-link {
	margin-top: 16px;
}

/* Small screens: rail becomes a horizontal strip under the page */
@media (max-width: 782px) {
	.depm-reader {
		--depm-viewer-h: 72vh;
		padding: 8px;
		border-radius: 0;
	}

	.admin-bar .depm-toolbar {
		top: 0;
	}

	.depm-reader__body {
		grid-template-columns: minmax(0, 1fr);
	}

	.depm-rail {
		order: 2;
		max-height: none;
		overflow-x: auto;
		overflow-y: hidden;
	}

	.depm-rail__list {
		grid-auto-flow: column;
		grid-auto-columns: 72px;
	}

	.depm-toolbar {
		justify-content: center;
	}

	.depm-toolbar__zoom {
		display: none !important;
	}

	.depm-menu__panel {
		right: auto;
		left: 50%;
		transform: translateX(-50%);
	}
}

@media (prefers-reduced-motion: reduce) {
	.depm-reader *,
	.depm-dialog * {
		transition: none !important;
	}
}

/* Printing */
.depm-print-area {
	display: none;
}

@media print {
	body.depm-printing > *:not(.depm-print-area) {
		display: none !important;
	}

	body.depm-printing .depm-print-area {
		display: block;
	}

	.depm-print-area img {
		display: block;
		width: 100%;
		height: auto;
		page-break-after: always;
		break-after: page;
	}

	.depm-print-area img:last-child {
		page-break-after: auto;
		break-after: auto;
	}
}
