/**
 * GlobalCalc Ad Infrastructure — gc-ads.css v1.1
 * ================================================
 * FIXES in v1.1:
 * · Removed double-padding: gc-page-with-rail no longer has padding:0 16px
 *   (the existing .gc-page already has padding:0 16px 60px — adding again caused
 *   32px horizontal padding instead of 16px, squeezing the content area)
 * · gc-page inside the rail layout: removed margin:0 auto override —
 *   it's inside a grid cell, centering is handled by the grid
 * · Rail sticky: added explicit height:100% on the grid row and
 *   align-self:start to ensure sticky works correctly in CSS Grid
 * · gc-ad-top: full-width breakout — outside the grid so it spans 100vw correctly
 * · gc-ad-bottom: same full-width treatment
 * · Mobile: gc-page padding preserved correctly on single-column layout
 */

/* ── PAGE LAYOUT WITH RAIL ─────────────────────────────────────── */
.gc-page-with-rail {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 0 28px;
  max-width: 1080px;
  margin: 0 auto;
  /* NO padding here — .gc-page already has padding:0 16px 60px */
  align-items: start;
}

/* Main content column */
.gc-page-with-rail .gc-main-col {
  min-width: 0;
  /* No max-width needed — grid track handles width */
}

/* Override .gc-page centering inside the grid — not needed, grid handles it */
.gc-page-with-rail .gc-main-col .gc-page {
  margin-left: 0;
  margin-right: 0;
  max-width: none;
}

/* Rail column — sticky requires align-self:start on the grid item */
.gc-page-with-rail .gc-rail-col {
  position: sticky;
  top: 60px;               /* 52px topbar + 8px breathing room */
  align-self: start;       /* CRITICAL for sticky in CSS Grid */
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* max-height ensures rail doesn't overflow viewport on short pages */
  max-height: calc(100vh - 68px);
  overflow-y: auto;
  scrollbar-width: none;   /* Hide scrollbar on rail */
}
.gc-page-with-rail .gc-rail-col::-webkit-scrollbar { display: none; }

/* Collapse rail on mobile / tablet */
@media (max-width: 900px) {
  .gc-page-with-rail {
    grid-template-columns: 1fr;
    /* Restore page horizontal padding on mobile when rail is gone */
    padding: 0;
  }
  .gc-rail-col {
    display: none !important;
  }
  /* Restore .gc-page centering when no rail */
  .gc-page-with-rail .gc-main-col .gc-page {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ── AD SLOT BASE ─────────────────────────────────────────────── */
[id^="gc-ad-"] {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: 0;
  transition: opacity 0.3s ease;
  contain: layout;
}

/* Reserve space BEFORE data-state is set to prevent CLS */
#gc-ad-top {
  min-height: 104px; /* 728x90 leaderboard + label */
}
@media (max-width: 767px) {
  #gc-ad-top { min-height: 64px; } /* 320x50 mobile banner + label */
}
#gc-ad-mid {
  min-height: 104px;
}
@media (max-width: 767px) {
  #gc-ad-mid { min-height: 264px; } /* 300x250 mrec + label + margin */
}
#gc-ad-bottom {
  min-height: 104px;
}
@media (max-width: 767px) {
  #gc-ad-bottom { min-height: 264px; }
}
#gc-ad-rail {
  min-height: 614px; /* 300x600 + label */
}

/* "Advertisement" label above every slot */
[id^="gc-ad-"]::before {
  content: 'Advertisement';
  display: block;
  font-family: var(--gc-font, -apple-system, sans-serif);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gc-text-dim, #6e7681);
  text-align: center;
  width: 100%;
  padding: 3px 0 2px;
  line-height: 1;
  flex-shrink: 0;
}

/* Loading shimmer */
[id^="gc-ad-"][data-state="loading"]::after {
  content: '';
  display: block;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--gc-surface, #161b22) 25%,
    var(--gc-surface-hover, #1c2333) 50%,
    var(--gc-surface, #161b22) 75%
  );
  background-size: 400% 100%;
  animation: gc-shimmer 1.6s ease infinite;
}

@keyframes gc-shimmer {
  0%   { background-position: 100% 50% }
  100% { background-position: 0% 50% }
}

[id^="gc-ad-"][data-state="filled"] > iframe {
  border: none;
  display: block;
}

[id^="gc-ad-"].gc-ad-empty::before {
  display: none;
}

/* ── SLOT SIZES ───────────────────────────────────────────────── */

/* TOP — full-width leaderboard, OUTSIDE the grid, spans full content width */
#gc-ad-top {
  background: var(--gc-surface, #161b22);
  border-bottom: 1px solid var(--gc-border, #30363d);
  padding: 6px 0;
  /* Full bleed — sits between header and the grid wrapper */
}
#gc-ad-top[data-state="loading"]::after {
  width: min(728px, 100%);
  height: 90px;
}
@media (max-width: 767px) {
  #gc-ad-top[data-state="loading"]::after {
    width: min(320px, 100%);
    height: 50px;
  }
}

