/* AI Grader Phase 3 - Scaffold UI overhaul
 * Houses:
 *   - .qb-actionbar (unified question-bank action row)
 *   - scaffold textarea contrast overrides (.theme-mimwise textarea is too dark)
 *   - .hint-pill (compact, accessible, never breaks paragraph flow)
 *   - .error-card / .error-card--block (clean block error)
 *   - .gap-marker / .error-marker subtle polish
 */

/* ---------- Question-bank action bar ---------- */

.qb-actionbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  margin: 0 0 1.25rem;
  border-radius: 14px;
  border: 1px solid var(--border, #e2e8f0);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  box-shadow: 0 4px 14px rgba(2, 6, 23, 0.18);
}

.qb-actionbar__heading {
  flex: 1 1 280px;
  min-width: 0;
}

.qb-actionbar__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink, #0f172a);
}

.qb-actionbar__subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted, #64748b);
}

.qb-actionbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.qb-actionbar__btn {
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.qb-actionbar__btn--primary {
  background: var(--accent, #3b82f6);
  border: 1px solid var(--accent, #3b82f6);
  color: #fff;
}
.qb-actionbar__btn--primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 6px 14px rgba(59, 130, 246, 0.28);
}

.qb-actionbar__btn--secondary {
  background: transparent;
  border: 1px solid var(--border, #e2e8f0);
  color: var(--ink, #0f172a);
}
.qb-actionbar__btn--secondary:hover {
  background: rgba(255, 255, 255, 0.06);
}

.theme-mimwise .qb-actionbar {
  border-color: var(--mw-border, rgba(255, 255, 255, 0.08));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.theme-mimwise .qb-actionbar__title {
  color: var(--mw-fg, #e9e4d6);
}
.theme-mimwise .qb-actionbar__subtitle {
  color: var(--mw-muted, rgba(233, 228, 214, 0.65));
}
.theme-mimwise .qb-actionbar__btn--primary {
  background: var(--mw-gold, #c4a052);
  border-color: var(--mw-gold, #c4a052);
  color: #1a1a1a;
}
.theme-mimwise .qb-actionbar__btn--primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px rgba(196, 160, 82, 0.4);
}
.theme-mimwise .qb-actionbar__btn--secondary {
  border-color: var(--mw-border, rgba(255, 255, 255, 0.18));
  color: var(--mw-fg, #e9e4d6);
}
.theme-mimwise .qb-actionbar__btn--secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--mw-gold, #c4a052);
}

/* Picker header: simplified label after Phase 3 button removal */
.qb-picker-header {
  display: flex;
  align-items: center;
  margin: 0.25rem 0 0.5rem;
}
.qb-picker-header__label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink, #0f172a);
}
.theme-mimwise .qb-picker-header__label {
  color: var(--mw-fg, #e9e4d6);
}

/* ---------- Scaffold textarea contrast (override theme override) ---------- */

/* Phase 3: form-theme.css forces every theme textarea to dark; the scaffold
 * gap/error inputs need a light, high-contrast surface so the user can see
 * what they're typing. Use !important to win over the theme rule. */
.theme-mimwise .gap-input-expanded,
.theme-mimwise .error-correction-input,
.theme-mimwise .error-correction-input--block,
.theme-mimwise textarea.gap-input-expanded,
.theme-mimwise textarea.error-correction-input,
.theme-mimwise textarea.error-correction-input--block {
  background: #ffffff !important;
  color: #0f172a !important;
  border: 2px solid var(--accent, #3b82f6) !important;
  box-shadow: 0 1px 2px rgba(2, 6, 23, 0.05) !important;
}
.theme-mimwise .error-correction-input,
.theme-mimwise .error-correction-input--block,
.theme-mimwise textarea.error-correction-input,
.theme-mimwise textarea.error-correction-input--block {
  border-color: #ef4444 !important;
}
.theme-mimwise .gap-input-expanded:focus,
.theme-mimwise .error-correction-input:focus,
.theme-mimwise .error-correction-input--block:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25) !important;
}
.theme-mimwise .error-correction-input:focus,
.theme-mimwise .error-correction-input--block:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
}

/* ---------- Compact hint pill ---------- */

/* Inline pill: never breaks paragraph flow. Full body sits in a SIBLING
 * block element below the line, toggled via the [hidden] attribute. */
.hint-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  line-height: 1.3;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(59, 130, 246, 0.22);
  background: rgba(59, 130, 246, 0.08);
  color: #1e3a8a;
  max-width: 100%;
  vertical-align: baseline;
}
.hint-pill[data-pill-variant="error"] {
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.07);
  color: #7f1d1d;
}
.theme-mimwise .hint-pill {
  background: rgba(59, 130, 246, 0.16);
  color: #c8defc;
  border-color: rgba(59, 130, 246, 0.4);
}
.theme-mimwise .hint-pill[data-pill-variant="error"] {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.4);
}

.hint-pill__icon {
  font-size: 0.85rem;
  line-height: 1;
}

.hint-pill__summary {
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48ch;
}

.hint-pill__toggle {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0 0.15rem;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 4px;
}
.hint-pill__toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}
.theme-mimwise .hint-pill__toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}
.hint-pill__toggle::before {
  content: "\25BE"; /* down chevron */
  display: inline-block;
  font-size: 0.85rem;
}
.hint-pill[data-expanded="1"] .hint-pill__toggle::before {
  content: "\25B4"; /* up chevron */
}

