/* 논문 독해 학습툴 (readpaper)
   - rp-*  : 페이지 상단(업로드 / PDF 목록) 전용
   - txm-* : 블록 추출 모달. 영어 텍스트 추출(textract.css)의 것을 그대로 재사용하고,
             여기서는 이 툴에만 있는 '이미지 영역 지정(드래그)' 관련 규칙만 덧붙인다. */

/* base.css의 .app-shell은 display:flex(가로)라, 페이지에 흐름 요소가 둘 이상이면 나란히 놓인다.
   이 페이지는 [PDF 입력·목록] 위 / [독해 카드] 아래로 쌓여야 하므로 세로로 바꾼다.
   (독해 카드가 남은 높이를 받아야 하니 display:block이 아니라 flex-direction만 바꾼다) */
.app-shell {
    flex-direction: column;
}

/* 상단 전용 팔레트 — 페이지 요청 색: teal/mint/yellow/cream/coral.
   피커 모달(#rpPickerModal)이 .rp-top 밖에 있어 :root에 둔다. */
:root {
    --rp-teal: #227c9d;
    --rp-mint: #17c3b2;
    --rp-yellow: #ffcb77;
    --rp-cream: #fef9ef;
    --rp-coral: #fe6d73;
    /* 옅은 배경·어두운 글자용 파생 톤 */
    --rp-teal-line: rgba(34, 124, 157, 0.28);
    --rp-mint-tint: rgba(23, 195, 178, 0.13);
    --rp-yellow-tint: rgba(255, 203, 119, 0.32);
    --rp-coral-tint: rgba(254, 109, 115, 0.14);
    --rp-mint-deep: #0e8a7d;
    --rp-yellow-deep: #a06a15;
    --rp-coral-deep: #e0474e;
}

.rp-top {
    flex: 0 0 auto;
    width: 100%;
}

.rp-page-head {
    text-align: center;
    margin: 2px 0 14px;
}

.rp-eyebrow {
    margin: 0 0 4px;
    font-family: var(--font-head);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--rp-coral);
    font-weight: 600;
}

.rp-title {
    margin: 0 0 4px;
    font-family: var(--font-head);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--rp-teal);
}

.rp-desc {
    margin: 0;
    font-size: 0.88rem;
    color: var(--c-navy-soft);
}

/* [PDF 입력 | PDF 목록] 좌우 2열 — 카드 폭을 화면 끝까지 쓴다 */
.rp-cards {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 14px;
    align-items: stretch;
    margin-bottom: 16px;
}

.rp-card {
    border: 1px solid var(--rp-teal-line);
    border-radius: 12px;
    background: var(--rp-cream);
    padding: 14px 16px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.rp-card-title {
    margin: 0 0 10px;
    font-family: var(--font-head);
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--rp-teal);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.rp-card-title-left {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.rp-card-hint {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--rp-yellow-deep);
    background: var(--rp-yellow-tint);
    border-radius: 999px;
    padding: 3px 10px;
    white-space: nowrap;
}

.rp-picker-btn {
    border: 1px solid var(--rp-mint);
    background: var(--rp-mint);
    color: #fff;
    border-radius: 4px;
    padding: 5px 12px;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
}

.rp-picker-btn:hover {
    background: #fff;
    color: var(--rp-mint-deep);
}

/* ---------- 업로드 드롭존 (좁게) + 오른쪽 불러오기 버튼 ---------- */

.rp-upload-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
    flex-wrap: wrap;
    flex: 1 1 auto;
}

.rp-upload-col {
    flex: 1 1 42%;
    min-width: 190px;
    max-width: 100%;
}

.rp-import-col {
    flex: 1 1 52%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
}

