html,
body {
    margin: 0;
    padding: 0;
    height: 100vh;
    font-family: Arial, sans-serif;
    background: #222;
    overflow: hidden;
}

/* Reduced height and zero padding to eliminate top toolbar bulk */
#toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    height: 44px; 
    background: #222;
    color: white;
    box-sizing: border-box;
    flex-wrap: nowrap;
    position: relative; 
}

/* Unified clean white background with black text for ALL top buttons and links */
#mainMenuBtn,
#toolbar button {
    flex: 0 0 auto;
    height: 30px; 
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px !important;
    font-size: 13px;
    font-weight: bold;
    background: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #ffffff !important;
    border-radius: 2px;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
}

#mainMenuBtn:hover,
#toolbar button:hover {
    background: #e5e5e5 !important;
    border-color: #e5e5e5 !important;
}

/* Mathematical absolute center layout for the Title */
.toolbar-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    display: flex;
    align-items: center;
}

.toolbar-right-spacer {
    margin-left: auto;
}

#dynamicTitle {
    font-size: 20px; 
    font-weight: 800;         
    letter-spacing: 1px;      
    color: #ffffff;           
    white-space: nowrap;
    pointer-events: auto;     
}

#searchInput {
    width: 200px; 
    height: 30px; 
    padding: 0 10px;
    font-size: 14px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 2px;
}

/* Dynamic layout calculation based exactly on top and bottom panel sizes */
#mainLayout {
    display: flex;
    height: calc(100vh - 44px - 65px);
    box-sizing: border-box;
}

#results {
    flex: 1;
    overflow-y: auto;
}

#bookContainer {
    background: #222;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 10px; 
    box-sizing: border-box;
}

#flipbook {
    width: 100%;
    height: 100%;
    max-width: 1000px;
    max-height: 1400px;
}

.resultItem {
    padding: 12px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
}

.resultItem:hover {
    background: #f5f5f5;
}

.resultItem strong {
    display: block;
    margin-bottom: 5px;
    color: #003366;
}

.page {
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

.page img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: fill;
}

.highlight {
    position: absolute;
    border: 2px solid red;
    background: rgba(255,0,0,0.15);
    pointer-events: none;
}

/* FIXED BOTTOM PANEL: Wrapper column layout structure */
#bottomToolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 65px;
    background: #222;
    color: white;
    display: flex;
    flex-direction: column; 
    align-items: center;
    justify-content: center;
    padding: 0 6px !important;
    box-sizing: border-box;
}

/* NEW RULE: Forces all navigation buttons/inputs to sit cleanly horizontally inside a row */
.pagination-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

/* Style for all the bottom navigation buttons */
#bottomToolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    height: 28px;
    cursor: pointer;
    background: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #ffffff !important;
    border-radius: 2px;
    font-weight: bold;
    font-size: 14px;
}

#bottomToolbar button:hover {
    background: #e5e5e5 !important;
    border-color: #e5e5e5 !important;
}

#pageInput {
    width: 50px;
    height: 28px;
    padding: 0 5px;
    text-align: center;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 2px;
}

#pageLabel {
    font-size: 14px;
    color: #fff;
    line-height: 28px;
}

#toggleSidebar {
    display: flex;
    align-items: center;
    gap: 6px;
}

#sidebar {
    width: 320px;
    background: #fff;
    border-right: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease, opacity 0.2s ease;
}

#sidebar.closed {
    width: 0;
    opacity: 0;
}

.stf__parent {
    margin: 0 auto !important;
}

.stf__wrapper {
    margin: 0 auto !important;
}

#bookContainer {
    position: relative;
}

#flipbook {
    position: relative;
}

.ocrLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.ocrRect {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid transparent; 
    background: transparent;       
    color: transparent;            
    user-select: text;
    pointer-events: auto;          
}

.ocrRect:hover {
    background: rgba(0, 123, 255, 0.08);
}

.ocrRect.search-match {
    background: rgba(255, 255, 0, 0.4) !important;
    border: 1px solid #e6b800 !important;
}

/* ==========================================================================
   OPEN SPREAD BOOK MODAL VIEW STYLES
   ========================================================================== */
#ocrModal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none;
    z-index: 9999;
}
#ocrModal.hidden {
    display: none;
}

#ocrModalContent {
    pointer-events: auto;
    position: absolute;
    background: #1e1e1e; 
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

#modalToolbar {
    background: #2a2a2a;
    color: white;
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    box-sizing: border-box;
    border-bottom: 1px solid #3a3a3a;
}
#modalToolbar button {
    height: 28px;
    padding: 0 10px;
    cursor: pointer;
    background: #ffffff; 
    border: 1px solid #ffffff;
    color: #000000;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
}
#modalToolbar button:hover {
    background: #e5e5e5;
    border-color: #e5e5e5;
}
#modalPageLabel {
    font-size: 13px;
    font-weight: bold;
    margin-left: 10px;
    margin-right: 10px;
}
#closeOcrModal {
    margin-left: auto; 
    background: #c62828 !important;
    border: 1px solid #b71c1c !important;
    color: #ffffff !important;
    font-weight: bold;
}
#closeOcrModal:hover {
    background: #d32f2f !important;
}

#modalBookSpread {
    flex: 1;
    display: flex;
    width: 100%;
    overflow: hidden;
    background: #222;
    gap: 4px; 
}

.modalPagePanel {
    flex: 1;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modalPanelHeader {
    background: #f5f5f5;
    color: #555;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
    padding: 6px 16px;
    border-bottom: 1px solid #e0e0e0;
}

.modalTextBody {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    font-size: 20px; 
    line-height: 1.7; 
    color: #222;
    white-space: pre-wrap;
    text-align: justify;
}

/* Row 2: Copyright stays stacked cleanly underneath the row wrapper container */
#toolbarCopyright {
    font-size: 11px;
    color: #aaa;              
    letter-spacing: 0.5px;
    text-align: center;
    width: 100%;
    display: block;
    margin-top: 6px; 
    pointer-events: none;
}