/* ==========================================================================
   Khảo Thí Số AI: Số Hóa Đề Thi, Sinh Barem, Chấm Điểm & Xuất PDF
   Commercial Grade Standards, SOLID, Responsive 320px to 1920px+
   Strictly AUTOGRADING Identity
   ========================================================================== */

.math-ocr-view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 1rem;
  box-sizing: border-box;
}

/* Header & Quota Capsule */
.ocr-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--surface-card, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.05));
}

.ocr-header-title-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ocr-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #cbd5e1);
  background: transparent;
  color: var(--text-color, #1e293b);
  cursor: pointer;
  transition: all 0.2s ease;
}

.ocr-back-btn:hover {
  background: var(--surface-hover, #f1f5f9);
}

.ocr-header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-color, #0f172a);
  margin: 0;
  letter-spacing: -0.02em;
}

.ocr-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #0284c7;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  border-radius: 20px;
  text-transform: uppercase;
}

.ocr-header-actions-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ocr-header-login-btn {
  min-height: 38px;
  font-weight: 700;
  white-space: nowrap;
}

.ocr-quota-capsule {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 30px;
  color: #334155;
  transition: all 0.2s ease;
  min-height: 38px;
}

.ocr-quota-capsule.warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #b45309;
}

.ocr-quota-capsule.depleted {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

/* Stepper Navigation */
.ocr-stepper-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-lg, 12px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ocr-step-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s ease;
  user-select: none;
  flex-shrink: 0;
}

.ocr-step-item:hover {
  background: #f1f5f9;
}

.ocr-step-item.active {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1d4ed8;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.15);
}

.ocr-step-item.completed {
  background: #ecfdf5;
  border-color: #10b981;
  color: #047857;
}

.ocr-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
  background: #cbd5e1;
  color: #334155;
  transition: all 0.2s ease;
}

.ocr-step-item.active .ocr-step-badge {
  background: #2563eb;
  color: #ffffff;
}

.ocr-step-item.completed .ocr-step-badge {
  background: #10b981;
  color: #ffffff;
}

.ocr-step-text {
  display: flex;
  flex-direction: column;
}

.ocr-step-num {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  line-height: 1;
}

.ocr-step-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: inherit;
  margin-top: 0.15rem;
  white-space: nowrap;
}

.ocr-step-connector {
  flex: 1;
  height: 2px;
  min-width: 16px;
  max-width: 60px;
  background: #e2e8f0;
  transition: background 0.2s ease;
}

.ocr-step-connector.completed {
  background: #10b981;
}

/* Radar Scanning Animation */
.ocr-scanning-container {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

.ocr-radar-box {
  position: relative;
  width: 100%;
  max-width: 320px;
  height: 80px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #0f172a;
  overflow: hidden;
}

.ocr-radar-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: #38bdf8;
  box-shadow: 0 0 10px #38bdf8, 0 0 20px #38bdf8;
  animation: ocrScanRadar 1.6s infinite linear;
}

@keyframes ocrScanRadar {
  0% { top: 0%; opacity: 0.8; }
  50% { top: 100%; opacity: 1; }
  100% { top: 0%; opacity: 0.8; }
}

.ocr-ticker-text {
  font-size: 0.88rem;
  font-weight: 600;
  color: #0284c7;
}

/* Main Layout Grid */
.ocr-main-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  width: 100%;
}

.math-ocr-conversion-card,
.ocr-stage-card {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ocr-stage-card.is-hidden,
.ocr-stage-card[style*="display: none"],
.ocr-stage-card[style*="display:none"] {
  display: none !important;
}

.ocr-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 0.75rem;
}

.ocr-card-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.ocr-step-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #eff6ff;
  color: #2563eb;
  font-weight: 800;
  font-size: 0.85rem;
  border: 1px solid #bfdbfe;
}

.ocr-card-heading {
  font-size: 1.05rem;
  font-weight: 800;
  color: #0f172a;
  margin: 0;
  line-height: 1.3;
}

.ocr-card-desc {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.15rem;
}

