/* TST Certificates & Awards — Frontend CSS  v3.0.0
   Brand Colors: Red #eb2227 | Yellow #fcee1f | Green #03a550
   New: Elementor responsive grid, alignment, card/image/button/popup controls,
        security switches, watermark via data-attr, auto-center last row.
*/

@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&family=Inter:wght@400;500;600&display=swap');

/* ── CSS Variables ─────────────────────────────────── */
:root {
  --tst-red:        #eb2227;
  --tst-yellow:     #fcee1f;
  --tst-green:      #03a550;
  --tst-dark:       #0d1117;
  --tst-card-bg:    #ffffff;
  --tst-white:      #ffffff;
  --tst-shadow-sm:  0 2px 8px rgba(0,0,0,0.08);
  --tst-shadow-md:  0 8px 32px rgba(0,0,0,0.14);
  --tst-shadow-lg:  0 20px 60px rgba(0,0,0,0.22);
  --tst-radius:     12px;
  --tst-transition: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Wrapper ─────────────────────────────────────────── */
.tst-cert-wrapper {
  position: relative;
}

/* ── Grid ───────────────────────────────────────────── */
/*
 * Responsive columns are driven by the Elementor responsive control which
 * sets --tst-cols-el on the grid via a CSS custom property selector.
 * We use flexbox so the last row can be centered (justify-content from
 * the Elementor alignment control) while cards keep a fixed computed width.
 *
 * Formula: card width = (100% - gap*(cols-1)) / cols
 * We use CSS calc() + custom properties so it adjusts automatically.
 */
.tst-cert-grid {
  --tst-cols-el: 3;            /* default; overridden by Elementor responsive control */
  --tst-col-gap: 18px;         /* overridden by Elementor column-gap selector        */
  --tst-row-gap: 18px;         /* overridden by Elementor row-gap selector           */

  display: flex;
  flex-wrap: wrap;
  gap: var(--tst-row-gap) var(--tst-col-gap);
  padding: 0;
  /* justify-content set by Elementor alignment control (default: center) */
  justify-content: center;
}

/* Each card takes exactly 1/N of the row (accounting for gaps). */
.tst-cert-grid .tst-cert-card {
  flex: 0 0 calc(
    (100% - var(--tst-col-gap) * (var(--tst-cols-el) - 1))
    / var(--tst-cols-el)
  );
  max-width: calc(
    (100% - var(--tst-col-gap) * (var(--tst-cols-el) - 1))
    / var(--tst-cols-el)
  );
  box-sizing: border-box;
}

/* ── Responsive Breakpoint Defaults ─────────────────── */
/* These are the fallback column counts used if the Elementor responsive
   control hasn't set --tst-cols-el for that viewport. */
@media (max-width: 1024px) {
  .tst-cert-grid:not([style*="--tst-cols-el"]) {
    --tst-cols-el: 2;
  }
}
@media (max-width: 640px) {
  .tst-cert-grid:not([style*="--tst-cols-el"]) {
    --tst-cols-el: 1;
  }
}

/* ── Card ───────────────────────────────────────────── */
.tst-cert-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--tst-card-bg);
  border-radius: var(--tst-radius);
  padding: 14px 12px 12px;
  box-shadow: var(--tst-shadow-md);
  transition: box-shadow var(--tst-transition), transform var(--tst-transition);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.05);

  /* Stagger entrance animation — starts paused, JS triggers via IO */
  opacity: 0;
  transform: translateY(24px);
  animation: tst-cardFadeUp 0.5s ease forwards;
  animation-play-state: paused;
}

.tst-cert-card:nth-child(1)    { animation-delay: 0.05s; }
.tst-cert-card:nth-child(2)    { animation-delay: 0.10s; }
.tst-cert-card:nth-child(3)    { animation-delay: 0.15s; }
.tst-cert-card:nth-child(4)    { animation-delay: 0.20s; }
.tst-cert-card:nth-child(5)    { animation-delay: 0.25s; }
.tst-cert-card:nth-child(6)    { animation-delay: 0.30s; }
.tst-cert-card:nth-child(7)    { animation-delay: 0.35s; }
.tst-cert-card:nth-child(8)    { animation-delay: 0.40s; }
.tst-cert-card:nth-child(9)    { animation-delay: 0.45s; }
.tst-cert-card:nth-child(10)   { animation-delay: 0.50s; }
.tst-cert-card:nth-child(n+11) { animation-delay: 0.55s; }

