/*
 * BopTour — onboarding tour shared styles.
 *
 * Used by both the Vue 3 <BopTour> component (most BOP plugins) and the
 * vanilla bop-tour-vanilla.js script (PHP/JS plugins). The classes below
 * are the contract between the framework code and the visual design:
 * any implementation that emits this markup will look identical to all
 * other BOP plugins.
 *
 * Required structure (any implementation):
 *
 *   <div class="bop-tour-overlay" data-bop-tour-active>
 *     <div class="bop-tour-spotlight" style="--x..--y..--w..--h.."></div>
 *     <div class="bop-tour-card" data-bop-placement="bottom">
 *       <div class="bop-tour-step-label">ÉTAPE 1 / 8</div>
 *       <h3 class="bop-tour-title">…</h3>
 *       <p class="bop-tour-body">…</p>
 *       <div class="bop-tour-actions">
 *         <button class="bop-tour-skip">Passer</button>
 *         <button class="bop-tour-btn bop-tour-btn-secondary">‹ Précédent</button>
 *         <button class="bop-tour-btn bop-tour-btn-primary">Suivant ›</button>
 *       </div>
 *     </div>
 *   </div>
 *
 * Tokens live in bop-tokens.css (--bop-tour-*).
 */

.bop-tour-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--bop-tour-z-overlay, 9998);
  background: transparent;
  pointer-events: none;
}

/* The spotlight is a 4-rectangle mask that dims everything OUTSIDE its
   box, leaving the highlighted target visible at full brightness. This
   approach lets clicks pass through to the target when needed — there is
   no real cutout element to intercept them. */
.bop-tour-spotlight {
  position: fixed;
  left: var(--bop-tour-spot-x, 0);
  top: var(--bop-tour-spot-y, 0);
  width: var(--bop-tour-spot-w, 0);
  height: var(--bop-tour-spot-h, 0);
  z-index: var(--bop-tour-z-spotlight, 9999);
  pointer-events: none;
  border-radius: var(--bop-tour-spotlight-radius, 14px);
  box-shadow:
    0 0 0 9999px var(--bop-tour-overlay-bg, rgba(15, 23, 42, 0.55)),
    var(--bop-tour-spotlight-ring, 0 0 0 3px rgba(255, 255, 255, 0.18));
  transition: left .18s ease, top .18s ease, width .18s ease, height .18s ease;
}

/* When no specific element is highlighted (e.g. an intro/outro step that
   speaks about the page in general), collapse the spotlight to nothing —
   the box-shadow still dims the whole viewport. */
.bop-tour-spotlight[data-bop-spot="none"] {
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-radius: 0;
  box-shadow: 0 0 0 9999px var(--bop-tour-overlay-bg, rgba(15, 23, 42, 0.55));
}