.rp-dropzone {
    height: 100%;
    box-sizing: border-box;
    border: 2px dashed var(--rp-mint);
    border-radius: 10px;
    background: #fff;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.rp-dropzone:hover,
.rp-dropzone:focus-visible {
    border-color: var(--rp-teal);
    background: var(--rp-mint-tint);
    outline: none;
}

.rp-dropzone.is-dragover {
    border-color: var(--rp-coral);
    background: var(--rp-yellow-tint);
}

.rp-dropzone.is-busy {
    opacity: 0.6;
    pointer-events: none;
}

.rp-dropzone-icon {
    width: 26px;
    height: 26px;
    margin: 0 auto 6px;
    display: block;
}

.rp-dropzone-title {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--rp-teal);
}

.rp-hidden-file-input {
    display: none;
}

.rp-status {
    margin-top: 8px;
    min-height: 16px;
    font-size: 0.78rem;
    color: var(--c-navy-soft);
}

.rp-status.is-error {
    color: var(--rp-coral-deep);
}

.rp-status.is-success {
    color: var(--rp-mint-deep);
}

/* ---------- 외부 논문 목록 불러오기 버튼 ---------- */

.rp-import-btn {
    border: 1px solid var(--rp-teal);
    background: #fff;
    color: var(--rp-teal);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.rp-import-btn:hover {
    background: var(--rp-teal);
    color: #fff;
}

/* ---------- PDF 목록 (현재 불러온 1건만 표시) ---------- */

.rp-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    /* 열을 안 정하면 트랙이 nowrap 제목의 min-content 폭으로 자라
       행이 카드 밖으로 뻗는다(뷰어 헤더와 같은 함정). 카드 폭에 가둔다. */
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    /* 우측 카드 폭 전체를 쓴다 */
    flex: 1 1 auto;
    align-content: center;
}

.rp-list-empty {
    border: 1px dashed var(--rp-mint);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    color: var(--c-navy-soft);
    background: var(--rp-mint-tint);
    font-size: 0.84rem;
}

.rp-list-item {
    border: 1px solid var(--rp-teal-line);
    border-radius: 8px;
    background: #fff;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    /* 그리드 아이템의 min-width:auto가 nowrap 제목의 min-content를 물고
       트랙 밖으로 넘치는 것을 막는다 (min-width:0이어야 트랙 폭으로 수축) */
    min-width: 0;
}

.rp-item-main {
    flex: 1 1 200px;
    min-width: 0;
}

