/* ==========================================================================
   CONVERTMASTER PRO — ADSENSE REVENUE OPTIMIZATION ENGINE (ads.css)
   Google Publisher Policy Compliant • Zero CLS • Responsive • Dark Mode Ready
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Theme & Design Tokens for Ad Slots
   -------------------------------------------------------------------------- */
:root {
  --ad-bg: rgba(248, 250, 252, 0.9);
  --ad-border: rgba(226, 232, 240, 0.9);
  --ad-label-color: #64748b;
  --ad-label-bg: rgba(241, 245, 249, 0.8);
  --ad-skeleton-base: #e2e8f0;
  --ad-skeleton-sweep: #f1f5f9;
  --ad-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
  --ad-shadow-hover: 0 8px 24px rgba(15, 23, 42, 0.08);
  --ad-radius: 12px;
}

[data-theme="dark"] {
  --ad-bg: rgba(30, 41, 59, 0.7);
  --ad-border: rgba(51, 65, 85, 0.8);
  --ad-label-color: #94a3b8;
  --ad-label-bg: rgba(15, 23, 42, 0.6);
  --ad-skeleton-base: #1e293b;
  --ad-skeleton-sweep: #334155;
  --ad-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --ad-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* --------------------------------------------------------------------------
   2. Master Ad Container & Wrapper
   -------------------------------------------------------------------------- */
.adsense-slot-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-sizing: border-box;
  margin-top: 1.25rem;
  margin-bottom: 1.25rem;
  clear: both;
}

/* Neutral, Compliant Labeling (Google AdSense Policy Required) */
.ad-tag-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ad-label-color);
  text-align: center;
  margin-bottom: 0.35rem;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ad-tag-label svg {
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   3. Core Reusable Ad Slot (.adsense-slot)
   -------------------------------------------------------------------------- */
.adsense-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--ad-bg);
  border: 1px dashed var(--ad-border);
  border-radius: var(--ad-radius);
  box-shadow: var(--ad-shadow);
  overflow: hidden;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
  box-sizing: border-box;
  text-align: center;
  margin: 0 auto;
}

.adsense-slot:hover {
  border-color: var(--color-primary-400, #3b82f6);
  box-shadow: var(--ad-shadow-hover);
}

/* Hide all ads cleanly if monetization is disabled via Admin */
body.ads-disabled .adsense-slot-container,
body.ads-disabled .adsense-slot,
body.ads-disabled .ad-sticky-bottom,
body.ads-disabled .ad-sticky-sidebar {
  display: none !important;
}

/* --------------------------------------------------------------------------
   4. Size Variants & Zero-CLS Height Reservation
   -------------------------------------------------------------------------- */

/* A. 728x90 Leaderboard (Desktop) -> 320x100 / Responsive (Mobile) */
.ad-leaderboard {
  width: 100%;
  max-width: 728px;
  min-height: 90px;
}

@media (max-width: 768px) {
  .ad-leaderboard {
    max-width: 320px;
    min-height: 100px;
  }
}

/* B. 300x250 Medium Rectangle (High CTR Hero & Post-Result) */
.ad-rectangle {
  width: 300px;
  max-width: 100%;
  min-height: 250px;
}

/* C. 970x250 Pre-Footer Billboard */
.ad-billboard {
  width: 100%;
  max-width: 970px;
  min-height: 250px;
}

@media (max-width: 1024px) {
  .ad-billboard {
    max-width: 728px;
    min-height: 90px;
  }
}

@media (max-width: 768px) {
  .ad-billboard {
    max-width: 320px;
    min-height: 100px;
  }
}

/* D. 300x600 Half Page (Desktop Sticky Sidebar on Long Pages) */
.ad-halfpage {
  width: 300px;
  min-height: 600px;
  max-width: 100%;
}

/* E. In-Line Content Break Unit */
.ad-inline {
  width: 100%;
  max-width: 728px;
  min-height: 90px;
  margin: 1.75rem auto;
}

/* --------------------------------------------------------------------------
   5. Native Card Ad Unit (.ad-native)
   Matches tool cards and engineering cards seamlessly
   -------------------------------------------------------------------------- */
.ad-native {
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--radius-lg, 16px);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.05));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 320px;
  position: relative;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.ad-native:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,0.1));
}

