/* Workspace Shell */
.app-view {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f1f5f9;
  overflow: hidden;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
  padding: 9px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  z-index: 40;
}
.topbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--blue-900);
  cursor: pointer;
}
.brand-mini img { width: 30px; height: 30px; border-radius: 8px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
}
.status-pill.free { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.status-pill.pro { background: #dcfce7; color: #166534; border-color: #bbf7d0; }

.marks-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 10px;
  font-size: 0.79rem;
  font-weight: 700;
  background: var(--blue-50);
  color: var(--blue-700);
  border: 1px solid var(--blue-100);
}
.marks-badge.warn { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

.btn-ghost { background: var(--slate-100); color: var(--slate-700); }
.btn-ghost:hover { background: var(--slate-200); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }

/* Mobile View Switcher */
.mobile-switcher {
  display: none;
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
  padding: 8px 12px;
  gap: 8px;
}
.mobile-switcher button {
  flex: 1;
  padding: 9px;
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  color: var(--slate-700);
  cursor: pointer;
}
.mobile-switcher button.active { background: var(--blue-600); color: var(--white); border-color: var(--blue-600); }

/* Split Workspace */
.workspace { flex: 1; display: grid; grid-template-columns: 445px 1fr; overflow: hidden; }

.editor-pane {
  background: var(--white);
  border-left: 1px solid var(--slate-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--slate-200);
  background: var(--slate-50);
}
.editor-tab {
  border: none;
  background: transparent;
  padding: 11px 6px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--slate-500);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  transition: all 0.2s;
}
.editor-tab.active { color: var(--blue-700); background: var(--white); border-bottom-color: var(--blue-600); }

.editor-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 13px; }
.tab-panel { display: flex; flex-direction: column; gap: 13px; }

.card-box {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: 14px;
  padding: 13px;
}
.card-box.highlighted { border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.card-box h4 {
  font-size: 0.9rem;
  color: var(--blue-900);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 3 Header Style Buttons */
.style-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 11px; }
.style-btn {
  border: 1.5px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-700);
  border-radius: 10px;
  padding: 8px 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
}
.style-btn.active { background: var(--blue-600); color: var(--white); border-color: var(--blue-600); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.form-group label { font-size: 0.77rem; font-weight: 700; color: var(--slate-700); }
.form-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--slate-200);
  border-radius: 9px;
  font-family: inherit;
  font-size: 0.84rem;
  background: var(--white);
  color: var(--slate-900);
}
.form-control:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12); }
textarea.form-control { min-height: 64px; resize: vertical; }

.check-row { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600; color: var(--slate-700); cursor: pointer; }
.slider-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.slider-row label { font-size: 0.77rem; font-weight: 700; color: var(--slate-700); }
.slider-row input[type="range"] { flex: 1; accent-color: var(--blue-600); }
.slider-val { font-size: 0.75rem; font-weight: 700; color: var(--blue-700); min-width: 40px; text-align: left; }

.symbols-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: 10px;
}
.sym-btn {
  border: 1px solid var(--blue-100);
  background: var(--white);
  color: var(--blue-900);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 0.81rem;
  font-weight: 700;
  cursor: pointer;
}
.sym-btn:hover { background: var(--blue-600); color: var(--white); }

/* Question Cards */
.q-editor-card {
  background: var(--white);
  border: 1.5px solid var(--slate-200);
  border-radius: 14px;
  padding: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.q-editor-card.selected { border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.q-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 9px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--slate-100);
}
.q-badge { background: var(--blue-600); color: var(--white); font-size: 0.75rem; font-weight: 800; padding: 3px 9px; border-radius: 8px; }
.q-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.icon-btn {
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  color: var(--slate-700);
  border-radius: 7px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn:hover { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-500); }
.icon-btn.del:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.sub-box { background: var(--slate-50); border: 1px dashed var(--slate-200); border-radius: 10px; padding: 9px; margin-top: 8px; }

