/* ===== BASE STYLES ===== */
body {
    background-color: var(--background-color);
    width: 100vw;
    height: 100vh;
    box-sizing: border-box;
}

/* ===== TOOLBAR SYSTEM ===== */
.toolbar-trigger {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    max-width: 750px;
    height: 77px;
    z-index: 999;
    background: transparent;
    cursor: pointer;
    left: 50%;
    transform: translateX(-50%);
}

.toolbar {
    width: 100%;
    max-width: 600px;
    height: auto;
    margin: var(--spacing-lg) auto;
    padding: var(--spacing-xs) var(--spacing-sm);
    text-align: center;
    position: fixed;
    top: -80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(10px);
    background-color: var(--toolbar-bg);
    border: 1px solid var(--toolbar-border);
    border-radius: var(--radius-xl);
    box-shadow: 0 2px 4px rgba(0 0 0 / 30%);
    box-sizing: border-box;
    overflow: hidden;
    transition: top 0.3s ease-out;
    z-index: var(--z-toolbar);
}

.toolbar:hover,
.toolbar-trigger:hover + .toolbar {
    top: 0;
    transition-delay: 0s;
}

/* Keep the toolbar visible when input is focused */
.toolbar:has(.current-page:focus) {
    top: 0 !important;
}

/* Add delay before hiding the toolbar again */
.toolbar-trigger:not(:hover) + .toolbar:not(:hover, :has(.current-page:focus)) {
    transition-delay: 1.5s;
}

/* Initial visibility class for showing toolbar on load */
.toolbar-initial-visible {
    top: 0;
}

/* Toolbar button styles */
.toolbar-btn {
    background: none;
    border: none;
    padding: var(--spacing-xs);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.toolbar-btn:hover {
    background-color: var(--toolbar-hover);
}

.toolbar-btn:active {
    background-color: var(--toolbar-border);
}

/* Disabled toolbar button state */
.toolbar-btn:disabled {
    cursor: none;
    opacity: 0.5;
    pointer-events: none;
}

/* Toolbar icon styles */
.toolbar-icon {
    width: 24px;
    height: 24px;
    opacity: 0.7;
}

.toolbar-btn:hover .toolbar-icon {
    opacity: 1;
}

/* ===== ZOOM FEATURE ===== */
.zoom-display {
    position: fixed;
    width: 450px;
    height: 300px;
    background: var(--background-color);
    border: 2px solid var(--primary-accent);
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 24px rgba(0 0 0 / 40%);
    z-index: var(--z-zoom);
    display: none;
    overflow: hidden;
    box-sizing: border-box;

    /* Add smooth transition */
    transition: all 0.25s ease-out !important;
    
    /* Ensure it doesn't interfere with mouse events */
    pointer-events: none;
}

.zoom-canvas {
    width: 100%;
    height: 100%;
    display: block;
    
    /* Ensure crisp pixel rendering */
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.zoom-viewbox {
    position: absolute;
    border: 2px solid var(--primary-accent);
    background: var(--primary-accent-light);
    pointer-events: none;
    z-index: var(--z-toolbar);
    display: none;
    transition: none; /* positioning handled via JS */
    box-sizing: border-box;
}

/* Zoom active state for book-layout */
.book-layout.zoom-active {
    cursor: crosshair;
}

.book-layout.zoom-active .pdf-page {
    cursor: crosshair;
}

/* Zoom button active state */
.toolbar-btn.zoom-active {
    background-color: var(--primary-accent);
    color: var(--text-on-light);
}

.toolbar-btn.zoom-active .toolbar-icon {
    filter: invert(1);
    opacity: 1;
}

/* ===== PAGE INDICATOR ===== */
.page-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
    color: #555;
    white-space: nowrap;
    padding: var(--spacing-xs);
}

.current-page {
    width: 40px;
    padding: var(--spacing-xs) 6px;
    backdrop-filter: blur(10px);
    background-color: transparent;
    border: 1px solid #ccc;
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
}

.current-page:focus {
    outline: none;
    border-color: var(--primary-accent);
    box-shadow: 0 0 0 2px var(--primary-accent-light);
}

/* Hide number input spinner arrows */
.current-page::-webkit-outer-spin-button,
.current-page::-webkit-inner-spin-button {
    appearance: none;
    margin: 0;
}

/* Firefox */
.current-page[type="number"] {
    appearance: textfield;
}

/* ===== FLIPBOOK LAYOUT ===== */

/* Full viewport flipbook container  */
.flipbook-container {
    position: fixed;
    inset: 0;
    transition: var(--transition-slow);
    overflow: visible; /* Allow content to be visible during transitions */
}

.flipbook-viewer {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: auto;
    height: 100%;
    min-height: 600px;
    padding: 0;
    transition: transform 0.5s ease;
}

/* ===== BOOK LAYOUT ===== */
.book-layout {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    transition:
        transform var(--transition-slow),
        opacity var(--transition-medium);
    transform-origin: center center;
}

/* Layout centering */
.book-layout.center-right {
    transform: translateX(-25%); /* Move left to center right page */
}

.book-layout.center-left {
    transform: translateX(25%); /* Move right to center left page */
}

.book-layout.center-dual {
    transform: translateX(0); /* Centered for dual pages */
}

/* Subtle shadow between pages - to create a book spine effect */
.book-layout.center-dual::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 100%;
    background: radial-gradient(
        ellipse 40px 100% at center,
        rgb(0 0 0 / 50%) 0%,
        rgb(0 0 0 / 25%) 30%,
        rgb(0 0 0 / 10%) 50%,
        rgb(0 0 0 / 0%) 100%
    );
    pointer-events: none;
    z-index: 25;
}

