/* Dashboard polish layer: loaded last to stabilize layout, responsiveness, and UI states. */

:root {
  --dashboard-sidebar: 264px;
  --dashboard-gutter: clamp(16px, 2.2vw, 32px);
  --dashboard-surface: #ffffff;
  --dashboard-border: #dbe3ee;
  --dashboard-muted: #64748b;
  --dashboard-ink: #102033;
  --dashboard-accent: #0f766e;
  --dashboard-accent-soft: rgba(15, 118, 110, 0.1);
  --theme-primary: #9c8c7b;
}

html {
  min-width: 320px;
}

body {
  overflow-x: hidden;
  background: #f6f8fb;
  color: var(--dashboard-ink);
}

body.dark-theme {
  --dashboard-surface: #111827;
  --dashboard-border: #263445;
  --dashboard-muted: #aab7c8;
  --dashboard-ink: #f8fafc;
  background: #0b1120;
}

body,
body * {
  font-weight: normal !important;
}

.fa,
.fas,
.fa-solid {
  font-weight: 900 !important;
}

.far,
.fa-regular {
  font-weight: 400 !important;
}

.navbar {
  min-height: var(--navbar-height);
  padding-inline: clamp(12px, 2vw, 28px);
  gap: 12px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--dashboard-border);
  box-shadow: 0 1px 10px rgba(15, 23, 42, 0.06);
}

body.dark-theme .navbar {
  background: rgba(17, 24, 39, 0.92);
}

[dir="rtl"] .navbar {
  flex-direction: row;
}

.navbar-right,
.navbar-center,
.navbar-left {
  min-width: 0;
  display: flex;
  align-items: center;
}

.navbar-center {
  flex: 1;
  justify-content: center;
}

.navbar-left {
  gap: 10px;
  justify-content: flex-end;
}

.navbar-logo,
.sidebar-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--dashboard-ink);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.navbar-logo i,
.sidebar-logo i {
  color: var(--dashboard-accent);
}

.navbar-title {
  margin: 0;
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 700;
  color: var(--dashboard-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-toggle,
.profile-btn,
.mobile-menu-toggle {
  min-height: 40px;
  border: 1px solid var(--dashboard-border);
  background: var(--dashboard-surface);
  color: var(--dashboard-ink);
  border-radius: 8px;
  cursor: pointer;
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
}

.profile-area {
  position: relative;
  min-width: 0;
}

.profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(280px, 32vw);
  padding: 0 12px;
  font-family: inherit;
}

.profile-email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  inset-inline-end: 0;
  min-width: 220px;
  display: none;
  padding: 8px;
  background: var(--dashboard-surface);
  border: 1px solid var(--dashboard-border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.16);
  z-index: 1100;
}

.profile-dropdown.open,
.profile-dropdown.show {
  display: block;
}

.dashboard-layout {
  direction: inherit;
  min-height: 100vh;
}

.sidebar {
  width: var(--dashboard-sidebar);
  background: var(--dashboard-surface);
  border-color: var(--dashboard-border);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

[dir="rtl"] .sidebar {
  right: 0;
  left: auto;
  border-left: 1px solid var(--dashboard-border);
  border-right: none;
}

[dir="ltr"] .sidebar {
  left: 0;
  right: auto;
  border-right: 1px solid var(--dashboard-border);
  border-left: none;
}

.sidebar-header {
  min-height: var(--navbar-height);
}

.sidebar-nav .nav-link {
  border-radius: 8px;
  min-height: 44px;
  font-weight: 600;
}

.sidebar-nav .nav-item.active .nav-link,
.sidebar-nav .nav-link.active {
  background: #0f766e;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.22);
}

.main-content,
[dir="rtl"] .main-content {
  width: auto;
  min-width: 0;
  margin-right: var(--dashboard-sidebar);
  margin-left: 0;
  padding: calc(var(--navbar-height) + 24px) var(--dashboard-gutter) 40px;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.06), transparent 30%),
    #f6f8fb;
}

[dir="ltr"] .main-content {
  margin-left: var(--dashboard-sidebar);
  margin-right: 0;
}

body.dark-theme .main-content {
  background: #0b1120;
}

input::placeholder,
textarea::placeholder {
  text-align: center;
  opacity: 0.78;
}