.bop-tour-card {
  position: fixed;
  left: var(--bop-tour-card-x, 50%);
  top: var(--bop-tour-card-y, 50%);
  transform: var(--bop-tour-card-transform, translate(-50%, -50%));
  z-index: var(--bop-tour-z-card, 10000);
  max-width: min(var(--bop-tour-card-max-width, 380px), calc(100vw - 32px));
  padding: var(--bop-tour-card-padding, 22px 24px);
  background: var(--bop-tour-card-bg, #f6f1e8);
  color: var(--bop-tour-card-fg, #11181f);
  border: 1px solid var(--bop-tour-card-border, rgba(17, 24, 31, 0.08));
  border-radius: var(--bop-tour-card-radius, 14px);
  box-shadow: var(--bop-tour-card-shadow, 0 20px 50px rgba(2, 6, 23, 0.28));
  /* Root font-family — each text element below also re-asserts this so
     WordPress theme rules with higher selector specificity don't win. */
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  pointer-events: auto;
  animation: bop-tour-card-in 0.22s ease both;
}

@keyframes bop-tour-card-in {
  from { opacity: 0; transform: var(--bop-tour-card-transform, translate(-50%, -50%)) scale(0.96); }
  to   { opacity: 1; transform: var(--bop-tour-card-transform, translate(-50%, -50%)) scale(1); }
}

/* All text inside the card sets `font-family` explicitly. Two layers:
     1. Selectors chained as `.bop-tour-card .bop-tour-X` so the
        specificity (0,2,0) beats common WP theme rules
        (`.entry-content h3` etc., specificity 0,1,1).
     2. `!important` on font-family as the ultimate fallback for themes
        that do use `!important` themselves.
   Other text properties (size, weight, line-height, letter-spacing)
   stay plain — themes rarely override those and we want them tweakable
   from a single override without `!important`. */
.bop-tour-card .bop-tour-step-label {
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  font-size: 11px;
  font-weight: 700;
  font-style: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bop-tour-step-label-fg, #8a93a1);
  margin: 0 0 10px 0;
}

.bop-tour-card .bop-tour-title {
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  font-size: 19px;
  font-weight: 700;
  font-style: normal;
  line-height: 1.25;
  letter-spacing: normal;
  margin: 0 0 8px 0;
  color: var(--bop-tour-card-fg, #11181f);
  text-transform: none;
}

.bop-tour-card .bop-tour-body {
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  font-size: 14px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.5;
  letter-spacing: normal;
  margin: 0 0 20px 0;
  color: var(--bop-tour-card-fg, #11181f);
  text-transform: none;
}

.bop-tour-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* The skip link sits on the left, the navigation buttons on the right. */
.bop-tour-card .bop-tour-skip {
  margin-right: auto;
  border: 0;
  background: transparent;
  padding: 8px 4px;
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  font-size: 14px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.2;
  letter-spacing: normal;
  text-transform: none;
  color: var(--bop-tour-btn-skip-fg, #5b6470);
  cursor: pointer;
}

.bop-tour-skip:hover {
  color: var(--bop-tour-btn-skip-fg-hover, var(--bop-tour-card-fg, #11181f));
  text-decoration: underline;
}

.bop-tour-card .bop-tour-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 18px;
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  font-size: 14px;
  font-weight: 600;
  font-style: normal;
  line-height: 1.2;
  letter-spacing: normal;
  text-transform: none;
  cursor: pointer;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.bop-tour-btn-secondary {
  background: var(--bop-tour-btn-secondary-bg, #ffffff);
  color: var(--bop-tour-btn-secondary-fg, #11181f);
  border-color: var(--bop-tour-btn-secondary-border, rgba(17, 24, 31, 0.18));
}

.bop-tour-btn-secondary:hover {
  border-color: var(--bop-tour-card-fg, #11181f);
}

.bop-tour-btn-primary {
  background: var(--bop-tour-btn-primary-bg, #11181f);
  color: var(--bop-tour-btn-primary-fg, #ffffff);
}

.bop-tour-btn-primary:hover {
  background: var(--bop-tour-btn-primary-bg-hover, #000);
}

.bop-tour-btn[disabled],
.bop-tour-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bop-tour-skip:focus-visible,
.bop-tour-btn:focus-visible {
  outline: 2px solid var(--bop-tour-card-fg, #11181f);
  outline-offset: 2px;
}

/* Placement-aware tweaks: when the card sits beside the spotlight, the
   card animates from the corresponding side. The framework code sets
   data-bop-placement based on auto-flip logic. */
.bop-tour-card[data-bop-placement="top"]    { --bop-tour-card-transform: translate(-50%, -100%); }
.bop-tour-card[data-bop-placement="bottom"] { --bop-tour-card-transform: translate(-50%, 0%); }
.bop-tour-card[data-bop-placement="left"]   { --bop-tour-card-transform: translate(-100%, -50%); }
.bop-tour-card[data-bop-placement="right"]  { --bop-tour-card-transform: translate(0%, -50%); }
.bop-tour-card[data-bop-placement="center"] { --bop-tour-card-transform: translate(-50%, -50%); }

/* Mobile: cards always anchor to a horizontal edge of the viewport so
   finger reach is comfortable and the spotlight stays visible. Default
   anchor is bottom; switch to top when the step requests placement="top"
   — typically when the highlighted target itself sits at the bottom of
   the screen (a bottom bar) and overlapping it would hide the spot. */
@media (max-width: 640px) {
  .bop-tour-card {
    left: 16px !important;
    right: 16px !important;
    max-width: none;
    --bop-tour-card-transform: translate(0, 0) !important;
  }
  .bop-tour-card[data-bop-placement="top"] {
    top: calc(16px + env(safe-area-inset-top, 0px)) !important;
    bottom: auto !important;
  }
  .bop-tour-card:not([data-bop-placement="top"]) {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
  }
  /* Trim the action buttons a touch so Passer + Précédent + Suivant
     fit on a single line on most phone widths. The previous rule
     (flex-wrap + skip 100%) made Passer stand alone above the nav
     buttons, which looked awkward and ate vertical space. */
  .bop-tour-actions { gap: 8px; }
  .bop-tour-card .bop-tour-skip { padding: 8px 2px; }
  .bop-tour-card .bop-tour-btn { padding: 9px 12px; }
}

/* Progress bar — segmented track at the top of the card, one segment
   per step, filled up to (and including) the current one. Static — it
   doesn't fade with the step content so users see their progress move
   forward as the new step appears. */
.bop-tour-card .bop-tour-progress {
  display: flex;
  gap: 4px;
  margin: 0 0 14px 0;
}

.bop-tour-card .bop-tour-progress-seg {
  flex: 1 1 0;
  height: 3px;
  border-radius: 999px;
  background: var(--bop-tour-progress-bg, rgba(17, 24, 31, 0.12));
  transition: background-color .25s ease;
}

.bop-tour-card .bop-tour-progress-seg[data-bop-done="1"] {
  background: var(--bop-tour-progress-fill, var(--bop-tour-card-fg, #11181f));
}

/* Loading state — shown while a step's async onEnter hook is resolving
   (e.g. opening a side panel, switching map mode). Disables the nav
   buttons to prevent the user from racing ahead before the host UI is
   ready. */
.bop-tour-card .bop-tour-loading {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px 0;
  color: var(--bop-tour-card-muted, #5b6470);
  font-family: var(--bop-font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif) !important;
  font-size: 13px;
  font-style: italic;
}

.bop-tour-card[data-bop-loading="1"] .bop-tour-loading {
  display: inline-flex;
}

.bop-tour-card[data-bop-loading="1"] .bop-tour-btn-primary,
.bop-tour-card[data-bop-loading="1"] .bop-tour-btn-secondary {
  opacity: 0.4;
  pointer-events: none;
}

.bop-tour-loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--bop-tour-card-border, rgba(17, 24, 31, 0.18));
  border-top-color: var(--bop-tour-card-fg, #11181f);
  border-radius: 999px;
  animation: bop-tour-spin .8s linear infinite;
  flex: 0 0 auto;
}

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

/* Reduced motion: disable the entry animation, spotlight transitions,
   the progress segment color transition and the loading spinner. */
@media (prefers-reduced-motion: reduce) {
  .bop-tour-card { animation: none; }
  .bop-tour-spotlight { transition: none; }
  .bop-tour-card .bop-tour-progress-seg { transition: none; }
  .bop-tour-loading-spinner { animation: none; }
}

/* Tour-restart trigger button (the "?" affordance, embeddable anywhere). */
.bop-tour-restart {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--bop-tour-restart-border, rgba(17, 24, 31, 0.18));
  background: var(--bop-tour-restart-bg, #ffffff);
  color: var(--bop-tour-restart-fg, #11181f);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bop-tour-restart:hover {
  background: var(--bop-tour-restart-bg-hover, #f1f5f9);
}

.bop-tour-restart:focus-visible {
  outline: 2px solid var(--bop-tour-restart-fg, #11181f);
  outline-offset: 2px;
}