/* Dropzone */
.ocr-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 1.25rem;
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.ocr-dropzone:hover,
.ocr-dropzone.dragover,
.ocr-dropzone.drag-active {
  border-color: #2563eb;
  background: #eff6ff;
}

.ocr-dropzone.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.ocr-dropzone.ocr-dropzone-attention {
  border-color: #f59e0b;
  background: #fffbeb;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.ocr-dropzone-icon {
  width: 44px;
  height: 44px;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.ocr-dropzone-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.ocr-dropzone-subtitle {
  font-size: 0.78rem;
  color: #64748b;
  margin-bottom: 0.85rem;
}

.ocr-dropzone-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.ocr-dropzone-actions .btn {
  min-height: 40px;
}

/* File Previews */
.ocr-file-preview-strip {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  padding: 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.ocr-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
}

.ocr-file-chip-remove {
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.95rem;
  line-height: 1;
  border: none;
  background: transparent;
  padding: 0;
}

.ocr-file-chip-remove:hover {
  color: #ef4444;
}

/* Rubric Table Wrapper */
.ocr-rubric-table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
}

.ocr-rubric-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.ocr-rubric-table th {
  background: #f8fafc;
  padding: 0.65rem 0.85rem;
  text-align: left;
  font-weight: 700;
  color: #334155;
  border-bottom: 1px solid #e2e8f0;
}

.ocr-rubric-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
  color: #1e293b;
}

.ocr-rubric-table tr:last-child td {
  border-bottom: none;
}

/* Score Ribbon */
.ocr-score-ribbon {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border: 1.5px solid #a7f3d0;
  border-radius: 10px;
  flex-wrap: wrap;
}

.ocr-score-badge-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #059669;
  color: #ffffff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  min-width: 90px;
}

.ocr-score-value {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.ocr-score-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 0.2rem;
  opacity: 0.9;
}

.ocr-score-meta {
  flex: 1;
  min-width: 200px;
}

/* Question Breakdown Cards */
.ocr-grading-question-item {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  background: #ffffff;
  transition: all 0.15s ease;
}

.ocr-grading-question-item:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

.ocr-q-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.ocr-q-num {
  font-weight: 800;
  font-size: 0.92rem;
  color: #1e1b4b;
}

.ocr-q-score {
  font-weight: 800;
  font-size: 0.88rem;
  color: #059669;
  background: #ecfdf5;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
}

.ocr-q-score.is-partial {
  color: #b45309;
  background: #fffbeb;
}

.ocr-q-score.is-zero {
  color: #b91c1c;
  background: #fef2f2;
}

.ocr-q-feedback {
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.5;
}

.ocr-q-correction {
  margin-top: 0.45rem;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  background: #f0f9ff;
  border-left: 3px solid #0284c7;
  font-size: 0.8rem;
  color: #0f172a;
  line-height: 1.45;
}

/* Action Buttons, Disabled States, Spinners & Contextual Stage Feedback */
.ocr-stage-1-action-row {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.65rem;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.ocr-stage-1-selectors {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
  min-width: 220px;
}

.ocr-primary-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.25rem;
  min-height: 44px;
  font-weight: 700;
  white-space: nowrap;
  transition: all 0.2s ease;
}

#math-ocr-view button:disabled,
#math-ocr-view select:disabled,
#math-ocr-view input:disabled,
#math-ocr-view .is-busy {
  opacity: 0.68 !important;
  cursor: not-allowed !important;
  transform: none !important;
  box-shadow: none !important;
}

.ocr-step-item.is-locked,
.ocr-back-btn.is-locked {
  opacity: 0.6;
  cursor: not-allowed;
}

.ocr-btn-spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  flex-shrink: 0;
  animation: ocrBtnSpin 0.75s linear infinite;
}

.ocr-spinner-primary {
  color: #0284c7;
}

@keyframes ocrBtnSpin {
  to { transform: rotate(360deg); }
}

.ocr-inline-progress-box {
  display: none;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem 0.95rem;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
}

.ocr-inline-progress-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ocr-inline-progress-text {
  font-size: 0.84rem;
  font-weight: 700;
  color: #0369a1;
}

