/*
 * Blog post template — two-column editorial layout.
 *
 * Design language: Swiss-modern editorial (grid-based, strong typographic
 * hierarchy, generous whitespace, accent-pink for links/CTA). Content column
 * is capped to a readable measure (~44rem ≈ 70ch); a sticky sidebar carries the
 * editable CTA card over the auto-generated table of contents. All values come
 * from the design tokens in variable.css — no hardcoded colors.
 *
 * Mobile (< 1024px) collapses to a single column and the sidebar stacks
 * below the article. Phase 2b upgrades mobile with a Contents accordion and a
 * sticky CTA bar, and finalizes the .is-active scroll-spy state reserved here.
 */

/* Breakpoints (custom properties can't be used in media conditions, so these
   px values are hardcoded in the queries below — keep them in sync):
     > 1200px  three columns: TOC rail · article · offer rail (both rails sticky)
     ≤ 1200px  two columns: article · sticky offer; TOC becomes a top accordion
     ≤ 820px   one column: TOC accordion, article, inline offer, bottom CTA bar */
:root {
  --blog-toc-w: 13rem;          /* left rail: table of contents */
  --blog-offer-w: 20rem;        /* right rail: offer card */
  --blog-measure: 44rem;        /* readable article width */
  --blog-sticky-top: 10rem;     /* clears the sticky header + breathing room above the rails */
  --blog-anchor-offset: 6.5rem; /* heading scroll-margin for anchor jumps */
}

/* ===== Layout ===== */

.blog-layout {
  display: grid;
  /* TOC rail · readable article · offer rail, centered as a group so the rails
     hug the text rather than splaying across wide empty gutters. */
  grid-template-columns: var(--blog-toc-w) minmax(0, var(--blog-measure)) var(--blog-offer-w);
  justify-content: center;
  gap: var(--space-8) var(--space-10);
  align-items: start;
}

/* Posts without headings render no TOC rail — drop its track so the article
   and offer stay centred instead of leaving a blank left gutter. */
.blog-layout--no-toc {
  grid-template-columns: minmax(0, var(--blog-measure)) var(--blog-offer-w);
}

.blog-content {
  min-width: 0; /* let long code/tables shrink instead of overflowing the grid */
}

/* Tablet/small-laptop: drop the left rail. The TOC spans the full width as a
   collapsible accordion on top; the offer stays as a sticky right rail. */
@media (max-width: 1200px) {
  .blog-layout {
    grid-template-columns: minmax(0, var(--blog-measure)) var(--blog-offer-w);
  }
  .blog-toc-col {
    grid-column: 1 / -1;
    position: static;
  }
}

/* Mobile: single column. Offer drops inline below the article; the fixed bottom
   CTA bar (further down) carries the persistent action. */
@media (max-width: 820px) {
  .blog-layout {
    grid-template-columns: minmax(0, var(--blog-measure));
  }
  .blog-offer-col {
    position: static;
    width: 100%;
    max-width: 26rem;
    margin-inline: auto;
  }
}

/* Anchor jumps and scroll-spy land the heading below the sticky header. */
.article-body :is(h2, h3)[id] {
  scroll-margin-top: var(--blog-anchor-offset);
}

/* ===== Feature image ===== */

.blog-feature-image {
  margin-bottom: var(--space-8);
}

.blog-feature-image img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-xl);
}

/* ===== Article body (rendered markdown) ===== */

.article-body {
  max-width: var(--blog-measure);
  color: var(--color-gray-700);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  line-height: 1.8;
}

.article-body > *:first-child {
  margin-top: 0;
}

.article-body h2,
.article-body h3,
.article-body h4 {
  color: var(--color-text);
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.25;
  scroll-margin-top: var(--blog-anchor-offset);
}

.article-body h2 {
  font-size: var(--text-2xl);
  margin: var(--space-10) 0 var(--space-4);
}

.article-body h3 {
  font-size: var(--text-xl);
  margin: var(--space-8) 0 var(--space-3);
}

.article-body h4 {
  font-size: var(--text-lg);
  margin: var(--space-6) 0 var(--space-2);
}

.article-body p {
  margin: 0 0 var(--space-6);
}

.article-body ul,
.article-body ol {
  margin: 0 0 var(--space-6);
  padding-left: var(--space-6);
}

.article-body li {
  margin-bottom: var(--space-2);
}

.article-body li::marker {
  color: var(--color-gray-400);
}

.article-body strong {
  color: var(--color-text);
  font-weight: 700;
}

.article-body a {
  color: var(--color-accent-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: color 200ms ease;
}

.article-body a:hover {
  color: var(--color-accent);
}

.article-body blockquote {
  margin: var(--space-8) 0;
  padding: var(--space-2) 0 var(--space-2) var(--space-5);
  border-left: 3px solid var(--color-accent);
  color: var(--color-gray-600);
  font-style: italic;
}

.article-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-surface-muted);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-md);
}

.article-body pre {
  margin: var(--space-6) 0;
  padding: var(--space-4);
  background: var(--color-surface-muted);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.article-body pre code {
  background: none;
  padding: 0;
}

.article-body hr {
  margin: var(--space-10) 0;
  border: 0;
  border-top: 1px solid var(--color-gray-100);
}

.blog-section-figure {
  margin: var(--space-8) 0;
}

.blog-section-figure img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-xl);
}

.blog-section-figure figcaption {
  margin-top: var(--space-3);
  text-align: center;
  color: var(--color-gray-500);
  font-size: var(--text-sm);
}

.article-body table {
  width: 100%;
  margin: var(--space-6) 0;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.article-body th,
.article-body td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-gray-100);
  text-align: left;
}

