/* ─── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #1a2e4a;
  --navy-mid:   #1e3a5f;
  --navy-light: #2a4a73;
  --teal:       #2d7d6f;
  --teal-light: #3a9e8c;
  --teal-bg:    #e8f5f3;
  --green:      #2e7d52;
  --green-bg:   #e8f5ee;
  --amber:      #b45309;
  --amber-bg:   #fef3c7;
  --red:        #c0392b;
  --red-bg:     #fdeaea;
  --blue:       #1e6fa8;
  --blue-bg:    #e8f1fa;
  --gray-50:    #f8fafc;
  --gray-100:   #f1f5f9;
  --gray-200:   #e2e8f0;
  --gray-300:   #cbd5e1;
  --gray-400:   #94a3b8;
  --gray-500:   #64748b;
  --gray-600:   #475569;
  --gray-700:   #334155;
  --gray-800:   #1e293b;
  --gray-900:   #0f172a;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 12px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.08);
  --radius:     12px;
  --radius-sm:  8px;
  --radius-xs:  6px;
  --font-en:    'Inter', system-ui, sans-serif;
  --font-ar:    'Tajawal', 'Inter', sans-serif;
}

html { font-size: 15px; }

body {
  font-family: var(--font-ar);
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ─── HEADER ────────────────────────────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 60%, #1a3d60 100%);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(0,0,0,.25);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-brand { display: flex; align-items: center; gap: 12px; }

.brand-logo {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.12);
  border-radius: 10px;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 1.1rem; font-weight: 700; letter-spacing: .03em; }
.brand-sub  { font-size: .7rem; opacity: .65; letter-spacing: .05em; text-transform: uppercase; }

.header-badges { display: flex; gap: 8px; margin-left: 8px; }

.badge {
  font-size: .7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  letter-spacing: .03em;
}
.badge-blue { background: rgba(30,111,168,.4); border: 1px solid rgba(30,111,168,.6); }
.badge-teal { background: rgba(45,125,111,.4); border: 1px solid rgba(45,125,111,.6); }

.header-stats {
  margin-left: auto;
  display: flex;
  gap: 20px;
}

.stat-item { display: flex; flex-direction: column; align-items: center; }
.stat-label { font-size: .65rem; opacity: .55; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: .85rem; font-weight: 600; }

/* ─── MAIN LAYOUT ───────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 24px;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

/* ─── PANELS ────────────────────────────────────────────────────────────────── */
.panel {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  border: 1px solid var(--gray-200);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  background: var(--gray-50);
}

.panel-icon {
  font-size: 1rem;
  color: var(--navy-mid);
  width: 22px;
  text-align: center;
}

.panel-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-700);
  letter-spacing: .02em;
  text-transform: uppercase;
}

/* ─── CONFIG PANEL ──────────────────────────────────────────────────────────── */
.panel-config { padding-bottom: 8px; }

.config-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
}
.config-section:last-child { border-bottom: none; }

.config-label {
  display: block;
  font-size: .72rem;
  font-weight: 600;
  color: var(--gray-500);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* Mode Toggle */
.mode-toggle { display: flex; flex-direction: column; gap: 8px; }

.mode-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: white;
  cursor: pointer;
  text-align: left;
  transition: all .2s;
  font-family: var(--font-en);
}

.mode-btn:hover { border-color: var(--navy-light); background: var(--blue-bg); }

.mode-btn.active {
  border-color: var(--navy-mid);
  background: linear-gradient(135deg, var(--navy-mid), var(--navy-light));
  color: white;
}

.mode-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.08);
  border-radius: 8px;
  flex-shrink: 0;
}

.mode-btn.active .mode-icon { background: rgba(255,255,255,.15); }

.mode-name { font-size: .82rem; font-weight: 600; }
.mode-desc { font-size: .68rem; opacity: .65; margin-top: 1px; }

/* Grade Selector */
.grade-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.grade-btn {
  padding: 10px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: white;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  font-family: var(--font-en);
  color: var(--gray-600);
  transition: all .18s;
}