.dashboard-section {
  display: none;
  max-width: 1440px;
  margin-inline: auto;
  animation: dashboardFade 180ms ease-out;
}

.dashboard-section.active {
  display: block;
}

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

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.section-header h2 {
  margin: 0;
  color: var(--dashboard-ink);
  font-size: clamp(22px, 2.3vw, 30px);
  line-height: 1.25;
}

.section-subtitle {
  margin: 6px 0 0;
  color: var(--dashboard-muted);
}

.my-exams-title-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.add-new-exam-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding-inline: 18px;
  border-radius: 10px;
  background: var(--dashboard-accent);
  border-color: var(--dashboard-accent);
  box-shadow: 0 8px 20px rgba(15, 118, 110, .2);
}

.add-new-exam-btn:hover {
  background: #0b625c;
  border-color: #0b625c;
}

.overview-cards,
.stats-grid,
.subscription-plans,
.settings-container {
  display: grid;
  gap: 16px;
}

.overview-cards {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.overview-grid,
.subscription-plans {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-container {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card,
.overview-card,
.builder-card,
.settings-card,
.stats-card,
.current-plan-card,
.plan-card,
.mysr-form {
  background: var(--dashboard-surface);
  border: 1px solid var(--dashboard-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.055);
}

.stat-card {
  min-height: 116px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-card-icon {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--dashboard-accent-soft);
  color: var(--dashboard-accent);
}

.stat-card-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-card-value {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 800;
  line-height: 1;
  color: var(--dashboard-ink);
}

.stat-card-label {
  color: var(--dashboard-muted);
  font-size: 13px;
}

.overview-card,
.builder-card,
.settings-card,
.stats-card {
  padding: 0;
  overflow: hidden;
}

/* dashboard.css originally uses .overview-card for the four compact KPI
   cards. The overview content cards share that name, so explicitly restore
   a normal block layout here. Without this, their header and body are placed
   side-by-side and the header appears clipped/hidden. */
.overview-grid > .overview-card {
  display: block;
  align-items: initial;
  gap: 0;
}

.overview-grid > .recent-exams-card:only-child {
  grid-column: 1 / -1;
}

.overview-card > .card-header,
.settings-card > .card-header,
.stats-card > .card-header,
.builder-card > .card-header {
  margin: 0;
  padding: 16px 18px;
  border-bottom: 1px solid var(--dashboard-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px 8px 0 0;
}

.overview-card > .card-header h3,
.settings-card > .card-header h3,
.stats-card > .card-header h3,
.builder-card > .card-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--dashboard-ink);
}

.recent-exams-card {
  min-width: 0;
  overflow: visible;
}

.recent-exams-card > .card-header {
  position: relative;
  z-index: 2;
  min-height: 58px;
  background: var(--dashboard-surface);
  border-radius: 8px 8px 0 0;
  visibility: visible;
  opacity: 1;
}

.recent-exams-card .table-responsive {
  overflow-x: auto;
  border-radius: 0 0 8px 8px;
}

.exam-actions-trigger {
  width: 38px;
  height: 38px;
  border: 1px solid var(--dashboard-border);
  border-radius: 8px;
  background: var(--dashboard-surface);
  color: var(--dashboard-ink);
  cursor: pointer;
}

.exam-actions-trigger:hover { background: var(--dashboard-accent-soft); color: var(--dashboard-accent); }

.exam-actions-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, .58);
  backdrop-filter: blur(5px);
}

.exam-actions-overlay.open { display: flex; }

