/* ---------- The question builder's Check step (owner ask 2026-10-31) ----------
   app/views/subjects/assignment_questions/_check.html.erb and its three
   controllers (question_builder: drag + keyboard moves + paste;
   question_cells: inline edits; question_select: selection, bulk, delete
   with undo). The parts are a nested list (a question's parts inside it, so
   a drag carries them), drawn as a table by one shared grid. Every colour is
   a theme token, so dark mode follows. */

.qb-scroll {
  max-height: 75vh;
  overflow: auto;
  overscroll-behavior: contain;
}

/* One grid for the header and every row, nested or not: select+handle,
   label, marks, answer, topic, difficulty, (dot points on wide screens),
   actions. */
.qb-grid {
  display: grid;
  grid-template-columns: 3rem minmax(5rem, 7rem) 3.75rem minmax(5rem, 1fr) minmax(7.5rem, 11rem) 6.75rem 2.25rem;
  align-items: start;
  column-gap: 0.4rem;
  padding: 0.3rem 0.6rem 0.3rem 0.4rem;
}
.qb-dots { display: none; }
@media (min-width: 1536px) {
  .qb-grid { grid-template-columns: 3rem minmax(5.5rem, 7rem) 3.75rem minmax(6rem, 1fr) minmax(8rem, 12rem) 6.75rem minmax(4rem, 7rem) 2.25rem; }
  .qb-dots { display: flex; flex-wrap: wrap; gap: 0.25rem; }
}

.qb-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-bg-subtle);
  color: var(--color-fg-3);
  font-size: var(--text-caption, 0.75rem);
  font-weight: 500;
  border-bottom: 1px solid var(--color-border-1);
}

.qb-list { list-style: none; margin: 0; padding: 0; }
.qb-node { border-top: 1px solid var(--color-border-1); }
.qb-children .qb-node { border-top-style: dashed; }
.qb-row { background: var(--color-bg-surface); }
.qb-row:focus-within { background: var(--color-bg-subtle); }
.qb-row.qb-current { background: var(--color-bg-brand-soft); }
.qb-row.qb-flagged { box-shadow: inset 4px 0 0 var(--color-warning-500); }
.qb-row.qb-picked { background: var(--color-bg-brand-soft); }

/* A part's depth shows as its label's indent, from the nesting itself, so a
   row being dragged into a question's parts indents as it goes. */
.qb-children .qb-label { padding-left: 1.25rem; }
.qb-children .qb-children .qb-label { padding-left: 2.5rem; }

/* "AI guess" beside a part the AI drafted that nobody has checked yet. */
.qb-ai-guess {
  margin-left: 0.25rem;
  padding: 0 0.3rem;
  border-radius: 0.25rem;
  font-size: var(--text-caption, 0.75rem);
  white-space: nowrap;
  color: var(--color-warning-700);
  background: var(--color-bg-subtle);
  border: 1px dashed var(--color-warning-500);
}

.qb-section-head {
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
  padding: 0.35rem 0.75rem;
  background: var(--color-bg-subtle);
  color: var(--color-fg-3);
  font-size: var(--text-caption, 0.75rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-top: 1px solid var(--color-border-1);
}
/* An empty section is still somewhere to drop a question. */
.qb-section > .qb-list:empty { min-height: 2.25rem; }
.qb-section > .qb-list:empty::after {
  content: attr(data-empty-text);
  display: block;
  padding: 0.6rem 1rem;
  color: var(--color-fg-4);
  font-size: var(--text-caption, 0.75rem);
}

/* Cells: inputs that read as text until pointed at or focused. */
.qb-input {
  width: 100%;
  min-height: 2rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-control, 0.5rem);
  background: transparent;
  color: var(--color-fg-1);
  font: inherit;
}
.qb-input::placeholder { color: var(--color-fg-4); }
.qb-row:hover .qb-input, .qb-input:focus { border-color: var(--color-border-2); background: var(--color-bg-surface); }
.qb-input:focus { outline: 2px solid var(--color-border-brand); outline-offset: 0; }
.qb-input-label { font-family: var(--font-mono, ui-monospace, monospace); font-weight: 600; }
.qb-input-num { font-family: var(--font-mono, ui-monospace, monospace); max-width: 3.6rem; }
.qb-select { appearance: auto; padding-right: 0.1rem; }
/* The tiny saved / wrong state of a cell after it saves. */
.qb-input.qb-saving { border-color: var(--color-border-brand); }
.qb-input.qb-saved { border-color: var(--color-success-500); transition: border-color 1.2s ease-out; }
.qb-input.qb-error { border-color: var(--color-danger-500); background: var(--color-danger-50); }
.qb-row .qb-input.qb-error { border-color: var(--color-danger-500); }