.ocr-inline-progress-track {
  width: 100%;
  height: 5px;
  background: #e0f2fe;
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.ocr-inline-progress-bar {
  width: 38%;
  height: 100%;
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 999px;
  animation: ocrProgressSlide 1.35s ease-in-out infinite;
}

@keyframes ocrProgressSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.ocr-inline-progress-hint {
  font-size: 0.75rem;
  color: #475569;
}

.ocr-stage-notice {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.45;
}

.ocr-stage-notice-body {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  flex: 1;
}

.ocr-stage-notice-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.ocr-stage-notice-warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.ocr-stage-notice-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.ocr-stage-notice-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.ocr-rubric-footer-cta {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.85rem;
}

.ocr-stage-3-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* KaTeX Formula Responsive Styles */
.katex {
  font-size: 1.05em;
  text-rendering: auto;
}

.katex-display {
  display: block;
  margin: 0.5rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.katex-display::-webkit-scrollbar {
  height: 4px;
}

.katex-display::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* Workspace Layout (Grid) */
.ocr-workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1180px) {
  .ocr-workspace-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Virtual Mathematical Keyboard & Formula Palette (Gauth Style)
   ========================================================================== */
.math-kb-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.math-kb-mode-switcher {
  display: inline-flex;
  background: #f1f5f9;
  border-radius: 20px;
  padding: 3px;
  align-self: flex-start;
  gap: 4px;
}

.math-kb-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  border: none;
  background: transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.math-kb-mode-btn.active {
  background: #ffffff;
  color: #0f172a;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.math-kb-screen-bar {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.math-kb-screen {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  max-height: 220px;
  padding: 0.75rem 1rem;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  font-size: 1.1rem;
  line-height: 1.6;
  color: #0f172a;
  display: block;
  overflow-y: auto;
  overflow-x: auto;
  word-break: break-word;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  transition: border-color 0.2s ease;
}

.math-kb-screen:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.math-kb-placeholder {
  color: #94a3b8;
  font-size: 0.95rem;
  font-style: italic;
  display: inline-block;
  padding: 0.25rem 0;
}

.btn-math-kb-solve {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0 1.25rem;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  align-self: flex-start;
  flex-shrink: 0;
  font-size: 0.92rem;
  font-weight: 800;
  color: #ffffff;
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25);
  transition: all 0.2s ease;
}

.btn-math-kb-solve:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(225, 29, 72, 0.35);
  background: linear-gradient(135deg, #fb7185 0%, #e11d48 100%);
}

.btn-math-kb-solve:active {
  transform: translateY(1px);
}

.math-kb-text-wrapper {
  width: 100%;
}

.math-kb-tabs-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.math-kb-tab-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.math-kb-tab-btn:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.math-kb-tab-btn.active {
  color: #2563eb;
  background: #eff6ff;
  font-weight: 700;
}

.math-kb-palettes {
  display: flex;
  flex-direction: column;
}

.math-kb-palette-pane {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
}

.math-kb-palette-pane.active {
  display: flex;
}

.math-kb-grid-top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(36px, 1fr));
  gap: 6px;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed #e2e8f0;
}

.math-kb-grid-main {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.math-kb-subgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 6px;
  padding-top: 0.25rem;
}

.math-key-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 40px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
  color: #1e293b;
  cursor: pointer;
  user-select: none;
  transition: all 0.12s ease;
  padding: 0 4px;
}

.math-key-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.math-key-btn:active {
  transform: translateY(1px) scale(0.98);
}

.math-key-num {
  background: #f8fafc;
  font-weight: 700;
  font-size: 1rem;
}

.math-key-op {
  background: #ffe4e6;
  color: #e11d48;
  font-weight: 800;
  font-size: 1.1rem;
  border-color: #fecdd3;
}

.math-key-op:hover {
  background: #fecdd3;
}

.math-key-action {
  background: #fee2e2;
  color: #dc2626;
  font-weight: 700;
  border-color: #fca5a5;
}

.math-key-action:hover {
  background: #fca5a5;
}

.math-key-nav {
  background: #f1f5f9;
  color: #475569;
  font-size: 1.1rem;
}