.exam-actions-dialog {
  width: min(420px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 20px;
  border: 1px solid var(--dashboard-border);
  background: var(--dashboard-surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .3);
}

.exam-actions-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.exam-actions-heading h3 { margin: 0; font-size: 17px; color: var(--dashboard-ink); }
.exam-actions-close { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--dashboard-muted); }
.exam-actions-list { display: grid; gap: 8px; }
.exam-action-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--dashboard-border); border-radius: 13px; background: var(--dashboard-surface); color: var(--dashboard-ink); font: inherit; cursor: pointer; box-shadow: 0 2px 5px rgba(15,23,42,.08); }
.exam-action-item:hover { transform: translateY(-1px); background: #fff; }
.exam-action-item i { width: 22px; text-align: center; font-size: 17px; }
.exam-action-item.action-link { color: #123fe8; }
.exam-action-item.action-danger { color: #ef1b1b; }
.exam-action-item[disabled] { opacity: .55; cursor: wait; transform: none; }
.qr-dialog-body { text-align: center; }
.qr-dialog-body canvas { max-width: 100%; height: auto !important; }
.exam-action-note { margin: 12px 0 0; color: var(--dashboard-muted); font-size: 12px; text-align: center; }

.statistics-status { margin: 0 0 16px; padding: 12px 16px; border: 1px solid var(--dashboard-border); border-radius: 8px; background: var(--dashboard-surface); color: var(--dashboard-muted); text-align: center; }
.statistics-status-error { border-color: rgba(239,68,68,.28); background: rgba(239,68,68,.08); color: #b91c1c; }

.card-body {
  padding: 18px;
}

.settings-card .card-body {
  min-height: 148px;
  display: flex;
  align-items: center;
  padding: 24px;
}

.settings-card .language-options,
.settings-card .theme-options,
.settings-card .account-info {
  width: 100%;
}

.settings-card .radio-label,
.settings-card .info-row {
  align-items: center;
}

.builder-container,
.subscription-container {
  display: grid;
  gap: 18px;
}

.form-row,
.results-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.results-controls {
  grid-template-columns: minmax(220px, 360px) auto;
}

.form-group {
  min-width: 0;
}

.form-input,
.form-textarea,
.form-select,
select,
textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
  max-width: 100%;
  box-sizing: border-box;
}

.checkbox-group,
.language-options,
.theme-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.radio-label,
.checkbox-label {
  min-height: 44px;
  align-items: center;
}

.settings-panel {
  align-items: start;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.option-card {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--dashboard-border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(248, 250, 252, 0.88));
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.option-card:hover {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.07);
}

.option-card input:disabled ~ span:last-child {
  color: var(--dashboard-muted);
}

.advanced-exam-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.segmented-field {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--dashboard-border);
  border-radius: 8px;
  background: #fbfdff;
}

.segmented-label {
  display: block;
  margin-bottom: 8px;
  color: var(--dashboard-muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: #eef3f8;
}

.segmented-options label {
  min-width: 0;
  cursor: pointer;
}

.segmented-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-options span {
  display: flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}

.segmented-options input:checked + span {
  background: var(--dashboard-surface);
  color: var(--dashboard-accent);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

body.dark-theme .option-card,
body.dark-theme .segmented-field {
  background: #111827;
}

body.dark-theme .segmented-options {
  background: #1e293b;
}

body.dark-theme .segmented-options span {
  color: #cbd5e1;
}

#section-new-exam .builder-container {
  gap: 0;
}

#section-new-exam .pg-card {
  width: min(92%, 700px);
  margin: 18px auto;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

#section-new-exam .pg-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--theme-primary);
  color: #ffffff;
  font-size: 15px;
  text-align: right;
}

#section-new-exam .pg-card-header i {
  flex: 0 0 auto;
  color: #ffffff;
  font-size: 18px;
}

#section-new-exam .pg-card-body {
  padding: 18px;
}

#section-new-exam .pg-card-body-compact {
  padding: 14px 18px;
}

#section-new-exam .pg-card-body-compact .inputMyApp {
  margin-bottom: 10px;
}

#section-new-exam .pg-card-body-compact .inputMyApp:last-child {
  margin-bottom: 0;
}

#section-new-exam .pg-intro-banner {
  border-color: rgba(156, 140, 123, 0.15);
  background: linear-gradient(135deg, #fdfbf7, #f8f5f0);
}

#section-new-exam .pg-intro-banner .pg-card-body {
  padding: 20px;
}

#section-new-exam .builder-intro-text {
  text-align: center;
  line-height: 1.6;
  font-size: 14px;
  color: #444444;
}

#section-new-exam .site-url {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 0 2px;
  border-top: 1px dashed rgba(15, 23, 42, 0.1);
  color: var(--theme-primary);
  font-size: 16px;
}

#section-new-exam .site-url h3 {
  margin: 0;
  font-family: Tahoma, var(--font-ar);
  font-size: 16px;
}

#section-new-exam .inputMyApp {
  width: 100%;
  min-height: 42px;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid #ddd6ce;
  border-radius: 8px;
  background: #ffffff;
  color: #333333;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