/* MID — between reset button and SEO content cards */
#gc-ad-mid {
  margin: 20px 0;
  background: transparent;
}
#gc-ad-mid[data-state="loading"]::after {
  width: min(728px, 100%);
  height: 90px;
}
@media (max-width: 767px) {
  #gc-ad-mid[data-state="loading"]::after {
    width: min(300px, 100%);
    height: 250px;
  }
}

/* RESULT — in-flow, reveals after first calculation */
#gc-ad-result {
  margin: 16px 0;
  background: transparent;
}
#gc-ad-result[data-state="loading"]::after {
  width: 300px;
  height: 250px;
}

/* RAIL — sticky right column, desktop only */
#gc-ad-rail {
  background: transparent;
  width: 300px;
}
#gc-ad-rail[data-state="loading"]::after {
  width: 300px;
  height: 600px;
}

/* BOTTOM — above footer, full-width like TOP */
#gc-ad-bottom {
  background: var(--gc-surface, #161b22);
  border-top: 1px solid var(--gc-border, #30363d);
  margin-top: 24px;
  padding: 6px 0;
}
#gc-ad-bottom[data-state="loading"]::after {
  width: min(728px, 100%);
  height: 90px;
}
@media (max-width: 767px) {
  #gc-ad-bottom[data-state="loading"]::after {
    width: min(300px, 100%);
    height: 250px;
  }
}

/* ── HOUSE ADS ─────────────────────────────────────────────────── */

.gc-house-ad {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  border-radius: 6px;
  padding: 12px 20px;
  background: var(--ha-bg, rgba(79,143,247,0.08));
  border: 1px solid var(--ha-border, rgba(79,143,247,0.2));
  transition: opacity 0.15s, transform 0.15s;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
}
.gc-house-ad:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

/* Leaderboard layout (top/mid/bottom slots on desktop) */
.gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) {
  flex-direction: row;
  gap: 12px;
  padding: 0 20px;
  height: 90px;
  max-width: 728px;
  justify-content: flex-start;
}
.gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) .gc-house-ad__sub,
.gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) .gc-house-ad__cta,
.gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) .gc-house-ad__eyebrow {
  display: none;
}
.gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) .gc-house-ad__label {
  font-size: 14px;
  font-weight: 600;
}

/* MREC (300×250) */
.gc-house-ad--mrec {
  width: 300px;
  max-width: 100%;
  height: 250px;
}

/* Rail (300×600) */
.gc-house-ad--rail {
  width: 300px;
  max-width: 100%;
  height: 600px;
}

.gc-house-ad__eyebrow {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gc-text-muted, #4b5563);
  width: 100%;
  text-align: center;
  margin-bottom: 4px;
  font-weight: 600;
}
.gc-house-ad__icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}
.gc-house-ad--mrec .gc-house-ad__icon,
.gc-house-ad--rail .gc-house-ad__icon {
  font-size: 36px;
  margin-bottom: 8px;
}
.gc-house-ad__label {
  font-family: var(--gc-font, sans-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--gc-text, #e6edf3);
  line-height: 1.3;
}
.gc-house-ad--mrec .gc-house-ad__label,
.gc-house-ad--rail .gc-house-ad__label {
  font-size: 15px;
  margin-bottom: 4px;
}
.gc-house-ad__sub {
  font-size: 12px;
  color: var(--gc-text, #1f2937);
  line-height: 1.4;
  max-width: 220px;
}
.gc-house-ad__cta {
  font-size: 11px;
  color: var(--gc-primary, #4f8ff7);
  font-weight: 600;
  margin-top: 10px;
  letter-spacing: 0.02em;
}

/* Mobile house ads */
@media (max-width: 767px) {
  .gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) {
    max-width: 100%;
    height: 50px;
    padding: 0 12px;
    gap: 8px;
  }
  .gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) .gc-house-ad__icon {
    font-size: 20px;
  }
  .gc-house-ad:not(.gc-house-ad--rail):not(.gc-house-ad--mrec) .gc-house-ad__label {
    font-size: 12px;
  }
}

/* ── RESULT SLOT ANIMATION ────────────────────────────────────── */
#gc-ad-result {
  animation: gc-slot-reveal 0.4s ease forwards;
}
@keyframes gc-slot-reveal {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── REDUCED MOTION ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  @keyframes gc-shimmer { 0%, 100% { background-position: 0% 50% } }
  @keyframes gc-slot-reveal { from, to { opacity: 1; transform: none } }
  .gc-house-ad { transition: none; }
}

/* ── PRINT ─────────────────────────────────────────────────────── */
@media print {
  [id^="gc-ad-"],
  .gc-rail-col,
  .gc-house-ad {
    display: none !important;
  }
  .gc-page-with-rail {
    grid-template-columns: 1fr;
  }
}

/* ── LIGHT THEME ───────────────────────────────────────────────── */
[data-theme="light"] #gc-ad-top,
[data-theme="light"] #gc-ad-bottom {
  background: var(--gc-surface, #fff);
}
[data-theme="light"] .gc-house-ad {
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
