/* ===== PAPER VIEWER LAYOUT ===== */
.viewer-body {
    background: #f0f2f5;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.viewer-navbar {
    flex-shrink: 0;
}

.viewer-navbar .nav-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.nav-divider {
    color: #ddd;
    font-weight: 300;
}

.viewer-paper-title {
    font-size: 0.9rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-btn {
    padding: 7px 16px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: white;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.viewer-btn:hover {
    background: #f0f2f5;
}

.btn-upload-here {
    border-color: #86efac;
    color: #16a34a;
}

.btn-upload-here:hover {
    background: #f0fdf4;
}

.btn-annotate-mode {
    border-color: #fbbf24;
    color: #d97706;
}

.btn-annotate-mode:hover {
    background: #fffbeb;
}

.btn-annotate-mode.active {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
    font-weight: 600;
}

.btn-report {
    border-color: #fca5a5;
    color: #dc2626;
}

.btn-report:hover {
    background: #fef2f2;
}

/* Report banner */
.report-banner {
    background: #fef2f2;
    border-bottom: 1px solid #fca5a5;
    color: #991b1b;
    padding: 10px 24px;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

.report-banner svg {
    flex-shrink: 0;
}

.report-banner-taken-down {
    background: #fef2f2;
    border-bottom: 2px solid #dc2626;
    color: #7f1d1d;
    font-weight: 500;
}

/* Report modal */
.report-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.report-modal {
    background: white;
    border-radius: 12px;
    padding: 28px 32px;
    max-width: 440px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.report-modal h3 {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: #dc2626;
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-modal p {
    margin: 0 0 16px;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.5;
}

.report-modal select,
.report-modal textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    margin-bottom: 12px;
    resize: vertical;
}

.report-modal textarea {
    min-height: 80px;
}

.report-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.report-modal-actions button {
    padding: 8px 20px;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
}

.report-modal-actions .btn-cancel {
    background: white;
}

.report-modal-actions .btn-submit-report {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
}

.report-modal-actions .btn-submit-report:hover {
    background: #b91c1c;
}


/* ===== THREE-PANEL LAYOUT ===== */
.viewer-layout {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    flex: 1;
    overflow: hidden;
}


/* ===== LEFT SIDEBAR ===== */
.viewer-sidebar-left {
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.sidebar-header h3 {
    font-size: 1rem;
    color: #2b2d42;
}

.annotation-count {
    background: #ef8354;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

.annotations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.empty-annotations {
    text-align: center;
    padding: 40px 20px;
    color: #aaa;
}

.empty-annotations p {
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.empty-hint {
    font-size: 0.82rem !important;
    color: #ccc !important;
}


/* Annotation sidebar items */
.annotation-sidebar-item {
    display: flex;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 4px;
}

.annotation-sidebar-item:hover {
    background: #f5f6fa;
}

.annotation-sidebar-item.selected {
    background: #eef0f7;
    border-left: 3px solid #ef8354;
}

.ann-sidebar-color {
    width: 4px;
    background: #ef8354;
    border-radius: 4px;
    flex-shrink: 0;
}

.ann-sidebar-content {
    flex: 1;
    min-width: 0;
}

.ann-sidebar-location {
    font-size: 0.72rem;
    color: #aaa;
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ann-sidebar-text {
    font-size: 0.85rem;
    color: #444;
    line-height: 1.5;
    margin-bottom: 6px;
    /* Truncate to 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ann-sidebar-meta {
    font-size: 0.75rem;
    color: #999;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ann-sidebar-meta .user-institution {
    color: #aaa;
    font-weight: 400;
}

.ann-delete-btn {
    border: none;
    background: none;
    color: #ccc;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
    transition: all 0.15s;
}

.ann-delete-btn:hover {
    color: #ef4444;
    background: #fef2f2;
}


/* ===== CENTER: PDF VIEWER ===== */
.viewer-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}


/* Loading spinner */
.spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #e0e4ef;
    border-top-color: #ef8354;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Upload prompt */
.viewer-upload-prompt {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.viewer-dropzone {
    text-align: center;
    padding: 60px 40px;
    border: 3px dashed #d0d5e0;
    border-radius: 20px;
    background: white;
    max-width: 500px;
    width: 100%;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}

.viewer-dropzone:hover,
.viewer-dropzone.dragover {
    border-color: #ef8354;
    background: #fff8f5;
}

.dropzone-large-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.viewer-dropzone h2 {
    font-size: 1.4rem;
    color: #2b2d42;
    margin-bottom: 8px;
}

.viewer-dropzone p {
    color: #888;
    margin-bottom: 20px;
}


/* PDF container */
.pdf-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.pdf-nav-btn {
    padding: 5px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    font-size: 0.82rem;
    cursor: pointer;
    color: #555;
    transition: all 0.15s;
}

.pdf-nav-btn:hover {
    background: #f0f2f5;
    border-color: #bbb;
}

.pdf-page-info {
    font-size: 0.85rem;
    color: #666;
}

.pdf-zoom-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: #888;
}

.zoom-hint {
    font-size: 0.72rem;
    color: #bbb;
    margin-left: 4px;
    font-style: italic;
}

.pdf-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    background: #e8eaef;
}


/* Individual PDF page */
.pdf-page-wrapper {
    position: relative;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    background: white;
}

.pdf-canvas {
    display: block;
}

/* PDF.js text layer — selectable text on top of canvas */
.pdf-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    opacity: 0.25;
    line-height: 1;
    z-index: 2;
}

.pdf-text-layer > span {
    color: transparent;
    position: absolute;
    white-space: pre;
    transform-origin: 0% 0%;
    cursor: text;
}

/* When in annotate mode, text layer becomes a crosshair target */
.annotate-cursor .pdf-text-layer {
    cursor: crosshair !important;
}
.annotate-cursor .pdf-text-layer > span {
    cursor: crosshair !important;
}

.pdf-text-layer ::selection {
    background: rgba(37, 99, 235, 0.35);
}

.annotation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    cursor: default;
    /* Markers sit visually on top but let clicks through to text layer */
    pointer-events: none;
    z-index: 3;
}

/* Re-enable pointer-events on annotation markers */
.annotation-marker-pin {
    pointer-events: auto;
}

.pdf-page-label {
    text-align: center;
    font-size: 0.75rem;
    color: #aaa;
    padding: 6px 0;
    background: #f8f9fa;
    border-top: 1px solid #eee;
}


/* ===== ANNOTATION MARKERS ON PDF ===== */
.annotation-marker-pin {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #ef8354;
    border: 2px solid white;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.15s, box-shadow 0.15s;
}

.annotation-marker-pin:hover {
    transform: rotate(-45deg) scale(1.2);
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

.annotation-marker-pin.selected {
    background: #2563eb;
    transform: rotate(-45deg) scale(1.2);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
}


/* ===== ANNOTATION CREATE POPUP ===== */
.annotation-create-popup {
    position: fixed;
    z-index: 200;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    border: 1px solid #e0e0e0;
    padding: 16px;
    width: 320px;
}

.annotation-create-popup textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
    outline: none;
    margin-bottom: 10px;
}

.annotation-create-popup textarea:focus {
    border-color: #ef8354;
    box-shadow: 0 0 0 3px rgba(239, 131, 84, 0.1);
}

.popup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.popup-cancel {
    padding: 7px 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 0.85rem;
    cursor: pointer;
    color: #666;
}

.popup-cancel:hover {
    background: #f5f5f5;
}

.popup-save {
    padding: 7px 16px;
    background: #ef8354;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.popup-save:hover {
    background: #d4723f;
}


/* ===== RIGHT SIDEBAR: COMMENTS ===== */
.viewer-sidebar-right {
    background: white;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.discussion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.discussion-header h3 {
    font-size: 1rem;
    color: #2b2d42;
}

.discussion-comments {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.empty-comments {
    text-align: center;
    padding: 40px 20px;
    color: #aaa;
    font-size: 0.9rem;
}


/* Comment items */
.comment-item {
    padding: 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #f8f9fc;
}

.comment-item.annotation-root {
    background: #fef9ee;
    border: 1px solid #fde68a;
}

.comment-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.comment-item-header strong {
    font-size: 0.85rem;
    color: #2b2d42;
}

.comment-item-header .user-institution {
    font-size: 0.78rem;
    color: #999;
    font-weight: 400;
}

.comment-item-time {
    font-size: 0.72rem;
    color: #bbb;
}

.comment-item-page {
    font-size: 0.72rem;
    color: #999;
    background: #f0f2f5;
    padding: 2px 8px;
    border-radius: 4px;
}

.comment-item p {
    font-size: 0.88rem;
    color: #444;
    line-height: 1.6;
}


/* Comment input */
.discussion-input {
    padding: 16px;
    border-top: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.discussion-input textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    min-height: 50px;
    outline: none;
    margin-bottom: 8px;
}

.discussion-input textarea:focus {
    border-color: #ef8354;
}

.discussion-input-actions {
    display: flex;
    justify-content: flex-end;
}

.btn-post-comment {
    padding: 8px 20px;
    background: #ef8354;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-post-comment:hover {
    background: #d4723f;
}


/* ===== NO-PDF NOTICE ===== */
.no-pdf-dropzone {
    border-color: #fca5a5 !important;
    background: #fefce8 !important;
    cursor: default;
}

.no-pdf-dropzone:hover {
    border-color: #f87171 !important;
    background: #fef9c3 !important;
}

.nopdf-icon {
    color: #dc2626;
    margin-bottom: 12px;
    opacity: 0.7;
}

.no-pdf-dropzone h2 {
    color: #991b1b;
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.no-pdf-dropzone p {
    color: #78716c;
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 8px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.no-pdf-dropzone p strong {
    color: #2b2d42;
}

.nopdf-subtitle {
    font-size: 0.85rem !important;
    color: #a8a29e !important;
}

.nopdf-external-link {
    display: inline-block;
    margin-top: 8px;
    padding: 8px 20px;
    background: #2b2d42;
    color: white;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.nopdf-external-link:hover {
    background: #ef8354;
}

.nopdf-divider {
    width: 80px;
    height: 1px;
    background: #e5e5e5;
    margin: 20px auto;
}

.nopdf-upload-hint {
    font-size: 0.82rem !important;
    color: #bbb !important;
}

.no-pdf-dropzone .btn-upload {
    margin-top: 4px;
    background: white;
    color: #555;
    border: 1px solid #ddd;
    padding: 8px 24px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.no-pdf-dropzone .btn-upload:hover {
    background: #f5f5f5;
    border-color: #bbb;
}

/* ===== PDF CONTEXT MENU ===== */
.pdf-context-menu {
    position: fixed;
    z-index: 9999;
    background: #1e1e2e;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 6px 0;
    min-width: 200px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.35);
    animation: ctxFadeIn 0.12s ease-out;
}

@keyframes ctxFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 16px;
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 0.88rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s;
}

.ctx-item:hover {
    background: rgba(255,255,255,0.08);
}

.ctx-item:first-child {
    border-radius: 10px 10px 0 0;
}
.ctx-item:last-child {
    border-radius: 0 0 10px 10px;
}

.ctx-item i,
.ctx-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}

.ctx-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 4px 0;
}


/* ===== DELETED / AUTH STATES ===== */

/* Soft-deleted annotation in sidebar */
.annotation-sidebar-item.deleted .ann-sidebar-color {
    background: #ccc;
}

.annotation-sidebar-item.deleted .ann-sidebar-text {
    color: #aaa;
    font-style: italic;
}

.annotation-sidebar-item.deleted .ann-sidebar-meta span {
    color: #bbb;
}

/* Soft-deleted comment in thread */
.comment-item.deleted p {
    color: #aaa;
    font-style: italic;
}

.comment-item.deleted strong {
    color: #bbb;
    font-weight: 500;
}

/* Delete button on individual comments */
.comment-delete-btn {
    border: none;
    background: none;
    color: #ccc;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
    transition: all 0.15s;
}

.comment-delete-btn:hover {
    color: #ef4444;
    background: #fef2f2;
}

/* Login prompt in comment thread */
.comment-login-prompt {
    text-align: center;
    padding: 16px 12px;
    font-size: 0.85rem;
    color: #999;
    border-top: 1px solid #eee;
    margin-top: 8px;
}

.comment-login-prompt a {
    color: #ef8354;
    font-weight: 600;
    text-decoration: none;
}

.comment-login-prompt a:hover {
    text-decoration: underline;
}


/* ═══════════════════════════════════════════════════════════════
   Read Aloud / TTS
   ═══════════════════════════════════════════════════════════════ */

/* Toolbar button active state */
.btn-read-aloud.active {
    background: linear-gradient(135deg, #ef8354, #e06e3a);
    color: #fff;
    border-color: #ef8354;
}

/* Floating control bar */
.tts-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: rgba(43, 45, 66, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
    z-index: 500;
    color: #fff;
    min-width: 380px;
    max-width: 90vw;
}

.tts-bar-left,
.tts-bar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tts-bar-center {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.tts-status {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tts-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s;
}

.tts-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.tts-btn svg {
    width: 16px;
    height: 16px;
}

.tts-btn.tts-close {
    background: transparent;
    opacity: 0.5;
}

.tts-btn.tts-close:hover {
    opacity: 1;
    background: rgba(255, 80, 80, 0.3);
}

.tts-speed-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    margin-right: 2px;
}

.tts-speed {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 0.78rem;
    cursor: pointer;
    outline: none;
}

.tts-speed option {
    background: #2b2d42;
    color: #fff;
}

/* Page being read aloud highlight */
.pdf-page-wrapper.tts-reading {
    outline: 3px solid #ef8354;
    outline-offset: 4px;
    border-radius: 4px;
}

/* One-time tip in TTS bar */
.tts-tip {
    display: none;
    font-size: 0.78rem;
    color: #ef8354;
    margin-top: 2px;
    transition: opacity 0.6s ease;
}


/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .viewer-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .viewer-sidebar-left,
    .viewer-sidebar-right {
        max-height: 250px;
    }

    .pdf-scroll-area {
        padding: 12px;
    }

    .tts-bar {
        min-width: unset;
        left: 8px;
        right: 8px;
        transform: none;
        width: auto;
        bottom: 12px;
    }
}