#section-new-exam .inputMyApp:focus {
  border-color: var(--theme-primary);
  box-shadow: 0 0 0 3px rgba(156, 140, 123, 0.14);
}

#builder-teacher-email {
  text-align: center;
}

#section-new-exam .option-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.05);
  text-align: right;
  cursor: pointer;
  user-select: none;
}

#section-new-exam .option-row:last-of-type {
  border-bottom: none;
}

#section-new-exam .option-row span:last-child {
  flex: 1;
  color: #444444;
  font-size: 14px;
  line-height: 1.5;
}

#section-new-exam .toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex: 0 0 36px;
}

#section-new-exam .toggle-switch input[type="checkbox"] {
  position: absolute !important;
  inset: 0;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  pointer-events: none;
}

#section-new-exam .toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: #c4c4c4;
  cursor: pointer;
  transition: background-color 0.25s ease;
}

#section-new-exam .toggle-slider::before {
  position: absolute;
  bottom: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  content: "";
  transition: transform 0.25s ease;
}

[dir="rtl"] #section-new-exam .toggle-slider::before {
  right: 2px;
}

[dir="rtl"] #section-new-exam .toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(-16px);
}

[dir="ltr"] #section-new-exam .toggle-slider::before {
  left: 2px;
}

[dir="ltr"] #section-new-exam .toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

#section-new-exam .toggle-switch input:checked + .toggle-slider {
  background: var(--theme-primary);
}

#section-new-exam .toggle-switch input:disabled + .toggle-slider {
  opacity: 0.62;
  cursor: not-allowed;
}

#section-new-exam .conditional-field {
  padding: 0 0 8px 8px;
}

#section-new-exam .conditional-field .inputMyApp {
  width: 100%;
  max-width: 300px;
  margin: 0;
}

#section-new-exam .pg-card-body > input[type="radio"] {
  position: fixed !important;
  top: -100px !important;
  left: -100px !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  pointer-events: none;
}

#section-new-exam .radio-card {
  display: block;
  margin: 6px 0;
  padding: 10px 14px;
  border: 1.5px solid #e0ddd8;
  border-radius: 10px;
  background: #fafaf8;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

#section-new-exam input[type="radio"]:checked + .radio-card {
  border-color: var(--theme-primary);
  background: #ffffff;
  box-shadow: 0 0 0 1px var(--theme-primary);
}

#section-new-exam .radio-card-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

#section-new-exam .radio-card-circle {
  position: relative;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 2px solid #bbbbbb;
  border-radius: 50%;
  transition: border-color 0.25s ease;
}

#section-new-exam input[type="radio"]:checked + .radio-card .radio-card-circle {
  border-color: var(--theme-primary);
}

#section-new-exam input[type="radio"]:checked + .radio-card .radio-card-circle::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--theme-primary);
  content: "";
}

#section-new-exam .radio-card-content span:last-child {
  color: #444444;
  font-size: 13px;
  line-height: 1.5;
}

#section-new-exam .option-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #f7f5f2;
  color: #777777;
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

#section-new-exam .option-hint i {
  flex: 0 0 auto;
  color: var(--theme-primary);
  font-size: 16px;
}

#section-new-exam .builder-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(92%, 700px);
  margin: 18px auto;
  padding: 16px 18px;
  border: 1px solid #fecaca;
  border-radius: 12px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 14px;
  line-height: 1.6;
  justify-content: center;
  text-align: center;
  direction: inherit;
}

#section-new-exam .builder-alert i {
  flex: 0 0 auto;
  color: #dc2626;
  font-size: 20px;
}

#section-new-exam .questions-container {
  width: 100%;
  margin: 0 auto;
}

#section-new-exam .builder-card {
  width: min(96%, 860px);
  margin: 24px auto;
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 18px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.1);
  overflow: visible;
}

#section-new-exam .builder-card .card-header {
  min-height: 62px;
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--theme-primary), #796b5e);
  color: #ffffff;
}

#section-new-exam .builder-card .card-header h3,
#section-new-exam .builder-card .card-header i {
  color: #ffffff;
}

#section-new-exam .add-question-actions,
#section-new-exam .builder-actions {
  width: min(96%, 860px);
  margin: 16px auto;
  justify-content: center;
}

#section-new-exam .builder-actions {
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