.rp-item-title {
    font-weight: 700;
    color: var(--rp-teal);
    font-size: 0.9rem;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rp-item-meta {
    font-size: 0.74rem;
    color: var(--c-navy-soft);
    /* 파일명이 길어도 한 줄로 끝낸다: 파일명 span만 줄어들며 말줄임 */
    display: flex;
    align-items: baseline;
    gap: 4px;
    min-width: 0;
    white-space: nowrap;
}

.rp-item-meta-file {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rp-item-meta-rest {
    flex: 0 0 auto;
}

.rp-item-actions {
    /* 피커 모달: 제목 오른쪽에 버튼 (메인 목록은 아래에서 제목 밑 가로 나열로 덮어씀) */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.rp-item-actions-row {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}

/* 메인 PDF 목록: 제목·메타 아래 한 줄에 배지+버튼 전부 나열.
   column에서 wrap이 남아 있으면 stretch가 컨테이너 폭이 아니라 라인 콘텐츠 폭
   (nowrap 제목)으로 늘어나 행이 또 터진다 — 반드시 nowrap. */
.rp-list .rp-list-item {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 7px;
}

.rp-list .rp-item-main {
    flex: 0 0 auto;
}

.rp-list .rp-item-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
}

.rp-badge {
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 3px 9px;
    white-space: nowrap;
}

.rp-badge.state-completed {
    background: var(--rp-mint-tint);
    color: var(--rp-mint-deep);
}

.rp-badge.state-running,
.rp-badge.state-queued {
    background: var(--rp-yellow-tint);
    color: var(--rp-yellow-deep);
}

.rp-badge.state-failed,
.rp-badge.state-unknown {
    background: var(--rp-coral-tint);
    color: var(--rp-coral-deep);
}

.rp-item-btn {
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--rp-teal);
    background: var(--rp-teal);
    color: #fff;
}

.rp-item-btn:hover:not(:disabled) {
    background: #fff;
    color: var(--rp-teal);
}

.rp-item-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.rp-item-btn.rp-item-delete {
    border-color: var(--rp-coral);
    background: #fff;
    color: var(--rp-coral-deep);
}

.rp-item-btn.rp-item-delete:hover:not(:disabled) {
    background: var(--rp-coral);
    color: #fff;
}

.rp-item-btn.rp-item-pages {
    border-color: var(--rp-yellow);
    background: var(--rp-yellow);
    color: var(--rp-yellow-deep);
}

.rp-item-btn.rp-item-pages:hover:not(:disabled) {
    background: #fff;
}

/* ---------- 인용 제거 토글 (영어 카드, 번역 버튼 왼쪽) ---------- */

.rp-cite-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    /* .panel-action-buttons 의 gap: 8px 가 간격을 잡는다 */
    font-size: 12px;
    font-weight: 600;
    color: var(--c-navy-soft);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.rp-cite-toggle input {
    width: 13px;
    height: 13px;
    accent-color: var(--c-orange);
    cursor: pointer;
    margin: 0;
}

/* ============================================================
   목록 불러오기 모달
   ============================================================ */

.rp-picker-modal {
    position: fixed;
    inset: 0;
    z-index: 3300;
    background: rgba(31, 35, 51, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.rp-picker-modal.open {
    display: flex;
}

.rp-picker-card {
    width: min(94vw, 820px);
    max-height: min(88vh, 760px);
    background: var(--c-cream-light);
    border: 1px solid var(--c-line);
    border-radius: 10px;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}

.rp-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--c-line);
    padding: 14px 18px;
}

.rp-picker-title {
    margin: 0;
    font-family: var(--font-head);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--c-navy);
}

.rp-picker-close {
    border: 0;
    background: transparent;
    color: var(--c-navy);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.rp-picker-body {
    overflow: auto;
    padding: 14px 18px 18px;
}

.rp-picker-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
}

.rp-list-item.is-current {
    border-color: var(--rp-mint);
    background: var(--rp-mint-tint);
}

/* ============================================================
   페이지 이미지 뷰어 — 모달리스 플로팅 창
   배경 오버레이를 두지 않아 창 밖 영역(독해·번역)이 계속 살아 있다.
   z-index는 헤더(2500) 위, 사이드 패널(3000)·모달(3300) 아래.
   ============================================================ */

.rp-viewer {
    position: fixed;
    top: 90px;
    left: 60px;
    z-index: 2900;
    width: min(92vw, 520px);
    height: min(80vh, 660px);
    min-width: 320px;
    min-height: 260px;
    /* 크기 조절이 getBoundingClientRect(테두리 포함) 기준으로 계산되므로
       테두리를 포함하는 border-box여야 최소치·화면 경계가 정확히 맞는다. */
    box-sizing: border-box;
    background: var(--c-cream-light);
    border: 1px solid var(--c-line);
    border-radius: 10px;
    box-shadow: 0 18px 44px rgba(31, 35, 51, 0.26);
    display: none;
    grid-template-rows: auto 1fr auto;
    /* 열을 안 정하면 헤더 행이 nowrap 제목의 min-content 폭만큼 자라
       창 밖으로 뻗고 X 버튼이 클리핑돼 사라진다(실제로 겪음). 트랙을 창 폭에 가둔다. */
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
}

.rp-viewer.open {
    display: grid;
}

.rp-viewer-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    background: var(--c-navy);
    color: #fff;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.rp-viewer.is-dragging .rp-viewer-head {
    cursor: grabbing;
}

.rp-viewer-grip {
    font-size: 14px;
    opacity: 0.75;
    letter-spacing: -2px;
}

