/* =====================================================
   PREMIUM FLIPBOOK — FlippingBook-Grade UI
   ===================================================== */

:root {
    --theme-color: #059669;
    --theme-color-dark: var(--theme-color);
    --red: var(--theme-color);
    --red-dark: var(--theme-color-dark);
    --bg: #ffffff;
    --bg-sidebar: #ffffff;
    --topbar-h: 52px;
    --toolbar-h: 60px;
    --sidebar-w: 340px;
    --font: 'Inter', -apple-system, sans-serif;
    --ease-flip: cubic-bezier(0.645, 0.045, 0.355, 1);
    --custom-bg-image: none;
    --custom-bg-color: #ffffff;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--custom-bg-color);
    background-image: var(--custom-bg-image);
    background-size: cover;
    background-position: center;
    color: #fff;
    -webkit-font-smoothing: antialiased;
}

/* =====================================================
   TOP BAR
   ===================================================== */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: var(--red);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    z-index: 900;
    /* box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3); */
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}
.topbar-right {
    justify-content: flex-end;
}
.topbar-center {
    display: flex;
    align-items: center;
}

.icon-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: white;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
}
.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.page-info {
    display: none;
} /* Hidden as per previous request, but available if needed */

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand-title {
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* max-width: 250px; */
}
.brand-badge {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    padding: 3px 10px;
    background: #e5e7eb;
    border-radius: 4px;
}
.hidden {
    display: none !important;
}

/* =====================================================
   SIDEBARS
   ===================================================== */
.sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: var(--toolbar-h);
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    z-index: 800;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    transition: transform 0.3s var(--ease-flip);
}

.sidebar-left {
    left: 0;
    transform: translateX(-100%);
}
.sidebar-left.open {
    transform: translateX(0);
}

.sidebar-right {
    right: 0;
    transform: translateX(100%);
}
.sidebar-right.open {
    transform: translateX(0);
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid #f0f0f0;
    min-height: 52px;
    flex-shrink: 0;
}
.sb-heading-left {
    display: flex;
    align-items: center;
    justify-content: start;
    gap: 10px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex: 1;
    text-align: center;
}
.sb-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sb-tabs {
    display: flex;
    gap: 0;
}
.sb-tab {
    padding: 14px 16px;
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 700;
    color: #9ca3af;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: all 0.2s;
}
.sb-tab.active {
    color: var(--red);
    border-bottom-color: var(--red);
}