.math-key-var {
  font-style: italic;
  font-family: 'KaTeX_Math', 'Times New Roman', serif;
  font-size: 1.05rem;
  color: #0284c7;
  background: #f0f9ff;
  border-color: #bae6fd;
}

.math-key-fn {
  color: #2563eb;
  background: #eff6ff;
  border-color: #bfdbfe;
  font-size: 0.85rem;
}

.math-key-sym {
  color: #0f172a;
  background: #f8fafc;
  font-size: 1rem;
}

/* Mobile & Tablet Responsiveness for Virtual Math Keyboard */
@media (max-width: 768px) {
  .math-kb-grid-main {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 640px) {
  .math-kb-screen-bar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .btn-math-kb-solve {
    width: 100%;
    min-height: 44px;
    height: 44px;
    justify-content: center;
  }

  .math-kb-screen {
    max-height: 160px;
  }
}

@media (max-width: 480px) {
  .math-kb-container {
    padding: 0.65rem;
    gap: 0.5rem;
  }

  .math-kb-grid-main {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .math-key-btn {
    min-height: 38px;
    font-size: 0.88rem;
    padding: 0 2px;
  }
}

/* Responsive Media Queries */
@media (max-width: 1024px) {
  .ocr-main-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .ocr-header-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .ocr-stepper-container {
    padding: 0.5rem;
  }

  .ocr-step-title {
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .math-ocr-view {
    padding: 0.5rem;
    gap: 0.75rem;
  }

  .ocr-header-bar {
    padding: 0.75rem;
  }

  .ocr-header-title {
    font-size: 1.05rem;
  }

  .ocr-step-item {
    padding: 0.4rem 0.6rem;
  }

  .ocr-step-text {
    display: none;
  }

  .ocr-step-connector {
    max-width: 24px;
  }

  .ocr-dropzone-actions {
    flex-direction: column;
    width: 100%;
  }

  .ocr-dropzone-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .ocr-stage-1-action-row,
  .ocr-stage-3-header-actions,
  .ocr-rubric-footer-cta {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .ocr-stage-1-selectors {
    width: 100%;
    min-width: 0;
  }

  .ocr-stage-1-selectors .form-control {
    flex: 1;
    max-width: none !important;
  }

  #btn-ocr-trigger-rubric,
  #btn-ocr-export-pdf,
  #btn-ocr-grade-next-student,
  #btn-ocr-proceed-step-2 {
    width: 100%;
    justify-content: center;
  }

  .ocr-score-ribbon {
    flex-direction: column;
    align-items: flex-start;
  }

  .ocr-score-badge-box {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    gap: 0.5rem;
  }
}

@media (max-width: 430px) {
  .math-ocr-view {
    padding: 0.5rem;
    gap: 0.75rem;
  }
  .ocr-header-bar {
    padding: 0.75rem;
  }
}

@media (max-width: 360px) {
  .ocr-dropzone-actions {
    flex-direction: column;
    width: 100%;
  }
}

/* ==========================================================================
   WORKFLOW MODE SWITCHER (SEPARATE EXAM VS COMBINED WORKSHEET)
   ========================================================================== */
.ocr-workflow-mode-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.ocr-mode-switch-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: #ffffff;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
}

.ocr-mode-switch-card:hover:not(:disabled) {
  border-color: #93c5fd;
  background: #f8fafc;
}

.ocr-mode-switch-card.active {
  border-color: #4f46e5;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
  box-shadow: 0 3px 12px rgba(79, 70, 229, 0.12);
}

.ocr-mode-switch-icon {
  font-size: 1.45rem;
  line-height: 1.2;
  flex-shrink: 0;
}

.ocr-mode-switch-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.ocr-mode-switch-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.ocr-mode-pill {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  letter-spacing: 0.02em;
}

.ocr-mode-switch-desc {
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.38;
}

.ocr-stage-1-cta-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.ocr-combined-shortcut-btn {
  font-weight: 700;
  white-space: nowrap;
}

/* Stage 2 Combined Worksheet Controls */
.ocr-combined-mode-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 0.95rem;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 10px;
}

.ocr-combined-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-size: 0.83rem;
  color: #1e1b4b;
  cursor: pointer;
  flex: 1;
  min-width: 240px;
  line-height: 1.42;
}