.rp-viewer-title {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--font-head);
    font-size: 0.86rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rp-viewer-close {
    /* 제목이 아무리 길어도 X는 줄어들거나 밀려나면 안 된다 */
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

.rp-viewer-body {
    overflow: auto;
    background: #EDE7DA;
    padding: 10px;
    box-sizing: border-box;
    /* 페이지를 손으로 잡고 끌어 움직인다 */
    cursor: grab;
    overscroll-behavior: contain;
}

.rp-viewer-body.is-panning {
    cursor: grabbing;
}

/* 회전을 위해 이미지를 무대(stage) 안에 절대배치한다.
   transform: rotate()는 레이아웃 크기를 바꾸지 않으므로, 90°/270°에서는 JS가
   무대의 가로·세로를 뒤바꿔 스크롤 범위를 맞춰준다. 크기는 전부 JS가 px로 넣는다. */
.rp-viewer-stage {
    position: relative;
    margin: 0 auto;
}

.rp-viewer-img {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    /* JS가 px로 덮어쓴다. 배치 전(무대 크기 0)에 원본 크기로 잠깐 튀는 것을 막는 초기값. */
    width: 100%;
    height: auto;
    max-width: none;
    transform-origin: center center;
    background: #fff;
    box-shadow: 0 2px 10px rgba(31, 35, 51, 0.14);
    /* 끌 때 이미지가 통째로 드래그되거나 선택되면 안 된다 */
    user-select: none;
    -webkit-user-drag: none;
}

.rp-viewer-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    /* 오른쪽 아래 크기 조절 손잡이와 겹치지 않도록 여백 */
    padding: 8px 22px 8px 12px;
    border-top: 1px solid var(--c-line);
    background: var(--c-cream-light);
    flex-wrap: wrap;
}

/* 모서리·변 크기 조절 손잡이 — 시각 그립 무늬는 오른쪽 아래에만 둔다 */
.rp-viewer-rs {
    position: absolute;
    width: 15px;
    height: 15px;
    touch-action: none;
    z-index: 5;
}

.rp-viewer-rs-nw { top: 0; left: 0; cursor: nwse-resize; }
.rp-viewer-rs-ne { top: 0; right: 0; cursor: nesw-resize; }
.rp-viewer-rs-sw { bottom: 0; left: 0; cursor: nesw-resize; }

.rp-viewer-rs-se {
    bottom: 0;
    right: 0;
    cursor: nwse-resize;
    width: 18px;
    height: 18px;
    background:
        linear-gradient(135deg, transparent 0 46%, var(--c-navy-soft) 46% 54%, transparent 54% 100%),
        linear-gradient(135deg, transparent 0 70%, var(--c-navy-soft) 70% 78%, transparent 78% 100%);
    opacity: 0.55;
}

.rp-viewer-rs-se:hover {
    opacity: 0.9;
}

/* 변 손잡이 — 모서리 손잡이 영역(15px, se는 18px)을 비워두고 그 사이를 채운다 */
.rp-viewer-rs-n { top: 0; left: 15px; right: 15px; width: auto; height: 7px; cursor: ns-resize; }
.rp-viewer-rs-s { bottom: 0; left: 15px; right: 18px; width: auto; height: 7px; cursor: ns-resize; }
.rp-viewer-rs-w { left: 0; top: 15px; bottom: 15px; width: 7px; height: auto; cursor: ew-resize; }
.rp-viewer-rs-e { right: 0; top: 15px; bottom: 18px; width: 7px; height: auto; cursor: ew-resize; }

/* 탭 접기 — 상단 바만 남기고 접는 알약 버튼 (독해창 접어두기와 같은 모양) */
.rp-viewer-fold {
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.65);
    background: transparent;
    color: #fff;
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
}

.rp-viewer-fold:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* 접힌 상태 — height:auto!important가 인라인 height(px)를 눌러 바 높이만 남긴다.
   펴면 클래스만 제거해도 인라인 height가 되살아난다. */
