/* ============================================
   CAMPAIGN WIDGETS - Standalone CSS
   Drop this file + campaign-widgets.js into any project
   ============================================ */

/* Font: use the OS system font — the SAME thing the admin tool renders the promo
   preview with. The tool's Geist does not reliably load (next/font shows it
   "unloaded" in-app), so it falls back to system-ui; meanwhile Google Fonts'
   "Geist" is a DIFFERENT, wider cut. Loading Geist here made the widget render
   ~1% wider than the tool and wrap text one word sooner. Matching the tool's
   actual font (system-ui) makes wrapping identical and removes all font-load
   flakiness. (For pixel-identical rendering on every visitor OS, self-host one
   Geist .woff2 in BOTH the tool and widget — tracked as a follow-up.) */

/* ---------- Announcement Bar (Marquee Ticker) ---------- */
.cw-announcement-slot {
  height: var(--cw-bar-height, 0px);
  overflow: hidden;
}

.cw-announcement-bar {
  position: relative;
  width: 100%;
  z-index: var(--cw-bar-z-index, 10);
  display: flex;
  align-items: center;
  height: 40px;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.3px;
  overflow: hidden;
  white-space: nowrap;
}

.cw-announcement-bar__track {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  height: 40px;
  animation: cw-marquee var(--cw-marquee-duration, 30s) linear infinite;
}

.cw-announcement-bar:hover .cw-announcement-bar__track {
  animation-play-state: paused;
}

@keyframes cw-marquee {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.cw-announcement-bar__item {
  display: inline;
  padding: 0 40px;
  white-space: nowrap;
  line-height: 40px;
  vertical-align: baseline;
}

/* Rich text children inside announcement items */
.cw-announcement-bar__item span,
.cw-announcement-bar__item b,
.cw-announcement-bar__item strong,
.cw-announcement-bar__item i,
.cw-announcement-bar__item em,
.cw-announcement-bar__item u {
  display: inline;
  vertical-align: baseline;
  line-height: 40px;
}

/* Ensure consistent bold weight */
.cw-announcement-bar strong,
.cw-announcement-bar b {
  font-weight: 700;
}

/* Auto offset fixed headers only when slot is in top zone */
body.cw-has-announcement-bar.cw-should-offset-fixed .rd-navbar-fixed .rd-navbar-panel {
  top: var(--cw-bar-height, 0px);
}

body.cw-has-announcement-bar.cw-should-offset-fixed .rd-navbar-fixed .rd-navbar-nav-wrap {
  top: max(0px, calc(var(--cw-bar-height, 0px) - 56px));
}

body.cw-has-announcement-bar.cw-should-offset-fixed .rd-navbar-fixed [class*='rd-navbar-fixed-element'] {
  top: calc(var(--cw-bar-height, 0px) + 4px);
}

body.cw-has-announcement-bar.cw-should-offset-fixed .rd-navbar-fixed .rd-navbar-collapse {
  top: calc(var(--cw-bar-height, 0px) + 56px);
}

body.cw-has-announcement-bar.cw-should-offset-fixed .rd-navbar-fixed .rd-navbar-search .rd-search {
  top: calc(var(--cw-bar-height, 0px) + 56px);
}

body.cw-has-announcement-bar.cw-should-offset-fixed #myHeader,
body.cw-has-announcement-bar.cw-should-offset-fixed .header-area {
  top: var(--cw-bar-height, 0px) !important;
}

/* ---------- Promo Card ---------- */
/* Mirror Tailwind's global border-box (the tool relies on it). Without this the
   widget's elements are content-box, so padding + min-height stack and e.g. the
   button renders taller than the tool. Scoped to the card so the host page is
   untouched. */
.cw-promo-card,
.cw-promo-card * {
  box-sizing: border-box;
}

.cw-promo-card {
  position: fixed;
  z-index: 99998;
  box-sizing: border-box;
  width: 400px;
  max-width: 90vw;
  min-width: 320px;
  border-radius: 12px;
  padding: 20px;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Single neutral text base for the whole card — mirrors the admin tool, where
     every field is `text-base font-normal` (16px / 400 / line-height 1.5) and
     only the content's inline styles (and the button's semibold) deviate. Fields
     inherit from here, so sizes/weights can't drift field-by-field again. */
  font-size: 16px;
  font-weight: 400;
  /* Fixed 24px length, NOT unitless 1.5 — matches Tailwind `text-base`
     (line-height:1.5rem=24px) which the tool uses. A unitless value would make
     large inline words (e.g. a 25.6px title span) get a 38px line box and render
     taller than the tool. A fixed length keeps every line at the tool's height. */
  line-height: 24px;
  /* Isolate the card's typography from the HOST SITE. Sites (like Leicester)
     set global letter-spacing / word-spacing / text-transform that INHERIT into
     the card, making every line wider than the admin tool and pushing text —
     especially the timer — onto an extra line. Resetting to the tool's defaults
     here guarantees the widget wraps exactly like the tool. WYSIWYG. */
  letter-spacing: normal;
  word-spacing: normal;
  text-transform: none;
  text-indent: 0;
  font-style: normal;
  font-variant: normal;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.15),
    0 8px 20px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  animation: cw-promoIn 0.5s ease forwards;
}

@keyframes cw-promoIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cw-promoOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
}

