/*
   Copyright (C) 2010-2025 Université de Lausanne, RISET
   <https://www.unil.ch/riset/>

   This file is part of Lumières.Lausanne.
   Lumières.Lausanne is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Lumières.Lausanne is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.

   This copyright notice MUST APPEAR in all copies of the file.
*/

/* Transcription title styling */
h2.transcription {
	margin-bottom: 0px;
}

/* Layout toggle button bar */
.layout-toggle-group {
	display: flex;
	gap: 0;
	align-items: center;
	padding: 8px 12px;
	border-radius: 4px;
	border: 1px solid #ddd;
	margin-bottom: 15px;
	position: relative;
}

/* Mode buttons (no gaps, separated by light border) */
.layout-btn {
	flex: 0 0 auto;
	padding: 6px 12px;
	background-color: #f5f5f5;
	border: 1px solid #ddd;
	border-radius: 0;
	cursor: pointer;
	font-size: 14px;
	transition: all 0.2s ease;
}

.layout-btn:first-child {
	border-radius: 3px 0 0 3px;
}

.layout-btn:nth-child(3) {
	border-radius: 0;
}

/* Options button styling */
.options-btn {
	margin-left: auto;
	border-radius: 0 3px 3px 0;
	display: flex;
	align-items: center;
	gap: 6px;
}

.dropdown-arrow {
	font-size: 10px;
	transition: transform 0.2s ease;
}

.options-btn.active .dropdown-arrow {
	transform: rotate(180deg);
}

/* Options dropdown menu */
.options-menu-wrapper {
	position: relative;
	display: inline-block;
}

.options-dropdown {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	right: auto;
	background-color: white;
	border: 1px solid #ddd;
	border-radius: 4px;
	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
	z-index: 1000;
	min-width: 220px;
	display: none;
	margin-top: 4px;
}

.options-dropdown.show {
	display: block;
}

.option-item {
	display: flex;
	align-items: center;
	padding: 8px 12px;
	cursor: pointer;
	user-select: none;
	border-bottom: 1px solid #f0f0f0;
}

.option-item:last-child {
	border-bottom: none;
}

.option-item:hover {
	background-color: #f9f9f9;
}

.option-item input[type="checkbox"] {
	margin-right: 8px;
	cursor: pointer;
	width: 16px;
	height: 16px;
	appearance: none;
	-webkit-appearance: none;
	-moz-appearance: none;
	background-color: #fff;
	border: 2px solid #ddd;
	border-radius: 3px;
	position: relative;
	transition: all 0.2s ease;
}

.option-item input[type="checkbox"]:hover {
	border-color: #f0750b;
}

.option-item input[type="checkbox"]:checked {
	background-color: #f0750b;
	border-color: #f0750b;
}

.option-item input[type="checkbox"]:checked::after {
	content: '';
	position: absolute;
	left: 3px;
	top: 0px;
	width: 4px;
	height: 8px;
	border: solid white;
	border-width: 0 2px 2px 0;
	transform: rotate(45deg);
}

.option-item span {
	flex: 1;
}

/* Active button state */
.layout-btn.active {
	background-color: #e8e8e8;
	font-weight: 600;
	border-color: #999;
}

.layout-btn:hover:not(.active) {
	background-color: #fafafa;
}

/* Two-column layout: transcription on left, viewer on right */
.transcription-viewer-container {
	display: flex;
	gap: 20px;
	width: 100%;
	position: relative;
	z-index: 1;
}

.transcription-content {
	flex: 1;
	min-width: 0;
	/* Allow flex item to shrink below content size */
}

.transcription-content #transcription-view-controls {
	margin-bottom: 12px;
}

.transcription-content #transcription-data {
	max-height: 655px;
	overflow-y: auto;
	overflow-x: hidden;
}

.viewer-panel {
	width: 450px;
	flex-shrink: 0;
	position: sticky;
	top: 20px;
	height: fit-content;
	max-height: calc(100vh - 40px);
	z-index: 10;
	/* Hide by default to prevent flicker on page load (issue #98) */
	/* JavaScript will set data-layout-mode which overrides this */
	display: none;
}

