/* ============================================================================
   NabGol — BACK GUARD  (the «می‌خواهید بروید؟» sheet and the fresh-chat toast)
   ----------------------------------------------------------------------------
   Owns exactly two elements, both built by chat-back-guard.js: `.nbg-leave`
   and `.nbg-bg-toast`. Nothing else on the page is restyled here.

   The sheet is shown on dozens of surfaces — the site, the Android app, the
   messengers' in-app browsers, whatever comes next — so it names none of them
   and borrows nothing from any of them: the robot's own face, one question,
   one safe choice and one quiet way out.

   One small card in the centre of the screen on every width (owner's rule:
   a new window never sits on the typing box, and a masterpiece is minimal).
   Dark is the default theme on this page; `html[data-theme="light"]` flips it.
   No backdrop blur (the phone's workbench dropped it for low-end devices,
   §34-3پ) — a dim scrim is enough to say "the page is waiting".
   ========================================================================== */

.nbg-leave,
.nbg-bg-toast {
  --nbl-face: #111a27;
  --nbl-face-2: #162234;
  --nbl-edge: rgba(148, 168, 200, 0.14);
  --nbl-hi: rgba(255, 255, 255, 0.06);
  --nbl-ink: #eef3f9;
  --nbl-ink-soft: #9fb0c4;
  --nbl-accent: #34d399;
  --nbl-accent-2: #10b981;
  --nbl-accent-ink: #6ee7b7;
  --nbl-on-accent: #04130d;
  --nbl-scrim: rgba(2, 6, 14, 0.58);
  --nbl-quiet: rgba(148, 168, 200, 0.08);
  --nbl-quiet-hover: rgba(148, 168, 200, 0.14);
  --nbl-shadow: 0 -1px 0 var(--nbl-hi) inset, 0 32px 80px -12px rgba(0, 0, 0, 0.6), 0 8px 24px rgba(0, 0, 0, 0.28);
  --nbl-font: var(--font-family, "Vazirmatn", "Segoe UI", Tahoma, sans-serif);
}

html[data-theme="light"] .nbg-leave,
html[data-theme="light"] .nbg-bg-toast {
  --nbl-face: #ffffff;
  --nbl-face-2: #f4f8f6;
  --nbl-edge: rgba(15, 23, 42, 0.08);
  --nbl-hi: rgba(255, 255, 255, 0.9);
  --nbl-ink: #0f172a;
  --nbl-ink-soft: #52627a;
  --nbl-accent: #10b981;
  --nbl-accent-2: #059669;
  --nbl-accent-ink: #047857;
  --nbl-on-accent: #ffffff;
  --nbl-scrim: rgba(15, 23, 42, 0.36);
  --nbl-quiet: rgba(15, 23, 42, 0.05);
  --nbl-quiet-hover: rgba(15, 23, 42, 0.09);
  --nbl-shadow: 0 30px 70px -14px rgba(15, 23, 42, 0.28), 0 6px 18px rgba(15, 23, 42, 0.08);
}

/* ── the question ──────────────────────────────────────────────────────── */
/* A small card in the middle of the screen, on every width. Never a bottom
   sheet: that would sit on the typing box the reader was just using. Small on
   purpose — one face, one line, one sentence, two buttons. */

.nbg-leave {
  position: fixed;
  inset: 0;
  z-index: 12100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: var(--nbl-font);
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
}
.nbg-leave[hidden] { display: none; }

.nbg-leave-scrim {
  position: absolute;
  inset: 0;
  background: var(--nbl-scrim);
  opacity: 0;
  transition: opacity 0.24s ease;
}
.nbg-leave.is-open .nbg-leave-scrim { opacity: 1; }

.nbg-leave-card {
  position: relative;
  width: min(292px, 100%);
  box-sizing: border-box;
  padding: 22px 18px 16px;
  border-radius: 22px;
  background:
    radial-gradient(90% 60% at 50% -8%, rgba(52, 211, 153, 0.12), transparent 64%),
    var(--nbl-face);
  border: 1px solid var(--nbl-edge);
  box-shadow: var(--nbl-shadow);
  color: var(--nbl-ink);
  text-align: center;
  opacity: 0;
  transform: translateY(8px) scale(0.94);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.24, 1.08), opacity 0.2s ease;
}
.nbg-leave.is-open .nbg-leave-card { opacity: 1; transform: none; }

/* The robot's own face in a thin, slowly turning emerald ring — the one thing
   on this card that belongs to whoever the reader was talking to. */