/* Preview Pane */
.preview-pane { display: flex; flex-direction: column; overflow: hidden; background: #e2e8f0; }
.preview-toolbar {
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.mode-pills { display: flex; gap: 5px; flex-wrap: wrap; }
.mode-pill {
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  color: var(--slate-700);
  padding: 5px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
}
.mode-pill.active { background: var(--blue-600); color: var(--white); border-color: var(--blue-600); }

.preview-stage {
  flex: 1;
  overflow: auto;
  padding: 22px 16px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

/* A4 Paper Visual */
.a4-sheet {
  width: 210mm;
  min-height: 297mm;
  background: var(--white);
  color: #000000;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
  position: relative;
  transform-origin: top center;
  overflow: hidden;
  font-family: var(--exam-font, 'Noto Naskh Arabic', serif);
  line-height: var(--exam-lh, 1.65);
}
.a4-inner {
  min-height: 297mm;
  padding: var(--m-top, 13mm) var(--m-right, 13mm) var(--m-bottom, 13mm) var(--m-left, 13mm);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
}
.a4-sheet.border-simple .a4-inner { border: 2px solid #000; margin: 6mm; min-height: calc(297mm - 12mm); }
.a4-sheet.border-double .a4-inner { border: 4px double #000; margin: 6mm; min-height: calc(297mm - 12mm); }
.a4-sheet.border-blue .a4-inner { border: 3px double #1d4ed8; margin: 6mm; min-height: calc(297mm - 12mm); }

.editable-zone { border-radius: 5px; transition: outline 0.15s ease, background 0.15s ease; cursor: pointer; }
.editable-zone:hover { outline: 1.5px dashed #3b82f6; background: rgba(59, 130, 246, 0.04); }
.editable-zone.preview-selected { outline: 2px solid #2563eb; background: rgba(37, 99, 235, 0.06); }

/* 3 Header Templates */
.exam-header-simple {
  border-bottom: 2px solid #000;
  padding-bottom: 8px;
  margin-bottom: 12px;
  font-size: var(--header-fs, 14px);
  font-weight: 700;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.simple-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 14px; }

.exam-header-school,
.exam-header-official {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  border-bottom: 2px solid #000;
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.exam-header-side { font-size: var(--header-fs, 14px); font-weight: 700; line-height: 1.5; }
.exam-header-center { text-align: center; font-size: var(--header-fs, 14px); font-weight: 700; line-height: 1.45; }
.logos-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 4px; }
.exam-logo { width: var(--logo-size, 54px); height: var(--logo-size, 54px); object-fit: contain; display: block; }

.exam-meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  border: 1.2px solid #000;
  border-radius: 6px;
  padding: 6px 12px;
  margin-bottom: 13px;
  font-size: var(--meta-fs, 13px);
  font-weight: 700;
  justify-content: var(--meta-align, space-between);
}
.exam-meta-item span { font-weight: 400; }

/* Questions & Dividers */
.exam-questions-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--q-gap, 13px);
  font-size: var(--q-fs, 15px);
}
.exam-questions-wrap.two-cols { display: block; column-count: 2; column-gap: 18px; column-rule: 1px solid #cbd5e1; }
.exam-questions-wrap.two-cols .exam-q-block { break-inside: avoid; margin-bottom: var(--q-gap, 13px); }

.exam-questions-wrap.div-dashed .exam-q-block { border-bottom: 1px dashed #64748b; padding-bottom: 10px; }
.exam-questions-wrap.div-solid .exam-q-block { border-bottom: 1px solid #334155; padding-bottom: 10px; }
.exam-questions-wrap.div-dashed .exam-q-block:last-child,
.exam-questions-wrap.div-solid .exam-q-block:last-child { border-bottom: none; padding-bottom: 4px; }

.exam-q-block { padding: 3px 5px; }
.exam-q-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-weight: 700; }
.exam-q-mark { font-size: 0.86em; white-space: nowrap; }
.exam-q-img { max-width: 100%; max-height: 150px; margin: 8px auto; display: block; border-radius: 4px; }

.exam-subitems { margin-top: 6px; padding-inline-start: 14px; display: flex; flex-direction: column; gap: 7px; }
.exam-branches { margin-top: 6px; padding-inline-start: 16px; display: flex; flex-direction: column; gap: 6px; }

/* 3 MCQ Styles */
.exam-options-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-top: 5px; padding-inline-start: 16px; }
.exam-options-circles { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 5px; padding-inline-start: 16px; }
.mcq-circle-item { display: inline-flex; align-items: center; gap: 5px; }
.mcq-dot {
  width: 19px;
  height: 19px;
  border: 1.3px solid #000;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 0.72em;
  font-weight: 700;
  line-height: 1;
}
.exam-options-parens { margin-top: 4px; padding-inline-start: 16px; font-weight: 600; }

/* Matching (Free & Table) */
.matching-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.92em; }
.matching-table th, .matching-table td { border: 1px solid #000; padding: 5px 8px; }
.matching-free {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 7px;
  padding-inline: 14px;
}
.matching-free-col { display: flex; flex-direction: column; gap: 6px; }

/* Image Row Question */
.img-row-bank {
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 10px;
  margin: 6px 0 8px;
  text-align: center;
  font-weight: 700;
  font-size: 0.92em;
}
.img-row-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(95px, 1fr));
  gap: 10px;
  margin-top: 8px;
  align-items: end;
}
.img-row-card { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.img-row-card img { max-width: 100%; max-height: 92px; object-fit: contain; border-radius: 4px; }
.img-row-blank {
  width: 90%;
  min-height: 20px;
  border-bottom: 1.5px dotted #000;
  text-align: center;
  font-size: 0.85em;
  font-weight: 700;
}

/* Handwriting & Dictation */
.handwriting-phrase { text-align: center; font-weight: 700; font-size: 1.05em; margin: 7px 0 4px; }
.essay-lines { margin-top: 8px; display: flex; flex-direction: column; gap: 20px; }
.essay-line { border-bottom: 1.2px dotted #334155; height: 1px; }

.dictation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 12px 16px;
  margin-top: 10px;
  padding-inline-start: 10px;
}
.dictation-slot { display: flex; align-items: flex-end; gap: 5px; font-weight: 700; }
.dictation-line { flex: 1; border-bottom: 1.3px dotted #000; height: 14px; }

.answer-key-box {
  margin-top: 5px;
  padding: 4px 10px;
  background: #eff6ff;
  border-inline-start: 3px solid #2563eb;
  color: #1e3a8a;
  font-size: 0.86em;
  font-weight: 700;
}

/* Bottom Grade Table & Score Circle */
.exam-bottom-extras {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 6px;
}
.grade-table {
  flex: 1;
  border-collapse: collapse;
  font-size: 12.5px;
  text-align: center;
}
.grade-table th, .grade-table td { border: 1.2px solid #000; padding: 4px 8px; }
.grade-table th { background: #f8fafc; font-weight: 700; }
.grade-table td:first-child { font-weight: 700; width: 62px; }

.score-circle {
  width: 78px;
  height: 78px;
  border: 2px solid #000;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
.score-circle-top { flex: 1; border-bottom: 2px solid #000; }
.score-circle-bottom {
  flex: 1;
  display: grid;
  place-items: center;
  font-size: 19px;
  font-weight: 800;
}

/* Footer */
.exam-footer-wrap { margin-top: auto; padding-top: 12px; }
.good-luck-box { text-align: center; margin-bottom: 8px; font-size: 13.5px; font-weight: 700; }
.good-luck-pill {
  display: inline-block;
  border: 1.5px solid #000;
  border-radius: 10px;
  padding: 3px 22px;
  background: #f8fafc;
}
.exam-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  padding-top: 6px;
  border-top: 1px solid #cbd5e1;
}

/* Watermark */
.trial-watermark {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  overflow: hidden;
  opacity: 0.13;
}
.trial-watermark span { transform: rotate(-28deg); font-size: 25px; font-weight: 800; color: #1d4ed8; white-space: nowrap; }

/* Half A4 & OMR */
.half-a4-sheet { display: flex; flex-direction: column; height: 297mm; padding: 8mm 12mm; justify-content: space-between; }
.half-a4-slot { flex: 1; overflow: hidden; font-size: 0.85em; display: flex; flex-direction: column; }
.cut-divider { border-top: 1.5px dashed #475569; margin: 6px 0; text-align: center; font-size: 11px; color: #475569; }

.omr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px 22px; margin-top: 12px; }
.omr-row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #cbd5e1; padding: 4px 0; font-weight: 700; }
.omr-bubbles { display: flex; gap: 8px; }
.omr-bubble { width: 23px; height: 23px; border: 1.5px solid #000; border-radius: 50%; display: grid; place-items: center; font-size: 11px; }

/* Modals & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--white);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 24px 54px rgba(15, 23, 42, 0.25);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--slate-200);
}
.modal-head h3 { font-size: 1.08rem; color: var(--blue-900); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(90px);
  background: var(--slate-900);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 700;
  z-index: 900;
  transition: transform 0.3s ease;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.3);
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 980px) {
  .mobile-switcher { display: flex; }
  .workspace { grid-template-columns: 1fr; }
  .workspace.mobile-show-edit .preview-pane { display: none; }
  .workspace.mobile-show-preview .editor-pane { display: none; }
  .editor-pane { border-left: none; }
  .form-grid { grid-template-columns: 1fr; }
}