/* ===== PAGE CONTAINERS ===== */
.page-container {
    position: relative;
    transition: 
        opacity var(--transition-medium),
        transform var(--transition-medium);

    /* Ensure proper spacing */
    padding: 0;
    margin: 0;
    box-sizing: border-box;

    /* Remove any default spacing */
    line-height: 0; /* Eliminates inline element spacing */
}

/* Behind page positioning */
.page-container.behind-page {
    position: absolute;
    z-index: -10; /* Ensure positioning behind current page-containers */
    top: 0;
}

.page-container.behind-page.prev {
    left: 0;
    order: 0;
}

.page-container.left {
    left: 0;
    order: 1;
    transform-origin: right center;
}

.page-container.right {
    right: 0;
    order: 2;
    transform-origin: left center;
}

.page-container.behind-page.next {
    right: 0;
    order: 3;
}

/* Empty page-container styles */
#page-container-empty {
    opacity: 0;
    pointer-events: none;
}

/* Canvas z-index layering */
.page-container.left > .front-side,
.page-container.prev > .front-side {
    z-index: -1;
}

.page-container.left > .back-side,
.page-container.prev > .back-side {
    z-index: 1;
}

.page-container.right > .front-side,
.page-container.next > .front-side {
    z-index: 1;
}

.page-container.right > .back-side,
.page-container.next > .back-side {
    z-index: -1;
}

/* Canvas positioning */
.pdf-page.front-side {
    position: relative;
}

.pdf-page.back-side {
    position: absolute;
    top: 0;
    left: 0;
}

/* ===== PDF PAGES ===== */
.pdf-page {
    max-height: 95vh;
    box-shadow: 0 8px 16px rgb(0 0 0 / 25%);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: box-shadow var(--transition-medium);
    background: var(--text-on-light);
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Page hover effects */
.pdf-page:hover {
    box-shadow: 0 16px 32px rgb(0 0 0 / 50%);
}

/* ===== LOADING STATES ===== */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: #9a9da0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--text-on-light);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 18px;
}

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

/* Fade transition for page jumps */
.book-layout.jumping {
    opacity: 0.3;
}

/* ===== PDF ANNOTATION OVERLAY STYLES ===== */
.annotation-overlay  {
    /* Invisible by default */
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    box-sizing: border-box;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
    z-index: 100; /* ensure overlays stay above the canvas but below the toolbar */
}

.annotation-overlay:hover,
.annotation-overlay.annotation-hover {
    background-color: rgb(0 123 255 / 30%);
    border-color: rgb(0 123 255 / 60%);
    box-shadow: 0 2px 8px rgb(0 123 255 / 30%);
}

.annotation-overlay:active {
    background-color: rgb(0 123 255 / 40%);
    transform: scale(0.98);
}

.annotation-overlay:focus-visible {
    outline: 2px solid var(--primary-accent);
    outline-offset: 2px;
}

/* Tooltip for annotation destinations */
.annotation-tooltip {
    position: absolute;
    box-sizing: border-box;
    background-color: #2b2a33;
    color: white;
    padding: 4px 8px;
    margin: 2px;
    border-radius: 4px;
    border: 1px solid rgb(255 255 255 / 80%);
    font-size: 12px;
    line-height: 1.4;
    font-family: system-ui, -apple-system, sans-serif;
    white-space: nowrap;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.annotation-tooltip.external {
    min-width: 0;
    max-width: min(500px, 90vw);

    /* 3 lines: 12px * 1.4 line-height * 3 = 50.4px content + 8px padding + 2px border = 60.4px */

    /* border-box: max-height includes padding and border */
    max-height: 61px;
    white-space: normal;
    word-break: break-all;
    overflow: hidden;
}

.annotation-tooltip.internal {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.annotation-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

/* Debug mode styles */

/* Debug mode - purple for more visible annotation overlays */
body.debug-annotations .annotation-overlay {
    background-color: rgb(128 0 255 / 30%);
    border: 2px solid rgb(128 0 255 / 80%);
    outline: 2px dashed rgb(255 0 255 / 80%);
    
}

/* Debug widget overlays - red for widgets without obvious URLs */
.annotation-overlay.debug-widget {
    background-color: rgb(255 0 0 / 30%);
    border: 2px solid rgb(255 0 0 / 80%);
    outline: 2px dashed rgb(255 255 0 / 80%);
}

body.debug-annotations .annotation-overlay.debug-widget {
    background-color: rgb(128 0 255 / 40%);
    border: 3px solid rgb(128 0 255);
    outline: 2px dashed rgb(255 0 255)
}

/* When zoom is active, make overlays pass through mouse events initially */
body.zoom-active .annotation-overlay {
    pointer-events: none;
}
