* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
    background: #f5f6f8;
    color: #1a202c;
}
a { color: inherit; text-decoration: none; }

.topbar {
    background: #1a365d;
    color: white;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 32px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.topbar .brand a { font-weight: 700; font-size: 18px; }
.topbar nav { display: flex; gap: 16px; }
.topbar nav a {
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.15s;
    font-size: 14px;
}
.topbar nav a:hover { background: rgba(255,255,255,0.15); }

main { padding: 0; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #cbd5e0;
    color: #2d3748;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.15s;
    user-select: none;
}
.btn:hover { background: #f7fafc; border-color: #a0aec0; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: #2b6cb0; color: white; border-color: #2b6cb0; }
.btn.primary:hover { background: #2c5282; }
.btn.danger { background: #c53030; color: white; border-color: #c53030; }
.btn.danger:hover { background: #9b2c2c; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.file-input { display: inline-block; cursor: pointer; }

.upload-card {
    background: white;
    padding: 16px 20px;
    border-radius: 8px;
    margin-bottom: 24px;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.status-text { color: #4a5568; font-size: 14px; }

.pdf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.pdf-card-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
}
.pdf-card-wrap .pdf-card {
    display: flex;
    border-radius: 10px 10px 0 0;
}
.pdf-card-wrap .pdf-card:only-child,
.pdf-card-wrap:not(:has(.answer-sheet-section)) .pdf-card {
    border-radius: 10px;
}
.pdf-delete-btn,
.pdf-rename-btn,
.pdf-share-btn {
    position: absolute;
    top: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: rgba(255,255,255,0.92);
    color: #718096;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s, border-color 0.15s;
    z-index: 2;
}
.pdf-delete-btn { right: 6px; }
.pdf-rename-btn { right: 38px; }
.pdf-share-btn { right: 70px; }
.pdf-card-wrap:hover .pdf-delete-btn,
.pdf-card-wrap:hover .pdf-rename-btn,
.pdf-card-wrap:hover .pdf-share-btn,
.pdf-delete-btn:focus,
.pdf-rename-btn:focus,
.pdf-share-btn:focus { opacity: 1; }
.pdf-delete-btn:hover {
    background: #fed7d7;
    color: #9b2c2c;
    border-color: #fc8181;
}
.pdf-rename-btn:hover {
    background: #bee3f8;
    color: #2c5282;
    border-color: #63b3ed;
}
.pdf-share-btn:hover {
    background: #c6f6d5;
    color: #22543d;
    border-color: #9ae6b4;
}
@media (hover: none) {
    .pdf-delete-btn,
    .pdf-rename-btn,
    .pdf-share-btn { opacity: 1; }
}
.pdf-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
}
.pdf-card:hover {
    border-color: #2b6cb0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.pdf-icon { font-size: 40px; }
.pdf-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.pdf-stats { display: flex; justify-content: center; }
.pdf-last { font-size: 11px; color: #718096; }
.pdf-action { font-size: 12px; color: #2b6cb0; margin-top: 4px; }
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    background: #c6f6d5;
    color: #22543d;
    font-size: 11px;
    font-weight: 600;
}
.badge.muted { background: #edf2f7; color: #718096; }
.empty { padding: 40px; color: #718096; text-align: center; grid-column: 1 / -1; }

/* === Answer sheets === */
.answer-upload-panel {
    flex: 1 1 100%;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
}
.answer-upload-title {
    font-size: 13px;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 8px;
}
.answer-upload-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.answer-upload-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.answer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background: #f7fafc;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #edf2f7;
}
.answer-type-select {
    padding: 4px 8px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 13px;
    background: white;
}
.answer-file-label {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}
.answer-file-name {
    font-size: 12px;
    color: #718096;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.answer-row-remove,
.answer-delete-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #a0aec0;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    border-radius: 4px;
    flex-shrink: 0;
}
.btn-view-answers:disabled,
.btn-apply-answers:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.btn-extract-objective {
    border: 1px solid #805ad5;
    background: #faf5ff;
    color: #553c9a;
}
.btn-extract-objective:hover { background: #805ad5; color: white; }
.btn-view-answers {
    border: 1px solid #2b6cb0;
    background: #ebf8ff;
    color: #2c5282;
}
.btn-view-answers:hover { background: #2b6cb0; color: white; }
.btn-apply-answers {
    border: 1px solid #38a169;
    background: #c6f6d5;
    color: #22543d;
}
.btn-apply-answers:hover { background: #38a169; color: white; }
.answers-view-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 12px;
    padding: 2px;
}
.answers-view-grid.is-subjective {
    grid-template-columns: 1fr;
}
.answers-view-cell {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}
.answers-view-num {
    font-size: 12px;
    font-weight: 700;
    color: #4a5568;
    margin-bottom: 4px;
}
.answers-view-ans {
    font-size: 15px;
    font-weight: 600;
    color: #2b6cb0;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
}
.answer-row-remove:hover,
.answer-delete-btn:hover { background: #fed7d7; color: #9b2c2c; }

.pdf-card-wrap .pdf-card {
    display: flex;
    border-radius: 10px 10px 0 0;
}
.answer-sheet-section {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-top: none;
    border-radius: 0 0 10px 10px;
    padding: 10px 12px;
    margin-top: -1px;
}
.answer-sheet-heading {
    font-size: 11px;
    font-weight: 700;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.answer-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.answer-sheet-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.answer-sheet-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    padding: 8px;
    background: white;
    border: 1px solid #edf2f7;
    border-radius: 8px;
}
.answer-sheet-main {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.answer-sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}
.btn-extract-objective,
.btn-view-answers,
.btn-apply-answers {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
}
.answer-type-badge {
    flex-shrink: 0;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
}
.answer-type-badge.type-객관식,
.answer-type-badge.type-서답형 { background: #bee3f8; color: #2c5282; }
.answer-type-badge.type-서술형 { background: #faf089; color: #744210; }
.answer-sheet-link {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #2b6cb0;
    text-decoration: none;
}
.answer-sheet-link:hover { text-decoration: underline; }
.answer-sheet-none { font-size: 12px; color: #a0aec0; }
.answer-add-bar {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-top: 1px dashed #cbd5e0;
    border-radius: 0 0 10px 10px;
    padding: 10px 12px;
}
.btn-add-answer-trigger {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #2b6cb0;
    border-radius: 6px;
    background: #ebf8ff;
    color: #2b6cb0;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-add-answer-trigger:hover {
    background: #2b6cb0;
    border-color: #2b6cb0;
    color: white;
}

/* === Classify modal === */
.classify-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.classify-overlay[hidden] { display: none; }
.classify-dialog {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}
.classify-sub {
    margin: 0 0 14px;
    font-size: 13px;
    color: #718096;
}
.classify-exam-col[hidden] { display: none; }
.classify-exam-col[hidden] + .classify-zone-col { }
.classify-zones:has(.classify-exam-col[hidden]) {
    grid-template-columns: repeat(2, 1fr);
}
.btn-classify-save {
    background: #38a169;
    border-color: #38a169;
}
.btn-classify-save:hover {
    background: #2f855a;
    border-color: #2f855a;
}
.upload-hint {
    flex: 1 1 100%;
    margin: 0;
    font-size: 13px;
    color: #718096;
}

/* === Multi-file classify (inline zones in modal) === */
.classify-panel {
    flex: 1 1 100%;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
}
.classify-title {
    font-size: 13px;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 10px;
}
.classify-pool-wrap { margin-bottom: 12px; }
.classify-zones {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}
@media (max-width: 640px) {
    .classify-zones { grid-template-columns: 1fr; }
}
.classify-zone-label {
    font-size: 12px;
    font-weight: 700;
    color: #4a5568;
    margin-bottom: 6px;
}
.classify-zone {
    min-height: 72px;
    padding: 8px;
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    background: #f7fafc;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color 0.15s, background 0.15s;
}
.classify-zone.drag-over {
    border-color: #2b6cb0;
    background: #ebf8ff;
}
.classify-zone-exam { border-color: #a0aec0; }
.classify-zone-objective { border-color: #63b3ed; background: #f0f9ff; }
.classify-zone-subjective { border-color: #ecc94b; background: #fffff0; }
.classify-chip {
    padding: 6px 10px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    cursor: grab;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: none;
}
.classify-chip.dragging { opacity: 0.5; }
.classify-chip.selected {
    outline: 2px solid #2b6cb0;
    background: #ebf8ff;
}
.classify-actions { display: flex; gap: 8px; align-items: center; }

/* === Scraper === */
.scraper-page { display: flex; flex-direction: column; height: calc(100vh - 56px); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 10px 16px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    align-items: center;
}
.tool-group { display: flex; align-items: center; gap: 6px; }
.num-input-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #fffaf0;
    border: 1px solid #f6ad55;
    border-radius: 6px;
    font-size: 12px;
    color: #744210;
    font-weight: 600;
}
.num-input-wrap input {
    width: 56px;
    padding: 3px 4px;
    border: 1px solid #ed8936;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    color: #744210;
    text-align: center;
    background: #fff;
}
.num-input-wrap input:focus { outline: 2px solid #f6ad55; outline-offset: 1px; }
.num-input-wrap.disabled { opacity: 0.45; pointer-events: none; }
.page-info, .zoom-info {
    font-size: 14px;
    padding: 0 6px;
    min-width: 60px;
    text-align: center;
}
.mode-btn { background: white; }
.mode-btn.active {
    background: #2b6cb0;
    color: white;
    border-color: #2b6cb0;
}
.mode-btn[data-mode="subjective"].active { background: #c05621; border-color: #c05621; }
.mode-btn[data-mode="mask"].active { background: #805ad5; border-color: #805ad5; }

.status-bar {
    display: flex;
    gap: 24px;
    padding: 6px 16px;
    background: #edf2f7;
    border-bottom: 1px solid #e2e8f0;
    font-size: 13px;
}
.mode-indicator { font-weight: 700; color: #2b6cb0; }
.status-msg { color: #4a5568; }

.canvas-wrap {
    flex: 1;
    overflow: auto;
    background: #cbd5e0;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}
#overlay {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.canvas-stage {
    position: relative;
    display: inline-block;
    background: white;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
#pdf-img { display: block; max-width: none; }
#overlay {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
}

/* === Viewer === */
.viewer-page { padding: 16px 24px; }
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    background: white;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid #e2e8f0;
}
.filters label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: #4a5568;
    gap: 4px;
}
.filters label.checkbox { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: inherit; }
.filters select, .filters input[type=text] {
    padding: 6px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: white;
}
.filters .selected-count { font-weight: 600; color: #1a365d; font-size: 14px; }
.filters .spacer { flex: 1; }

.problem-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.problem-card {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    transition: all 0.15s;
    cursor: pointer;
}
.problem-card.selected { border-color: #2b6cb0; background: #ebf4ff; }
.problem-card:hover { border-color: #4a5568; }
.problem-card .img-wrap {
    position: relative;
    margin-bottom: 8px;
}
.problem-card img {
    width: 100%;
    height: 220px;
    object-fit: contain;
    background: #f7fafc;
    border-radius: 4px;
    display: block;
}
.problem-card .fav-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: rgba(255,255,255,0.92);
    color: #cbd5e0;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.1s;
    z-index: 2;
}
.problem-card .fav-btn:hover {
    color: #ecc94b;
    border-color: #ecc94b;
}
.problem-card .fav-btn:active {
    transform: scale(0.92);
}
.problem-card .fav-btn.on {
    color: #f6ad00;
    background: #fffbe6;
    border-color: #f6ad00;
    text-shadow: 0 0 1px #d69e2e;
}
.problem-card .fav-btn:disabled {
    opacity: 0.6;
    cursor: progress;
}
.exam-count-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(74, 85, 104, 0.85);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    min-width: 24px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    border: 1.5px solid #ffffff;
    z-index: 2;
    pointer-events: none;
    line-height: 1;
}
.exam-count-badge.used {
    background: #3182ce;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(49, 130, 206, 0.4);
}
.exam-count-badge.zero {
    background: rgba(160, 174, 192, 0.75);
    color: #ffffff;
}
.selection-order-badge {
    position: absolute;
    top: 6px;
    left: 44px;
    background: #2b6cb0;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    border: 2px solid #ffffff;
    z-index: 3;
    pointer-events: none;
    line-height: 1;
}
.problem-card .name { font-weight: 600; font-size: 13px; margin-bottom: 4px; word-break: break-all; }
.problem-card .meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
    margin: 3px 0;
    flex-wrap: wrap;
}
.problem-card .ans { color: #c53030; font-size: 13px; }
.problem-card .acc-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1.5px 6px;
    border-radius: 4px;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.25;
}
.problem-card .acc-badge.acc-high {
    background: #def7ec;
    color: #03543f;
    border: 1px solid #bcf0da;
}
.problem-card .acc-badge.acc-mid {
    background: #fef08a;
    color: #713f12;
    border: 1px solid #fde047;
}
.problem-card .acc-badge.acc-low {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.problem-card .acc-badge.acc-none {
    background: #f3f4f6;
    color: #9ca3af;
    border: 1px solid #e5e7eb;
    font-weight: 500;
}
.problem-card .unit { color: #4a5568; font-size: 12px; margin: 2px 0; }
.problem-card .level { color: #4a5568; font-size: 12px; }
.problem-card .pick {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
    background: white;
    padding: 24px;
    border-radius: 10px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.modal-card.layout-card {
    width: 1040px;
    max-width: 96vw;
    max-height: 94vh;
    overflow-y: auto;
    padding: 22px 26px;
}
.modal-card.edit-card {
    width: 1000px;
    max-width: 95vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    padding: 22px 24px;
}
.modal-card.edit-card h3#edit-title {
    margin: 0 0 14px 0;
    font-size: 17px;
    font-weight: 700;
    color: #1a202c;
    flex-shrink: 0;
}
.modal-card.edit-card .edit-body {
    display: flex;
    gap: 20px;
    align-items: stretch;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.modal-card.edit-card .edit-img-pane {
    flex: 1 1 62%;
    min-width: 0;
    min-height: 0;
    background: #f7fafc;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-card.edit-card .edit-img-scroll-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #f7fafc;
}
.modal-card.edit-card .edit-img-scroll-area img {
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin: 0 auto;
}
.modal-card.edit-card .edit-img-toolbar {
    padding: 8px 12px;
    background: #edf2f7;
    border-top: 1px solid #cbd5e0;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.modal-card.edit-card .edit-form-pane {
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding-right: 4px;
}
.modal-card.edit-card .modal-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    flex-shrink: 0;
}
@media (max-width: 760px) {
    .modal-card.edit-card { width: 95vw; max-height: 94vh; }
    .modal-card.edit-card .edit-body { flex-direction: column; overflow-y: auto; }
    .modal-card.edit-card .edit-img-pane { max-height: 48vh; flex: 0 0 auto; }
    .modal-card.edit-card .edit-form-pane { flex: 1 1 auto; overflow-y: visible; }
}
.layout-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 10px;
}
.layout-header-row h3 {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
}
.layout-zoom-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #edf2f7;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    padding: 3px 8px;
}
.btn-zoom {
    background: #ffffff;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: #4a5568;
    line-height: 1.3;
    transition: all 0.15s;
}
.btn-zoom:hover {
    background: #ebf8ff;
    color: #2b6cb0;
    border-color: #90cdf4;
}
#zoom-level-text {
    font-size: 12px;
    font-weight: 700;
    color: #2d3748;
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.layout-mode-bar { display: flex; gap: 18px; padding: 4px 0 4px; }
.layout-mode-bar label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.modal-card label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    color: #4a5568;
}
.modal-card input, .modal-card select {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    margin-top: 4px;
}
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 20px; }
.modal-actions .spacer { flex: 1; }
.muted { color: #718096; font-size: 13px; }

.layout-stage-container {
    position: relative;
    max-height: 56vh;
    overflow: auto;
    background: #4a5568;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.25);
    margin: 8px 0 12px;
}
.layout-stage {
    position: relative;
    display: inline-block;
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border-radius: 2px;
}
#layout-img { display: block; max-width: none; }
#layout-canvas { position: absolute; top: 0; left: 0; cursor: move; }

.undo-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #2d3748;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 9999;
    font-size: 14px;
    animation: undo-slide-up 0.2s ease-out;
}
.undo-toast .undo-msg { font-weight: 500; }
.undo-toast .undo-timer {
    font-variant-numeric: tabular-nums;
    color: #cbd5e0;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
}
.undo-toast .undo-btn {
    background: #4299e1;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}
.undo-toast .undo-btn:hover { background: #3182ce; }
.undo-toast .undo-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.undo-toast .undo-close {
    background: transparent;
    color: #a0aec0;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.undo-toast .undo-close:hover { color: white; }
@keyframes undo-slide-up {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.trash-page { max-width: 1100px; margin: 0 auto; padding: 20px; }
.trash-header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 24px; }
.trash-header h1 { margin: 0 16px 0 0; font-size: 22px; }
.trash-info { color: #4a5568; flex: 1; min-width: 240px; font-size: 14px; }
.trash-actions { display: flex; gap: 8px; }
.trash-list { display: flex; flex-direction: column; gap: 14px; }
.trash-empty { text-align: center; padding: 48px; color: #a0aec0; font-size: 16px; }
.trash-empty.hidden { display: none; }
.trash-batch {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.trash-batch-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.trash-batch-title { font-weight: 600; font-size: 15px; }
.trash-batch-meta { color: #718096; font-size: 12px; margin-top: 2px; }
.trash-batch-right { display: flex; align-items: center; gap: 10px; }
.trash-timer {
    background: #edf2f7;
    color: #2d3748;
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.trash-timer b { color: #c53030; margin-left: 4px; }
.trash-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
}
.trash-thumb {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    color: #2d3748;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.trash-thumb.more {
    background: #edf2f7;
    color: #4a5568;
    font-style: italic;
}

/* Right-click context menu for boxes on scraper canvas */
.ctx-menu {
    position: fixed;
    z-index: 9999;
    background: #ffffff;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    padding: 6px 0;
    min-width: 200px;
    font-size: 14px;
}
.ctx-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 8px 14px;
    cursor: pointer;
    color: #1a202c;
}
.ctx-menu button:hover:not(:disabled) {
    background: #edf2f7;
}
.ctx-menu button:disabled {
    color: #a0aec0;
    cursor: not-allowed;
}
.ctx-menu button.danger {
    color: #c53030;
}
.ctx-menu button.danger:hover:not(:disabled) {
    background: #fff5f5;
}
.ctx-menu hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 4px 0;
}
.ctx-menu-title {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 700;
    color: #4a5568;
    background: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
}

/* ========================================================
   PDF Folder Grouping & Custom Context Menu
   ======================================================== */
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header-row h1 {
    margin: 0;
    font-size: 22px;
}
.folders-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.folder-section {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 20px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.folder-section.drag-target {
    border-color: #3182ce;
    background: #ebf8ff;
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.25);
}
.folder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid #edf2f7;
    user-select: none;
}
.ungrouped-section .folder-header {
    border-bottom: 1px solid #edf2f7;
    margin-bottom: 14px;
    padding-bottom: 8px;
}
.folder-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.folder-toggle-btn {
    background: none;
    border: none;
    padding: 4px 8px;
    margin-left: -8px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: #2d3748;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
}
.folder-toggle-btn:hover {
    background: #edf2f7;
}
.folder-toggle-btn.non-collapsible {
    cursor: default;
}
.folder-toggle-btn.non-collapsible:hover {
    background: none;
}
.folder-arrow {
    font-size: 11px;
    color: #718096;
    transition: transform 0.2s ease;
    display: inline-block;
}
.folder-arrow.is-collapsed {
    transform: rotate(-90deg);
}
.folder-icon {
    font-size: 18px;
}
.folder-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a202c;
}
.folder-count-badge {
    font-size: 12px;
    background: #edf2f7;
    color: #4a5568;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}
.folder-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-folder-add-pdf {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #2b6cb0;
    background: #ebf8ff;
    border: 1px solid #bee3f8;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.btn-folder-add-pdf:hover {
    background: #3182ce;
    color: #ffffff;
    border-color: #3182ce;
}
.btn-folder-action {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 13px;
    color: #4a5568;
    transition: all 0.15s;
}
.btn-folder-action:hover {
    background: #edf2f7;
    color: #1a202c;
    border-color: #cbd5e0;
}
.btn-folder-delete:hover {
    background: #fed7d7;
    color: #9b2c2c;
    border-color: #fc8181;
}
.folder-content {
    padding-top: 14px;
}
.folder-content.is-collapsed {
    display: none;
}
.folder-empty-placeholder {
    grid-column: 1 / -1;
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 28px;
    text-align: center;
    color: #718096;
    font-size: 14px;
    background: #f8fafc;
}
.pdf-card-wrap.is-dragging {
    opacity: 0.4;
    transform: scale(0.98);
}

/* Custom Context Menu */
.custom-context-menu {
    position: fixed;
    z-index: 10000;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    min-width: 180px;
    padding: 6px 0;
    font-size: 13px;
    user-select: none;
    animation: ctxFadeIn 0.1s ease-out;
}
@keyframes ctxFadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}
.context-menu-header {
    padding: 6px 14px;
    font-size: 11px;
    font-weight: 700;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #f0f4f8;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    color: #2d3748;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.context-menu-item:hover {
    background: #edf2f7;
    color: #1a202c;
}
.context-menu-item.danger {
    color: #e53e3e;
}
.context-menu-item.danger:hover {
    background: #fff5f5;
    color: #c53030;
}
.context-menu-divider {
    height: 1px;
    background: #edf2f7;
    margin: 4px 0;
}
.context-menu-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

/* Folder move selection modal */
.folder-select-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow-y: auto;
    margin: 16px 0;
    padding: 4px;
}
.folder-select-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
    font-weight: 500;
}
.folder-select-item:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}
.folder-select-item.selected {
    background: #ebf8ff;
    border-color: #3182ce;
    color: #2b6cb0;
    font-weight: 700;
}

/* Layout Numbering Configuration */
.layout-numbering-box {
    margin-top: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 14px;
}
.numbering-box-header {
    margin-bottom: 10px;
}
.numbering-box-title {
    font-size: 13px;
    font-weight: 700;
    color: #2d3748;
}
.numbering-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1.25fr;
    gap: 12px;
}
@media (max-width: 820px) {
    .numbering-grid {
        grid-template-columns: 1fr;
    }
}
.numbering-col {
    background: #ffffff;
    border: 1px solid #edf2f7;
    border-radius: 8px;
    padding: 10px 12px;
}
.numbering-col-title {
    font-size: 12px;
    font-weight: 700;
    color: #3182ce;
    margin-bottom: 8px;
}
.numbering-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.numbering-row label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #4a5568;
    font-weight: 500;
    margin: 0;
}
.numbering-row input[type="number"] {
    width: 58px;
    padding: 3px 6px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
}
.numbering-row input[type="number"]:focus {
    border-color: #3182ce;
    outline: none;
}

/* === Global OMR Sheet Styles === */
.omr-row {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 14px;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px;
    transition: all 0.15s ease;
}
.omr-row.is-correct {
    background: #f0fff4;
    border-color: #9ae6b4;
}
.omr-row.is-wrong {
    background: #fff5f5;
    border-color: #feb2b2;
}
.omr-num {
    font-weight: 700;
    font-size: 14px;
    color: #2d3748;
    min-width: 44px;
    white-space: nowrap;
}
.omr-bubbles {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    align-items: center !important;
    justify-content: center !important;
}
.omr-bubble-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 50%;
    border: 1px solid #cbd5e0;
    background: white;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.1s ease;
    flex-shrink: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}
.omr-bubble-btn:hover { background: #edf2f7; border-color: #a0aec0; }
.omr-bubble-btn.selected { background: #2b6cb0; color: white; border-color: #2b6cb0; box-shadow: 0 1px 3px rgba(43, 108, 176, 0.4); }
.omr-bubble-btn.correct-ans { background: #38a169; color: white; border-color: #38a169; }
.omr-bubble-btn.wrong-ans { background: #e53e3e; color: white; border-color: #e53e3e; }