.nbg-leave-mark {
  position: relative;
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
}
.nbg-leave-halo {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, var(--nbl-accent), rgba(52, 211, 153, 0) 40%, rgba(96, 165, 250, 0.5) 64%, rgba(52, 211, 153, 0) 82%, var(--nbl-accent));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
  animation: nbg-leave-spin 8s linear infinite;
}
.nbg-leave-face {
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: var(--nbl-face-2) center / cover no-repeat;
  box-shadow: 0 0 0 1px var(--nbl-edge);
}
.nbg-leave-face.is-empty {
  background-image: radial-gradient(circle at 35% 30%, #6ee7b7, #10b981 55%, #047857);
}
.nbg-leave-door {
  position: absolute;
  inset-inline-start: -5px;
  bottom: -4px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--nbl-face);
  color: var(--nbl-accent-ink);
  box-shadow: 0 0 0 1px var(--nbl-edge);
}
.nbg-leave-door svg { width: 11px; height: 11px; transform: scaleX(-1); } /* RTL: walks out towards the start edge */

.nbg-leave-title {
  margin: 0 0 4px;
  font-size: 16.5px;
  line-height: 1.5;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--nbl-ink);
}
.nbg-leave-body {
  margin: 0 0 16px;
  font-size: 12.75px;
  line-height: 1.85;
  font-weight: 400;
  color: var(--nbl-ink-soft);
}
/* Two clauses, two lines — the break falls on the semicolon, never mid-thought. */
.nbg-leave-body > span { display: block; }

.nbg-leave-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.nbg-leave-actions button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  min-height: 40px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-family: var(--nbl-font);
  font-size: 14px !important;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease;
}
.nbg-leave-actions button:active { transform: scale(0.97); }
.nbg-leave-actions button:focus-visible {
  outline: 2px solid var(--nbl-accent);
  outline-offset: 2px;
}
.nbg-leave-stay {
  font-weight: 800 !important;
  color: var(--nbl-on-accent) !important;
  background: linear-gradient(180deg, var(--nbl-accent), var(--nbl-accent-2)) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 8px 18px -10px rgba(16, 185, 129, 0.8);
}
.nbg-leave-go {
  font-weight: 600 !important;
  color: var(--nbl-ink-soft) !important;
  background: var(--nbl-quiet) !important;
}
.nbg-leave-go:hover { background: var(--nbl-quiet-hover) !important; color: var(--nbl-ink) !important; }

/* DESTRUCTIVE: the red is the action, and then the safe answer is the quiet
   one. #dc2626 (not #ef4444) because white on it measures 4.9:1. */
.nbg-leave-card.is-danger .nbg-leave-stay {
  color: var(--nbl-ink) !important;
  background: var(--nbl-quiet) !important;
  box-shadow: none;
  font-weight: 700 !important;
}
.nbg-leave-card.is-danger .nbg-leave-stay:hover { background: var(--nbl-quiet-hover) !important; }
.nbg-leave-go.is-danger {
  color: #ffffff !important;
  font-weight: 800 !important;
  background: linear-gradient(180deg, #dc2626, #b91c1c) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 8px 18px -10px rgba(220, 38, 38, 0.8);
}
.nbg-leave-go.is-danger:hover { background: linear-gradient(180deg, #e02f2f, #c01d1d) !important; }
.nbg-leave-card.is-danger .nbg-leave-door { color: #f87171; }

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

/* ── the toast ─────────────────────────────────────────────────────────── */

.nbg-bg-toast {
  position: fixed;
  z-index: 12090;
  top: calc(env(safe-area-inset-top, 0px) + 68px);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  padding: 7px 8px 7px 16px;
  padding-inline-start: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--nbl-face);
  border: 1px solid var(--nbl-edge);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.18);
  color: var(--nbl-ink);
  font-family: var(--nbl-font);
  font-size: 14px;
  line-height: 1.6;
  direction: rtl;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.97);
  transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.2, 0.9, 0.24, 1.04);
  pointer-events: none;
}
html[data-theme="light"] .nbg-bg-toast { box-shadow: 0 14px 34px -12px rgba(15, 23, 42, 0.25), 0 2px 6px rgba(15, 23, 42, 0.06); }
.nbg-bg-toast.is-in { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; }
.nbg-bg-toast-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--nbl-accent);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18);
}
.nbg-bg-toast-text { overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.nbg-bg-toast-action {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  margin: 0;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.14) !important;
  color: var(--nbl-accent-ink) !important;
  font: inherit;
  font-family: var(--nbl-font);
  font-size: 13.5px !important;
  font-weight: 800 !important;
  cursor: pointer;
}
.nbg-bg-toast-action:hover { background: rgba(52, 211, 153, 0.22) !important; }
.nbg-bg-toast-action:focus-visible { outline: 2px solid var(--nbl-accent); outline-offset: 2px; }
.nbg-bg-toast-timer {
  position: absolute;
  inset-inline: 16px;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--nbl-accent);
  opacity: 0.55;
  transform-origin: left center;
  animation: nbg-bg-toast-drain linear forwards;
}
@keyframes nbg-bg-toast-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

@media (prefers-reduced-motion: reduce) {
  .nbg-leave-card, .nbg-leave-scrim, .nbg-bg-toast { transition: none !important; }
  .nbg-leave-halo, .nbg-bg-toast-timer { animation: none !important; }
}
