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

.trial-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 16px;
  padding: 30px;
  width: 90%;
  max-width: 520px;
  z-index: 9999;
  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; }

.trial-toast {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #333;
  color: #fff;
  padding: 16px 22px;
  border-radius: 12px;
  opacity: 0;
  transition: all .35s ease;
  z-index: 10000;
  box-shadow: 0 8px 25px rgba(0,0,0,.18);
  max-width: 90%;
  text-align: right;
  direction: rtl;
}
.trial-toast.show { opacity: 1; }
.toast-success { background: #28a745; border-left: 4px solid #1e7e34; }
.toast-error { background: #dc3545; border-left: 4px solid #a71d2a; }
.toast-warning { background: #ffc107; color: #000; border-left: 4px solid #d39e00; }
.toast-info { background: #17a2b8; border-left: 4px solid #117a8b; }
.toast-close { float: left; margin-right: 12px; margin-left: 4px; cursor: pointer; font-weight: 900; font-size: 18px; }
.toast-close:hover { color: #eee; }

.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;
}

.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); }
.trial-popup .popup-loader-overlay .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)); }
}

/* =====================================
   FIX: trial-popup فوق gp-header-row-2
===================================== */

/* البوب اب نفسه */
#trial-popup {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  transform: translate(-50%, -50%) !important;
  z-index: 2147483647 !important;

  width: min(92vw, 560px) !important;
  max-height: 90vh !important;
  overflow-y: auto !important;
}

/* إن كان لديك طبقة خلفية منفصلة */
.trial-popup-overlay,
#trial-popup-overlay,
.tpm-popup-overlay,
#tpm-popup-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483646 !important;
}

/* الهيدر يبقى تحته */
.gp-header-row-2,
.gp-header,
#masthead,
.site-header {
  z-index: 10 !important;
}

/* أثناء فتح البوب اب */
html.tpm-popup-open,
body.tpm-popup-open {
  overflow: hidden !important;
}

html.tpm-popup-open .gp-header-row-2,
body.tpm-popup-open .gp-header-row-2,
html.tpm-popup-open .gp-header,
body.tpm-popup-open .gp-header,
html.tpm-popup-open #masthead,
body.tpm-popup-open #masthead,
html.tpm-popup-open .site-header,
body.tpm-popup-open .site-header {
  z-index: 1 !important;
  position: relative !important;
}

/* منع أي قص محتمل من الحاويات */
html.tpm-popup-open #page,
body.tpm-popup-open #page,
html.tpm-popup-open .site,
body.tpm-popup-open .site,
html.tpm-popup-open .gp-container,
body.tpm-popup-open .gp-container {
  overflow: visible !important;
  transform: none !important;
}