#section-new-exam #builder-save-btn {
  width: min(100%, 320px);
  padding: 14px 48px;
  border-radius: 12px;
  background: var(--theme-primary);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

#section-new-exam #builder-preview-btn {
  width: min(100%, 320px);
}

#section-new-exam .bw-question-card {
  margin-bottom: 20px;
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.07);
}

#section-new-exam .bw-q-header {
  display: grid;
  grid-template-columns: 36px auto minmax(190px, 1fr) 40px;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
  border-bottom: 1px solid var(--dashboard-border);
}

#section-new-exam .bw-q-drag-handle,
#section-new-exam .bw-q-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 9px;
  background: #e8eef5;
  color: #475569;
}

#section-new-exam .bw-q-drag-handle { cursor: grab; }

#section-new-exam .bw-q-type-select {
  width: 100%;
  min-height: 42px;
  padding: 8px 38px 8px 12px;
  color: var(--dashboard-ink);
  cursor: pointer;
}

#section-new-exam .bw-q-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(239, 68, 68, .25);
  border-radius: 10px;
  background: rgba(239, 68, 68, .09);
  color: #dc2626;
  font-size: 18px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

#section-new-exam .bw-q-delete-btn:hover {
  background: #dc2626;
  color: #fff;
  transform: scale(1.04);
}

#section-new-exam .bw-q-body {
  padding: clamp(14px, 2.5vw, 24px);
}

#section-new-exam .bw-input,
#section-new-exam .bw-q-type-select {
  max-width: 100%;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  background: #ffffff;
  text-align: center;
}

#section-new-exam .bw-input:focus,
#section-new-exam .bw-q-type-select:focus {
  border-color: var(--dashboard-accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
  outline: none;
}

#section-new-exam .bw-q-text {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  line-height: 1.8;
}

#section-new-exam .bw-q-options-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 9px;
}

#section-new-exam .bw-q-options-table th {
  padding: 4px 8px;
  color: var(--dashboard-muted);
  font-size: 12px;
  text-align: center;
}

#section-new-exam .bw-q-options-table td {
  padding: 4px 6px;
  border: 0;
}

#section-new-exam .bw-q-hidden-option {
  display: none;
}

#section-new-exam .bw-q-option-input {
  width: 100%;
  min-height: 44px;
}

#section-new-exam .bw-q-mark-input {
  width: 70px;
  min-height: 42px;
}

#section-new-exam .bw-q-correct-cell input {
  width: 20px;
  height: 20px;
  accent-color: var(--dashboard-accent);
}

#section-new-exam .bw-q-img-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 18px;
}

#section-new-exam .bw-q-image-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 18px;
  border: 1px solid rgba(15, 118, 110, .25);
  border-radius: 10px;
  background: var(--dashboard-accent-soft);
  color: var(--dashboard-accent);
  cursor: pointer;
}

#section-new-exam .bw-q-option-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}

#section-new-exam .bw-q-add-option-inline {
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  margin: 10px auto 0;
  padding: 8px 18px;
  border: 1px dashed var(--dashboard-accent);
  border-radius: 10px;
  background: var(--dashboard-accent-soft);
  color: var(--dashboard-accent);
}

#section-new-exam .bw-q-remove-option-inline {
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 18px;
  border: 1px dashed #dc2626;
  border-radius: 10px;
  background: rgba(239, 68, 68, .08);
  color: #dc2626;
  cursor: pointer;
}

#section-new-exam .add-question-actions {
  position: sticky;
  bottom: 12px;
  z-index: 8;
  padding: 12px;
  border: 1px solid var(--dashboard-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 35px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(12px);
}

#section-new-exam .add-question-actions .dropdown {
  position: relative;
  overflow: visible;
}

#section-new-exam #questionTypeMenu {
  top: auto;
  bottom: calc(100% + 10px);
  inset-inline-start: 0;
  inset-inline-end: auto;
  z-index: 80;
  width: min(310px, calc(100vw - 40px));
  padding: 8px;
  overflow: visible;
  border: 1px solid var(--dashboard-border);
  border-radius: 13px;
  background: var(--dashboard-surface);
  box-shadow: 0 20px 55px rgba(15, 23, 42, .22);
}

#section-new-exam #questionTypeMenu.show {
  display: grid;
  opacity: 1;
  visibility: visible;
  transform: none;
}

