/* Layout primitives */
html, body { height: 100%; }
body { overflow: hidden; font-size: 14px; }

.app-main {
    height: calc(100vh - 56px);
    overflow: auto;
    position: relative;
}

/* Review page grid
 *
 * The layout chain is:
 *   .app-main  (fixed viewport height)
 *     .review-wrapper       — 3-col grid
 *       .review-centre      — 2-col grid (QP | MS)
 *         .pdf-pane         — flex column: toolbar + scroll area
 *           .pdf-scroll     — the element that actually scrolls
 *
 * For .pdf-scroll to be scrollable, every ancestor cell along the chain
 * must be prevented from auto-sizing to its content. Both grid items and
 * flex items default to min-height: auto / min-width: auto, which causes
 * them to grow to fit the PDF instead of clipping to the viewport — so
 * we have to explicitly set them to 0 at each level.
 */
.review-wrapper {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 320px;
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    overflow: hidden;
}

.review-left,
.review-right {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.review-centre {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.pdf-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid #dee2e6;
}
.review-centre .pdf-pane:last-child { border-right: none; }

.pdf-toolbar {
    display: flex;
    align-items: center;
    gap: .25rem;
    padding: .35rem .5rem;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    flex-shrink: 0;
}

.pdf-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    background: #525659;
    padding: 10px;
    outline: none;
}

.pdf-page {
    position: relative;
    margin: 0 auto 10px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
    /* The canvas is positioned absolutely inside. */
}

.pdf-page canvas { display: block; }

.pdf-page .overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* A single boundary marker — horizontal line across the page. */
.marker-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    border-top: 2px solid;
    pointer-events: none;
}
.marker-line.start  { border-color: #0d6efd; }
.marker-line.end    { border-color: #dc3545; }
.marker-line.start::before,
.marker-line.end::before {
    content: attr(data-label);
    position: absolute;
    top: -18px;
    left: 4px;
    font-size: 11px;
    padding: 1px 5px;
    color: white;
    background: inherit;
    border-radius: 3px;
}
.marker-line.start { background: transparent; }
.marker-line.start::before { background: #0d6efd; }
.marker-line.end::before   { background: #dc3545; }

/* Cursor while in "marking" mode */
.pdf-scroll.marking,
.pdf-scroll.marking * { cursor: crosshair !important; }

/* Question list */
.question-list {
    flex: 1;
    overflow-y: auto;
}
.question-list .q-item {
    padding: .5rem .75rem;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}
.question-list .q-item:hover   { background: #f5f7fa; }
.question-list .q-item.active  { background: #cfe2ff; }
.question-list .q-item .q-meta { color: #6c757d; font-size: 12px; }
.question-list .q-item button[data-add-part] {
    font-size: 11px;
    text-decoration: none;
}

.marker-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: .25rem .5rem;
    align-items: center;
}

/* Question Bank viewer — three-pane layout.
 *
 * Columns share the viewport as 20% / 30% / 50% so the preview pane
 * always occupies half the screen. The filter column has a 240px
 * minimum so it stays usable on smaller displays — at narrow widths the
 * list and preview absorb the extra space in a 1.5 : 2.5 ratio.
 */
.viewer-wrapper {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(0, 1.5fr) minmax(0, 2.5fr);
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    overflow: hidden;
}
.viewer-left,
.viewer-right {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.viewer-centre {
    overflow-y: auto;
    min-height: 0;
    padding: 1rem;
    background: #f5f7fa;
}
.viewer-filter-heading {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: #6c757d;
    letter-spacing: .03em;
    margin-bottom: .25rem;
}

/* Topic facet list */
.topic-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 240px;
    overflow-y: auto;
}
.topic-list .topic-item {
    display: flex;
    align-items: center;
    padding: .3rem .5rem;
    border-radius: .25rem;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.2;
}
.topic-list .topic-item:hover  { background: #eef4ff; }
.topic-list .topic-item.active { background: #0d6efd; color: white; }
.topic-list .topic-item.active .topic-count { background: rgba(255,255,255,.25); color: white; }
.topic-list .topic-name { flex: 1; }
.topic-list .topic-count {
    font-size: 11px;
    background: #e9ecef;
    color: #495057;
    border-radius: .75rem;
    padding: 1px 7px;
    min-width: 22px;
    text-align: center;
}
.topic-list .topic-item.zero .topic-name  { color: #adb5bd; }
.topic-list .topic-item.zero .topic-count { opacity: .5; }

/* Question cards in the centre list */
.question-card {
    display: flex;
    align-items: flex-start;
    background: white;
    border: 1px solid #e3e6ea;
    border-left: 3px solid transparent;
    border-radius: .375rem;
    padding: .6rem .75rem;
    margin-bottom: .5rem;
    cursor: pointer;
    transition: background-color .1s, border-color .1s;
}
.question-card:hover { background: #f8fbff; }
.question-card.active {
    border-color: #0d6efd;
    border-left-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13,110,253,.12);
}
.question-card .q-check {
    margin: 2px 10px 0 0;
}
.question-card .q-main { flex: 1; min-width: 0; }
.question-card .q-head {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: 2px;
}
.question-card .q-label   { font-weight: 600; }
.question-card .q-marks   { font-size: 12px; color: #6c757d; }
.question-card .q-session { font-size: 12px; color: #6c757d; margin-left: auto; }
.question-card .q-topic {
    display: inline-block;
    font-size: 11px;
    background: #e7f1ff;
    color: #0a58ca;
    padding: 1px 7px;
    border-radius: .75rem;
    margin-right: .35rem;
}
.question-card .q-excerpt {
    color: #6c757d;
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Preview pane */
#preview-pane { padding: 0; }
.preview-section + .preview-section { border-top: 1px solid #e3e6ea; }
.preview-section-head {
    padding: .4rem .75rem;
    background: #f8f9fa;
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    border-bottom: 1px solid #e3e6ea;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.preview-scroll {
    max-height: 40vh;
    overflow: auto;
    background: #525659;
    padding: .5rem;
}
.preview-scroll .pdf-page-box {
    position: relative;
    margin: 0 auto .5rem;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.preview-scroll .pdf-page-box canvas { display: block; }

/* Exam index sortable headers */
#exams-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
#exams-table th.sortable:hover { background: #e9ecef; }
#exams-table th.sortable.active { color: #0d6efd; }

/* Upload page drop zone */
.drop-zone {
    position: relative;
    border: 2px dashed #adb5bd;
    border-radius: .5rem;
    background: #f8f9fa;
    padding: 2.25rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
}
.drop-zone:hover,
.drop-zone:focus {
    border-color: #0d6efd;
    background: #eef4ff;
    outline: none;
}
.drop-zone.is-drag-over {
    border-color: #0d6efd;
    background: #dbe7ff;
}
.drop-zone .drop-zone-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: .5rem;
    color: #6c757d;
}
#staged-list .file-ok   { color: #198754; }
#staged-list .file-bad  { color: #dc3545; }
#staged-list li { padding: .25rem .5rem; }