.rp-viewer.collapsed-top {
    height: auto !important;
    min-height: 0;
    grid-template-rows: auto;
}

.rp-viewer.collapsed-top .rp-viewer-body,
.rp-viewer.collapsed-top .rp-viewer-foot,
.rp-viewer.collapsed-top .rp-viewer-rs {
    display: none;
}

.rp-viewer-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* display:flex가 hidden 속성(UA display:none)을 이겨버려 pages 모드에도
   AI 전용 그룹(원본 보기·삭제)이 보였다. hidden을 명시적으로 복원한다. */
.rp-viewer-group[hidden] {
    display: none;
}

.rp-viewer-btn {
    min-width: 28px;
    height: 26px;
    border: 1px solid var(--c-line);
    background: #fff;
    color: var(--c-navy);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.rp-viewer-btn-wide {
    min-width: 44px;
}

.rp-viewer-btn:hover:not(:disabled) {
    background: var(--c-tint);
}

.rp-viewer-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.rp-viewer-info {
    min-width: 56px;
    text-align: center;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--c-navy-soft);
    white-space: nowrap;
}

.rp-viewer-btn-danger {
    border-color: #C0392B;
    color: #C0392B;
}

/* 하단 '창 닫기' — 헤더 X와 같은 역할의 보조 닫기 버튼 */
.rp-viewer-btn-close {
    border-color: var(--rp-coral);
    color: var(--rp-coral-deep);
    font-weight: 700;
}

.rp-viewer-btn-close:hover:not(:disabled) {
    background: var(--rp-coral);
    color: #fff;
}

/* AI변환 이미지 뷰어는 추출 모달(3300) 위에도 떠야 한다 —
   변환 직후 모달을 닫지 않고 결과를 바로 확인할 수 있게. */
.rp-viewer.rp-viewer-topmost {
    z-index: 3400;
}

/* ============================================================
   모달 확장 — 이미지 영역 지정(드래그) / AI 텍스트 추출
   ============================================================ */

/* 드래그 중 임시 사각형 + 확정된 선택 영역. 페이지 이미지 위에 얹힌다. */
.rp-select-rect,
.rp-selection-fixed {
    position: absolute;
    display: none;
    pointer-events: none;
    z-index: 5;
}

.rp-select-rect {
    border: 1.5px dashed var(--c-orange);
    background: rgba(240, 136, 62, 0.12);
}

.rp-selection-fixed {
    border: 2px solid var(--c-orange);
    background: rgba(240, 136, 62, 0.16);
}

/* 영역 지정 모드(텍스트 추출·해석&재구성 공용)에서는 블록 오버레이가 드래그를 가로채면 안 된다. */
.mode-capture .txm-overlay-box,
.mode-reinterpret .txm-overlay-box {
    pointer-events: none;
    opacity: 0;
}

.mode-capture .txm-page-overlay-wrap,
.mode-reinterpret .txm-page-overlay-wrap {
    cursor: crosshair;
}

/* 이미지 해석&재구성 버튼 — 초록 계열로 구분 */
.rp-reinterpret-btn {
    border-color: #2E7D5B;
    background: #2E7D5B;
}

.rp-reinterpret-btn.active {
    background: #fff;
    color: #2E7D5B;
    border-color: #2E7D5B;
}

/* 오른쪽 패널 */
.rp-model-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.rp-model-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--c-navy-soft);
    white-space: nowrap;
}

.rp-model-select {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 11px;
    padding: 4px 6px;
    border: 1px solid var(--c-line);
    border-radius: 4px;
    background: #fff;
    color: var(--c-navy);
}

.rp-area-btn {
    border-color: var(--c-orange);
    background: var(--c-orange);
}

.rp-area-btn.active {
    background: #fff;
    color: var(--c-orange);
    border-color: var(--c-orange);
}

/* 캡쳐 카드 출처 배지 (블록 지정 / AI 추출 구분) */
.rp-source-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    border-radius: 999px;
    padding: 2px 7px;
    margin-left: 6px;
    vertical-align: middle;
}