.ocr-combined-checkbox-label input[type="checkbox"] {
  margin-top: 0.2rem;
  width: 16px;
  height: 16px;
  accent-color: #4f46e5;
  flex-shrink: 0;
}

.ocr-combined-selectors {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ocr-combined-selectors .form-control {
  width: auto;
  min-width: 120px;
}

/* ==========================================================================
   STAGE 3: RED-PEN ANNOTATED VIEWER & INTERACTIVE QUESTION FEEDBACK
   ========================================================================== */
.ocr-stage-3-results-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 1.15rem;
  margin-top: 1.15rem;
  align-items: start;
}

.ocr-stage-3-results-layout > .ocr-annotated-pages-container[style*="display: none"] + .ocr-grading-questions-container {
  grid-column: 1 / -1;
}

.ocr-annotated-panel {
  border: 1px solid #fecdd3;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}

.ocr-annotated-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, #fff1f2 0%, #ffffff 100%);
  border-bottom: 1px solid #fecdd3;
}

.ocr-annotated-title-wrap {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.ocr-annotated-pen-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.ocr-annotated-heading {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 800;
  color: #881337;
}

.ocr-annotated-subtext {
  font-size: 0.77rem;
  color: #475569;
  margin-top: 0.15rem;
  line-height: 1.38;
}

.ocr-annotated-page-pills {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  overflow-x: auto;
}

.ocr-page-pill-btn {
  padding: 0.25rem 0.65rem;
  font-size: 0.76rem;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  white-space: nowrap;
}

.ocr-page-pill-btn.active {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

.ocr-annotation-viewer-mount {
  min-height: 420px;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
}

.ocr-annotation-viewer-mount .viewer-toolbar {
  height: auto;
  min-height: 44px;
  padding: 0.45rem 0.75rem;
}

.ocr-annotation-viewer-mount .viewer-canvas-area {
  min-height: 360px;
  max-height: 70vh;
  padding: 1rem;
}

/* ==========================================================================
   ENHANCED COMPACT & MOBILE ERGONOMIC ANNOTATION VIEWER
   ========================================================================== */
.ocr-annotated-panel-header--compact {
  padding: 0.5rem 0.85rem;
  align-items: center;
}

.ocr-annotated-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-ocr-fullscreen {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.74rem;
  font-weight: 700;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-ocr-fullscreen:hover,
.btn-ocr-fullscreen.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

/* Floating Action Dock inside Viewer */
.viewer-floating-dock {
  position: absolute;
  right: 1rem;
  bottom: 1.25rem;
  z-index: 25;
  display: none;
  flex-direction: column;
  gap: 0.55rem;
  pointer-events: auto;
}

.floating-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(203, 213, 225, 0.85);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #1e293b;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.floating-btn:active {
  transform: scale(0.92);
  background: #e2e8f0;
}

#btn-float-peek {
  background: rgba(254, 242, 242, 0.95);
  border-color: #fca5a5;
  color: #dc2626;
  font-weight: 800;
}

#btn-float-peek.is-peeking {
  background: #dc2626;
  color: #ffffff;
}

/* Fullscreen Focus Mode */
.ocr-panel-fullscreen-active {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 100000 !important;
  border-radius: 0 !important;
  border: none !important;
  box-shadow: none !important;
  background: #ffffff !important;
  display: flex !important;
  flex-direction: column !important;
}

.ocr-panel-fullscreen-active .ocr-annotation-viewer-mount {
  flex: 1 1 auto !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
}

.ocr-panel-fullscreen-active .viewer-canvas-area {
  flex: 1 1 auto !important;
  height: 100% !important;
  max-height: 100% !important;
}

body.ocr-fullscreen-locked {
  overflow: hidden !important;
}

body.ocr-fullscreen-locked #zalo-chat-widget,
body.ocr-fullscreen-locked .zalo-chat-container,
body.ocr-fullscreen-locked .mobile-bottom-bar,
body.ocr-fullscreen-locked .bottom-nav {
  display: none !important;
}

