/* Ads, promo blocks and the consent banner (App\Services\Ads, docs/modules/ads.md). Linked only on pages that show
   them. Every box is reserved before anything loads (--ad-w × --ad-h + the label line), so filling it never shifts
   the layout; the sizes match App\Services\Ads::SLOTS. Mobile first; fits 320 px. */
.ad-row {
  padding-block: var(--space-4);
}

.ad-slot {
  --ad-w: 300px;
  --ad-h: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: var(--ad-w);
  margin-inline: auto;
  overflow: hidden;
}

.ad-slot[hidden],
.ad-row[hidden] {
  display: none;
}

.ad-label {
  display: block;
  height: 16px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Spacing letters apart breaks Devanagari conjuncts. */
.ad-label:lang(hi),
.promo-label:lang(hi) {
  letter-spacing: 0;
}

.ad-slot[data-ad-kind="adsense"],
.ad-slot[data-ad-kind="code"],
.ad-slot[data-ad-kind="demo"] {
  min-height: calc(var(--ad-h) + 16px);
}

.ad-slot ins,
.ad-slot iframe,
.ad-demo {
  display: block;
  width: 100%;
  height: var(--ad-h);
  border: 0;
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.ad-slot-header,
.ad-slot-footer {
  --ad-w: 320px;
  --ad-h: 100px;
}

.ad-slot-sidebar {
  --ad-w: 300px;
  --ad-h: 600px;
  display: none;
}

.ad-slot-sticky {
  --ad-w: 320px;
  --ad-h: 50px;
}

.ad-slot-in-content,
.ad-slot-links {
  margin-block: var(--space-6);
}

@media (min-width: 768px) {
  .ad-slot-header,
  .ad-slot-footer,
  .ad-slot-list {
    --ad-w: 728px;
    --ad-h: 90px;
  }

  .ad-slot-in-content,
  .ad-slot-links {
    --ad-w: 336px;
    --ad-h: 280px;
  }
}

@media (min-width: 1024px) {
  .ad-slot-sidebar {
    display: flex;
  }
}

/* Image ads keep their own proportions inside the box (width/height attributes: the space is known at once). */
.ad-image {
  display: block;
  max-width: 100%;
}

.ad-image img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: var(--ad-h);
  border-radius: var(--radius);
}

.ad-html {
  width: 100%;
  overflow-wrap: anywhere;
}

.ad-html > :first-child {
  margin-top: 0;
}

.ad-html > :last-child {
  margin-bottom: 0;
}

/* The demo: every position as a labelled box of its reserved size. */
.ad-demo {
  display: grid;
  place-content: center;
  gap: 2px;
  padding: var(--space-2);
  border: 2px dashed var(--border);
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* Posts and lists: the sidebar slot in a second column from 1180 px, sticky while the page scrolls. */
.ad-aside {
  display: none;
}

@media (min-width: 1180px) {
  .post:has(> .ad-aside),
  .post-list-page:has(> .ad-aside) {
    position: relative;
    max-width: calc(var(--container) + 2 * var(--gutter));
    padding-right: calc(var(--gutter) + 300px + var(--space-6));
  }

  .ad-aside {
    position: absolute;
    top: var(--space-6);
    right: var(--gutter);
    bottom: var(--space-12);
    display: block;
    width: 300px;
  }

  .ad-aside > .ad-slot {
    position: sticky;
    top: 88px;
  }
}

/* Sticky mobile footer: above the bottom bar (never over it), closable, phones only. Shown by ads.js. */
.ad-sticky {
  position: fixed;
  right: 0;
  bottom: calc(57px + env(safe-area-inset-bottom, 0px));
  left: 0;
  z-index: 39;
  display: flex;
  justify-content: center;
  padding: 2px 44px 4px;
  border-top: 1px solid var(--border);
  background: var(--surface, #fff);
}

.ad-sticky[hidden] {
  display: none;
}

.ad-sticky-close {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
}

body:has(> .ad-sticky:not([hidden])) {
  padding-bottom: calc(57px + 74px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 768px) {
  .ad-sticky {
    display: none !important;
  }

  body:has(> .ad-sticky:not([hidden])) {
    padding-bottom: 0;
  }
}

@media print {
  .ad-row,
  .ad-slot,
  .ad-sticky,
  .promos,
  .consent {
    display: none !important;
  }
}

/* Promo blocks (Admin → Ads → Promos) */
.promos {
  display: grid;
  gap: var(--space-3);
}

.promo-link,
.promo-demo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface, #fff);
  color: inherit;
  text-decoration: none;
}

.promo-demo {
  border: 2px dashed var(--border);
}

.promo-link:hover .promo-title,
.promo-link:focus-visible .promo-title {
  text-decoration: underline;
}

.promo-img {
  flex: none;
  width: 96px;
  height: auto;
  border-radius: var(--radius);
}

.promo-body {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.promo-label {
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.promo-title {
  color: var(--brand-text);
  overflow-wrap: anywhere;
}

.promo-text {
  color: var(--text-muted);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* Cookie consent banner: first in the page, fixed at the bottom above the mobile bottom bar; ads.js shows it. */
.consent {
  position: fixed;
  right: var(--space-3);
  bottom: calc(57px + env(safe-area-inset-bottom, 0px) + var(--space-2));
  left: var(--space-3);
  z-index: var(--z-toast, 80);
  max-width: 720px;
  max-height: calc(100vh - 57px - var(--space-6));
  margin-inline: auto;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
}

.consent:not([data-ready]),
.consent[hidden] {
  display: none;
}

@media (min-width: 768px) {
  .consent {
    bottom: var(--space-3);
  }
}

.consent-inner {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
}

.consent-title {
  margin: 0 0 var(--space-1);
  font-size: var(--text-base);
}

.consent-title:focus {
  outline: none;
}

.consent-title:focus-visible {
  outline: 2px solid var(--focus, var(--brand));
  outline-offset: 2px;
}

.consent p {
  margin: 0;
  font-size: var(--text-sm);
}

.consent-settings {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
}

.consent-settings summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--brand-text);
  font-weight: 600;
  cursor: pointer;
}

.consent-options {
  display: grid;
  gap: var(--space-2);
}

.consent-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.consent-actions .btn {
  min-height: 44px;
}

@media (min-width: 640px) {
  .consent-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }
}