.rp-source-badge.source-block {
    background: var(--c-tint);
    color: #1f5ea6;
}

.rp-source-badge.source-ai {
    background: #FDEBDC;
    color: #B65A18;
}

/* 이미지 추출 모달 — 캡쳐 카드 */
.rp-cap-thumb {
    display: block;
    width: 100%;
    border: 1px solid var(--c-line);
    border-radius: 4px;
    background: #fff;
    margin-bottom: 6px;
}

.rp-cap-ai-btn {
    border-color: #2E7D5B !important;
    background: #2E7D5B !important;
}

/* AI 추출 진행 중 오버레이 — 모달 본문 전체를 덮는다 */
.txm-body {
    position: relative;
}

.rp-ocr-busy {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(252, 250, 244, 0.78);
    border-radius: 8px;
}

.rp-ocr-busy.open {
    display: flex;
}

.rp-ocr-busy-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid var(--c-line);
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: 0 10px 24px rgba(31, 35, 51, 0.12);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--c-navy);
}

.rp-ocr-busy-spinner {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 3px solid rgba(58, 110, 164, 0.18);
    border-top-color: var(--c-orange);
    animation: txm-spin 0.8s linear infinite;
}

@media (max-width: 980px) {
    /* 좁은 화면에서는 카드 2열을 포기하고 위아래로 쌓는다 */
    .rp-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .rp-picker-list .rp-item-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* 좁은 화면에서는 드롭존이 한 줄을 다 쓰고 불러오기 버튼이 그 아래로 내려간다 */
    .rp-upload-col {
        flex: 1 1 100%;
    }
}

@media (max-width: 600px) {
    .rp-viewer {
        width: calc(100vw - 20px);
        height: min(70vh, 520px);
        left: 10px;
    }
}
/* ============================================================
   인라인 작업대 / 플로팅 독해창 (구 readpaper_v2.css — A/B 종료로 병합)
   - rp-inline-workspace : 텍스트 추출(#rpBlockModal)을 인라인 카드로
   - rp-reader-win       : 영어/한국어 번역기를 담는 플로팅 독해창
   - z-index 조정        : 독해창(2950) 때문에 단어 뜻 팝업을 2980으로 올린다
   기획서: docs/steng/논문독해학습툴-v2기획.md
   ============================================================ */

/* ============================================================
   인라인 텍스트 추출 작업대
   ============================================================ */

.rp-ws-placeholder {
    border: 1px dashed var(--rp-mint);
    border-radius: 10px;
    background: var(--rp-mint-tint);
    color: var(--c-navy-soft);
    text-align: center;
    padding: 26px 16px;
    font-size: 0.88rem;
    margin-bottom: 16px;
}

/* display를 가진 규칙이 hidden 속성(UA display:none)을 이기는 함정 방지 */
.rp-ws-placeholder[hidden] {
    display: none;
}

/* v1의 .txm-modal(fixed 오버레이) 자리 — 여기서는 흐름 안의 카드다.
   내부(.txm-header/.txm-body/txm-pages/...)는 textract.css 것을 그대로 쓴다. */
.rp-inline-workspace {
    display: none;
    border: 1px solid var(--rp-teal-line);
    border-radius: 12px;
    background: var(--c-cream-light);
    overflow: hidden;
    margin-bottom: 16px;
}

.rp-inline-workspace.open {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: minmax(0, 1fr);
}

/* 모달은 콘텐츠 래퍼가 높이를 줬지만 인라인은 여기서 직접 준다.
   왼쪽 페이지 열은 내부 스크롤 → 오른쪽 도구 패널이 항상 시야에 있다. */
.rp-inline-workspace .txm-body {
    height: min(78vh, 900px);
}

/* 헤더: 제목 | 줌 컨트롤 | 닫기 — 제목이 길면 말줄임으로 컨트롤 자리를 지킨다 */
.rp-inline-workspace .txm-header {
    gap: 12px;
}