.grade-btn:hover { border-color: var(--teal); color: var(--teal); }
.grade-btn.active {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.grade-info {
  font-size: .72rem;
  color: var(--gray-500);
  padding: 6px 8px;
  background: var(--gray-50);
  border-radius: var(--radius-xs);
}

/* Topic Input */
.topic-input-wrap { position: relative; }

.topic-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font-en);
  font-size: .9rem;
  color: var(--gray-800);
  outline: none;
  transition: border-color .2s;
  background: white;
}

.topic-input:focus { border-color: var(--navy-mid); }
.topic-input::placeholder { color: var(--gray-400); }

.topic-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 180px;
  overflow-y: auto;
  display: none;
}

.suggestion-item {
  padding: 8px 14px;
  font-size: .82rem;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  transition: background .12s;
}
.suggestion-item:hover { background: var(--blue-bg); }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-lesson { font-weight: 500; color: var(--gray-800); }
.suggestion-chapter { font-size: .7rem; color: var(--gray-500); margin-top: 1px; }

.topic-match {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--teal-bg);
  border-radius: var(--radius-xs);
  border-left: 3px solid var(--teal);
  font-size: .72rem;
  color: var(--teal);
}
.match-icon { font-size: .8rem; }

/* Chapter selector */
.chapter-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  color: var(--gray-500);
  padding: 8px 4px;
}

.ch-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--navy-mid);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 2px;
}

.chapter-list::-webkit-scrollbar { width: 4px; }
.chapter-list::-webkit-scrollbar-track { background: var(--gray-100); border-radius: 4px; }
.chapter-list::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

.chapter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all .15s;
  background: white;
}

.chapter-item:hover {
  border-color: var(--navy-light);
  background: var(--blue-bg);
}

.chapter-item.active {
  border-color: var(--navy-mid);
  background: linear-gradient(135deg, var(--navy-mid), var(--navy-light));
  color: white;
}

.ch-num {
  font-size: .7rem;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0,0,0,.1);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: .02em;
}

.chapter-item.active .ch-num { background: rgba(255,255,255,.2); }

.ch-info { flex: 1; min-width: 0; }

.ch-title-en {
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.ch-title-ar {
  font-family: var(--font-ar);
  font-size: .7rem;
  opacity: .7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.ch-count {
  font-size: .65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 100px;
  background: rgba(0,0,0,.08);
  flex-shrink: 0;
}

.chapter-item.active .ch-count { background: rgba(255,255,255,.2); }

.chapter-selected-info {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--blue-bg);
  border: 1px solid #93c5fd;
  border-radius: var(--radius-xs);
  border-left: 3px solid var(--blue);
}

.csi-title {
  font-size: .82rem;
  font-weight: 600;
  color: var(--navy-mid);
  line-height: 1.4;
}

.csi-ar {
  font-family: var(--font-ar);
  font-size: .78rem;
  color: var(--blue);
  direction: rtl;
  text-align: right;
  margin-top: 3px;
}

.csi-lessons {
  font-size: .7rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* Difficulty */
.difficulty-selector { display: flex; flex-direction: column; gap: 6px; }

.diff-option input { display: none; }

.diff-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .18s;
}
.diff-option input:checked + .diff-card {
  border-color: var(--navy-mid);
  background: var(--blue-bg);
}
.diff-card:hover { border-color: var(--gray-400); background: var(--gray-50); }

.diff-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green  { background: #22c55e; }
.dot-yellow { background: #f59e0b; }
.dot-red    { background: #ef4444; }

.diff-name { font-size: .83rem; font-weight: 600; color: var(--gray-700); }
.diff-desc { font-size: .7rem; color: var(--gray-500); }

/* Generate Button */
.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: calc(100% - 40px);
  margin: 16px 20px;
  padding: 14px;
  background: linear-gradient(135deg, var(--navy-mid), var(--navy-light));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-en);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  box-shadow: 0 4px 12px rgba(30,58,95,.35);
  letter-spacing: .02em;
}

.generate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(30,58,95,.45);
}

.generate-btn:active { transform: translateY(0); }

.generate-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

.btn-icon { font-size: 1rem; }

.generate-btn.loading .btn-text::after {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

/* History */
.history-section {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--gray-100);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.clear-history {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: .72rem;
  font-family: var(--font-en);
}
.clear-history:hover { color: var(--red); }

.history-list { display: flex; flex-direction: column; gap: 6px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--gray-50);
  border-radius: var(--radius-xs);
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: all .15s;
  font-size: .78rem;
}
.history-item:hover { background: var(--blue-bg); border-color: var(--blue); }

.history-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-dot-approved { background: var(--green); }
.history-dot-revision { background: var(--amber); }

.history-topic { font-weight: 500; color: var(--gray-700); flex: 1; }
.history-meta  { font-size: .68rem; color: var(--gray-400); }

/* ─── PIPELINE PANEL ────────────────────────────────────────────────────────── */
.panel-pipeline { min-height: 520px; }

.pipeline-mode-label {
  margin-left: auto;
  font-size: .7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  background: var(--navy-mid);
  color: white;
  letter-spacing: .03em;
}

.pipeline-container { padding: 24px 20px; }

/* Idle */
.pipeline-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  gap: 24px;
}

