/* Question tables — select / drag; worksheets include bare tables in .question */
table[class*='tqq'],
table[id^='tqq'],
.question table.selected-table,
.question table.qg-table-shrinkwrap,
.question table.qg-table-user-sized {
  cursor: grab;
  border-collapse: collapse;
}

table[class*='tqq'].dragging,
table[id^='tqq'].dragging,
.question table.dragging {
  cursor: grabbing;
  z-index: 9999;
}

table[class*='tqq'].selected-table,
table[id^='tqq'].selected-table,
.question table.selected-table {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Initial layout: shrink-wrap content */
table[class*='tqq'].qg-table-shrinkwrap,
table[id^='tqq'].qg-table-shrinkwrap,
.question table.qg-table-shrinkwrap {
  position: static !important;
  width: max-content !important;
  min-width: 0 !important;
  max-width: none !important;
  table-layout: auto !important;
  height: auto !important;
  margin: 0 !important;
}

table[class*='tqq'].qg-table-shrinkwrap td:first-child,
table[class*='tqq'].qg-table-shrinkwrap th:first-child,
table[id^='tqq'].qg-table-shrinkwrap td:first-child,
table[id^='tqq'].qg-table-shrinkwrap th:first-child {
  width: auto !important;
  max-width: none !important;
}

/* User-resized: allow explicit px width from JS (not max-content) */
table[class*='tqq'].qg-table-user-sized:not(.user-positioned),
table[id^='tqq'].qg-table-user-sized:not(.user-positioned),
.question table.qg-table-user-sized {
  position: static !important;
  min-width: 0 !important;
  height: auto !important;
  margin: 0 !important;
  table-layout: auto !important;
}

table[class*='tqq'].user-positioned,
table[id^='tqq'].user-positioned {
  position: absolute !important;
  margin: 0 !important;
  height: auto !important;
}

table[class*='tqq'].user-positioned.qg-table-user-sized,
table[id^='tqq'].user-positioned.qg-table-user-sized {
  position: absolute !important;
}

/* Answer sheet (#grd1): mirror question-sheet table size (inline width from wsheetSyncTableToTwin) */
.questiona table[data-wsheet-answer-twin='1'],
.questiona table[id^='tqqa'] {
  position: static !important;
  height: auto !important;
  margin: 0 !important;
  table-layout: auto !important;
  box-sizing: border-box !important;
  min-width: 0 !important;
  display: table !important;
}

.questiona table[data-wsheet-answer-twin='1'] th,
.questiona table[id^='tqqa'] th {
  white-space: normal !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
  line-height: 1.15 !important;
  max-height: 2.35em;
  overflow: hidden;
}

.questiona table[data-wsheet-answer-twin='1'] td,
.questiona table[id^='tqqa'] td {
  white-space: nowrap;
}

/* Exit tickets: outer selection ring; in-flow tables centred under question */
.page-main .qcont table[class*='tqq'],
.page-main .exit-q-slot > table[class*='tqq'],
.page-main .exit4p-q-slot > table[class*='tqq'] {
  display: table !important;
}

.page-main .qcont table[class*='tqq'].selected-table,
.page-main .exit-q-slot > table[class*='tqq'].selected-table,
.page-main .exit4p-q-slot > table[class*='tqq'].selected-table {
  outline: none !important;
  box-shadow: 0 0 0 2px #ff3366 !important;
  box-sizing: border-box !important;
}

.exit-q-slot > table[class*='tqq'].qg-table-shrinkwrap:not(.user-positioned),
.qcont table[class*='tqq'].qg-table-shrinkwrap:not(.user-positioned),
.exit4p-q-slot > table[class*='tqq'].qg-table-shrinkwrap:not(.user-positioned) {
  display: table !important;
  width: max-content !important;
  max-width: 88% !important;
  min-width: 0 !important;
  table-layout: auto !important;
  margin-left: auto !important;
  margin-right: auto !important;
  margin-top: 0.35em !important;
  margin-bottom: 0 !important;
}

.exit-q-slot > table[class*='tqq'].qg-table-user-sized:not(.user-positioned),
.qcont table[class*='tqq'].qg-table-user-sized:not(.user-positioned),
.exit4p-q-slot > table[class*='tqq'].qg-table-user-sized:not(.user-positioned) {
  display: table !important;
  margin-left: auto !important;
  margin-right: auto !important;
  margin-top: 0.35em !important;
  margin-bottom: 0 !important;
  /* Keep auto layout like shrinkwrap/fit — fixed was redistributing columns on first scroll */
  table-layout: auto !important;
  min-width: 0 !important;
}

.exit-q-slot > table[class*='tqq'].qg-table-user-sized:not(.user-positioned) td,
.qcont table[class*='tqq'].qg-table-user-sized:not(.user-positioned) td,
.exit4p-q-slot > table[class*='tqq'].qg-table-user-sized:not(.user-positioned) td {
  white-space: nowrap !important;
}

/* Exit user-sized: match initial fit exactly (same wrap + 2-line header clip).
   Lifting max-height made the first wheel tick look like a size/font jump. */
.exit-q-slot > table[class*='tqq'].qg-table-user-sized:not(.user-positioned) th,
.qcont table[class*='tqq'].qg-table-user-sized:not(.user-positioned) th,
.exit4p-q-slot > table[class*='tqq'].qg-table-user-sized:not(.user-positioned) th {
  white-space: normal !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
  line-height: 1.15 !important;
  max-height: 2.35em !important;
  overflow: hidden !important;
}

.question table.qg-table-user-sized:not(.user-positioned) th,
.question table.qg-table-user-sized:not(.user-positioned) td {
  white-space: nowrap !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  max-height: none !important;
  overflow: visible !important;
}

/* Initial load: column headings may wrap (~2 lines); body cells stay on one line */
table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
table[id^='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
.question table:not(.qg-table-user-sized):not(.user-positioned) th,
.qcont table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
.exit-q-slot > table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
.exit4p-q-slot > table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
.mid1 table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
.mtop table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th,
[id^='box'] table:not(.qg-table-user-sized):not(.user-positioned) th,
[id^='q']:not([id^='qn']) table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) th {
  white-space: normal !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
  line-height: 1.15 !important;
  max-height: 2.35em;
  overflow: hidden;
}

table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) td,
table[id^='tqq']:not(.qg-table-user-sized):not(.user-positioned) td,
.question table:not(.qg-table-user-sized):not(.user-positioned) td,
.qcont table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) td,
.mid1 table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) td,
.mtop table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) td,
[id^='box'] table:not(.qg-table-user-sized):not(.user-positioned) td,
[id^='q']:not([id^='qn']) table[class*='tqq']:not(.qg-table-user-sized):not(.user-positioned) td {
  white-space: nowrap;
}

/* All res question tables: no minimum width floor */
table[class*='tqq'],
table[id^='tqq'],
.question table,
.questiona table,
.qcont table,
.mid1 table[class*='tqq'],
.mtop table[class*='tqq'],
[id^='box'] table[class*='tqq'],
[id^='q']:not([id^='qn']) table[class*='tqq'] {
  min-width: 0 !important;
}
