:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #dbe3ee;
  --border-strong: #94a3b8;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --primary-border: #93c5fd;
  --accent-a: #0f766e;
  --accent-a-soft: #f0fdfa;
  --accent-b: #6d28d9;
  --accent-b-soft: #f5f3ff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Sticky Top Progress Header */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding-block: 10px;
  padding-inline: 16px;
}

.top-bar-inner {
  max-width: 1080px;
  margin-inline: auto;
}

.top-bar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-block-end: 6px;
}

.brand-tag {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}

.progress-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #0d9488);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Main Container */
.app-root {
  max-width: 1080px;
  margin-inline: auto;
  padding-block: 16px calc(32px + env(safe-area-inset-bottom));
  padding-inline: 14px;
}

.loading-box {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}

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

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-block-end: 16px;
}

.card-narrow {
  max-width: 720px;
  margin-inline: auto;
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  margin-block-end: 10px;
}

h1 {
  margin: 0 0 10px;
  font-size: 1.4rem;
  line-height: 1.4;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
  line-height: 1.45;
}

h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  line-height: 1.45;
}

p {
  margin: 0 0 10px;
}

.muted {
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* Consent Info List */
.consent-list {
  margin: 14px 0;
  padding-inline-start: 20px;
}

.consent-list li {
  margin-block-end: 8px;
}

.ethics-box {
  background: var(--surface-alt);
  border-inline-start: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-block: 14px;
}

/* Bilingual Toggle & Card Header */
.card-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-block-end: 12px;
}

.lang-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding-inline: 14px;
  padding-block: 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.lang-toggle-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

/* Collapsible Context Card */
.context-details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-block-end: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.context-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  background: #f8fafc;
  list-style: none;
}

.context-summary::-webkit-details-marker {
  display: none;
}

.context-summary::after {
  content: "▾";
  font-size: 1.1rem;
  color: var(--primary);
  transition: transform 0.2s ease;
}

.context-details[open] .context-summary::after {
  transform: rotate(180deg);
}

.context-body {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.problem-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-block-end: 10px;
}

.profile-pill {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #78350f;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.93rem;
  margin-block-end: 10px;
}

.opening-box {
  background: #f1f5f9;
  border-inline-start: 3px solid #64748b;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.92rem;
  white-space: pre-line;
}

/* Mobile Sticky Segmented Tab Bar */
.mobile-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  position: sticky;
  top: 58px;
  z-index: 30;
  background: var(--bg);
  padding-block: 8px;
  margin-block-end: 10px;
}

.tab-btn {
  min-height: 46px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.tab-btn.active-a {
  background: var(--accent-a);
  border-color: var(--accent-a);
  color: #fff;
}

.tab-btn.active-b {
  background: var(--accent-b);
  border-color: var(--accent-b);
  color: #fff;
}

.tab-check {
  font-size: 0.85rem;
  opacity: 0.9;
}

/* Dialogue Comparison Grid */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-block-end: 16px;
}

.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.side-header {
  padding: 11px 14px;
  font-weight: 700;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.side-header.side-a {
  background: var(--accent-a-soft);
  color: var(--accent-a);
  border-bottom: 2px solid #99f6e4;
}

.side-header.side-b {
  background: var(--accent-b-soft);
  color: var(--accent-b);
  border-bottom: 2px solid #ddd6fe;
}

.turns-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  padding: 11px 13px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.65;
  white-space: pre-line;
  word-break: break-word;
}

.bubble-teacher {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  margin-inline-end: 10px;
}

.bubble-student {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  margin-inline-start: 10px;
}

.bubble-role {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-block-end: 4px;
  color: var(--text-muted);
}

.bubble-teacher .bubble-role {
  color: #1e40af;
}

.ltr-block {
  direction: ltr;
  text-align: left;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (min-width: 768px) {
  .mobile-tabs {
    display: none;
  }
}

@media (max-width: 767px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }
  .side-panel.mobile-hidden {
    display: none;
  }
}

/* Form Controls & Thumb-Friendly Segmented Pills */
.question-block {
  padding-block: 14px;
  border-bottom: 1px solid var(--border);
}

.question-block:last-child {
  border-bottom: none;
  padding-block-end: 4px;
}

.question-title {
  font-weight: 700;
  font-size: 0.98rem;
  margin-block-end: 4px;
}

.question-help {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-block-end: 10px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-group-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

@media (max-width: 560px) {
  .pill-group-5.comparative-5 {
    grid-template-columns: 1fr;
  }
}

.pill-btn {
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.14s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.pill-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.pill-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.pill-btn.selected-a {
  background: var(--accent-a);
  border-color: var(--accent-a);
  color: #fff;
}

.pill-btn.selected-b {
  background: var(--accent-b);
  border-color: var(--accent-b);
  color: #fff;
}

.pill-btn.selected-warn {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

/* Paired 1-5 Bars (Dignity / Plausibility) */
.paired-scale-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 680px) {
  .paired-scale-grid {
    grid-template-columns: 1fr;
  }
}

.paired-scale-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.paired-scale-label {
  font-weight: 700;
  font-size: 0.92rem;
  margin-block-end: 8px;
}

.scale-anchors {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-block-start: 6px;
}

/* Red Flag Matrix */
.flag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-block: 8px;
  border-bottom: 1px dashed var(--border);
}

.flag-row:last-child {
  border-bottom: none;
}

.flag-text {
  font-size: 0.92rem;
  font-weight: 500;
  flex: 1 1 220px;
}

.flag-toggles {
  display: flex;
  gap: 8px;
}

/* Form B ERIC Checkboxes */
.rubric-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-block: 10px;
}

.check-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 48px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.14s ease;
}

.check-card.checked {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.check-card.checked-none {
  border-color: var(--warn);
  background: var(--warn-soft);
}

.check-card input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  margin-block: 12px;
}

.status-badge.pass {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #86efac;
}

.status-badge.fail {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #fcd34d;
}

.status-badge.pending {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Textarea */
textarea {
  width: 100%;
  min-height: 96px;
  padding: 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

/* Navigation Bar & Guard Hint */
.guard-hint {
  background: var(--warn-soft);
  color: #92400e;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-block-end: 12px;
  text-align: center;
}

.nav-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-block-start: 16px;
}

.btn-primary {
  min-height: 48px;
  padding: 11px 24px;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  min-height: 48px;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translateX(50%) translateY(0);
}