.sb-heading {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sidebar-close {
    width: 30px;
    height: 30px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    color: #6b7280;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.sidebar-close:hover {
    background: #e5e7ea;
    color: var(--red);
}

.sb-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.sb-panel.active {
    display: flex;
    flex-direction: column;
}
.sb-empty {
    padding: 24px 16px;
    color: #9ca3af;
    font-size: 13px;
}

/* TOC */
.toc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 16px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    border-bottom: 1px solid #f9f9f9;
    background: transparent;
    border-left: 3px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toc-item:hover {
    background: color-mix(in srgb, var(--theme-color), transparent 95%);
    color: var(--theme-color);
    border-left-color: var(--theme-color);
}
.toc-item.active {
    background: color-mix(in srgb, var(--theme-color), transparent 92%);
    color: var(--theme-color);
    border-left-color: var(--theme-color);
    font-weight: 600;
}
.toc-parent {
    background: #fdfdfd !important;
}
.toc-parent .toc-item-title {
    font-weight: 700;
    color: var(--theme-color);
    text-transform: uppercase;
}
.toc-parent .toc-item-pg {
    color: var(--theme-color);
}
.toc-item-title {
    flex: 1;
    padding-right: 12px;
    line-height: 1.4;
}
.toc-item-pg {
    font-size: 11px;
    font-weight: 700;
    color: #6b7280;
    flex-shrink: 0;
}
.toc-item.active .toc-item-pg,
.toc-item:hover .toc-item-pg {
    color: var(--theme-color);
}
.toc-caret {
    display: inline-block;
    width: 16px;
    font-size: 10px;
    cursor: pointer;
    color: var(--theme-color);
    transition: transform 0.2s;
}
.toc-children {
    margin-bottom: 8px;
}

/* Thumbnails — 2-column grid, each thumb is one "spread" */
.thumbs-wrap {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    flex: 1;
}

.thumb-item {
    cursor: pointer;
    transition: transform 0.2s;
    width: 100%;
}
.thumb-item:hover {
    transform: translateY(-2px);
}
.thumb-item.active .thumb-img-wrap {
    border-color: var(--red);
    box-shadow: 0 0 0 2px rgba(227, 25, 55, 0.2);
}

.thumb-img-wrap {
    width: 100%;
    border: 2px solid #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    background: transparent;
    display: flex; /* side-by-side for spreads */
    align-items: stretch;
    transition: border-color 0.2s;
    min-height: 60px;
}
.thumb-img-wrap canvas {
    flex: 1;
    display: block;
    width: 50%;
    height: auto;
    min-width: 0;
}
/* Single cover page thumb */
.thumb-img-wrap.single canvas {
    width: 100%;
    max-width: 55%;
    margin: 0 auto;
}

.thumb-label {
    text-align: center;
    margin-top: 5px;
    font-size: 11px;
    font-weight: 700;
    color: #9ca3af;
    letter-spacing: 0.02em;
}
.thumb-item.active .thumb-label {
    color: var(--red);
}

/* Search */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px;
    background: #f3f4f6;
    border-radius: 24px;
    padding: 9px 14px;
    border: 2px solid transparent;
    transition:
        border-color 0.2s,
        background 0.2s;
}
.search-bar:focus-within {
    border-color: var(--red);
    background: #fff;
}
.search-bar svg {
    flex-shrink: 0;
    color: #9ca3af;
}
.search-bar input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 13px;
    font-family: var(--font);
    color: #374151;
}
.search-bar input::placeholder {
    color: #9ca3af;
}
.search-clear {
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    transition: color 0.15s;
}
.search-clear:hover {
    color: var(--red);
}
.search-clear.hidden {
    display: none;
}
.search-status {
    padding: 8px 16px 12px;
    font-size: 12px;
    color: #9ca3af;
    font-weight: 500;
    border-bottom: 1px solid #f0f0f0;
}
.search-results {
    flex: 1;
    overflow-y: auto;
}

.result-item {
    padding: 14px 16px;
    border-bottom: 1px solid #f5f5f5;
    cursor: pointer;
    transition: background 0.15s;
}
.result-item:hover {
    background: #fff5f5;
}
.result-pg {
    font-size: 11px;
    font-weight: 800;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 5px;
}
.result-snippet {
    font-size: 13px;
    line-height: 1.5;
    color: #374151;
}
.result-snippet mark {
    background: #ffe4e6;
    color: var(--red);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}

/* =====================================================
   BACKDROP
   ===================================================== */
.backdrop {
    position: fixed;
    inset: 0;
    z-index: 700;
    background: rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s;
    pointer-events: none; /* Allow interaction with book underneath */
}
.backdrop.hidden {
    display: none;
}

/* =====================================================
   MAIN VIEWER
   ===================================================== */
.viewer {
    position: fixed;
    top: var(--topbar-h);
    bottom: var(--toolbar-h);
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: transparent;
    transition:
        left 0.3s var(--ease-flip),
        right 0.3s var(--ease-flip),
        width 0.3s var(--ease-flip);
}
.viewer.sidebar-l-open {
    left: var(--sidebar-w);
}
.viewer.sidebar-r-open {
    right: var(--sidebar-w);
}

/* Loading screen */
.loading-screen {
    position: absolute;
    inset: 0;
    background: #141414;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    transition: opacity 0.5s;
}
.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}
.load-ring {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 4px solid rgba(227, 25, 55, 0.15);
    border-top-color: var(--red);
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
.load-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    margin-bottom: 16px;
}
.load-bar-wrap {
    width: 240px;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto 8px;
}
.load-bar {
    height: 100%;
    background: var(--red);
    width: 0%;
    transition: width 0.3s;
    border-radius: 4px;
}
.load-pct {
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
}

/* Per-page loading spinner (small) */
.mini-spin {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px; /* Center using negative margin to avoid conflicting with rotate transform */
    border-radius: 50%;
    border: 3px solid rgba(227, 25, 55, 0.1);
    border-top-color: var(--red);
    animation: spin 0.7s linear infinite;
}