.idle-illustration { position: relative; width: 100px; height: 100px; }

.idle-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px dashed;
  opacity: .25;
  animation: pulse 3s ease-in-out infinite;
}

.ring-outer {
  width: 100px; height: 100px;
  top: 0; left: 0;
  border-color: var(--navy-mid);
}
.ring-inner {
  width: 70px; height: 70px;
  top: 15px; left: 15px;
  border-color: var(--teal);
  animation-delay: .8s;
}

.idle-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 52px; height: 52px;
  background: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
}

.idle-text {
  font-size: .82rem;
  color: var(--gray-500);
  text-align: center;
  max-width: 280px;
  line-height: 1.6;
}

/* Pipeline Flow */
.pipeline-flow {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}

/* Stage */
.pipeline-stage { position: relative; }

.stage-node {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--gray-200);
  background: white;
  position: relative;
  transition: all .3s;
}

.stage-node-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  font-weight: 600;
}

.node-controller { border-color: var(--navy-light); }
.node-controller .stage-node-icon { background: var(--navy-mid); color: white; }

.node-teacher { border-color: var(--teal); }
.node-teacher .stage-node-icon { background: var(--teal); color: white; }

.node-critic { border-color: var(--green); }
.node-critic .stage-node-icon { background: var(--green); color: white; }

.stage-node-title { font-size: .88rem; font-weight: 600; color: var(--gray-800); }
.stage-node-sub   { font-size: .7rem; color: var(--gray-500); }

.stage-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gray-300);
  margin-left: auto;
  transition: all .3s;
}

/* Stage states */
.stage-active .stage-node {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30,111,168,.12);
}
.stage-active .stage-status-dot {
  background: var(--blue);
  animation: pulse-dot .8s ease-in-out infinite;
}
.stage-done .stage-node  { border-color: var(--green); }
.stage-done .stage-status-dot { background: var(--green); }

/* Stage detail */
.stage-detail {
  padding: 12px 18px 14px;
  border: 2px solid var(--gray-200);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--gray-50);
  margin-bottom: 0;
  font-size: .8rem;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}
.detail-row:last-child { margin-bottom: 0; }
.detail-key { font-weight: 600; color: var(--gray-500); white-space: nowrap; min-width: 100px; }
.detail-val { color: var(--gray-700); }
.detail-val-wrap { white-space: normal; line-height: 1.5; }

/* Draft box */
.draft-box {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
}
.draft-label { font-size: .68rem; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.draft-content { font-size: .82rem; color: var(--gray-700); line-height: 1.6; min-height: 20px; }

/* Criteria Grid */
.criteria-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.criteria-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .72rem;
  font-weight: 500;
  color: var(--gray-500);
  padding: 5px 8px;
  background: white;
  border-radius: var(--radius-xs);
  border: 1px solid var(--gray-200);
}
.criteria-item.pass { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.criteria-item.fail { background: var(--red-bg); border-color: var(--red); color: var(--red); }

.crit-icon { font-size: .8rem; }

/* Score bar */
.score-bar-wrap { display: flex; align-items: center; gap: 8px; }
.score-label { font-size: .7rem; color: var(--gray-500); font-weight: 600; min-width: 36px; }
.score-bar {
  flex: 1; height: 6px;
  background: var(--gray-200);
  border-radius: 100px;
  overflow: hidden;
}
.score-fill {
  height: 100%;
  border-radius: 100px;
  background: var(--green);
  width: 0;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.score-num { font-size: .75rem; font-weight: 600; color: var(--gray-700); min-width: 36px; text-align: right; }

/* Revision Banner */
.revision-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--amber-bg);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-xs);
  font-size: .78rem;
  color: var(--amber);
  line-height: 1.5;
}
.revision-icon { font-size: .9rem; flex-shrink: 0; margin-top: 1px; }