@keyframes tst-cardFadeUp {
  to { opacity: 1; transform: translateY(0); }
}

/* Top color signal stripe */
.tst-cert-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--tst-red) 33%, var(--tst-yellow) 33% 66%, var(--tst-green) 66%);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s ease;
}
.tst-cert-card:hover::before { transform: scaleX(1); }

.tst-cert-card:hover {
  transform: translateY(-5px) scale(1.015);
}

/* ── Thumbnail ──────────────────────────────────────── */
.tst-cert-thumb {
  display: block;
  width: 100%;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
  transition: opacity 0.25s ease;
  position: relative;
}

/* Hover overlay hint */
.tst-cert-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 165, 80, 0.12);
  opacity: 0;
  transition: opacity 0.25s ease;
  border-radius: 8px;
}
.tst-cert-thumb:hover::after { opacity: 1; }

.tst-cert-thumb img {
  width: 100%;
  height: 120px;         /* overridden by Elementor img_height control */
  object-fit: contain;   /* overridden by Elementor img_fit control    */
  background: #fafafa;
  border-radius: 8px;
  display: block;
  pointer-events: none;
  transition: transform 0.3s ease;
  /* Security hardening defaults */
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* Hover zoom — toggled via Elementor selector, still honored by default */
.tst-cert-card:hover .tst-cert-thumb img {
  transform: scale(1.04);
}

/* No-zoom override when disabled via Elementor */
.tst-cert-grid[data-hover-zoom="no"] .tst-cert-card:hover .tst-cert-thumb img {
  transform: none;
}

.tst-cert-thumb__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 120px;
  font-size: 40px !important;
  color: var(--tst-green);
}

/* ── View Button ────────────────────────────────────── */
.tst-cert-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  font-family: 'Rajdhani', 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--tst-green);
  color: #fff !important;
  text-decoration: none;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  border: none;
  line-height: 1.4;
}

.tst-cert-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  border-radius: inherit;
  pointer-events: none;
}

.tst-cert-btn:hover {
  background: #028a42;
  color: #fff !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(3,165,80,0.4);
}

.tst-cert-btn:active { transform: translateY(0); }

.tst-cert-btn--disabled {
  opacity: 0.4;
  cursor: default;
  background: #aaa;
}

/* Icon sizing inside button */
.tst-cert-btn svg,
.tst-cert-btn i {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  font-size: 13px;
}

/* ── Empty state ────────────────────────────────────── */
.tst-cert-empty {
  color: #888;
  text-align: center;
  padding: 24px;
  font-family: 'Inter', sans-serif;
}