#section-new-exam #questionTypeMenu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--dashboard-ink);
  text-align: start;
}

#section-new-exam #questionTypeMenu .dropdown-item:hover {
  background: var(--dashboard-accent-soft);
  color: var(--dashboard-accent);
}

#section-new-exam .builder-preview {
  position: relative;
  top: auto;
  width: min(96%, 860px);
  max-height: none;
  margin: 22px auto 42px;
  overflow: visible;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 18px;
  background: #f8fafc;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.14);
}

#section-new-exam .bw-preview-wrapper { padding: clamp(16px, 3vw, 30px); }
#section-new-exam .bw-preview-header { margin-bottom: 22px; padding: 22px; border-radius: 14px; background: linear-gradient(135deg, var(--dashboard-accent), #155e75); color: #fff; text-align: center; }
#section-new-exam .bw-preview-title, #section-new-exam .bw-preview-info, #section-new-exam .bw-preview-duration { color: #fff; }
#section-new-exam .bw-preview-question { margin-bottom: 16px; padding: 18px; border: 1px solid var(--dashboard-border); border-radius: 14px; background: #fff; }
#section-new-exam .bw-preview-option { display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 11px 13px; border: 1px solid #dbe3ee; border-radius: 10px; background: #f8fafc; }
#section-new-exam .bw-preview-correct { border-color: rgba(16, 185, 129, .45); background: rgba(16, 185, 129, .09); }
#section-new-exam .bw-preview-opt-letter { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; background: var(--dashboard-accent-soft); color: var(--dashboard-accent); }

.results-title-group { display: flex; align-items: center; gap: 12px; }
.results-back-btn { min-height: 42px; gap: 8px; }

body.dark-theme #section-new-exam .pg-card,
body.dark-theme #section-new-exam .radio-card,
body.dark-theme #section-new-exam .inputMyApp,
body.dark-theme #section-new-exam .builder-card {
  background: #111827;
  color: #f8fafc;
}

body.dark-theme #section-new-exam .bw-question-card,
body.dark-theme #section-new-exam .bw-preview-question,
body.dark-theme #section-new-exam .bw-input,
body.dark-theme #section-new-exam .bw-q-type-select {
  background: #111827;
  color: #f8fafc;
}

body.dark-theme #section-new-exam .bw-q-header,
body.dark-theme #section-new-exam .builder-preview,
body.dark-theme #section-new-exam .bw-preview-option {
  background: #1e293b;
  color: #e5e7eb;
}

body.dark-theme #section-new-exam .pg-intro-banner,
body.dark-theme #section-new-exam .option-hint {
  background: #1e293b;
}

body.dark-theme #section-new-exam .builder-intro-text,
body.dark-theme #section-new-exam .option-row span:last-child,
body.dark-theme #section-new-exam .radio-card-content span:last-child {
  color: #e5e7eb;
}

.table-container {
  width: 100%;
  overflow-x: auto;
  background: var(--dashboard-surface);
  border: 1px solid var(--dashboard-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.055);
}

.table-container table,
.mini-table,
.results-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.mini-table {
  min-width: 520px;
}

th,
td {
  vertical-align: middle;
}

.empty-row td {
  padding: 28px 16px !important;
  color: var(--dashboard-muted);
}

.add-question-actions,
.builder-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn,
button {
  min-width: 0;
}

.btn span,
button span {
  overflow-wrap: anywhere;
}

.modal-overlay {
  padding: 16px;
}

.modal {
  width: min(96vw, 720px);
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: 8px;
}

.modal-auth {
  width: min(96vw, 440px);
}

#results-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  padding: clamp(12px, 2vw, 24px);
  background: rgba(15, 23, 42, 0.62);
  overflow: auto;
}

#results-modal-overlay > div,
#results-modal-content {
  width: min(1120px, 100%);
  margin: 0 auto;
  border-radius: 8px !important;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(2, 6, 23, 0.28);
}

#results-modal-body {
  max-height: calc(100vh - 96px);
  overflow: auto;
  background: #f8fafc;
}

#results-modal-body textarea,
#results-modal-body input {
  font-family: inherit;
}

#results-modal-body img {
  height: auto;
  object-fit: contain;
}

.essay-grade-input {
  max-width: 120px;
}