.qb-total { color: var(--color-fg-3); padding: 0.35rem 0.4rem; display: inline-block; }

/* The notes take a line of their own under the row's cells. */
.qb-flags { grid-column: 2 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 0.75rem; margin: 0; padding: 0 0.4rem 0.2rem; list-style: none; }
.qb-flags:empty { display: none; }
.qb-flags li { font-size: var(--text-caption, 0.75rem); color: var(--color-warning-700); }

/* The grip: a checkbox and the drag handle, big enough for a finger or a
   Pencil on an iPad (44px tall hit area). */
.qb-grip { display: flex; align-items: center; gap: 0.15rem; min-height: 2rem; }
.qb-check { width: 1.05rem; height: 1.05rem; accent-color: var(--color-brand); }
.qb-handle {
  display: inline-grid;
  place-items: center;
  width: 1.6rem;
  height: 2.25rem;
  margin-block: -0.15rem;
  border-radius: var(--radius-control, 0.5rem);
  color: var(--color-fg-4);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.qb-handle:hover, .qb-handle:focus-visible { color: var(--color-fg-1); background: var(--color-bg-subtle); }
.qb-handle:focus-visible { outline: 2px solid var(--color-border-brand); }

/* While dragging: the place it would land (the ghost), the row in hand, and
   a strip over the bottom edge of every part to drop onto to make it a
   sub-part. The strip overlays the row rather than growing it, so nothing
   shifts under the pointer as a drag starts. */
.qb-dragging .qb-children:empty {
  position: relative;
  z-index: 2;
  min-height: 0.75rem;
  margin-top: -0.75rem;
  border-bottom: 2px dotted var(--color-border-brand);
}
.qb-dragging, .qb-dragging * { cursor: grabbing !important; }
.qb-ghost > .qb-row { background: var(--color-bg-brand-soft); outline: 2px dashed var(--color-border-brand); outline-offset: -2px; }
.qb-ghost > .qb-row * { visibility: hidden; }
.qb-drag { opacity: 0.92; box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); }
.qb-moved > .qb-row { animation: qb-moved 1.2s ease-out; }
@keyframes qb-moved { from { background: var(--color-bg-brand-soft); } to { background: var(--color-bg-surface); } }

.qb-mini { min-height: 2rem; padding: 0.15rem 0.55rem; font-size: var(--text-caption, 0.75rem); }

/* The row menu: a <details>, so it works by touch and keyboard alike. */
.qb-menu { position: relative; }
.qb-menu > summary { list-style: none; cursor: pointer; }
.qb-menu > summary::-webkit-details-marker { display: none; }
.qb-menu-panel {
  position: absolute;
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 10rem;
  padding: 0.25rem;
  border: 1px solid var(--color-border-1);
  border-radius: var(--radius-control, 0.5rem);
  background: var(--color-bg-surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}
.qb-menu-panel > a, .qb-menu-panel > button, .qb-menu-panel button {
  display: block;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-control, 0.5rem);
  text-align: left;
  font-size: var(--text-body, 0.875rem);
  color: var(--color-fg-1);
}
.qb-menu-panel > a:hover, .qb-menu-panel button:hover { background: var(--color-bg-subtle); }

.qb-bulk {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border-1);
  background: var(--color-bg-brand-soft);
}
.qb-bulk[hidden] { display: none; }
.qb-bulk-field { display: grid; gap: 0.1rem; font-size: var(--text-caption, 0.75rem); color: var(--color-fg-3); font-weight: 500; }
.qb-bulk-field .qb-input { border-color: var(--color-border-2); background: var(--color-bg-surface); min-width: 6rem; }
.qb-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; flex-basis: 100%; color: var(--color-fg-1); }
.qb-confirm[hidden] { display: none; }

.qb-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  z-index: 60;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem 0.5rem 1rem;
  border-radius: var(--radius-card, 0.75rem);
  background: var(--color-bg-inverse);
  color: var(--color-fg-inverse);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}
.qb-toast[hidden] { display: none; }

/* The Publish bar stays in view at the bottom while the parts scroll. */
.qb-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  /* clear of the Intu Bot bubble, which sits over the bottom right */
  padding: 0.55rem 10rem 0.55rem 1rem;
  border-top: 1px solid var(--color-border-1);
  background: var(--color-bg-surface);
}