@media (max-width: 768px) {
  .ocr-hide-mobile {
    display: none !important;
  }

  .ocr-heading-full {
    display: none !important;
  }

  .ocr-annotated-panel-header--compact {
    padding: 0.45rem 0.65rem;
  }

  .ocr-annotated-heading {
    font-size: 0.86rem;
  }

  /* Ẩn bộ chọn trang lặp đôi trong toolbar khi đã có pills ở trên */
  .ocr-annotated-panel .viewer-toolbar .toolbar-group-nav {
    display: none !important;
  }

  /* Ẩn 5 nút zoom tĩnh trên toolbar, chuyển sang floating dock */
  .ocr-annotated-panel .viewer-toolbar .toolbar-group-zoom {
    display: none !important;
  }

  .ocr-annotated-panel .viewer-toolbar {
    min-height: 38px;
    padding: 0.25rem 0.6rem;
    justify-content: flex-end;
  }

  /* Kích hoạt floating dock trên mobile */
  .ocr-annotated-panel .viewer-floating-dock {
    display: flex !important;
  }

  /* Tối ưu không gian canvas trên mobile */
  .ocr-annotation-viewer-mount {
    min-height: 480px;
    max-height: 75vh;
  }

  .ocr-annotation-viewer-mount .viewer-canvas-area {
    min-height: 420px;
    max-height: 70vh;
    padding: 0.4rem;
  }
}

@media (max-width: 480px) {
  .btn-ocr-fullscreen .fullscreen-label {
    display: none;
  }

  .ocr-annotation-viewer-mount {
    min-height: 440px;
  }
}

/* Pedagogical Strengths & Improvements in Score Ribbon */
.ocr-pedagogical-highlights {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.ocr-highlight-pill {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  line-height: 1.4;
}

.ocr-highlight-pill.is-strength {
  background: #ecfdf5;
  color: #065f46;
  border-left: 3px solid #10b981;
}

.ocr-highlight-pill.is-improve {
  background: #fffbeb;
  color: #92400e;
  border-left: 3px solid #f59e0b;
}

/* Interactive Question Breakdown & Red-Pen Notes */
.ocr-extracted-rubric-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.75rem;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  font-size: 0.8rem;
  color: #1e1b4b;
}

.ocr-questions-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.ocr-questions-section-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 800;
  color: #0f172a;
}

.ocr-questions-section-hint {
  font-size: 0.75rem;
  color: #64748b;
}

.ocr-grading-question-item.is-interactive {
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.ocr-grading-question-item.is-interactive:hover {
  border-color: #fda4af;
  box-shadow: 0 3px 10px rgba(220, 38, 38, 0.08);
}

.ocr-q-title-group,
.ocr-q-score-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.ocr-q-status-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.ocr-q-status-dot.is-full { background: #dcfce7; color: #15803d; }
.ocr-q-status-dot.is-partial { background: #fef3c7; color: #b45309; }
.ocr-q-status-dot.is-zero { background: #fee2e2; color: #b91c1c; }

.ocr-q-page-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: #475569;
}

.ocr-btn-locate-redpen {
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 6px;
  border: 1px solid #fecdd3;
  background: #fff1f2;
  color: #be123c;
  cursor: pointer;
}

.ocr-q-redpen-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.4rem 0;
}

.ocr-redpen-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 6px;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #9f1239;
  font-size: 0.76rem;
  font-weight: 700;
}

.ocr-q-criteria {
  font-size: 0.8rem;
  color: #334155;
  background: #f8fafc;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.4rem;
}

@media (max-width: 1024px) {
  .ocr-stage-3-results-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .ocr-workflow-mode-bar {
    grid-template-columns: 1fr;
  }

  .ocr-stage-1-cta-group {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  #btn-ocr-grade-combined-shortcut,
  #btn-ocr-print-annotated-pdf {
    width: 100%;
    justify-content: center;
  }

  .ocr-combined-selectors {
    width: 100%;
  }

  .ocr-combined-selectors .form-control {
    flex: 1;
  }
}