.hint-pill-full {
  display: block;
  margin: 0.4rem 0 0.6rem;
  padding: 0.55rem 0.7rem;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  border-radius: 8px;
  border-left: 3px solid rgba(59, 130, 246, 0.6);
  background: rgba(59, 130, 246, 0.06);
  color: #1e293b;
}
.hint-pill-full[data-pill-variant="error"] {
  border-left-color: rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.06);
  color: #7f1d1d;
}
.theme-mimwise .hint-pill-full {
  background: rgba(59, 130, 246, 0.14);
  color: #dbeafe;
}
.theme-mimwise .hint-pill-full[data-pill-variant="error"] {
  background: rgba(239, 68, 68, 0.14);
  color: #fecaca;
}

/* ---------- Block error card ---------- */

.error-card {
  display: block;
  margin: 0.85rem 0;
  padding: 0.85rem 0.95rem;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.32);
  border-left: 4px solid #ef4444;
  background: rgba(239, 68, 68, 0.05);
  max-width: 100%;
}
.theme-mimwise .error-card {
  background: rgba(239, 68, 68, 0.09);
  border-color: rgba(239, 68, 68, 0.45);
}

.error-card__label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b91c1c;
  margin: 0 0 0.45rem;
}
.theme-mimwise .error-card__label {
  color: #fca5a5;
}

.error-card__wrong {
  margin: 0 0 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px dashed rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.06);
  color: #b91c1c;
  text-decoration: line-through;
  text-decoration-color: rgba(220, 38, 38, 0.85);
  text-decoration-thickness: 2px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.5;
}
.theme-mimwise .error-card__wrong {
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.55);
}

.error-card__correction-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
  color: var(--muted, #475569);
}
.theme-mimwise .error-card__correction-label {
  color: rgba(233, 228, 214, 0.75);
}

.error-card__textarea {
  width: 100%;
  min-height: 4.2rem;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
}

.error-card__hint {
  margin-top: 0.55rem;
}

/* Inline error: keep the wavy-underline look, but never break paragraph flow */
.error-marker {
  display: inline;
  text-decoration: wavy underline;
  text-decoration-color: #ef4444;
  text-decoration-thickness: 2px;
  color: #dc2626;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.theme-mimwise .error-marker {
  color: #fca5a5;
}