/* Connector */
.stage-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 32px;
  position: relative;
}
.connector-line {
  width: 2px;
  flex: 1;
  background: var(--gray-300);
}
.connector-arrow {
  font-size: .8rem;
  color: var(--gray-400);
  line-height: 1;
}

/* Loop Indicator */
.loop-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 4px 0;
  background: var(--amber-bg);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-xs);
}
.loop-line { flex: 1; height: 1px; background: #fcd34d; }
.loop-badge {
  font-size: .72rem;
  font-weight: 600;
  color: var(--amber);
  white-space: nowrap;
}

/* Verdict Box */
.verdict-box {
  margin-top: 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.verdict-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
}
.verdict-inner.approved { background: var(--green-bg); border: 2px solid var(--green); border-radius: var(--radius-sm); }
.verdict-inner.revision { background: var(--amber-bg); border: 2px solid #f59e0b; border-radius: var(--radius-sm); }

.verdict-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}
.verdict-inner.approved .verdict-icon { background: var(--green); color: white; }
.verdict-inner.revision  .verdict-icon { background: #f59e0b; color: white; }

.verdict-text { font-size: 1rem; font-weight: 700; flex: 1; }
.verdict-inner.approved .verdict-text { color: var(--green); }
.verdict-inner.revision  .verdict-text { color: var(--amber); }

.verdict-meta { font-size: .75rem; color: var(--gray-500); }

/* ─── NUM QUESTIONS ─────────────────────────────────────────────────────────── */
.num-q-selector {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.num-q-btn {
  padding: 8px 4px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-xs);
  background: white;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  font-family: var(--font-en);
  color: var(--gray-600);
  transition: all .15s;
  text-align: center;
}
.num-q-btn:hover { border-color: var(--navy-mid); color: var(--navy-mid); }
.num-q-btn.active { border-color: var(--navy-mid); background: var(--navy-mid); color: white; }

.num-q-note {
  font-size: .72rem;
  color: var(--gray-500);
  padding: 4px 6px;
  background: var(--gray-50);
  border-radius: var(--radius-xs);
}

/* ─── PIPELINE PROGRESS ─────────────────────────────────────────────────────── */
.q-progress-bar {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--blue-bg);
  border: 1px solid #93c5fd;
  border-radius: var(--radius-xs);
}
.q-progress-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 6px;
}
.q-progress-track {
  height: 4px;
  background: #bfdbfe;
  border-radius: 100px;
  overflow: hidden;
}
.q-progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 100px;
  width: 0;
  transition: width .5s ease;
}

/* ─── RESULT PANEL ──────────────────────────────────────────────────────────── */
.panel-result { min-height: 480px; overflow-y: auto; max-height: calc(100vh - 88px); }

.result-actions { display: flex; gap: 8px; margin-left: auto; }

/* Quiz header right */
.quiz-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.quiz-progress-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.q-chip {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: white;
  font-size: .6rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-500);
  transition: all .2s;
}
.q-chip.answered  { border-color: var(--blue);  background: var(--blue-bg);  color: var(--blue); }
.q-chip.correct   { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.q-chip.incorrect { border-color: var(--red);   background: var(--red-bg);   color: var(--red); }
.q-chip.loading   { border-color: var(--gray-300); animation: pulse-dot .8s infinite; }

.submit-all-btn {
  padding: 7px 18px;
  border-radius: var(--radius-xs);
  border: none;
  background: linear-gradient(135deg, var(--teal), var(--teal-light));
  color: white;
  font-size: .78rem;
  font-weight: 600;
  font-family: var(--font-en);
  cursor: pointer;
  transition: all .18s;
  box-shadow: 0 2px 8px rgba(45,125,111,.3);
}
.submit-all-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(45,125,111,.4); }
.submit-all-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Quiz content */
.quiz-content { display: flex; flex-direction: column; gap: 0; }

