.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999998 !important;
  opacity: 0;
  animation: overlayFadeIn 0.35s ease-out forwards;
}
.popup-overlay.closing { animation: overlayFadeOut 0.25s ease-in forwards; }

.trial-popup {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  background: #fff;
  border-radius: 16px;
  padding: 30px;
  width: 90%;
  max-width: 520px;
  z-index: 999999 !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  text-align: center;
  direction: rtl;
  opacity: 0;
  animation: popupFadeIn 0.35s ease forwards;
}

.popup-header { margin-bottom: 18px; }
.popup-header h3 { color: #333; font-size: 24px; margin-bottom: 8px; font-weight: 800; }
.popup-header p { color: #666; font-size: 15px; line-height: 1.6; margin: 0; }

.popup-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.popup-btn {
  padding: 14px 14px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 800;
  border: none;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  text-decoration: none;
}
.popup-btn:disabled { opacity: 0.7; cursor: not-allowed; }
.popup-btn.free-plan { background-color: #f2f3f5; color: #333; }
.popup-btn.free-plan:hover:not(:disabled) { background-color: #e7e9ee; }
.popup-btn.trial-btn { background-color: #5373FD; color: white; }
.popup-btn.trial-btn:hover:not(:disabled) { background-color: #3a5af5; transform: translateY(-1px); }
.popup-btn.plans-btn { background: transparent; color: #5373FD; border: 2px solid #5373FD; }
.popup-btn.plans-btn:hover:not(:disabled) { background-color: #f5f8ff; }

.popup-close {
  position: absolute;
  top: 14px;
  left: 14px;
  background: none;
  border: none;
  font-size: 26px;
  cursor: pointer;
  color: #999;
  padding: 5px;
  line-height: 1;
  z-index: 10;
}
.popup-close:hover { color: #333; }

#tpm-notice-stack {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000002 !important;
  width: min(94vw, 520px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  direction: rtl;
}

.trial-toast.tpm-notice-card {
  position: relative;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 13px;
  align-items: start;
  background: rgba(255,255,255,.98);
  color: #111827;
  padding: 18px 18px 16px 50px;
  border-radius: 20px;
  opacity: 0;
  transform: translateY(-14px) scale(.98);
  transition: opacity .28s ease, transform .28s ease;
  z-index: 1000002 !important;
  box-shadow: 0 18px 45px rgba(15,23,42,.18), 0 3px 12px rgba(15,23,42,.08);
  text-align: right;
  direction: rtl;
  overflow: hidden;
  pointer-events: all;
  border: 1px solid rgba(226,232,240,.95);
  font-family: 'Noto Kufi Arabic', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.trial-toast.tpm-notice-card::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: #2563eb;
}
.trial-toast.tpm-notice-card.show { opacity: 1; transform: translateY(0) scale(1); }
.trial-toast.tpm-notice-card.toast-success::before { background: linear-gradient(180deg, #16a34a, #22c55e); }
.trial-toast.tpm-notice-card.toast-error::before { background: linear-gradient(180deg, #dc2626, #ef4444); }
.trial-toast.tpm-notice-card.toast-warning::before { background: linear-gradient(180deg, #f59e0b, #facc15); }
.trial-toast.tpm-notice-card.toast-info::before { background: linear-gradient(180deg, #2563eb, #38bdf8); }

.tpm-notice-icon {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  font-weight: 900;
  background: #eff6ff;
  color: #2563eb;
  box-shadow: inset 0 0 0 1px rgba(37,99,235,.12);
}
.toast-success .tpm-notice-icon { background: #ecfdf3; color: #15803d; box-shadow: inset 0 0 0 1px rgba(22,163,74,.18); }
.toast-error .tpm-notice-icon { background: #fef2f2; color: #b91c1c; box-shadow: inset 0 0 0 1px rgba(220,38,38,.18); }
.toast-warning .tpm-notice-icon { background: #fffbeb; color: #b45309; box-shadow: inset 0 0 0 1px rgba(245,158,11,.22); }

.tpm-notice-body { min-width: 0; padding-top: 1px; }
.tpm-notice-title {
  display: block;
  color: #0f172a;
  font-size: 16px;
  font-weight: 900;
  margin-bottom: 7px;
  line-height: 1.55;
}
.tpm-notice-message {
  color: #475569;
  font-size: 13.5px;
  line-height: 1.9;
  font-weight: 650;
}
.trial-toast.tpm-notice-card .toast-close {
  position: absolute;
  top: 11px;
  left: 12px;
  width: 31px;
  height: 31px;
  border: 0;
  border-radius: 999px;
  background: #f1f5f9;
  color: #64748b;
  cursor: pointer;
  font-weight: 900;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s ease, color .2s ease, transform .2s ease;
  margin: 0;
  float: none;
}
.trial-toast.tpm-notice-card .toast-close:hover { background:#e2e8f0; color:#0f172a; transform: scale(1.04); }

@media (max-width: 560px) {
  #tpm-notice-stack { top: 14px; width: calc(100vw - 22px); }
  .trial-toast.tpm-notice-card { grid-template-columns: 38px 1fr; gap: 10px; padding: 15px 14px 14px 44px; border-radius: 18px; }
  .tpm-notice-icon { width: 36px; height: 36px; border-radius: 14px; font-size: 18px; }
  .tpm-notice-title { font-size: 14.5px; }
  .tpm-notice-message { font-size: 12.5px; line-height: 1.85; }
}

.tpm-guest-note {
  background: #fff7e6;
  border: 1px solid #ffd591;
  color: #8c5a00;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 13px;
  line-height: 1.5;
  margin: 10px 0 0;
}


.tpm-guest-note.tpm-login-gate-note {
  background: #eef4ff;
  border-color: #b8c7ff;
  color: #18315f;
}

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
  margin-left: 8px;
}

#tpm-offer-container { padding: 0 6px; margin-bottom: 10px; direction: rtl; }
.popup-offer-message {
  background: #e0f5e7;
  color: #1e6b34;
  border: 1px solid #a7d7b8;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 800;
  text-align: center;
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}
#tpm-countdown-timer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-family: system-ui,-apple-system,"Segoe UI",Roboto,Arial;
}
.timer-segment {
  background: #f8f9fa;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
  min-width: 62px;
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}
.timer-number { display:block; font-size:24px; font-weight:900; color:#007bff; line-height:1.1; margin-bottom:2px; }
.timer-label { display:block; font-size:10px; color:#6b7280; letter-spacing:.5px; }

.trial-popup .popup-loader-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.92);
  z-index: 10;
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  border-radius: 16px;
  color: #333;
  text-align: center;
}
.trial-popup.checking-state .popup-loader-overlay { display: flex; }
.trial-popup.checking-state .popup-buttons { filter: blur(2px); }
.loading-spinner {  border: 4px solid #f3f3f3;
  border-top: 4px solid #4e54c8;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  animation: spin 1s linear infinite;
  margin-bottom: 10px;
}

.tpm-grade-picker {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid #eef0f3;
  border-radius: 14px;
  background: linear-gradient(180deg, #fbfcff, #f6f8ff);
  text-align: right;
}
.tpm-grade-picker-head { display:flex; flex-direction:column; gap:4px; margin-bottom:12px; }
.tpm-grade-title { font-size:15px; }
.tpm-grade-picker-hint { font-size:12px; color:#6b7280; }
.tpm-grade-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap:10px; }
.tpm-grade-card {
  background:#fff;
  border:1px solid #e5e7eb;
  border-radius:14px;
  padding:12px 10px;
  text-align:center;
  cursor:pointer;
  transition: all .2s ease;
  box-shadow: 0 3px 10px rgba(0,0,0,.04);
}
.tpm-grade-card:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0,0,0,.07); }
.tpm-grade-card-icon { font-size: 22px; line-height: 1; margin-bottom: 6px; }
.tpm-grade-card-title { font-size: 13px; font-weight: 900; color: #111827; }
.tpm-grade-card.is-selected { border-color: #5373FD; box-shadow: 0 0 0 3px rgba(83,115,253,.18); }
.tpm-grade-actions { display:flex; gap:10px; margin-top: 12px; }
.tpm-grade-actions .popup-btn { flex: 1; }

.manual-trial-btn {
  position: fixed;
  bottom: 30px;
  left: 30px;
  padding: 15px 25px;
  background: #5373FD;
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 5px 15px rgba(83, 115, 253, 0.3);
  z-index: 1000;
  transition: all .3s ease;
  font-size: 16px;
  font-weight: 700;
}
.rtl .manual-trial-btn, body.rtl .manual-trial-btn { left: auto; right: 30px; }
.manual-trial-btn:hover { transform: translateY(-1px); }

@keyframes popupFadeIn {
  from { opacity:0; transform:translate(-50%,-45%) scale(.96); }
  to { opacity:1; transform:translate(-50%,-50%) scale(1); }
}
@keyframes overlayFadeIn { from{opacity:0} to{opacity:1} }
@keyframes overlayFadeOut { from{opacity:1} to{opacity:0} }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width:480px) {
  .trial-popup { padding:20px; width:95%; }
  .popup-header h3 { font-size:20px; }
  .popup-btn { padding:12px; font-size:15px; }
  .tpm-grade-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


/* Production fixes */
.gp-header-row-2,
.gp-header,
#masthead,
.site-header {
  z-index: 100 !important;
}

#trial-popup {
  max-height: 90vh !important;
  overflow-y: auto !important;
}


.manual-trial-btn {
  z-index: 100000 !important;
}


/* Production fix: toast must stay above popup */
.trial-toast{z-index:2147483647 !important;}
.popup-overlay{z-index:2147483645 !important;}
#trial-popup,.trial-popup{z-index:2147483646 !important;}

/* TPM 8A9 — Beta campaign popup visual mode */
.trial-popup.tpm-beta-campaign-popup {
  background: radial-gradient(circle at top right, #eef6ff 0, #ffffff 45%, #f8fbff 100%);
  border: 1px solid rgba(83,115,253,.18);
}
.trial-popup.tpm-beta-campaign-popup .popup-header h3 {
  color: #102a56;
}
.trial-popup.tpm-beta-campaign-popup .popup-header p {
  color: #334155;
  font-weight: 650;
}
.trial-popup.tpm-beta-campaign-popup .tpm-beta-note {
  background: #eef2ff;
  color: #26367c;
  border-color: #c7d2fe;
}
.trial-popup.tpm-beta-campaign-popup .popup-btn.trial-btn {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
}
.trial-popup.tpm-beta-campaign-popup .popup-btn.plans-btn {
  background: #fff;
}


/* TPM 8A10 — cleaner beta signup flow */
.trial-popup.tpm-beta-campaign-popup .tpm-grade-actions .popup-btn {
  min-height: 48px;
  white-space: normal;
  line-height: 1.35;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.trial-popup.tpm-beta-campaign-popup #tpm-grade-confirm {
  white-space: nowrap;
}
.trial-popup.tpm-beta-campaign-popup .tpm-beta-note {
  font-size: 14px;
  line-height: 1.8;
}

/* TPM 1.5.2 — fixed menu trigger replaces the old floating trigger */
#tpm-floating-trigger,
.manual-trial-btn#tpm-floating-trigger {
  display: none !important;
}

.tpm-menu-trigger-item {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  align-self: center !important;
  margin-inline: 6px !important;
  padding: 0 !important;
  height: auto !important;
  line-height: 1 !important;
}

.tpm-menu-trigger,
a.tpm-menu-trigger {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  min-height: 34px !important;
  height: 34px !important;
  max-height: 36px !important;
  padding: 6px 12px !important;
  margin: 0 !important;
  border-radius: 999px !important;
  background: linear-gradient(135deg, #5373FD 0%, #6C4DFF 100%) !important;
  color: #fff !important;
  font-size: 13.5px !important;
  font-weight: 850 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  box-shadow: 0 5px 13px rgba(83,115,253,.22) !important;
  border: 1px solid rgba(255,255,255,.22) !important;
  white-space: nowrap !important;
  box-sizing: border-box !important;
}

.tpm-menu-trigger:hover,
a.tpm-menu-trigger:hover,
.tpm-menu-trigger:focus,
a.tpm-menu-trigger:focus {
  color: #fff !important;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(83,115,253,.30) !important;
}

.tpm-menu-trigger-icon {
  display: inline-flex !important;
  line-height: 1 !important;
  font-size: 12px !important;
}

.tpm-menu-trigger-label {
  display: inline-block !important;
  line-height: 1 !important;
}

@media (max-width: 768px) {
  .tpm-menu-trigger,
  a.tpm-menu-trigger {
    width: auto !important;
    min-height: 32px !important;
    height: 32px !important;
    padding: 6px 10px !important;
    font-size: 12.5px !important;
    margin: 4px 0 !important;
  }
}

/* TPM 1.5.4 — manual menu link style and grade picker hover fix */
.menu-item a[href="#tpm-open-popup"],
.menu-item a[href*="#tpm-open-popup"],
.menu-item a[href="#tpm-popup"],
.menu-item a[href*="#tpm-popup"],
.tpm-menu-trigger,
a.tpm-menu-trigger {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  min-height: 30px !important;
  height: 30px !important;
  max-height: 32px !important;
  padding: 5px 11px !important;
  margin: 0 4px !important;
  border-radius: 999px !important;
  background: linear-gradient(135deg, #5373FD 0%, #6C4DFF 100%) !important;
  color: #fff !important;
  font-size: 12.8px !important;
  font-weight: 850 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  box-shadow: 0 4px 11px rgba(83,115,253,.20) !important;
  border: 1px solid rgba(255,255,255,.22) !important;
  white-space: nowrap !important;
  box-sizing: border-box !important;
}

.menu-item a[href="#tpm-open-popup"]::before,
.menu-item a[href*="#tpm-open-popup"]::before,
.menu-item a[href="#tpm-popup"]::before,
.menu-item a[href*="#tpm-popup"]::before {
  content: '✨';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  margin-inline-end: 4px;
}

.menu-item a[href="#tpm-open-popup"]:hover,
.menu-item a[href*="#tpm-open-popup"]:hover,
.menu-item a[href="#tpm-popup"]:hover,
.menu-item a[href*="#tpm-popup"]:hover,
.menu-item a[href="#tpm-open-popup"]:focus,
.menu-item a[href*="#tpm-open-popup"]:focus,
.menu-item a[href="#tpm-popup"]:focus,
.menu-item a[href*="#tpm-popup"]:focus {
  color: #fff !important;
  transform: translateY(-1px);
  box-shadow: 0 7px 16px rgba(83,115,253,.28) !important;
}

@media (max-width: 768px) {
  .menu-item a[href="#tpm-open-popup"],
  .menu-item a[href*="#tpm-open-popup"],
  .menu-item a[href="#tpm-popup"],
  .menu-item a[href*="#tpm-popup"],
  .tpm-menu-trigger,
  a.tpm-menu-trigger {
    width: auto !important;
    min-height: 30px !important;
    height: 30px !important;
    padding: 5px 10px !important;
    font-size: 12.2px !important;
  }
}

.tpm-grade-card:hover,
.tpm-grade-card:focus,
.tpm-grade-card.is-selected {
  background: linear-gradient(135deg, #5373FD 0%, #6C4DFF 100%) !important;
  border-color: rgba(83,115,253,.85) !important;
  color: #fff !important;
}

.tpm-grade-card:hover .tpm-grade-card-icon,
.tpm-grade-card:hover .tpm-grade-card-title,
.tpm-grade-card:focus .tpm-grade-card-icon,
.tpm-grade-card:focus .tpm-grade-card-title,
.tpm-grade-card.is-selected .tpm-grade-card-icon,
.tpm-grade-card.is-selected .tpm-grade-card-title {
  color: #fff !important;
}

/* TPM 1.5.5 — manual menu trigger alignment requested for IQEC header */
.menu-item a[href="#tpm-open-popup"],
.menu-item a[href*="#tpm-open-popup"],
.menu-item a[href="#tpm-popup"],
.menu-item a[href*="#tpm-popup"],
a.tpm-menu-trigger {
  position: relative !important;
  top: 17px !important;
}

@media (max-width: 768px) {
  .menu-item a[href="#tpm-open-popup"],
  .menu-item a[href*="#tpm-open-popup"],
  .menu-item a[href="#tpm-popup"],
  .menu-item a[href*="#tpm-popup"],
  a.tpm-menu-trigger {
    top: 0 !important;
  }
}

/* TPM 1.5.6 — course lesson pre-gate state */
a.tpm-lesson-access-checking {
  opacity: .72 !important;
  cursor: progress !important;
}


/* TPM 1.5.9 — Profile menu hover guard
   Notices must not create an invisible pointer layer above the header/profile menu.
   Only the close button remains clickable. */
#tpm-notice-stack:empty {
  display: none !important;
}
#tpm-notice-stack {
  pointer-events: none !important;
}
.trial-toast.tpm-notice-card {
  pointer-events: none !important;
}
.trial-toast.tpm-notice-card .toast-close {
  pointer-events: auto !important;
}

/* TPM 1.5.10 — login-only path for existing students */
.tpm-login-only-btn {
  background: #111827 !important;
  color: #fff !important;
  border-color: #111827 !important;
}
.tpm-login-only-btn:hover,
.tpm-login-only-btn:focus {
  background: #0f172a !important;
  border-color: #0f172a !important;
}

/* TPM 1.5.11 — unified guest login/signup popup */
.tpm-free-choice-hint {
  margin: -4px 4px 2px;
  padding: 0 8px;
  color: #64748b;
  font-size: 12.5px;
  line-height: 1.65;
  font-weight: 700;
  text-align: center;
}
.trial-popup[data-context="manual"] .tpm-login-only-btn,
.trial-popup[data-context="login_gate"] .tpm-login-only-btn,
.trial-popup[data-context="grade_required"] .tpm-login-only-btn {
  order: 1;
}
.trial-popup[data-context="manual"] #trial-popup-free-plan,
.trial-popup[data-context="login_gate"] #trial-popup-free-plan,
.trial-popup[data-context="grade_required"] #trial-popup-free-plan {
  order: 2;
}
.trial-popup[data-context="manual"] .tpm-free-choice-hint,
.trial-popup[data-context="login_gate"] .tpm-free-choice-hint,
.trial-popup[data-context="grade_required"] .tpm-free-choice-hint {
  order: 3;
}
.trial-popup[data-context="manual"] #trial-popup-trial-btn,
.trial-popup[data-context="login_gate"] #trial-popup-trial-btn,
.trial-popup[data-context="grade_required"] #trial-popup-trial-btn {
  order: 4;
}
.trial-popup[data-context="manual"] #trial-popup-plans-btn,
.trial-popup[data-context="login_gate"] #trial-popup-plans-btn,
.trial-popup[data-context="grade_required"] #trial-popup-plans-btn {
  order: 5;
}
