/**
 * RM Quiz Builder - Matrix question type ("complete the table")
 * Per-column token banks + a rows x columns grid of single-token cells.
 */

/* ---- Token banks (one per column) ---- */
.rmqb-matrix-banks {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 18px;
}
.rmqb-matrix-bank-group {
    flex: 1 1 240px;
    min-width: 220px;
}
.rmqb-matrix-bank-label {
    font-weight: 700;
    color: #1f2937;
    font-size: 13px;
    margin: 0 0 6px 2px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.rmqb-matrix-bank {
    list-style: none;
    margin: 0;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 52px;
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
}
.rmqb-matrix-bank.drag-over { border-color: #3b82f6; background: #eff6ff; }

/* ---- Token ---- */
.rmqb-matrix-token {
    display: inline-flex;
    align-items: center;
    padding: 9px 15px;
    background: linear-gradient(to bottom, #ffffff, #f8f9fa);
    border: 1px solid #d1d5db;
    border-radius: 18px;
    cursor: grab;
    transition: all 0.15s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    user-select: none;
}
.rmqb-matrix-token:hover { border-color: #9ca3af; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12); }
.rmqb-matrix-token:active { cursor: grabbing; }
.rmqb-matrix-token:focus { outline: 2px solid #3b82f6; outline-offset: 2px; }
.rmqb-matrix-token.dragging { opacity: 0.4; }
.rmqb-matrix-token.touch-dragging { opacity: 1; }
.rmqb-matrix-token.keyboard-grabbed { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3); }
.rmqb-matrix-token.correct { border-color: #22c55e; background: #f0fdf4; }
.rmqb-matrix-token.incorrect { border-color: #ef4444; background: #fef2f2; }

/* ---- The grid ---- */
.rmqb-matrix-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.rmqb-matrix-table th,
.rmqb-matrix-table td {
    border: 1px solid #e5e7eb;
    padding: 10px;
    vertical-align: top;
    text-align: left;
}
.rmqb-matrix-colhead {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    font-weight: 700;
    color: #1f2937;
}
.rmqb-matrix-corner {
    background: #f8fafc;
    width: 26%;
}
.rmqb-matrix-rowhead {
    background: #f8fafc;
    font-weight: 600;
    color: #1f2937;
}
.rmqb-matrix-rowhead .rmqb-matrix-row-desc {
    display: block;
    margin-top: 4px;
    font-weight: 400;
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
}

/* A drop cell (holds one token) */
.rmqb-matrix-cell {
    background: #ffffff;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}
.rmqb-matrix-cell.drag-over { box-shadow: inset 0 0 0 2px #3b82f6; background: #eff6ff; }
.rmqb-matrix-cell-slot {
    min-height: 42px;
    display: flex;
    align-items: center;
}

/* Mobile dropdown fallback: hidden on desktop, shown at <=640px */
.rmqb-matrix-cell-select { display: none; }

/* ---- Instructions ---- */
.rmqb-matrix-instructions {
    margin-bottom: 12px;
    padding: 10px 15px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid #f59e0b;
    border-radius: 4px;
    color: #92400e;
    font-weight: 600;
}
.rmqb-matrix-instructions .rmqb-matrix-sub {
    font-weight: normal;
    font-size: 13px;
    display: block;
    margin-top: 4px;
    color: #a16207;
}

@media (max-width: 640px) {
    .rmqb-matrix-table, .rmqb-matrix-table tbody, .rmqb-matrix-table tr { display: block; width: 100%; }
    .rmqb-matrix-table thead { display: none; }
    .rmqb-matrix-table td, .rmqb-matrix-table th { display: block; width: 100% !important; box-sizing: border-box; }
    .rmqb-matrix-cell::before {
        content: attr(data-column-label);
        display: block;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        color: #6b7280;
        margin-bottom: 4px;
    }
    .rmqb-matrix-rowhead { border-bottom: none; }

    /* On phones, swap drag-and-drop for a dropdown per cell */
    .rmqb-matrix-banks { display: none; }
    .rmqb-matrix-cell-slot { display: none; }
    .rmqb-matrix-cell-select {
        display: block;
        width: 100%;
        padding: 10px;
        border: 2px solid #cbd5e1;
        border-radius: 6px;
        font-size: 16px; /* >=16px avoids iOS zoom-on-focus */
        background: #ffffff;
        color: #374151;
        box-sizing: border-box;
    }
    .rmqb-matrix-cell-select:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    }
    .rmqb-matrix-cell-select:disabled { background: #f3f4f6; color: #9ca3af; }
}