.rp-inline-workspace .txm-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rp-ws-zoom {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rp-ws-zoom-btn {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--c-line);
    border-radius: 4px;
    background: #fff;
    color: var(--c-navy);
    font-size: 12px;
    cursor: pointer;
}

.rp-ws-zoom-btn:hover:not(:disabled) {
    background: var(--c-tint);
}

.rp-ws-zoom-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.rp-ws-zoom-slider {
    width: 120px;
    accent-color: var(--rp-teal);
    cursor: pointer;
}

.rp-ws-zoom-val {
    min-width: 42px;
    text-align: right;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--c-navy-soft);
}

/* 확대/축소 본체 — 오버레이 블록·드래그 선택이 전부 % 좌표라 래퍼 폭만 키우면 따라온다.
   100% 초과분은 .txm-pages(overflow:auto)의 가로 스크롤로 본다. */
.rp-inline-workspace .txm-page-overlay-wrap {
    width: calc(90% * var(--rp-ws-scale, 1));
}

/* ============================================================
   플로팅 독해창
   z-index 2950 = 페이지 이미지 뷰어(2900) 위, 단어 뜻 팝업(2980)·
   구문분석 사이드패널(3000)·숙어(3200)·추출TEXT(3300)·AI 뷰어(3400) 아래.
   ============================================================ */

.rp-reader-win {
    position: fixed;
    top: 80px;
    left: 120px;
    z-index: 2950;
    width: min(94vw, 900px);
    height: min(82vh, 620px);
    min-width: 720px;
    min-height: 420px;
    /* 리사이즈가 getBoundingClientRect(테두리 포함) 기준 — border-box 필수 */
    box-sizing: border-box;
    background: var(--c-cream-light);
    border: 1px solid var(--c-line);
    border-radius: 10px;
    box-shadow: 0 18px 44px rgba(31, 35, 51, 0.26);
    display: none;
    grid-template-rows: auto 1fr auto;
    /* 열 없는 grid의 auto 트랙 폭주 함정 방지 */
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
}

.rp-reader-win.open {
    display: grid;
}

.rp-reader-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    background: var(--rp-teal);
    color: #fff;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.rp-reader-win.is-dragging .rp-reader-head {
    cursor: grabbing;
}

.rp-reader-title {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--font-head);
    font-size: 0.86rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rp-reader-body {
    overflow: auto;
    background: var(--c-cream);
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    min-height: 0;
}

/* 번역기(.container/#simpleReadRoot)를 창 크기에 맞춘다 */
.rp-reader-body .container {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    max-width: none;
    background: transparent;
}

.rp-reader-body .study-view {
    min-height: 0;
    gap: 12px;
}

.rp-reader-body .panel {
    padding: 14px;
    font-size: 15px;
}

/* 창 높이가 고정이라 마지막 줄이 경계에 걸려 잘려 보이는 일이 있다 —
   영어/한국어 스크롤 영역 맨 아래에 두 줄(line-height 1.7 × 2) 여백을 확보 */
.rp-reader-body .content-box {
    padding-bottom: 3.4em;
}

/* 창 폭이 페이지보다 좁아 뷰포트 기준 미디어쿼리가 안 먹는다 —
   버튼이 세로로 찌그러지는 대신 다음 줄로 흐르게 한다 */
.rp-reader-body .panel-title {
    flex-wrap: wrap;
    row-gap: 6px;
}

.rp-reader-body .panel-title-text {
    white-space: nowrap;
}