#openseadragon-viewer {
	width: 100%;
	height: 600px;
	background-color: #000;
	border: 1px solid #ccc;
	position: relative;
	/* allows overlay elements like marker toast */
}

.content .transcription-data {
	padding: 0 20px;
}

/* Table of contents styling - Fixed position on right side */
#transcription-toc {
	position: fixed !important;
	top: 250px !important;
	right: 50px !important;
	bottom: auto !important;
	left: auto !important;
	background: #c4c5b4 !important;
	width: 200px !important;
	padding: 15px !important;
	font-size: 11px !important;
	max-height: calc(100% - 250px - 150px) !important;
	overflow-y: auto !important;
	z-index: 9999 !important;
	box-shadow: 0 3px 10px grey !important;
	display: block !important;
	visibility: visible !important;
	margin: 0 !important;
}

#transcription-toc .title {
	font-weight: bold;
	margin-bottom: 5px;
}

#transcription-toc li {
	list-style: disc inside;
	margin: 0 !important;
	padding: 2px 0 !important;
}

#transcription-toc .toclevel2 {
	padding-left: 10px !important;
}

#transcription-toc a {
	color: #0066cc !important;
	text-decoration: none !important;
}

#transcription-toc a:hover {
	color: #0052a3 !important;
	text-decoration: underline !important;
}

/* Prevent cite_as from overlapping viewer */
.field_group.cite_as {
	position: static !important;
	margin-top: 20px;
}

/* Responsive: stack on smaller screens */
@media (max-width: 1200px) {
	.transcription-viewer-container {
		flex-direction: column;
	}

	.viewer-panel {
		width: 100%;
		position: static;
		max-height: none;
	}

	.transcription-content #transcription-data {
		max-height: none;
	}
}

/* Layout mode styles - match toolbar button style */
.layout-toggle-group {
	display: flex;
	gap: 3px;
	margin-bottom: 10px;
	justify-content: center;
}

.layout-btn {
	/* Match tb_but_text style from main toolbar */
	font-size: 84.651%;
	line-height: 17px;
	padding: 4px 8px;
	margin: 4px 3px 0;
	background-color: #DEDEDE;
	border: 1px solid #98958E;
	border-radius: 2px;
	color: #6C6C6C;
	cursor: pointer;
	text-decoration: none;
	display: inline-block;
	transition: all 0.2s ease;
}

.layout-btn:hover {
	color: #222;
	background-color: #F9F8F4;
	border-color: #776C4E;
}

.layout-btn.active {
	background-color: #776C4E;
	color: #fff;
	border-color: #776C4E;
}

.layout-btn.active:hover {
	background-color: #6A5F42;
	border-color: #6A5F42;
}

/* Split-view mode (default) - show viewer panel */
body[data-layout-mode="split-view"] .viewer-panel {
	display: block;
}

/* Text-only mode */
body[data-layout-mode="text-only"] .viewer-panel {
	display: none;
}

body[data-layout-mode="text-only"] .transcription-content {
	max-width: 100%;
	display: block;
}

body[data-layout-mode="text-only"] .transcription-viewer-container {
	display: block;
}

body[data-layout-mode="text-only"] #transcription-view-controls {
	margin-bottom: 12px;
}

/* Hide notes position toggle button by default, show only in text-only mode */
#notes-position-toggle {
	display: none !important;
}

body[data-layout-mode="text-only"] #notes-position-toggle {
	display: inline-block !important;
}

/* Align transcription utility buttons sizing with layout buttons */
#transcription-view-controls a.ui-button {
	padding: 6px 12px;
	font-size: 12px;
}

/* Extra guard class applied via JS to handle jQuery UI inline styles */
#notes-position-toggle.notes-toggle-hidden {
	display: none !important;
	visibility: hidden !important;
}

/* Show side notes based on notes position preference, not layout mode */
body[data-notes-position="margin"] .transcription-content-wrapper {
	display: flex;
	flex-direction: row;
	align-items: flex-start;
	gap: 0;
	position: relative;
}

body[data-notes-position="margin"] #transcription-data {
	flex: 1;
	min-width: 0;
	max-width: calc(100% - 340px);
}

body[data-layout-mode="text-only"][data-notes-position="margin"] #transcription-data {
	max-height: none;
	overflow-y: visible;
}

