/* pdfbuddy styles. Colors come from Bootstrap's theme variables so light and dark both work. */

:root {
    --app-accent: #0d6efd;
    --app-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
    --app-mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", Menlo, "Noto Sans Mono CJK SC", monospace;
}

body {
    font-family: var(--app-font);
}

code, pre, .font-monospace {
    font-family: var(--app-mono);
}

code {
    font-size: 0.875em;
    overflow-wrap: anywhere;
}

/* When a document is open the viewport becomes an app shell: the pages
   pane scrolls internally while navbar, toolbar and footer stay put.
   The toolbar card keeps its natural height; the tab card takes the rest. */
body.doc-open {
    height: 100vh;
    overflow: hidden;
}

body.doc-open main,
body.doc-open #viewerSection,
body.doc-open #viewerSection > .card:last-child,
body.doc-open #viewerSection .card-body,
body.doc-open #viewerTabContent,
body.doc-open .tab-pane {
    min-height: 0;
}

body.doc-open #viewerSection > .card:first-child {
    flex-shrink: 0;
}

/* Navbar */
.app-navbar {
    background: linear-gradient(135deg, #1e1e1e 0%, #0b5ed7 100%);
    border-bottom: 2px solid var(--app-accent);
}

.app-navbar .navbar-brand,
.app-navbar .btn-outline-light {
    color: #fff;
}

/* Find bar */
.find-bar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background-color: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
}

.find-bar .form-control {
    max-width: 340px;
}

/* Load area */
.load-area {
    border: 3px dashed var(--app-accent);
    border-radius: 12px;
    padding: 2.5rem 1.5rem;
    transition: background-color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    background-color: rgba(13, 110, 253, 0.06);
}

.load-area:hover,
.load-area:focus-visible {
    background-color: rgba(13, 110, 253, 0.12);
    outline: none;
}

.load-area.dragover {
    background-color: rgba(25, 135, 84, 0.15);
    border-color: var(--bs-success);
    transform: scale(1.01);
}

.feature-grid li {
    margin-bottom: 0.25rem;
}

/* Cards / tabs */
.card {
    border-radius: 10px;
}

.card-header-tabs .nav-link {
    white-space: nowrap;
}

.tab-count {
    font-size: 0.65em;
}

.toolbar .btn,
.toolbar .form-select {
    white-space: nowrap;
}

.page-input {
    width: 4.5rem;
    text-align: center;
}

.zoom-select {
    width: auto;
}

/* Sidebar */
.sidebar {
    width: 190px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar.collapsed {
    display: none;
}

.sidebar-scroll {
    overflow-y: auto;
    min-height: 0;
    flex-grow: 1;
}

.thumb-item {
    display: block;
    width: 100%;
    background: none;
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 4px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    text-align: center;
}

.thumb-item:hover {
    background-color: var(--bs-tertiary-bg);
}

.thumb-item.active {
    border-color: var(--app-accent);
}

.thumb-item canvas {
    max-width: 100%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.thumb-label {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
    margin-top: 2px;
}

/* Outline */
.outline-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--bs-body-color);
    padding: 0.2rem 0.3rem;
    border-radius: 4px;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.outline-item:hover:not(:disabled) {
    background-color: var(--bs-tertiary-bg);
}

.outline-item:disabled {
    color: var(--bs-secondary-color);
    cursor: default;
}

/* The Pages pane must not use .d-flex: display:flex !important would defeat
   Bootstrap's .tab-pane display:none and the pane would never hide. */
#pages.tab-pane.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Inspection panes scroll inside the tab card in app-shell mode */
body.doc-open #metadata.tab-pane.active,
body.doc-open #resources.tab-pane.active {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Pages pane */
.pages-row {
    min-height: 0;
}

.pages-scroll {
    overflow-y: auto;
    min-height: 0;
    background-color: var(--bs-tertiary-bg);
    border-radius: 0.375rem;
    padding: 1rem 0;
}

.pages-scroll:focus-visible {
    outline: none;
}

.page-wrap {
    position: relative;
    margin: 0 auto 1rem;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    width: fit-content;
}

.page-wrap canvas {
    display: block;
}

.page-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bs-secondary-color);
    background: #fff;
}

/* Text layer: minimal subset of pdf.js's pdf_viewer.css (Apache-2.0),
   hand-trimmed to what TextLayer.render() needs. */
.textLayer {
    position: absolute;
    inset: 0;
    overflow: clip;
    opacity: 1;
    line-height: 1;
    text-size-adjust: none;
    forced-color-adjust: none;
    transform-origin: 0 0;
    caret-color: CanvasText;
    z-index: 0;
}

.textLayer span,
.textLayer br {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0 0;
}

.textLayer ::selection {
    background: rgba(13, 110, 253, 0.4);
    color: transparent;
}

/* Search highlights sit above the text layer but below nothing else;
   pointer-events off so text selection keeps working through them. */
.highlightLayer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.highlightLayer .hl {
    position: absolute;
    background: rgba(255, 213, 0, 0.35);
    border-radius: 2px;
}

.highlightLayer .hl.current {
    background: rgba(255, 140, 0, 0.55);
    outline: 2px solid rgba(255, 140, 0, 0.8);
}

/* Metadata / Resources panes */
.meta-table td {
    font-size: 0.85rem;
    vertical-align: top;
    overflow-wrap: anywhere;
}

.meta-table td:first-child {
    font-weight: 600;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    width: 1%;
    padding-right: 1rem;
}

.resource-section {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1rem;
}

.resource-section-header {
    background-color: var(--bs-tertiary-bg);
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    font-weight: 600;
    font-size: 0.875rem;
}

.resource-section-body {
    padding: 0.75rem 1rem;
}

.link-card.link-external { border-left: 4px solid var(--bs-info); }
.link-card.link-internal { border-left: 4px solid var(--bs-secondary); }

.image-card img {
    max-width: 100%;
    max-height: 140px;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.25rem;
    background: repeating-conic-gradient(#8883 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}

.code-block {
    max-height: 320px;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 0.8125rem;
    line-height: 1.45;
    background-color: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    padding: 0.75rem 1rem;
    color: var(--bs-body-color);
    tab-size: 4;
}

/* Toasts */
#toastContainer {
    z-index: 1090;
    max-width: 420px;
}

#toastContainer .alert {
    overflow-wrap: anywhere;
}

/* Print target: never on screen, filled by UIManager.printDocument() */
.print-only {
    display: none;
}

/* Small screens */
@media (max-width: 991.98px) {
    .sidebar {
        position: absolute;
        z-index: 20;
        background-color: var(--bs-body-bg);
        height: 100%;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.35);
    }

    .pages-row {
        position: relative;
    }
}

@media (max-width: 575.98px) {
    .load-area {
        padding: 1.5rem 0.75rem;
    }

    .card-header-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
}

/* Print */
@media print {
    :root, [data-bs-theme="dark"] {
        color-scheme: light;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        height: auto !important;
        overflow: visible !important;
    }

    .app-navbar, footer, .find-bar, #toastContainer, .btn, [data-action], #loadSection, #loadingSection, .modal, #viewerSection {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    .print-only img {
        display: block;
        width: 100%;
        page-break-after: always;
        break-inside: avoid;
    }
}