.result-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--gray-100);
}

/* ─── QUESTION MCQ CARDS ────────────────────────────────────────────────────── */
.question-cards { display: flex; flex-direction: column; }

.mcq-card {
  border-bottom: 1px solid var(--gray-100);
  padding: 20px;
  transition: background .2s;
}
.mcq-card:last-child { border-bottom: none; }
.mcq-card.submitted-correct { background: linear-gradient(135deg, #f0fdf4, #f8fafc); }
.mcq-card.submitted-wrong   { background: linear-gradient(135deg, #fef2f2, #f8fafc); }

.mcq-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.mcq-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy-mid);
  color: white;
  font-size: .72rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.mcq-meta {
  display: flex;
  gap: 6px;
}

.mcq-diff-badge {
  font-size: .65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
}
.diff-basic        { background: #dcfce7; color: #166534; }
.diff-intermediate { background: #fef9c3; color: #854d0e; }
.diff-advanced     { background: #fee2e2; color: #991b1b; }

.mcq-generating {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
  color: var(--gray-500);
  font-size: .82rem;
}
.mcq-generating-dots span {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gray-400);
  margin: 0 1px;
  animation: bounce .9s ease-in-out infinite;
}
.mcq-generating-dots span:nth-child(2) { animation-delay: .15s; }
.mcq-generating-dots span:nth-child(3) { animation-delay: .3s; }

.mcq-question {
  font-family: var(--font-ar);
  font-size: 1rem;
  line-height: 1.8;
  color: var(--gray-800);
  direction: rtl;
  text-align: right;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  border-right: 3px solid var(--navy-mid);
}

/* Options */
.mcq-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.mcq-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  background: white;
  direction: rtl;
}
.mcq-option:hover:not(.disabled) {
  border-color: var(--navy-mid);
  background: var(--blue-bg);
}
.mcq-option.selected {
  border-color: var(--navy-mid);
  background: var(--blue-bg);
}
.mcq-option.correct {
  border-color: var(--green);
  background: var(--green-bg);
}
.mcq-option.wrong {
  border-color: var(--red);
  background: var(--red-bg);
}
.mcq-option.disabled { cursor: default; }
.mcq-option.correct-not-selected {
  border-color: var(--green);
  background: var(--green-bg);
  opacity: .7;
}

.opt-label {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all .15s;
  order: 2;
}
.mcq-option.selected .opt-label {
  border-color: var(--navy-mid);
  background: var(--navy-mid);
  color: white;
}
.mcq-option.correct .opt-label {
  border-color: var(--green);
  background: var(--green);
  color: white;
}
.mcq-option.wrong .opt-label {
  border-color: var(--red);
  background: var(--red);
  color: white;
}
.mcq-option.correct-not-selected .opt-label {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.opt-text {
  font-family: var(--font-ar);
  font-size: .9rem;
  color: var(--gray-700);
  flex: 1;
  line-height: 1.5;
  order: 1;
}

.opt-icon {
  font-size: .9rem;
  order: 3;
}

/* Explanation */
.mcq-explanation {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--teal-bg);
  border: 1px solid var(--teal-light);
  border-radius: var(--radius-xs);
  border-right: 3px solid var(--teal);
  font-family: var(--font-ar);
  font-size: .85rem;
  color: var(--teal);
  direction: rtl;
  text-align: right;
  line-height: 1.6;
  display: none;
}
.mcq-explanation.visible { display: block; animation: fadeInUp .25s ease; }

/* ─── SCORE SUMMARY ─────────────────────────────────────────────────────────── */
.score-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 24px;
  border-top: 1px solid var(--gray-100);
}

.ss-ring {
  position: relative;
  width: 120px; height: 120px;
}

.ss-inner {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.ss-num {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--navy-mid);
  line-height: 1;
}
.ss-pct {
  font-size: .75rem;
  color: var(--gray-500);
  margin-top: 2px;
}

.ss-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
}

.ss-actions {
  display: flex;
  gap: 10px;
}

.action-btn {
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--gray-300);
  background: white;
  font-size: .75rem;
  font-weight: 500;
  font-family: var(--font-en);
  cursor: pointer;
  color: var(--gray-600);
  transition: all .15s;
}
.action-btn:hover { background: var(--gray-100); }
.action-btn-primary {
  background: var(--navy-mid);
  color: white;
  border-color: var(--navy-mid);
}
.action-btn-primary:hover { background: var(--navy-light); }

/* Empty state */
.result-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  gap: 14px;
  padding: 40px;
}