.rp-reader-body .panel-action-buttons {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.rp-reader-foot {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* 오른쪽 아래 크기 조절 손잡이와 겹치지 않게 여백 */
    padding: 8px 22px 8px 12px;
    border-top: 1px solid var(--c-line);
    background: var(--c-cream-light);
    /* 하단 바만 남긴 상태에서는 이 바를 잡고 끌어 옮긴다 */
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.rp-reader-win.is-dragging .rp-reader-foot {
    cursor: grabbing;
}

.rp-reader-foot button {
    cursor: pointer;
}

/* ---------- 모서리·변 크기 조절 손잡이 ---------- */

.rp-reader-rs {
    position: absolute;
    width: 15px;
    height: 15px;
    touch-action: none;
    z-index: 5;
}

.rp-reader-rs-nw { top: 0; left: 0; cursor: nwse-resize; }
.rp-reader-rs-ne { top: 0; right: 0; cursor: nesw-resize; }
.rp-reader-rs-sw { bottom: 0; left: 0; cursor: nesw-resize; }

.rp-reader-rs-se {
    bottom: 0;
    right: 0;
    cursor: nwse-resize;
    width: 18px;
    height: 18px;
    /* 뷰어와 같은 그립 무늬 — 시각 표시는 오른쪽 아래에만 둔다 */
    background:
        linear-gradient(135deg, transparent 0 46%, var(--c-navy-soft) 46% 54%, transparent 54% 100%),
        linear-gradient(135deg, transparent 0 70%, var(--c-navy-soft) 70% 78%, transparent 78% 100%);
    opacity: 0.55;
}

.rp-reader-rs-se:hover {
    opacity: 0.9;
}

/* 변 손잡이 — 모서리 손잡이 영역(15px, se는 18px)을 비워두고 그 사이를 채운다.
   기본 규칙의 15px 고정 크기를 auto로 풀어 변 전체로 늘린다. */
.rp-reader-rs-n { top: 0; left: 15px; right: 15px; width: auto; height: 7px; cursor: ns-resize; }
.rp-reader-rs-s { bottom: 0; left: 15px; right: 18px; width: auto; height: 7px; cursor: ns-resize; }
.rp-reader-rs-w { left: 0; top: 15px; bottom: 15px; width: 7px; height: auto; cursor: ew-resize; }
.rp-reader-rs-e { right: 0; top: 15px; bottom: 18px; width: 7px; height: auto; cursor: ew-resize; }

/* ---------- 접어두기 (상단/하단 바만 남기기) ---------- */

.rp-reader-head {
    position: relative;
}

/* 바 중앙에 고정 — 제목 길이와 무관하게 항상 정중앙 */
.rp-reader-fold {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border: 1px solid rgba(255, 255, 255, 0.65);
    background: transparent;
    color: #fff;
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
}

.rp-reader-fold:hover {
    background: rgba(255, 255, 255, 0.18);
}

.rp-reader-fold-bottom {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* 접힌 상태 — height:auto!important가 인라인 height(px)를 눌러
   바 높이만 남긴다. 펼치면 클래스만 제거해도 인라인 height가 되살아난다. */
.rp-reader-win.collapsed-top,
.rp-reader-win.collapsed-bottom {
    height: auto !important;
    min-height: 0;
    grid-template-rows: auto;
}

.rp-reader-win.collapsed-top .rp-reader-body,
.rp-reader-win.collapsed-top .rp-reader-foot,
.rp-reader-win.collapsed-bottom .rp-reader-head,
.rp-reader-win.collapsed-bottom .rp-reader-body,
.rp-reader-win.collapsed-top .rp-reader-rs,
.rp-reader-win.collapsed-bottom .rp-reader-rs {
    display: none;
}

/* 단어 뜻 팝업(기본 2600)이 독해창(2950) 뒤에 숨지 않게 올린다.
   사이드패널(3000) 아래를 유지해 기존 겹침 순서는 보존. */
#definition-popup {
    z-index: 2980;
}

/* PDF 목록 카드의 '독해창 열기' — 목록 불러오기(mint)와 구분되는 teal */
.rp-reader-open-btn {
    border-color: var(--rp-teal);
    background: var(--rp-teal);
}

.rp-reader-open-btn:hover {
    background: #fff;
    color: var(--rp-teal);
}