/* ── Dark theme ─────────────────────────────────────── */
.tst-cert-dark { --tst-card-bg: #12181f; }
.tst-cert-dark .tst-cert-card { border-color: rgba(255,255,255,0.06); box-shadow: 0 2px 12px rgba(0,0,0,0.4); }
.tst-cert-dark .tst-cert-thumb img { background: #1a2535; }

/* ════════════════════════════════════════════════════
   MODAL
════════════════════════════════════════════════════ */
.tst-cert-modal {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.tst-cert-modal.active { display: flex; }

/* Backdrop */
.tst-cert-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,14,20,0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  animation: tst-overlayIn 0.25s ease;
}
@keyframes tst-overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Modal Box */
.tst-cert-modal__box {
  position: relative;
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 880px;
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--tst-shadow-lg), 0 0 0 1px rgba(255,255,255,0.08);
  padding: 0;
  box-sizing: border-box;
  /* Default zoom animation — overridden by JS when other animation chosen */
  animation: tst-modalZoom 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

/* ── Animation presets ───────────────────────────────── */
@keyframes tst-modalZoom {
  from { opacity: 0; transform: scale(0.92) translateY(20px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}
@keyframes tst-modalSlideUp {
  from { opacity: 0; transform: translateY(60px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes tst-modalSlideDown {
  from { opacity: 0; transform: translateY(-60px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes tst-modalFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.tst-cert-modal__box[data-anim="slide-up"]   { animation-name: tst-modalSlideUp; }
.tst-cert-modal__box[data-anim="slide-down"] { animation-name: tst-modalSlideDown; }
.tst-cert-modal__box[data-anim="fade"]       { animation-name: tst-modalFade; }
.tst-cert-modal__box[data-anim="zoom"]       { animation-name: tst-modalZoom; }

/* Modal header bar */
.tst-cert-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--tst-dark);
  border-radius: 16px 16px 0 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Traffic signal dots */
.tst-cert-modal__signals {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tst-cert-modal__signals span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  animation: tst-signalPulse 2.5s ease-in-out infinite;
}
.tst-cert-modal__signals span:nth-child(1) { background: var(--tst-red);    animation-delay: 0s; }
.tst-cert-modal__signals span:nth-child(2) { background: var(--tst-yellow); animation-delay: 0.8s; }
.tst-cert-modal__signals span:nth-child(3) { background: var(--tst-green);  animation-delay: 1.6s; }

@keyframes tst-signalPulse {
  0%,100% { box-shadow: none; opacity: 0.7; }
  50%      { box-shadow: 0 0 8px 3px currentColor; opacity: 1; }
}

.tst-cert-modal__title {
  font-family: 'Rajdhani','Inter',sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Close Button */
.tst-cert-modal__close {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 20px;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}
.tst-cert-modal__close:hover {
  background: var(--tst-red);
  border-color: var(--tst-red);
  transform: scale(1.08);
}

/* Body */
.tst-cert-modal__body { padding: 16px; }

/* ── Protection wrap ────────────────────────────────── */
.tst-cert-protect {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}

/* user-select / touch-callout controlled via JS data attrs */
.tst-cert-protect[data-no-select="yes"] {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tst-cert-protect img,
.tst-cert-protect iframe {
  width: 100%;
  display: block;
  pointer-events: none;
  border: none;
  border-radius: 8px;
}

.tst-cert-protect iframe {
  /*
   * Height is set to 2000px by JS so the iframe is taller than the PDF page —
   * this prevents internal iframe scroll (which we cannot control cross-origin).
   * The modal box (overflow:auto) handles all scrolling instead.
   */
  height: 2000px;
  min-height: 100%;
  pointer-events: none; /* shield sits above; JS forwards wheel to modal box */
}

/* ── Watermark ──────────────────────────────────────── */
/*
 * Watermark text and color are injected by JS into a CSS custom property
 * and a data attribute so they can be configured via Elementor controls
 * without requiring a PHP page reload.
 */
.tst-cert-protect[data-watermark="yes"]::after {
  content: attr(data-watermark-text);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Rajdhani','Inter',sans-serif;
  font-size: clamp(14px, 3.5vw, 36px);
  font-weight: 700;
  color: var(--tst-wm-color, rgba(3,165,80,0.22));
  transform: rotate(-35deg);
  pointer-events: none;
  text-align: center;
  line-height: 1.4;
  letter-spacing: 2px;
  text-transform: uppercase;
  z-index: 2;
}

/* Background stripe pattern */
.tst-cert-protect[data-watermark="yes"]::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    repeating-linear-gradient(
      -35deg,
      transparent 0px, transparent 80px,
      rgba(235,34,39,0.04) 80px, rgba(235,34,39,0.04) 81px
    ),
    repeating-linear-gradient(
      55deg,
      transparent 0px, transparent 80px,
      rgba(252,238,31,0.04) 80px, rgba(252,238,31,0.04) 81px
    );
}

/* ── Transparent shield over image ─────────────────── */
.tst-cert-protect .tst-cert-shield {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  background: transparent;
  cursor: default;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/*
 * PDF shield — sits above the iframe so browser's native PDF context menu
 * (Save as…, Print, Rotate, Inspect) is intercepted before it reaches the
 * iframe document. pointer-events must be "all" so the shield captures the
 * right-click; scroll is forwarded by JS via the wheel event listener.
 */
.tst-cert-protect .tst-cert-pdf-shield {
  position: absolute;
  inset: 0;
  z-index: 4;            /* above the iframe (z-index:auto) and watermark z-index:2 */
  display: block;
  background: transparent;
  pointer-events: all;   /* must be "all" to intercept right-click on iframe */
  cursor: default;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Images inside protect wrap */
.tst-cert-protect img {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* ── Ripple keyframe (injected by JS, kept here for backup) ── */
@keyframes tst-ripple { to { width:200px; height:200px; opacity:0; } }

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .tst-cert-modal__box   { border-radius: 12px; }
  .tst-cert-modal__header { border-radius: 12px 12px 0 0; }
  .tst-cert-protect[data-watermark="yes"]::after { font-size: 14px; }
}