/* MT Exam Studio — components.css (reusable UI components) */
/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 20, 0.35);
  display: flex;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 1000;
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease);
  pointer-events: none;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 640px;
  max-width: min(640px, calc(100vw - 16px));
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  margin: auto;
  transform: translateY(10px);
  transition: transform var(--duration-slow) var(--ease), opacity var(--duration-slow) var(--ease);
}
.modal-overlay.open .modal-box { transform: translateY(0); opacity: 1; }

/* Large modal variant — wider, more distinct, solid look */
.modal-box.modal-lg {
  max-width: 860px;
  max-width: min(860px, calc(100vw - 16px));
  width: 94%;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  box-shadow: 0 20px 56px rgba(10, 30, 20, 0.25);
}
.modal-box.modal-lg .modal-header {
  padding: 14px 18px;
  background: var(--color-primary-soft);
  border-radius: 20px 20px 0 0;
  border-bottom: 1px solid var(--color-border);
}
.modal-box.modal-lg .modal-header h2 {
  font-size: 1.05rem;
  color: var(--color-primary-dark);
  font-weight: 700;
}
.modal-box.modal-lg .modal-body { padding: 18px; }
.modal-box.modal-lg .modal-footer {
  padding: 12px 18px;
  background: var(--color-bg);
  border-radius: 0 0 20px 20px;
}

/* Bottom sheet variant */
.modal-box.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  transform: translateY(100%);
  opacity: 0;
}
.modal-overlay.open .modal-box.sheet {
  transform: translateY(0);
  opacity: 1;
}
.sheet-handle {
  display: none;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}
.modal-header h2 { font-size: .95rem; margin: 0; flex: 1; min-width: 0; }

/* Per-action popup colours */
.modal-box.tone-primary .modal-header { background: var(--color-primary-light); }
.modal-box.tone-primary .modal-header h2 { color: var(--color-primary-dark); }
.modal-box.tone-info .modal-header { background: var(--color-info-light); }
.modal-box.tone-info .modal-header h2 { color: var(--color-info); }
.modal-box.tone-warn .modal-header { background: var(--color-warn-bg); }
.modal-box.tone-warn .modal-header h2 { color: var(--color-warn); }
.modal-box.tone-danger .modal-header { background: var(--color-error-bg); }
.modal-box.tone-danger .modal-header h2 { color: var(--color-error); }
.modal-box.modal-lg.tone-primary .modal-header { background: var(--color-primary-light); }
.modal-box.modal-lg.tone-warn .modal-header { background: var(--color-warn-bg); }
.modal-box.modal-lg.tone-info .modal-header { background: var(--color-info-light); }
.modal-header.has-back {
  display: flex;
  align-items: center;
  gap: 4px;
}
.modal-header.has-back h2 { flex: 1; min-width: 0; }
.modal-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  border-radius: 10px;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 8px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.modal-back:hover { background: rgba(0,0,0,.06); color: var(--color-text); }
.modal-back:active { transform: scale(.94); }
.modal-close {
  background: none;
  border: 0;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
}
.modal-help {
  background: none;
  border: 0;
  font-size: 1rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px 6px;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  border-radius: 8px;
  transition: background .15s ease, transform .1s ease;
}
.modal-help:hover { background: rgba(0,0,0,.06); color: var(--color-text); }
.modal-help:active { transform: scale(.94); }
.modal-help-panel {
  background: var(--color-info-light);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: .84rem;
  line-height: 1.55;
  flex-shrink: 0;
}
.modal-body { padding: 16px; overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--color-border);
}


/* Footer buttons — wrap side-by-side on small screens */
@media (max-width: 640px) {
  .modal-footer {
    flex-wrap: wrap;
  }
  .modal-footer > div {
    flex-wrap: wrap;
  }
  .modal-footer > div > .btn {
    flex: 1 1 auto;
    min-height: 40px;
    white-space: normal;
  }
}