.cw-promo-card.cw-closing {
  animation: cw-promoOut 0.35s ease forwards;
}

/* Position variants */
.cw-promo-card--bottom-left {
  bottom: 24px;
  left: 24px;
}

.cw-promo-card--bottom-right {
  bottom: 24px;
  right: 24px;
}

.cw-promo-card--top-left {
  top: 60px;
  left: 24px;
}

.cw-promo-card--top-right {
  top: 60px;
  right: 24px;
}

.cw-promo-card--center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(20px) scale(0.95);
  animation: cw-promoInCenter 0.5s ease forwards;
}

@keyframes cw-promoInCenter {
  to {
    transform: translate(-50%, -50%) translateY(0) scale(1);
  }
}

/* Promo card close button */
.cw-promo-card__close {
  position: absolute;
  top: -12px;
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #333;
  opacity: 0.8;
  transition: all 0.2s ease;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 10;
}

/* Close button positioning based on card position */
.cw-promo-card--bottom-right .cw-promo-card__close,
.cw-promo-card--top-right .cw-promo-card__close {
  left: -12px;
  right: auto;
}

.cw-promo-card--bottom-left .cw-promo-card__close,
.cw-promo-card--top-left .cw-promo-card__close {
  right: -12px;
  left: auto;
}

.cw-promo-card--center .cw-promo-card__close {
  right: -12px;
  left: auto;
}

.cw-promo-card__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 1);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Fields inherit the card's base (16px / 400 / 1.5). Each rule sets ONLY what the
   tool overrides: spacing + the pill padding/radius. Tool source per field noted. */
.cw-promo-card__title {
  /* tool: mb-1 px-2 py-1 rounded */
  margin: 0 0 4px 0;
  padding: 4px 8px;
  border-radius: 4px;
}

/* Allow inline styles to override */
.cw-promo-card__title span {
  font-size: inherit;
}

.cw-promo-card__subtitle {
  /* tool: mb-2 px-2 py-1 rounded */
  margin: 0 0 8px 0;
  padding: 4px 8px;
  border-radius: 4px;
}

/* Allow inline styles to override */
.cw-promo-card__subtitle span {
  font-size: inherit;
}

.cw-promo-card__description {
  /* tool: mb-2 px-2 py-1 rounded */
  margin: 0 0 8px 0;
  padding: 4px 8px;
  border-radius: 4px;
}

/* Allow inline styles to override */
.cw-promo-card__description span {
  font-size: inherit;
}

/* Ensure consistent bold weight across all promo card elements */
.cw-promo-card strong,
.cw-promo-card b {
  font-weight: 700;
}

.cw-promo-card__timer {
  /* tool: mb-4 px-2 py-1 rounded (inherits 16px/400; bg comes from dateStyle) */
  margin: 0 0 16px 0;
  padding: 4px 8px;
  border-radius: 4px;
  text-align: center;
  /* The admin tool guarantees the timer is ALWAYS one line (its editor reverts
     any edit that would wrap). We match that: keep it on one line here, and
     fitTimer() in the JS scales the font down a hair if the text is a touch wider
     than the card (e.g. font-metric rounding at the boundary) so it never wraps
     to two lines or spills off the edge. WYSIWYG with the tool. */
  white-space: nowrap;
}

.cw-promo-card__btn-wrapper {
  display: flex;
  width: 100%;
}

.cw-promo-card__btn {
  /* tool: a plain block with text-align center (a contenteditable div). NOT a
     flex container — flexing the button turns each inline <span> in a rich-text
     label into a separate flex item, so a styled label splits into blocks laid
     out side-by-side instead of flowing as one wrapping line of text. Block +
     text-align keeps the label flowing exactly like the tool. */
  display: inline-block;
  text-align: center;
  width: auto;
  min-height: 40px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
  cursor: pointer;
  letter-spacing: normal;
  transition: all 0.25s ease;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.cw-promo-card__btn--full {
  display: block;
  width: 100%;
}

.cw-promo-card__btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.cw-promo-card__btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}


/* Shimmer decoration */
.cw-promo-card__shimmer {
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100px;
  height: 200%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.04),
    transparent
  );
  transform: rotate(25deg);
  animation: cw-shimmer 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes cw-shimmer {
  0%, 100% {
    transform: rotate(25deg) translateX(-100%);
  }
  50% {
    transform: rotate(25deg) translateX(100%);
  }
}

/* ---------- Responsive ---------- */

/* Tablet */
@media (max-width: 768px) {
  .cw-announcement-bar {
    font-size: 13px;
  }

  .cw-announcement-bar__item {
    padding: 0 30px;
  }

  .cw-promo-card {
    max-width: 280px;
    min-width: 220px;
    padding: 20px;
  }

}

/* Mobile */
@media (max-width: 480px) {
  .cw-announcement-bar {
    font-size: 12px;
  }

  .cw-announcement-bar__item {
    padding: 0 20px;
  }

  .cw-promo-card {
    max-width: calc(100vw - 32px);
    min-width: unset;
    left: 16px !important;
    right: 16px !important;
    bottom: 36px !important;
    top: auto !important;
    transform: none !important;
    padding: 18px;
  }
}

/* ---------- Print: hide everything ---------- */
@media print {
  .cw-announcement-bar,
  .cw-promo-card {
    display: none !important;
  }
}