.book-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateX(var(--book-shift, 0px));
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

/* Container inside wrapper */
.book-container {
    position: relative;
    width: calc(var(--page-w) * 2);
    height: var(--page-h);
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
}

/* StPageFlip mounts into #book */
#book {
    position: relative;
    width: 100%;
    height: 100%;
    flex-shrink: 0;
    transform-style: preserve-3d;
}

/* Central spine shadow */
.book-spine-shadow {
    position: absolute;
    top: 50%;
    left: 50%;
    /* Width managed by JS for responsiveness */
    transform: translate(-50%, -50%);
    /* Realistic deep inner book gradient */
    background: linear-gradient(
        to right,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.05) 25%,
        rgba(0, 0, 0, 0.1) 47%,
        rgba(0, 0, 0, 0.15) 50%,
        rgba(0, 0, 0, 0.1) 53%,
        rgba(0, 0, 0, 0.05) 75%,
        rgba(0, 0, 0, 0) 100%
    );
    pointer-events: none;
    z-index: 12; /* Ensure it stays above the pages (which are z=10+) */
    display: none;
    transform-style: preserve-3d;
}

/* Page Stacks (Realistic lines effect) */
.page-stack {
    position: absolute;
    top: 50%;
    height: var(--stack-h, 0px);
    background: #f8f8f8;
    z-index: 5; /* Sit below the pages */
    pointer-events: none;
    /* box-shadow: inset -2px 0 6px rgba(0,0,0,0.05), inset 2px 0 6px rgba(0,0,0,0.05), 0 4px 12px rgba(0, 0, 0, 0.15); */
    transform: translateY(-50%);

    /* Tighter, more realistic paper edge grain */
    background-image: repeating-linear-gradient(
        to right,
        #b1b1b1,
        #e3e3e3 0.2px,
        #f9f9f9 0.2px,
        #f9f9f9 0.4px
    );
    /* border: 5px solid #000000; */
}

.stack-l {
    border-radius: 1px 0 0 1px;
    border: none;
}
.stack-r {
    border-radius: 0 1px 1px 0;
    border: none;
}

/* Page flip shadow — StPageFlip generates .stf__item elements */
/* These are canvases; the library handles the 3D itself */

/* NAV ARROWS */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 15, 15, 0.45);
    backdrop-filter: blur(12px);
    color: #ffffff;
    transition: all 0.2s;
    z-index: 200;
    opacity: 1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Keep visible by default */

.viewer.zoomed .nav-arrow {
    display: none !important;
}
.nav-arrow:hover {
    background: var(--theme-color);
    color: white;
    box-shadow: 0 6px 24px var(--theme-color);
    transform: translateY(-50%) scale(1.08);
}
.nav-prev {
    left: 20px;
}
.nav-next {
    right: 20px;
}

/* =====================================================
   BOTTOM TOOLBAR
   ===================================================== */
.toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-h);
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 900;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.tool-sep {
    width: 1px;
    height: 24px;
    background: #e5e7eb;
    margin: 0 8px;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.tool-btn:hover {
    background: #f3f4f6;
    color: var(--red);
}
.tool-btn.active {
    background: #fff5f5;
    color: var(--red);
}

.page-input-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 4px;
}
.page-input {
    width: 75px;
    height: 34px;
    padding: 0 5px;
    text-align: center;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}
.page-input:focus {
    border-color: var(--red);
}
.page-sep {
    font-size: 13px;
    color: #9ca3af;
    white-space: nowrap;
}

/* =====================================================
   FULLSCREEN
   ===================================================== */
body.fs .topbar {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}
body.fs .toolbar {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}
body.fs.fs-show-top .topbar,
body.fs .topbar:hover,
body.fs .topbar:focus-within {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}
body.fs.fs-show-bottom .toolbar,
body.fs .toolbar:hover,
body.fs .toolbar:focus-within {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}
body.fs .viewer {
    top: 0;
    bottom: 0;
}

/* Override StPageFlip canvas styles for premium look */
.stf__parent {
    background: transparent !important;
}