/* Side notes panel when notes position is set to margin */
body[data-notes-position="margin"] .side-notes-panel {
	display: block !important;
	width: 300px;
	flex-shrink: 0;
	padding-left: 20px;
	margin-left: 20px;
	border-left: 1px solid #ccc;
	position: relative;
}

body[data-notes-position="margin"] .side-note {
	position: absolute;
	left: 20px;
	right: 0;
	margin-bottom: 0;
}

body[data-notes-position="margin"] .transcription-doc-notes,
body[data-notes-position="margin"] .transcription-ed-notes {
	display: none !important;
}

/* Bottom notes when notes position is set to bottom */
body[data-notes-position="bottom"] .side-notes-panel {
	display: none !important;
}

/* Viewer-only mode */
body[data-layout-mode="viewer-only"] .viewer-panel {
	display: block;
	position: static;
	width: 800px;
	max-width: 90%;
	max-height: none;
	height: auto;
}

body[data-layout-mode="viewer-only"] .transcription-content {
	display: none;
}

body[data-layout-mode="viewer-only"] .transcription-viewer-container {
	justify-content: center;
}

body[data-layout-mode="viewer-only"] #openseadragon-viewer {
	height: 800px;
}

/* Hide Repere indicator in viewer-only (facsimile) mode */
body[data-layout-mode="viewer-only"] .marker-indicator {
	display: none;
}

/* Line breaks hidden by default to prevent flash (issue #101).
   They become visible only when body has .linebreaks-visible. */
div.transcription-data br:not(.verse br) {
	display: none;
}
div.transcription-data .brsep {
	display: none;
}
body.linebreaks-visible div.transcription-data br:not(.verse br) {
	display: inline;
}
body.linebreaks-visible div.transcription-data .brsep {
	display: inline;
}

/* Side notes styling */
.side-notes-panel {
	display: none;
	font-size: 0.9em;
}

.side-notes-panel .side-note {
	margin-bottom: 15px;
	padding: 8px;
	background: #f9f9f9;
	border-left: 3px solid #ccc;
	font-size: 0.95em;
	line-height: 1.4;
}

body[data-layout-mode="text-only"] .side-notes-panel .side-note {
	margin-bottom: 0;
}

.side-notes-panel .side-note.note-editorial {
	border-left-color: #f0750b;
}

.side-notes-panel .side-note.note-document {
	border-left-color: #555;
}

/* Disable CSS counter for side notes - they use JS-generated numbers */
.side-notes-panel .side-note.note-document:before,
.side-notes-panel .side-note.note-editorial:before {
	content: none !important;
}

.side-notes-panel .side-note .note-number {
	font-weight: bold;
	margin-right: 5px;
}

.page-tag {
	color: #111;
	/* keep markers readable but aligned with normal text color */
	font-weight: bold;
}

.side-notes-panel .note-back-link {
	font-size: 0.85em;
	margin-left: 5px;
}

.side-notes-panel .notes-title {
	font-weight: bold;
	margin-bottom: 10px;
	padding-bottom: 5px;
	border-bottom: 2px solid #333;
}

/* Highlight note references in text */
a.note-ref-link {
	text-decoration: none;
}

a.note-ref-link:hover {
	background-color: #ffffcc;
}

/* ========================================================================
   PHASE 3: Conditional Logic - Mode Availability States
   ======================================================================== */

/* When no facsimile: disable facsimile-related buttons */
#layout-toggle-buttons[data-has-facsimile="false"] .layout-btn[data-layout="split-view"],
#layout-toggle-buttons[data-has-facsimile="false"] .layout-btn[data-layout="viewer-only"] {
	opacity: 0.5;
	cursor: not-allowed;
	background-color: #f0f0f0;
	color: #999;
	pointer-events: none;
}

/* Disabled state styling (for button[disabled] attribute) */
.layout-btn:disabled,
.layout-btn[disabled] {
	opacity: 0.5;
	cursor: not-allowed;
	background-color: #f0f0f0;
	color: #999;
	pointer-events: none;
}

.layout-btn:disabled:hover,
.layout-btn[disabled]:hover {
	background-color: #f0f0f0;
}