.btn-save-essay-grades {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pro-locked-overlay {
  border-radius: 8px;
}

.toast-container {
  top: calc(var(--navbar-height) + 14px);
  right: 50%;
  left: auto;
  width: min(440px, calc(100vw - 28px));
  max-width: none;
  transform: translateX(50%);
  align-items: stretch;
  z-index: 2000;
}

[dir="rtl"] .toast-container {
  right: 50%;
  left: auto;
  transform: translateX(50%);
}

.toast { min-width: 0; width: 100%; border-radius: 12px; box-shadow: 0 16px 40px rgba(15, 23, 42, .22); }

@media (min-width: 768px) and (max-width: 1100px) {
  :root { --dashboard-sidebar: 220px; --dashboard-gutter: 14px; }
  #section-new-exam .pg-card,
  #section-new-exam .builder-card,
  #section-new-exam .add-question-actions,
  #section-new-exam .builder-actions,
  #section-new-exam .builder-preview { width: 100%; }
  #section-new-exam .builder-card .card-body { padding: 14px; }
  .exam-table,
  .results-table,
  .table-container table { min-width: 100%; table-layout: fixed; }
  .exam-table th,
  .exam-table td,
  .results-table th,
  .results-table td { padding-inline: 8px; overflow-wrap: anywhere; }
  .table-container { max-width: 100%; overflow-x: auto; }
}

@media (max-width: 600px) {
  .my-exams-title-actions,
  .add-new-exam-btn {
    width: 100%;
  }

  #section-new-exam .bw-q-header {
    grid-template-columns: 34px 42px 1fr 38px;
    gap: 6px;
    padding: 10px;
  }
  #section-new-exam .bw-q-type-select { min-width: 0; font-size: 12px; }
  #section-new-exam #questionTypeMenu { position: absolute; bottom: calc(100% + 8px); }
}

@media (max-width: 1180px) {
  .overview-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .overview-grid,
  .settings-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .form-row,
  .results-controls,
  .subscription-plans,
  .advanced-exam-options {
    grid-template-columns: 1fr;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .results-controls .export-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 767px) {
  .navbar {
    padding-inline: 64px 12px;
  }

  [dir="rtl"] .navbar {
    padding-inline: 12px 64px;
  }

  .navbar-logo span,
  .navbar-title,
  .profile-email,
  .profile-btn .fa-chevron-down {
    display: none;
  }

  .profile-btn {
    width: 42px;
    justify-content: center;
    padding: 0;
  }

  .lang-toggle span {
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-toggle {
    position: fixed;
    top: 12px;
    inset-inline-start: 12px;
    z-index: 1200;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
  }

  .sidebar,
  [dir="rtl"] .sidebar,
  [dir="ltr"] .sidebar {
    top: 0;
    width: min(86vw, 300px);
    transform: translateX(-105%);
    right: auto;
    left: 0;
  }

  [dir="ltr"] .sidebar {
    transform: translateX(-105%);
  }

  [dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    transform: translateX(105%);
  }

  .sidebar.open {
    transform: translateX(0) !important;
  }

  .main-content,
  [dir="rtl"] .main-content,
  [dir="ltr"] .main-content {
    margin: 0;
    padding: calc(var(--navbar-height) + 18px) 14px 28px;
  }

  .overview-cards {
    grid-template-columns: 1fr;
  }

  .stat-card {
    min-height: 96px;
  }

  .card-header,
  .card-body {
    padding: 14px;
  }

  .add-question-actions,
  .builder-actions,
  .export-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .add-question-actions .btn,
  .builder-actions .btn,
  .export-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .dropdown,
  .dropdown .btn {
    width: 100%;
  }

  .dropdown-menu {
    position: static;
    width: 100%;
    margin-top: 8px;
    margin-bottom: 0;
  }

  .option-grid {
    grid-template-columns: 1fr;
  }

  .segmented-options {
    grid-template-columns: 1fr;
  }

  #results-modal-overlay {
    padding: 8px;
  }

  #results-modal-body {
    max-height: calc(100vh - 48px);
  }
}

@media (max-width: 420px) {
  .lang-toggle {
    width: 42px;
    padding: 0;
    justify-content: center;
  }

  .lang-toggle span {
    display: none;
  }

  .stat-card {
    align-items: flex-start;
  }
}