/* Make page-el canvases render crisply */
.page-el {
    /* The physical shadow is tied to the actual paper, preventing ghost left-shadows */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    background-color: #ffffff;
    user-select: none;
}
.page-el canvas.base-canvas {
    image-rendering: -webkit-optimize-contrast;
    display: block;
    width: 100%;
    height: 100%;
}
#book-wrapper {
    transition: transform 0.1s ease-out;
    transform-origin: center center;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.viewer.zoomed {
    cursor: grab;
    overflow: auto;
    display: block;
}
.viewer.zoomed:active {
    cursor: grabbing;
}
/* Disable flipping engine interactions when zoomed to prioritize navigation and panning */
.viewer.zoomed #book {
    pointer-events: none;
}
.viewer.zoomed #book-wrapper {
    margin: 100px auto; /* Large breathing room for corners */
    display: block;
    position: relative;
    transform-origin: 0 0;
}
.zoom-pct-box {
    font-size: 11px;
    font-weight: 700;
    color: #4b5563;
    min-width: 40px;
    padding: 0 8px;
    text-align: center;
    user-select: none;
    cursor: pointer;
}
.zoom-pct-box:hover {
    color: var(--red);
}

/*
  Search Highlights Overlay
  Transparent container sitting exactly on top of the base PDF render.
  Pointer events disabled so StPageFlip naturally grabs clicks.
*/
.search-overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5; /* Sit slightly above base render inside the page context */
}

/* Wide spread thumbnail */
.thumb-img-wrap.thumb-wide {
    aspect-ratio: 2 / 1.414;
}
.thumb-img-wrap.thumb-wide canvas {
    width: 100%;
    height: auto;
}

/* =====================================================
   NOTES SYSTEM
   ===================================================== */
.notes-wrap {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-left: 1px solid #f0f0f0;
}