.empty-icon { font-size: 2.5rem; color: var(--gray-300); }
.empty-text { font-size: .85rem; color: var(--gray-400); text-align: center; line-height: 1.6; }

/* Loading state */
.result-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  gap: 16px;
}

.loading-dots {
  display: flex;
  gap: 6px;
}
.loading-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--navy-mid);
  animation: bounce .9s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: .15s; }
.loading-dots span:nth-child(3) { animation-delay: .3s; }

.loading-text { font-size: .82rem; color: var(--gray-500); }

/* Result content */
.result-content { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* Meta bar */
.result-meta-bar { display: flex; flex-wrap: wrap; gap: 6px; }

.meta-chip {
  font-size: .7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  letter-spacing: .02em;
}
.chip-grade    { background: var(--navy-mid); color: white; }
.chip-diff     { background: var(--amber-bg); color: var(--amber); border: 1px solid #fcd34d; }
.chip-topic    { background: var(--blue-bg); color: var(--blue); border: 1px solid #93c5fd; }
.chip-mode     { background: var(--gray-100); color: var(--gray-600); }
.chip-attempts { background: var(--teal-bg); color: var(--teal); border: 1px solid var(--teal-light); }

/* Verdict badge */
.result-verdict { display: flex; }

.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 700;
}
.verdict-badge.approved { background: var(--green-bg); color: var(--green); border: 2px solid var(--green); }
.verdict-badge.revision { background: var(--amber-bg); color: var(--amber); border: 2px solid #f59e0b; }

.verdict-score {
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  background: rgba(0,0,0,.08);
}

/* Question Card */
.question-card, .answer-card {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.card-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.label-ar { font-family: var(--font-ar); font-size: .82rem; font-weight: 600; color: var(--navy-mid); }
.label-en { font-size: .7rem; color: var(--gray-400); }

.question-text, .answer-text {
  padding: 16px;
  font-family: var(--font-ar);
  font-size: 1rem;
  line-height: 1.8;
  color: var(--gray-800);
  background: white;
  direction: rtl;
  text-align: right;
}

.toggle-answer {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-en);
  text-align: left;
}
.toggle-icon { margin-left: auto; color: var(--gray-400); font-size: .75rem; transition: transform .2s; }
.toggle-icon.open { transform: rotate(180deg); }

/* Critic breakdown */
.critic-breakdown {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.breakdown-title {
  padding: 10px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  font-size: .72rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.breakdown-grid {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .78rem;
}
.breakdown-icon { font-size: .85rem; width: 18px; flex-shrink: 0; }
.breakdown-key  { font-weight: 600; min-width: 90px; color: var(--gray-600); }
.breakdown-note { color: var(--gray-500); flex: 1; }
.breakdown-row.pass .breakdown-icon { color: var(--green); }
.breakdown-row.fail .breakdown-icon { color: var(--red); }
.breakdown-row.pass .breakdown-key  { color: var(--green); }
.breakdown-row.fail .breakdown-key  { color: var(--red); }

/* ─── LOG DRAWER ────────────────────────────────────────────────────────────── */
.log-drawer {
  background: var(--gray-900);
  color: #a0aec0;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: .72rem;
  border-top: 1px solid #2d3748;
}

.log-toggle {
  padding: 8px 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .72rem;
  color: #718096;
  user-select: none;
  transition: color .15s;
}
.log-toggle:hover { color: #a0aec0; }

.log-content { max-height: 160px; overflow-y: auto; }
.log-entries { padding: 8px 24px 16px; display: flex; flex-direction: column; gap: 3px; }

.log-entry { display: flex; gap: 10px; line-height: 1.5; }
.log-time  { color: #4a5568; white-space: nowrap; }
.log-msg   { }
.log-msg.info    { color: #90cdf4; }
.log-msg.success { color: #9ae6b4; }
.log-msg.warn    { color: #fbd38d; }
.log-msg.error   { color: #fc8181; }

/* ─── ANIMATIONS ────────────────────────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: .25; transform: scale(1); }
  50%       { opacity: .4;  transform: scale(1.05); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.8); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeInUp .3s ease forwards; }

/* ─── RESPONSIVE ────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .main { grid-template-columns: 280px 1fr 300px; gap: 16px; }
}

/* ─── MOBILE TABS ───────────────────────────────────────────────────────────── */
.mobile-tabs {
  display: none;
  position: sticky;
  top: 64px;
  z-index: 90;
  background: white;
  border-bottom: 2px solid var(--gray-200);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.mobile-tab {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  font-family: var(--font-en);
  font-size: .78rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  transition: all .2s;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.mobile-tab.active {
  color: var(--navy-mid);
  border-bottom-color: var(--navy-mid);
}

.mobile-tab-icon { font-size: 1rem; }
.mobile-tab-label { font-size: .65rem; letter-spacing: .04em; text-transform: uppercase; }

@media (max-width: 900px) {
  .mobile-tabs { display: flex; }

  .header-stats  { display: none; }
  .header-badges { display: none; }
  .header-inner  { padding: 0 16px; gap: 12px; }

  /* Lock body — scroll happens inside panels only */
  body { overflow: hidden; height: 100dvh; }

  .main {
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
    margin-top: 0;
    /* Fill remaining height below header (64px) + tabs (48px) */
    height: calc(100dvh - 64px - 48px);
    overflow: hidden;
  }

  /* Hide all panels by default; JS shows active one */
  .panel-config,
  .panel-pipeline,
  .panel-result {
    display: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
    border-top: none;
  }

  /* Active panel fills height and scrolls inside itself */
  .panel.mobile-active {
    display: block;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Config panel tweaks */
  .config-section { padding: 14px 16px; }
  .generate-btn { width: calc(100% - 32px); margin: 14px 16px; }

  /* Pipeline panel */
  .panel-pipeline { min-height: unset; }
  .pipeline-container { padding: 16px; }
  .pipeline-idle { min-height: 260px; }

  /* Quiz panel */
  .panel-result {
    min-height: unset;
    max-height: unset;
    overflow-y: visible;
  }

  .mcq-card { padding: 16px; }
  .mcq-question { font-size: .95rem; }
  .opt-text { font-size: .88rem; }

  /* Bigger touch targets */
  .mcq-option { padding: 13px 14px; min-height: 48px; }
  .grade-btn  { padding: 12px; min-height: 44px; }
  .chapter-item { padding: 11px 12px; min-height: 48px; }
  .mode-btn { padding: 14px; }

  /* Chapter list taller on mobile */
  .chapter-list { max-height: 300px; }

  /* Quiz header chips wrap */
  .quiz-header-right { flex-wrap: wrap; }
  .quiz-progress-chips { max-width: 100%; }

  /* Score summary */
  .ss-actions { flex-direction: column; width: 100%; }
  .action-btn { width: 100%; padding: 12px; text-align: center; font-size: .85rem; }
}

/* ─── MCQ EXTRA ─────────────────────────────────────────────────────────────── */
.mcq-loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 0;
}
.mcq-loading-label {
  font-size: .8rem;
  color: var(--gray-500);
}
.mcq-topic {
  flex: 1;
  font-size: .72rem;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mcq-score-badge {
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 100px;
  background: var(--gray-100);
  color: var(--gray-600);
  flex-shrink: 0;
}
.card-ready { animation: fadeInUp .25s ease; }