/* Toast */
.toast-container {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 2000;
  max-width: 90vw;
  pointer-events: none;
}
.toast-action {
  flex-shrink: 0;
  background: var(--color-primary-dark);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.toast-action:hover { background: var(--color-primary-deep); }
.toast {
  padding: 8px 14px;
  border-radius: 20px;
  background: #323940;
  color: #fff;
  font-size: .85rem;
  box-shadow: var(--shadow-lg);
  animation: toastSlide .3s ease-out;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}
.toast.success { background: var(--color-ok); }
.toast.warning { background: var(--color-warn-fill); color: #6B4F00; }
.toast.error { background: var(--color-error-fill); color: #8B1A1A; }
.toast .toast-close { background: none; border: 0; color: inherit; opacity: .7; cursor: pointer; margin-left: auto; padding: 0; }
@keyframes toastSlide {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.toast.closing {
  animation: toastSlideOut .25s ease-in forwards;
}
@keyframes toastSlideOut {
  to { transform: translateY(-20px); opacity: 0; }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner.lg { width: 32px; height: 32px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(247, 249, 248, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
  flex-direction: column;
  gap: 12px;
}
.loading-overlay .loading-text { color: var(--color-text); font-size: .9rem; }

/* Progress-card loading (mobile friendly) */
.loading-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px 20px;
  width: min(320px, 86vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: cardPop .25s ease;
}
.loading-emoji { font-size: 1.8rem; line-height: 1; animation: emojiBounce 1s ease-in-out infinite; }
.loading-progress {
  height: 8px;
  border-radius: 4px;
  background: var(--color-border);
  overflow: hidden;
}
.loading-progress-bar {
  height: 100%;
  width: 40%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  animation: loadingSlide 1.3s ease-in-out infinite;
}
.loading-steps { display: flex; justify-content: center; gap: 10px; }
.loading-step {
  font-size: 1.1rem;
  opacity: .3;
  transition: opacity .3s ease;
}
.loading-step.active { opacity: 1; animation: stepPulse 1s ease-in-out infinite; }
@keyframes cardPop {
  from { transform: scale(.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes loadingSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
@keyframes emojiBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
@keyframes stepPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .6; transform: scale(.88); }
}

/* Tabs */
.tab-bar { display: flex; gap: 4px; border-bottom: 2px solid var(--color-border); margin-bottom: 12px; }
.tab-bar .tab-item {
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: .15s;
}
.tab-bar .tab-item.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* Empty state */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--color-text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { margin: 6px 0; }

/* Review badge (per question) */
.review-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .72rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.review-badge.needs_review,
.review-badge.ai_extracted,
.review-badge.edited {
  background: var(--color-warn-bg);
  color: var(--color-warn);
  border: 1px solid #f0da83;
}
.review-badge.approved,
.review-badge.none {
  background: var(--color-ok-bg);
  color: var(--color-ok);
  border: 1px solid #b5dcb7;
}
.review-badge.error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid #f5c2c2;
}

/* Section controls */
.section-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--color-surface);
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--color-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
}
.section-header .section-title { font-weight: 600; font-size: .9rem; }
.section-body { padding: 10px 14px; }

/* Question row in editor */
.q-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
  position: relative;
}
.q-row:last-child { border-bottom: 0; }
.q-row .q-number {
  font-weight: 700;
  font-size: .9rem;
  color: var(--color-text-muted);
  min-width: 34px;
  padding-top: 4px;
  text-align: center;
}
.q-row .q-content { flex: 1; }
.q-row .q-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.q-row:hover .q-actions { opacity: 1; }
.q-row .q-marks { width: 60px; text-align: center; }
.q-row[draggable="true"] { cursor: grab; }
.q-row[draggable="true"]:active { cursor: grabbing; }
.q-row.q-row-dragging { opacity: .5; border-style: dashed; }
.q-row.q-row-dragover {
  border-bottom: 2px solid var(--color-primary);
  box-shadow: 0 2px 0 0 var(--color-primary);
}

/* ===== Touch devices: always show action buttons, bigger tap targets ===== */
@media (hover: none) {
  .q-row .q-actions { opacity: 1; }
  .q-row .q-actions .btn { min-width: 44px; min-height: 44px; }
  .btn { min-height: 32px; }
  .btn.sm { min-height: 32px; }
  .math-toolbar .math-btn { min-height: 44px; }
}

/* ===== Mobile: no bottom sheets, all centered ===== */
@media (max-width: 640px) {
  .modal-body { padding: 14px; }

  .toast-container {
    top: auto;
    bottom: 24px;
    max-width: 96vw;
  }
  .toast { font-size: .82rem; padding: 6px 12px; }
}

/* ===== Small phones ===== */
@media (max-width: 480px) {
  .toast-container {
    max-width: 96vw;
  }
  .toast { font-size: .82rem; padding: 6px 12px; }
}