.sb-notes-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}
.sb-notes-content::-webkit-scrollbar {
    width: 6px;
}
.sb-notes-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.note-item {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 0;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    margin-bottom: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
    flex-shrink: 0; /* Prevents notes from shrinking when list grows */
}
.note-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.06);
    border-color: var(--theme-color);
}
.note-item-thumb {
    padding: 10px 12px 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.note-item-body {
    padding: 12px;
    flex: 1;
}
.note-item-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.note-item-text {
    font-size: 13px;
    color: #4b5563;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.note-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    color: #9ca3af;
    background: rgba(0, 0, 0, 0.03);
    border: none;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    z-index: 5;
}
.note-item-delete:hover {
    background: #fee2e2;
    color: #ef4444;
    transform: rotate(90deg);
}

.note-marker {
    position: absolute;
    z-index: 1000;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.note-marker svg {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.note-marker:hover svg {
    transform: scale(1.2) translateY(-2px);
}

/* Modal UI for Notes Popup */
.modal-root {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
}
.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}
.modal-card {
    position: relative;
    z-index: 10;
    width: 90%;
    max-width: 500px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    animation: modalScaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalScaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Global Add Note Button */
.global-add-note {
    position: absolute;
    right: -80px;
    top: 0px;
    width: 30px;
    height: 30px;
    background-color: color-mix(in srgb, var(--theme-color, #f74762), white 90%);
    color: var(--theme-color, #f74762);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    border-radius: 5px;
    padding: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.global-add-note:hover {
    background-color: var(--theme-color, #f74762);
    color: #fff;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}
.global-add-note svg {
    width: 28px;
    height: 28px;
}

/* Draggable Marker */
.note-marker {
    cursor: grab;
    user-select: none;
}
.note-marker:active {
    cursor: grabbing;
}

.sb-notes-footer {
    padding: 16px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    flex-shrink: 0;
}
.notes-help-text {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.6;
    margin: 16px 0;
}
.notes-help-text ul {
    margin: 0 0 12px 0;
    padding-left: 20px;
    text-align: left;
}
.notes-help-text li {
    margin-bottom: 6px;
}
.btn-sidebar-add {
    display: block;
    width: 100%;
    margin: 0 auto 12px;
    background: var(--theme-color, #f74762);
    color: #fff;
    border: none;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.btn-sidebar-add:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}
.btn-sidebar-download {
    width: 100%;
    background: #fff;
    color: var(--theme-color, #f74762);
    border: 2px solid var(--theme-color, #f74762);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}
.btn-sidebar-download:hover {
    background: var(--theme-color, #f74762);
    color: #fff;
}
.btn-sidebar-download svg {
    color: var(--theme-color, #f74762);
}
/* Note Marker Refined Style */
.note-marker {
    position: absolute;
    width: 32px;
    height: 32px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    z-index: 1000;
    transform: translate(-50%, -100%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    border: 2px solid white;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.note-marker:hover {
    transform: translate(-50%, -100%) scale(1.15);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.note-marker:active {
    cursor: grabbing;
}
.note-marker svg {
    width: 20px;
    height: 20px;
}

.note-editor {
    position: fixed;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.note-editor-text {
    font-size: 13px;
    color: #374151;
    padding: 4px;
    min-height: 40px;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font);
}
.note-editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.note-colors {
    display: flex;
    gap: 6px;
}
.color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}
.color-dot.active {
    transform: scale(1.3);
    border-color: rgba(0, 0, 0, 0.2);
}
.note-trash {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.note-trash:hover {
    color: #ef4444;
}

.thumb-pg-badge {
    position: absolute;
    bottom: 4px;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 700;
    pointer-events: none;
}
.thumb-pg-badge.left {
    left: 4px;
}
.thumb-pg-badge.right {
    right: 4px;
}

/* Custom Context Menu */
.context-menu {
    position: fixed;
    z-index: 3000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 8px;
    width: 180px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
}
.context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
}
.context-item:hover {
    background: #f3f4f6;
}
.context-item svg {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}
.context-sep {
    height: 1px;
    background: #f0f0f0;
    margin: 4px 12px;
}

/* =====================================================
   MODALS
   ===================================================== */
.modal-root {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}
.modal-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-sm {
    width: 340px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
}
.modal-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: #9ca3af;
    cursor: pointer;
    line-height: 1;
}
.modal-close-btn:hover {
    color: #1f2937;
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #667385;
    margin-bottom: 6px;
}
.form-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-bottom: 8px;
}
.form-group input[type='number'],
.form-group input[type='text'] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
}
.form-group input:focus {
    border-color: var(--red);
}

.modal-footer {
    padding: 16px 20px;
    background: #f9fafb;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
.btn-primary {
    background: var(--red);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover {
    background: var(--red-dark);
}

/* Settings Panel Styles */
.settings-section h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #9ca3af;
    margin-bottom: 16px;
    font-weight: 700;
}
.color-picker-row {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}
.premium-color-input {
    position: relative;
    width: 64px;
    height: 48px;
    border-radius: 8px;
    border: 2px solid #e5e7eb;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.23s;
}
.premium-color-input:hover {
    border-color: var(--theme-color);
}
.premium-color-input input[type='color'] {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 100px;
    height: 100px;
    cursor: pointer;
    border: none;
    padding: 0;
}
.color-visual {
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.preset-box {
    flex: 1;
}
.preset-box label {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 8px;
    display: block;
}
.swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 30px;
}
.swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #e5e7eb;
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}
.swatch:hover {
    transform: scale(1.15);
}
.swatch.active {
    box-shadow: 0 0 0 2px var(--theme-color);
}
.settings-warning {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #fffbeb;
    border: 1px solid #fef3c7;
    color: #92400e;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.4;
    margin-top: 10px;
}
.btn-secondary {
    background: transparent;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover {
    background: #f9fafb;
    color: #374151;
    border-color: #d1d5db;
}

.modal-card.modal-sm {
    max-width: 440px;
}
.modal-card.modal-md {
    max-width: 600px;
}
.modal-card.modal-confirm {
    max-width: 380px;
}
.share-body {
    text-align: center;
}
.qr-container {
    padding: 20px;
    background: #fff;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    display: inline-block;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}
.qr-container img {
    display: block;
    width: 160px;
    height: 160px;
}
.share-link-box {
    display: flex;
    gap: 8px;
}
.share-link-box input {
    flex: 1;
    min-width: 0;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 12px;
    background: #f9fafb;
}
.share-link-box button {
    padding: 0 16px;
    background: #4b5563;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.share-link-box button:active {
    opacity: 0.8;
}

/* Zoom Overlay */
.zoom-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: #000;
    display: flex;
    flex-direction: column;
}
.zoom-header {
    height: 60px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 20px;
    z-index: 10;
}
#btn-zoom-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
#btn-zoom-close:hover {
    background: var(--red);
}

.zoom-content {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
.zoom-content canvas {
    box-shadow: 0 32px 100px rgba(0, 0, 0, 0.5);
    max-width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .modal-card {
        width: 95vw;
    }
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: #374151;
    color: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1000;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(20px);
}
.toast-close {
    background: transparent;
    border: none;
    color: #9ca3af;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.toast-close:hover {
    color: #fff;
}

/* =====================================================
   NEW UI COMPONENT STYLES
   ===================================================== */
/* Loading Screen */
#loading-screen {
    background: #f4f4f4;
}
.loading-content {
    background: #f4f4f4;
}
.loading-brand {
    margin-bottom: 24px;
    text-align: center;
    color: var(--theme-color);
}
.theme-text-bold {
    font-weight: 800;
    font-size: 38px;
}
.theme-text-normal {
    font-weight: 600;
    font-size: 25px;
}
.loading-cover {
    display: block;
    max-width: 300px;
    margin: 0 auto;
    /* box-shadow: 0 10px 20px rgba(0,0,0,0.15); */
    border: 1px solid #ddd;
}

/* Download Modal */
.modal-md {
    width: 440px;
    max-width: 95vw;
}
.download-box {
    display: flex;
    align-items: center;
    background: #f4f4f4;
    padding: 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
    gap: 16px;
    cursor: pointer;
}
.download-box:hover {
    background: #ebebeb;
}
.download-icon {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.icon-text {
    position: absolute;
    bottom: 4px;
    background: var(--theme-color);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 4px;
    border-radius: 2px;
}
.download-info h4 {
    margin: 0 0 6px;
    font-size: 16px;
    color: var(--theme-color);
    font-weight: 600;
}
.download-info p {
    margin: 0;
    font-size: 13px;
    color: #555;
}

/* Share Modal Custom */
.share-tabs-nav {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin: -16px -16px 16px -16px;
}
.share-tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    border-bottom: 3px solid transparent;
}
.share-tab-btn.active {
    color: var(--theme-color);
    border-bottom: 3px solid #888;
}
.share-content {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}
.share-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}
.share-current-page {
    font-size: 13px;
    color: var(--theme-color);
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-copy {
    background: var(--theme-color);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 4px;
    margin-left: auto;
    font-weight: 600;
    cursor: pointer;
    width: 80px;
}
.btn-copy:hover {
    background: var(--theme-color-dark);
}
.social-text {
    font-size: 13px;
    color: var(--theme-color);
    margin-bottom: 10px;
}
.social-icons {
    display: flex;
    gap: 8px;
}
.social-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    border: none;
    color: white;
    cursor: pointer;
    background: transparent;
    overflow: hidden;
}

/* =====================================================
   UNIVERSAL TOOLTIP
   ===================================================== */
.universal-tooltip {
    position: fixed;
    background: var(--theme-color);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}
.universal-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: var(--theme-color) transparent transparent transparent;
}
.universal-tooltip.tooltip-bottom::after {
    top: auto;
    bottom: 100%;
    border-color: transparent transparent var(--theme-color) transparent;
}

/* =====================================================
   THEME APPLIED TO NAVBARS & OVERRIDES
   ===================================================== */
.toolbar {
    background: var(--theme-color);
    border-top: none;
    color: #fff;
}
.tool-btn {
    color: #fff;
}
.tool-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}
.tool-btn.active {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}
.tool-sep {
    background: rgba(255, 255, 255, 0.2);
}
.page-input {
    background: rgba(0, 0, 0, 0.1);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
}
.page-input:focus {
    border-color: #fff;
}
.page-sep,
.zoom-pct-box {
    color: rgba(255, 255, 255, 0.8);
}
.zoom-pct-box:hover {
    color: #fff;
}

body.loading .topbar,
body.loading .toolbar {
    display: none !important;
}

/* Modal header overrides */
.modal-header {
    background: var(--theme-color);
    color: #fff;
}
.modal-header h3 {
    color: #fff;
}
.modal-close-btn {
    color: #fff;
    opacity: 0.8;
}
.modal-close-btn:hover {
    background: transparent;
    color: #fff;
    opacity: 1;
}

/* Sidebar head overrides */
.sidebar-head-theme {
    background: var(--theme-color);
    border-bottom: none;
}
#sb-left-title {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
#close-left {
    color: #fff;
    background: transparent;
}
#close-left:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* TOC Override Removed and Integrated */

/* Modal and Loading Screen adjustments */
body.loading .viewer {
    top: 0;
    bottom: 0;
}
.btn-primary:hover {
    filter: brightness(0.85); /* Darkens the dynamically set theme color */
}

/* =====================================================
   RESPONSIVE OVERRIDES
   ===================================================== */

@media (max-width: 1024px) {
    :root {
        --sidebar-w: 300px;
    }
    .topbar {
        padding: 0 10px;
    }
    .toolbar {
        padding: 0 10px;
    }
    .tool-btn {
        width: 36px;
        height: 36px;
    }
    .icon-btn {
        padding: 6px 8px;
    }
}

@media (max-width: 850px) {
    .brand-title {
        max-width: 750px;
    }
    .topbar-left {
        flex: 0;
    }
}

@media (max-width: 768px) {
    :root {
        --topbar-h: 48px;
        --toolbar-h: 56px;
    }

    .tool-sep {
        display: none;
    }

    /* Hide non-essential toolbar buttons */
    #tool-print,
    #tool-share,
    #tool-download,
    #tool-zoom-in,
    #tool-zoom-out,
    #zoom-pct,
    #tool-fullscreen,
    #tool-volume {
        display: none !important;
    }

    #tool-more {
        display: flex !important;
    }

    .toolbar-left,
    .toolbar-right {
        gap: 4px;
    }
    .toolbar-center {
        gap: 2px;
    }

    .page-input-wrap {
        margin: 0;
    }
    .page-input {
        width: 60px;
        font-size: 12px;
    }
}

@media (max-width: 600px) {
    .brand-title {
        max-width: 500px;
        font-size: 12px;
    }
    .icon-btn span {
        display: none;
    }

    /* Keep core nav */
    #tool-toc,
    #tool-thumbs,
    #tool-notes,
    #tool-settings {
        display: flex !important;
    }

    .toolbar {
        justify-content: center;
        gap: 15px;
    }

    .toolbar-left,
    .toolbar-right {
        flex: 0;
    }

    .nav-arrow {
        width: 40px;
        height: 40px;
    }
    .nav-prev {
        left: 10px;
    }
    .nav-next {
        right: 10px;
    }
}

@media (max-width: 400px) {
    .brand-title {
        max-width: 300px;
    }
    .toolbar {
        gap: 8px;
    }
    .tool-btn {
        width: 32px;
        height: 32px;
    }
    .page-input {
        width: 50px;
    }
    #tool-first,
    #tool-last {
        display: none !important;
    }
}

/* =====================================================
   MORE MENU (Overflow)
   ===================================================== */
#tool-more {
    display: none; /* Hidden on desktop */
}

.more-menu {
    position: fixed;
    bottom: calc(var(--toolbar-h) + 12px);
    right: 12px;
    width: 180px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    z-index: 2000;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.more-menu.hidden {
    display: flex !important; /* Keep flex but animate away */
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.more-menu-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.more-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: #4b5563;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}

.more-menu-item:hover {
    background: #f3f4f6;
    color: var(--theme-color);
}

.more-menu-item svg {
    flex-shrink: 0;
}

.more-sep {
    height: 1px;
    background: #f0f0f0;
    margin: 4px 8px;
}

@media (max-width: 768px) {
    #tool-more {
        display: flex;
    }
}

/* =====================================================
   PDF HYPERLINK OVERLAY
   ===================================================== */
.pdf-link-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
    overflow: hidden;
}

.pdf-link-annot {
    position: absolute;
    pointer-events: auto;
    cursor: pointer;
    background: transparent;
    border-radius: 3px;
    transition: background 0.15s ease, box-shadow 0.15s ease;
    text-decoration: none;
    display: block;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
}

.pdf-link-annot:hover {
    background: rgba(37, 99, 235, 0.12);
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.25);
}

.pdf-link-annot:focus-visible {
    outline: 2px solid var(--theme-color);
    outline-offset: 1px;
}