.article-body th {
  color: var(--color-text);
  font-weight: 700;
}

/* ===== Author + back link ===== */

.blog-author {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  max-width: var(--blog-measure);
  margin-top: var(--space-10);
  padding: var(--space-6);
  background: var(--color-surface-muted);
  border-radius: var(--radius-2xl);
}

.blog-author-avatar {
  flex-shrink: 0;
  width: 4rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  color: var(--color-accent);
}

.blog-author-name {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.blog-author-bio {
  color: var(--color-gray-600);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.blog-back {
  margin-top: var(--space-8);
}

/* ===== Sidebar ===== */

/* ===== Sticky rails ===== */

.blog-toc-col,
.blog-offer-col {
  position: sticky;
  top: var(--blog-sticky-top);
  align-self: start;
}

/* ===== Offer card (reusable — shared/_offer_card) =====
   Echoes the homepage offer card: gradient header carries the central offer
   badge, white body carries the per-post CTA copy and the estimate button. */

.offer-card {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.offer-card-head {
  background: linear-gradient(135deg, var(--color-primary-active), #a82c00);
  color: var(--color-white);
  padding: var(--space-6) var(--space-6) var(--space-5);
  text-align: center;
}

.offer-card-ribbon {
  display: block;
  margin-bottom: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  /* Light-pink tint from the primary hue reads clearly on the dark gradient. */
  color: var(--color-primary-light);
}

.offer-card-deal {
  line-height: 1.1;
}

.offer-card-deal strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-3xl);
  letter-spacing: -0.02em;
}

.offer-card-deal span {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.92);
}

.offer-card-body {
  padding: var(--space-6);
  text-align: center;
}

.offer-card-heading {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.offer-card-text {
  color: var(--color-gray-600);
  font-size: var(--text-sm);
  line-height: 1.6;
  margin-bottom: var(--space-5);
}

.offer-card-btn {
  width: 100%;
  justify-content: center;
}

.offer-card-phone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  color: var(--color-primary-dark);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: color 200ms ease;
}

.offer-card-phone:hover {
  color: var(--color-primary-active);
}

/* ===== Table of contents ===== */

/* On desktop the TOC is always shown in the sticky sidebar, so the accordion
   summary is just a toggle affordance we hide. Mobile styles below turn it into
   a tappable "Contents" panel (see the max-width block). */
.blog-toc-summary {
  display: none;
}

.blog-toc-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  /* gray-500 (4.8:1 on white) not gray-400 (2.94:1) — a 12px bold label is not
     "large text", so it needs the full 4.5:1 AA ratio. */
  color: var(--color-gray-500);
  margin-bottom: var(--space-3);
}

.blog-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--color-gray-100);
}

.blog-toc-link {
  display: block;
  padding: var(--space-1) 0 var(--space-1) var(--space-4);
  margin-left: -2px; /* overlap the list's left border for the active marker */
  border-left: 2px solid transparent;
  color: var(--color-gray-600);
  font-size: var(--text-sm);
  line-height: 1.4;
  transition: color 200ms ease, border-color 200ms ease;
}

.blog-toc-link:hover {
  color: var(--color-primary-active);
}

/* Scroll-spy active state — the toc controller adds .is-active to the link for
   the section in view. The 2px marker is the functional position indicator on
   the TOC spine, not decorative card trim. */
.blog-toc-link.is-active {
  color: var(--color-primary-active);
  border-left-color: var(--color-primary);
  font-weight: 600;
}

/* ===== TOC becomes a collapsible "Contents" accordion once it leaves the
   left rail (≤1200px) ===== */

@media (max-width: 1200px) {
  .blog-toc-accordion {
    border: 1px solid var(--color-gray-100);
    border-radius: var(--radius-xl);
    background: var(--color-white);
    overflow: hidden;
  }

  .blog-toc-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px; /* comfortable touch target */
    padding: var(--space-3) var(--space-4);
    color: var(--color-text);
    font-weight: 700;
    cursor: pointer;
    list-style: none;
  }

  /* Hide the native disclosure triangle; we draw our own chevron. */
  .blog-toc-summary::-webkit-details-marker {
    display: none;
  }

  .blog-toc-summary::after {
    content: "";
    width: 0.6rem;
    height: 0.6rem;
    border-right: 2px solid var(--color-gray-500);
    border-bottom: 2px solid var(--color-gray-500);
    transform: rotate(45deg);
    transition: transform 200ms ease;
  }

  .blog-toc-accordion[open] .blog-toc-summary::after {
    transform: rotate(-135deg);
  }

  .blog-toc-accordion .blog-toc {
    padding: 0 var(--space-4) var(--space-4);
  }

  /* The summary already labels the panel on mobile. */
  .blog-toc-accordion .blog-toc-title {
    display: none;
  }
}

/* ===== Mobile: sticky bottom CTA bar (shown once the offer drops inline) ===== */

.blog-cta-bar {
  display: none;
}

@media (max-width: 820px) {
  .blog-cta-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    padding: var(--space-3) var(--space-4);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
    background: var(--color-white);
    border-top: 1px solid var(--color-gray-100);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
  }

  .blog-cta-bar .btn-accent {
    flex: 1;
    justify-content: center;
  }

  .blog-cta-bar-phone {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-gray-200);
    color: var(--color-text);
  }

  /* Reserve space so the fixed bar never covers the footer or last content.
     Scoped to pages that actually render the bar. */
  body:has(.blog-cta-bar) {
    padding-bottom: 5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .article-body a,
  .offer-card-phone,
  .blog-toc-link,
  .blog-toc-summary::after {
    transition: none;
  }
}