/* Gap marker baseline tweaks */
.gap-marker {
  display: inline-block;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-bottom: 2px solid #3b82f6;
  border-radius: 4px;
  padding: 1px 6px;
  margin: 0 1px;
  font-size: 0.95rem;
  color: #1e40af;
  font-weight: 600;
  cursor: pointer;
  vertical-align: baseline;
}
.theme-mimwise .gap-marker {
  background: rgba(59, 130, 246, 0.18);
  color: #c8defc;
  border-color: rgba(59, 130, 246, 0.55);
}

/* The textarea container that hangs below an inline gap marker */
.gap-input-container {
  display: block;
  margin: 0.6rem 0;
}

/* ---------- KaTeX failure tone-down ---------- */
/* Phase 3: KaTeX renders unknown commands like `\xii`, `\sumj`, `\alphai`
 * with an inline `style="color:#cc0000"` on a .katex-error span. That inline
 * style beats any stylesheet rule without `!important`, so we force-inherit
 * here. Bad TeX should look like dim plain text, not an alarming red. */
.katex-error,
.katex-error * {
  color: inherit !important;
  background: transparent !important;
  text-decoration: none !important;
  font-style: normal !important;
}
.theme-mimwise .katex-error,
.theme-mimwise .katex-error * {
  color: rgba(233, 228, 214, 0.55) !important;
}

/* Some renderers wrap the failed source in a generic span with the
 * KaTeX colour applied as inline style. Catch those too. */
[style*="color:#cc0000"],
[style*="color: #cc0000"] {
  color: inherit !important;
}

/* ---------- Simplified question-source options ---------- */

.qb-options {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 2rem;
  align-items: flex-start;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border, #e2e8f0);
}

.qb-options__count {
  flex: 0 0 auto;
}

.qb-options__difficulty {
  flex: 1 1 280px;
  min-width: 240px;
}

.qb-options__label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 0.4rem;
  color: var(--ink, #0f172a);
}
.theme-mimwise .qb-options__label {
  color: var(--mw-fg, #e9e4d6);
}

.qb-options__count-row {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.qb-options__count-input {
  width: 84px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  font-size: 0.95rem;
  font-weight: 600;
}

.qb-options__count-hint,
.qb-options__count-hint a {
  font-size: 0.8rem;
  color: var(--muted, #64748b);
}
.theme-mimwise .qb-options__count-hint {
  color: rgba(233, 228, 214, 0.65);
}

.qb-options__hint {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted, #64748b);
}
.theme-mimwise .qb-options__hint {
  color: rgba(233, 228, 214, 0.65);
}

/* Difficulty pill toggle */
.qb-difficulty {
  display: inline-flex;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}
.theme-mimwise .qb-difficulty {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--mw-border, rgba(255, 255, 255, 0.15));
}

.qb-difficulty-btn {
  padding: 0.5rem 1.05rem;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--border, #e2e8f0);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: #475569;
  transition: background 0.12s ease, color 0.12s ease;
}
.qb-difficulty-btn:last-child { border-right: 0; }
.qb-difficulty-btn:hover {
  background: rgba(59, 130, 246, 0.08);
}
.qb-difficulty-btn.is-active {
  background: #eff6ff;
  color: #1e40af;
  font-weight: 700;
}

.theme-mimwise .qb-difficulty-btn {
  border-right-color: var(--mw-border, rgba(255, 255, 255, 0.12));
  color: rgba(233, 228, 214, 0.78);
}
.theme-mimwise .qb-difficulty-btn:hover {
  background: rgba(196, 160, 82, 0.18);
  color: var(--mw-fg, #e9e4d6);
}
.theme-mimwise .qb-difficulty-btn.is-active {
  background: var(--mw-gold, #c4a052);
  color: #1a1a1a;
  box-shadow: inset 0 0 0 1px var(--mw-gold, #c4a052);
}

/* Hide a gap or error wrapper completely if the runtime decides to skip it */
.gap-wrapper--hidden,
.error-wrapper--hidden {
  display: none !important;
}