.ad-native-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.ad-native-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--color-primary-500, #3b82f6);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.ad-native-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--ad-bg);
  border-radius: var(--radius-md, 8px);
  border: 1px dashed var(--ad-border);
  min-height: 220px;
  width: 100%;
}

/* --------------------------------------------------------------------------
   6. Post-Result High-RPM Ad Unit (.ad-post-result)
   Expands smoothly with fade-in after user calculates Age or BMI
   -------------------------------------------------------------------------- */
.ad-post-result {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-top: 0;
  transition: max-height 0.45s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.45s ease,
              margin-top 0.3s ease;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ad-post-result.is-active {
  max-height: 380px;
  opacity: 1;
  margin-top: 1.25rem;
}

/* --------------------------------------------------------------------------
   7. Mobile Sticky Bottom Ad (.ad-sticky-bottom)
   High viewability mobile banner with auto-hide on keyboard/input focus
   -------------------------------------------------------------------------- */
.ad-sticky-bottom {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  z-index: 1100;
  width: 100%;
  max-width: 420px;
  background: var(--bg-card, #ffffff);
  border-top: 1px solid var(--border-color, #e2e8f0);
  border-left: 1px solid var(--border-color, #e2e8f0);
  border-right: 1px solid var(--border-color, #e2e8f0);
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
  padding: 0.35rem 0.5rem 0.5rem 0.5rem;
  display: none;
  flex-direction: column;
  align-items: center;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

@media (max-width: 768px) {
  .ad-sticky-bottom {
    display: flex;
  }
}

/* Auto-hide state when virtual keyboard opens or user focuses an input */
.ad-sticky-bottom.is-hidden {
  transform: translateX(-50%) translateY(120%);
  pointer-events: none;
  opacity: 0;
}

.ad-sticky-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem 0.25rem 0.5rem;
}

.ad-sticky-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted, #94a3b8);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.ad-sticky-close:hover {
  color: var(--text-primary, #0f172a);
  background: var(--bg-surface-subtle, #f1f5f9);
}

.ad-sticky-content {
  width: 320px;
  max-width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --------------------------------------------------------------------------
   8. Desktop Sticky Sidebar (.ad-sticky-sidebar)
   300x600 Half-page sticky ad alongside long technical content
   -------------------------------------------------------------------------- */
.ad-sidebar-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  position: relative;
}

@media (min-width: 1200px) {
  .ad-sidebar-layout {
    grid-template-columns: 1fr 320px;
  }
}

.ad-sticky-sidebar {
  display: none;
}

@media (min-width: 1200px) {
  .ad-sticky-sidebar {
    display: block;
    position: sticky;
    top: 90px;
    align-self: start;
    z-index: 10;
  }
}

/* --------------------------------------------------------------------------
   9. Shimmer Skeleton Loading State
   Eliminates layout shifts and conveys professional polish
   -------------------------------------------------------------------------- */
.ad-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    var(--ad-skeleton-base) 0%,
    var(--ad-skeleton-sweep) 50%,
    var(--ad-skeleton-base) 100%
  );
  background-size: 200% 100%;
  animation: ad-skeleton-shimmer 1.8s infinite linear;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  z-index: 1;
  transition: opacity 0.3s ease;
}

.ad-skeleton.is-loaded {
  opacity: 0;
  pointer-events: none;
}

@keyframes ad-skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ad-skeleton-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ad-skeleton-sweep);
  opacity: 0.7;
}

.ad-skeleton-line {
  height: 10px;
  border-radius: 4px;
  background: var(--ad-skeleton-sweep);
  opacity: 0.7;
}

.ad-skeleton-line.w-60 { width: 60%; }
.ad-skeleton-line.w-40 { width: 40%; }
.ad-skeleton-line.w-80 { width: 80%; }

/* Ad Slot Placeholder Icon & Text */
.ad-placeholder-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ad-label-color);
  opacity: 0.85;
}

.ad-placeholder-text svg {
  opacity: 0.6;
}

/* --------------------------------------------------------------------------
   10. In-Article Native Ad (Inside Article Reader Modal)
   -------------------------------------------------------------------------- */
.in-article-ad-box {
  margin: 2rem 0;
  padding: 1.25rem;
  background: var(--bg-surface-subtle, #f8fafc);
  border: 1px dashed var(--border-color, #e2e8f0);
  border-radius: var(--radius-md, 12px);
  text-align: center;
}
