/* Giao diện câu hỏi tham khảo từ Website - match-dnd, fill inline, select, drag-groups */

/* Chặn tràn ngang toàn trang làm bài */
html {
    overflow-x: hidden;
    max-width: 100%;
}

body.exam-take-body {
    overflow-x: hidden;
}

/* Giữ khung trang max 1200px — không ghi đè .wrap (chỉ ảnh đề bài mới full-width trong thẻ câu hỏi) */
.exam-take-body .wrap {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.exam-take-body .panel,
.exam-take-body .panel-body,
.exam-take-body #examForm,
.exam-take-body .question-card,
.exam-take-body .question-content,
.exam-take-body .choices,
.exam-take-body .choice,
.exam-take-body .question-prompt-html {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.exam-inline-img,
.exam-take-body img {
    display: block;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    box-sizing: border-box;
}

/* Ảnh minh họa đề bài — full chiều ngang trên màn hình lớn (phụ đề + prompt MCQ/…) */
@media (min-width: 769px) {
    .question-card .question-prompt-html img,
    .question-card .question-prompt-html .imgbox img {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain;
        margin: 0;
    }

    .question-card .question-prompt-html .imgbox {
        width: 100%;
        display: block;
    }
}

/* Question title and subtitle */
.q-title {
    font-size: 20px;
    font-weight: 900;
    margin: 0 0 4px;
}

.q-sub {
    margin: 0 0 16px;
    color: var(--muted, #6b7280);
    font-size: 16px;
    font-weight: 900;
}

.q-sub.question-prompt-html {
    color: inherit;
    font-weight: normal;
    font-size: inherit;
}

.divider {
    height: 1px;
    background: var(--border, #e5e7eb);
    margin: 18px 0;
}

.choice .text {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    color: #111827;
    white-space: normal;
}

.choice .text br {
    display: block;
    content: '';
    margin-top: 0.15em;
}

.choices {
    display: grid;
    gap: 10px;
    max-width: 100%;
}

.choice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    background: #fff;
    cursor: pointer;
    user-select: none;
    transition: .15s ease;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.choice:hover {
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.choice input {
    margin-top: 3px;
    flex-shrink: 0;
}

.choice .label {
    font-weight: 900;
    width: 26px;
    flex-shrink: 0;
    color: #111827;
}

/* Image box */
.imgbox {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 16px;
    overflow: hidden;
    background: #fafafa;
    margin-bottom: 14px;
    max-width: 100%;
}

.imgbox img {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    margin: 0 auto;
}

/* Image-choice: khung ảnh co theo nội dung */
.choice-imgbox {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 16px;
    overflow: hidden;
    background: #fafafa;
    margin: 8px 0 10px;
    width: 100%;
    max-width: 100%;
    display: block;
    min-height: unset;
    box-sizing: border-box;
}

.choice-imgbox img {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: 200px;
    height: auto;
    object-fit: contain;
    object-position: center;
    margin: 0 auto;
}

.question-card,
.question-content,
.question-prompt-html {
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.question-card img,
.question-content img,
.question-prompt-html img,
.q-sub img {
    display: block;
    max-width: 100%;
    height: auto;
    box-sizing: border-box;
}

.question-prompt-html .imgbox {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    overflow: hidden;
}

.question-prompt-html > *,
.question-prompt-html table {
    max-width: 100% !important;
}

/* Arrange - wordbank and slot */
.wordbank {
    border: 1px solid var(--border, #e5e7eb);
    background: #eaf7f7;
    border-radius: 16px;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.slot {
    margin-top: 12px;
    border: 2px dashed #cbd5e1;
    background: #fff;
    border-radius: 16px;
    min-height: 64px;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip {
    background: #fff;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 900;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.chip:active {
    transform: scale(0.97);
}

.chip.chip-selected {
    border-color: var(--brand, #c9303c);
    box-shadow: 0 0 0 3px rgba(201, 48, 60, .22);
}

.dg-chip {
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.dg-chip.chip-selected {
    border-color: var(--brand, #c9303c);
    box-shadow: 0 0 0 3px rgba(201, 48, 60, .22);
}

.dg-dropzone.chip-drop-target {
    outline: 2px dashed rgba(201, 48, 60, .4);
    outline-offset: 2px;
    border-radius: 14px;
}

.gap-drag-prompt {
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.55;
}

.gap-drag-body {
    margin: 0 0 16px;
}

.gap-drag-body.has-figure {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 20px 24px;
}

.gap-drag-body.has-figure .gap-drag-figure {
    flex: 0 0 300px;
    width: 300px;
    max-width: min(300px, 100%);
    margin: 0;
}

.gap-drag-body.has-figure .gap-sentence {
    flex: 1 1 240px;
    min-width: 0;
    margin: 0;
    align-self: center;
}

.gap-drag-figure {
    width: 320px;
    max-width: 100%;
    margin: 0 0 18px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(15, 23, 42, .12);
    background: #f8fafc;
}

.gap-drag-figure img,
.exam-take-body .gap-drag-figure img,
.question-card .gap-drag-figure img {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    object-fit: cover;
    margin: 0;
}

.gap-sentence {
    font-size: 17px;
    font-weight: 600;
    line-height: 2.5;
    margin: 0 0 16px;
    white-space: normal;
}

.gap-sentence br {
    display: block;
    content: '';
    margin-top: 0.35em;
}

.gap-drag .gap-wordbank {
    justify-content: center;
    align-items: center;
    margin-top: 8px;
    padding: 18px 16px;
    min-height: 76px;
    background: #e7f6ee;
    border: none;
}

.gap-drag .gap-wordbank .chip {
    border: 1px dashed #94a3b8;
    font-weight: 700;
    background: #fff;
}

.gap-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 8.2rem;
    min-height: 2.2rem;
    padding: 2px 8px;
    margin: 0 6px;
    vertical-align: middle;
    background: #e6eaef;
    border-radius: 8px;
    border: none;
}

.gap-slot.chip-drop-target,
.gap-wordbank.chip-drop-target {
    outline: 2px dashed rgba(201, 48, 60, .4);
    outline-offset: 2px;
}

.gap-slot .chip {
    margin: 0;
    padding: 6px 10px;
}

.gap-wordbank {
    margin-top: 4px;
}

@media (max-width: 768px) {
    .gap-drag-body.has-figure {
        flex-direction: column;
    }
    .gap-drag-body.has-figure .gap-drag-figure {
        flex: none;
        width: 100%;
        max-width: 360px;
    }
    .gap-drag-figure {
        width: 100%;
        max-width: 360px;
    }
    .gap-sentence {
        font-size: 16px;
        line-height: 2.5;
    }
    .gap-slot {
        min-width: 6.2rem;
        display: inline-flex;
    }
}

/* Drag groups - use bank and groups from existing */
.bank {
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    padding: 12px;
    background: #fbfbfd;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 74px;
}

.groups {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.group {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 16px;
    background: #fff;
    overflow: hidden;
}

.group h4 {
    margin: 0;
    padding: 10px 12px;
    font-size: 13px;
    color: #0f172a;
    background: #e9fbf6;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.dropzone {
    min-height: 120px;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.dropzone.over {
    outline: 3px solid rgba(201, 48, 60, .20);
    outline-offset: 2px;
    border-radius: 14px;
}

/* Giao diện câu hỏi tham khảo từ Website - match-dnd, fill inline, select, drag-groups */

/* Fill - ô trống trong đoạn văn */
.fillline {
    font-size: 16px;
    line-height: 1.9;
    font-weight: 900;
}
.blank {
    display: inline-block;
    min-width: 92px;
    padding: 6px 10px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #fff;
    vertical-align: middle;
    box-sizing: border-box;
}
.blank[style*="width"] {
    min-width: unset;
    padding: 4px 6px;
}
.blank input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 15px;
    background: transparent;
}

/* Select - dropdown nhúng trong câu */
.selectbox {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    background: #fff;
    vertical-align: middle;
}
.selectbox select {
    border: none;
    outline: none;
    font-size: 15px;
    font-weight: 900;
    background: transparent;
    cursor: pointer;
    min-width: 160px;
}

/* ===== match-dnd (Nối câu - 2 cột, bấm chọn / line) ===== */
.match-dnd {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
    margin-top: 10px;
}
.match-line { position: relative; }
.match-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
    color: rgba(201, 48, 60, .85);
}
.match-dnd .col {
    /*
    border: 1px solid #dee2e6;
    border-radius: 16px;
    */
    background: #fff;
    overflow: hidden;
}
.match-dnd .col h4 {
    margin: 0;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 700;
    background: #f0f9ff;
    border-bottom: 1px solid #dee2e6;
}
.match-dnd .col.right h4 { background: #fdf2f8; }
.match-dnd .list {
    padding: 12px;
    display: grid;
    gap: 10px;
    min-height: 120px;
}
.line-item {
    width: 100%;
    text-align: left;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    padding: 12px;
    background: #fff;
    cursor: pointer;
    user-select: none;
    font-weight: 900;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.line-item.is-linked {
    border-color: rgba(201, 48, 60, .35);
    background: #fffafb;
}
.line-item .mini-tag,
.line-item .match-link-out {
    margin-left: auto;
    flex-shrink: 0;
}
.match-mobile-hint {
    display: none;
    grid-column: 1 / -1;
    margin: 0 0 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fff2f3;
    border: 1px solid #f3d5d8;
    color: #7a1f27;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
}
.line-item .dot { display: none; }
.line-item.selected {
    outline: 3px solid rgba(201, 48, 60, .25);
}
.line-item .badge-num {
    width: 34px;
    min-width: 34px;
    height: 34px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #0f172a;
}
.line-item .badge-letter {
    width: 34px;
    min-width: 34px;
    height: 34px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #0f172a;
}
.mini-tag { font-size: 12px; color: #6b7280; margin-left: 6px; }
.match-dnd .tools { margin-top: 12px; display: flex; gap: 10px; }
.toolbtn {
    padding: 10px 12px;
    border-radius: 999px;
    border: 1px solid var(--border, #e5e7eb);
    background: #fff;
    cursor: pointer;
    font-weight: 900;
}

/* match-dnd DRAG mode: pool chips + ô thả */
.match-drag.match-dnd .match-drag-pool {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-content: flex-start;
    align-items: flex-start;
    min-height: 120px;
}
.match-drag.match-dnd .drag-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    background: #fff;
    cursor: grab;
    user-select: none;
    font-weight: 800;
    color: #111827;
}
.match-drag.match-dnd .drag-item:active {
    cursor: grabbing;
}
.match-drag.match-dnd .drag-item .badge-num {
    width: 28px;
    min-width: 28px;
    height: 28px;
    border-radius: 10px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
}
.match-drag.match-dnd .col.right .list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.match-drag.match-dnd .drop-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) minmax(140px, 200px);
    gap: 10px;
    align-items: stretch;
    padding: 10px 12px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    background: #fff;
}
.match-drag.match-dnd .drop-row.over {
    outline: 2px dashed rgba(201, 48, 60, .35);
    outline-offset: 2px;
}
.match-drag.match-dnd .drop-text {
    align-self: center;
    font-weight: 700;
    color: #1f2937;
}
.match-drag.match-dnd .slotbox {
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 10px;
    background: #f8fafc;
    color: #64748b;
    font-weight: 700;
}
.match-drag.match-dnd .slotbox.filled {
    border-style: solid;
    border-color: rgba(201, 48, 60, .35);
    background: #fff5f6;
    color: #111827;
}
.match-drag.match-dnd .slotbox .remove {
    margin-left: auto;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.match-drag.match-dnd .slotbox .remove:hover {
    background: rgba(201, 48, 60, .1);
    color: #c9303c;
}

/* ===== drag-groups: bank + dropzones ===== */
.dg-bank {
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    padding: 12px;
    background: #fbfbfd;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 70px;
}
.dg-bank.over {
    outline: 3px solid rgba(201, 48, 60, .2);
    outline-offset: 2px;
}
.dg-chip {
    background: #fff;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 900;
    cursor: grab;
    user-select: none;
}
.dg-chip:active { cursor: grabbing; }
.dg-groups {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.dg-group {
    border: 1px solid #dee2e6;
    border-radius: 16px;
    background: #fff;
    overflow: hidden;
}
.dg-group h4 {
    margin: 0;
    padding: 10px 12px;
    font-size: 13px;
    color: #0f172a;
    background: #e9fbf6;
    border-bottom: 1px solid #dee2e6;
}
.dg-dropzone {
    min-height: 100px;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.dg-dropzone.over {
    outline: 3px solid rgba(201, 48, 60, .2);
    outline-offset: 2px;
    border-radius: 14px;
}

/* Footer nav - Trang trước / Trang sau */
.footer-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-top: 1px solid var(--border, #e5e7eb);
    background: #fff;
}
.navbtn {
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--border, #e5e7eb);
    background: #fff;
    font-weight: 900;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.navbtn.primary {
    border-color: transparent;
    background: var(--brand, #c9303c);
    color: #fff;
}
.page-ind {
    font-weight: 900;
    color: #111827;
    background: #fff;
    border: 1px solid var(--border, #e5e7eb);
    padding: 10px 14px;
    border-radius: 999px;
    min-width: 56px;
    text-align: center;
}

@media (max-width: 768px) {
    .q-title {
        font-size: 17px;
        line-height: 1.35;
    }
    .q-sub {
        font-size: 14px;
    }
    .choice {
        padding: 10px;
    }
    .fillline {
        font-size: 15px;
        line-height: 1.7;
    }
    .match-dnd { grid-template-columns: 1fr; }
    .match-line .match-lines {
        display: none;
    }
    .match-mobile-hint {
        display: block;
    }
    .match-line.match-dnd {
        gap: 10px;
    }
    .match-dnd .list {
        min-height: 0;
        padding: 8px;
    }
    .line-item {
        padding: 10px;
        font-size: 14px;
    }
    .line-item .mini-tag,
    .line-item .match-link-out {
        display: inline-flex;
        align-items: center;
        padding: 3px 8px;
        border-radius: 999px;
        background: #fff2f3;
        color: #7a1f27;
        font-size: 12px;
        font-weight: 800;
    }
    .match-drag.match-dnd .drop-row {
        grid-template-columns: 1fr;
    }
    .dg-groups { grid-template-columns: 1fr; }
    .footer-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -6px 18px rgba(0, 0, 0, .08);
        gap: 8px;
    }
    .navbtn {
        flex: 1;
        justify-content: center;
        padding: 11px 10px;
        font-size: 14px;
        min-height: 44px;
    }
    .page-ind {
        flex-shrink: 0;
        min-width: 48px;
        padding: 8px 10px;
        font-size: 14px;
    }
    .choice-imgbox img {
        max-height: 140px;
        width: 100% !important;
        max-width: 100% !important;
    }
    .exam-inline-img,
    .exam-take-body .panel-body img,
    .question-prompt-html img,
    .question-card .imgbox img {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain;
    }
}
