/* Trình nhập công thức toán — file riêng để không đụng vào host/style.css. */

/* Ô nhập câu hỏi: textarea nhiều dòng (đề toán thường dài hơn một dòng). */
.field textarea.question-text {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 62px;
}

/* ---- Thanh công cụ công thức ---- */

/* Chỉ hiện thanh công cụ của thẻ câu hỏi đang gõ — danh sách 20 câu không bị
   che kín bởi 20 bảng nút. Nút chèn dùng mousedown + preventDefault nên con trỏ
   vẫn nằm trong ô nhập, :focus-within không bị mất khi bấm nút. */
.formula-toolbar {
  display: none;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 6px;
}
.question-card:focus-within .formula-toolbar { display: flex; }
.question-card:not(:focus-within) .formula-hint { display: none; }
.formula-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.03);
}
/* U22 — chạm tối thiểu 40px (khớp .btn-sm ở host/style.css), trước là 34px. */
.formula-btn {
  min-width: 40px;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.formula-btn:hover {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--accent);
}
.formula-btn:active { transform: scale(0.95); }
.formula-btn .katex { font-size: 1em; }

.formula-hint code {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}

/* ---- Khung xem trước (đúng thứ học sinh sẽ thấy trên điện thoại) ---- */

.math-preview {
  margin: -8px 0 14px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: rgba(37, 99, 235, 0.05);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: auto; /* công thức dài thì cuộn ngang, không phá vỡ bố cục thẻ */
}
.math-preview:empty { display: none; }

.choice-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.choice-preview {
  margin: 0;
  padding: 6px 8px;
  font-size: 14px;
}

.paste-note {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: rgba(37, 99, 235, 0.08);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
}

.math-error-msg {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--danger);
}

/* KaTeX kế thừa màu chữ (currentColor) nên tự hợp theme hiện tại; chỉ cần chặn tràn ngang. */
.mathtext { overflow-wrap: break-word; }
.mathtext .katex-display { margin: 0.4em 0; }
.math-raw { font-family: ui-monospace, monospace; color: var(--danger); }
