/* ==========================================================================
   Rishabh Debnath — Blog Article Reader Design System
   Scalable, SEO & GEO-Optimized Article Layout
   ========================================================================== */

/* ==========================================================================
   GLOBAL OVERFLOW SAFEGUARD
   Prevents any child from causing the page to scroll horizontally.
   Applies to all current and future articles via this shared stylesheet.
   ========================================================================== */
.article-page,
.article-page *,
.article-page *::before,
.article-page *::after {
  /* Nothing inside an article page should ever escape max-width. */
  box-sizing: border-box;
}

/* Hard page-level overflow lock */
.article-page {
  padding-top: calc(var(--header-height) + 32px);
  padding-bottom: 80px;
  position: relative;
  z-index: 1;
  /* Prevent any child from blowing out horizontal bounds */
  overflow-x: hidden;
  /* Safari containment safety */
  max-width: 100vw;
}

/* Breadcrumb Navigation */
.breadcrumb-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.breadcrumb-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.breadcrumb-nav a:hover {
  color: var(--accent-primary);
}

.breadcrumb-separator {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 500;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Article Hero / Header Area */
.article-header {
  margin-bottom: 36px;
}

.article-category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent-primary);
  background: rgba(0, 230, 184, 0.08);
  border: 1px solid rgba(0, 230, 184, 0.2);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.article-h1 {
  font-family: var(--font-heading);
  font-size: clamp(1.85rem, 4vw, 2.6rem);
  font-weight: 700;
  line-height: 1.25;
  color: #FFFFFF;
  letter-spacing: -0.02em;
  margin-bottom: 18px;
}

.article-lead {
  font-size: 1.12rem;
  line-height: 1.7;
  color: #CBD5E1;
  margin-bottom: 24px;
}

/* Article Metadata Bar */
.article-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px 20px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  margin-bottom: 36px;
}

.author-meta-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.author-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(0, 230, 184, 0.2), rgba(59, 130, 246, 0.2));
  border: 1px solid rgba(0, 230, 184, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.9rem;
}

.author-info-text {
  display: flex;
  flex-direction: column;
}

.author-name {
  font-family: var(--font-heading);
  font-size: 0.92rem;
  font-weight: 600;
  color: #FFFFFF;
}

.author-role {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--accent-primary);
}

.article-timestamps {
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.timestamp-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Main Article Content Grid (TOC + Reading Column) */
.article-layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 48px;
  align-items: start;
  /* min-width: 0 is critical — CSS Grid children default to min-width: auto
     which allows them to overflow their column boundary */
  min-width: 0;
}

.article-main-column {
  max-width: 780px;
  width: 100%;
  /* Must have min-width: 0 or the grid column cannot shrink below content size */
  min-width: 0;
  /* Extra safety: contain horizontal overflow at column level */
  overflow-x: hidden;
}

/* Key Takeaways Box (GEO / AI Highlight) */
.key-takeaways-card {
  background: linear-gradient(135deg, rgba(13, 20, 32, 0.95), rgba(11, 17, 28, 0.98));
  border: 1px solid rgba(0, 230, 184, 0.3);
  border-left: 4px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 24px 28px;
  margin-bottom: 36px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  /* Prevent content inside from escaping */
  min-width: 0;
  overflow-x: hidden;
}

.takeaways-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.takeaways-icon {
  color: var(--accent-primary);
  display: flex;
}

.takeaways-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.takeaways-list {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.takeaways-list li {
  position: relative;
  padding-left: 22px;
  font-size: 0.94rem;
  line-height: 1.6;
  color: #E2E8F0;
  /* Allow long strings (URLs, code) to break safely */
  overflow-wrap: break-word;
  word-break: break-word;
}

.takeaways-list li::before {
  content: "→";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent-primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Sticky Table of Contents Sidebar */
.article-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 24px);
  /* Fixed width sidebar — must not grow or shrink beyond column */
  min-width: 0;
  max-width: 280px;
  width: 100%;
}

.toc-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 22px;
  box-shadow: var(--shadow-card);
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-primary);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
}

.toc-list {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 70vh;
  overflow-y: auto;
}

.toc-link {
  font-size: 0.84rem;
  color: var(--text-secondary);
  text-decoration: none;
  line-height: 1.45;
  transition: all var(--transition-fast);
  display: block;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
}

.toc-link:hover {
  color: #FFFFFF;
  background-color: rgba(255, 255, 255, 0.04);
}

.toc-link.active {
  color: var(--accent-primary);
  font-weight: 500;
  background-color: rgba(0, 230, 184, 0.08);
}

/* Article Prose Typography & Content Styling */
.article-body {
  color: #CBD5E1;
  font-size: 1.04rem;
  line-height: 1.8;
  /* Critical: prevent any prose content from overflowing the column */
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.article-body h2 {
  font-family: var(--font-heading);
  font-size: 1.55rem;
  font-weight: 600;
  color: #FFFFFF;
  margin-top: 48px;
  margin-bottom: 18px;
  line-height: 1.35;
  letter-spacing: -0.015em;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  scroll-margin-top: calc(var(--header-height) + 24px);
  /* Long headings must wrap, not expand */
  overflow-wrap: break-word;
  word-break: break-word;
}

.article-body h2:first-of-type {
  margin-top: 12px;
  border-top: none;
  padding-top: 0;
}

.article-body h3 {
  font-family: var(--font-heading);
  font-size: 1.22rem;
  font-weight: 600;
  color: #F1F5F9;
  margin-top: 32px;
  margin-bottom: 14px;
  line-height: 1.4;
  scroll-margin-top: calc(var(--header-height) + 24px);
  overflow-wrap: break-word;
  word-break: break-word;
}

.article-body p {
  margin-bottom: 22px;
  /* Paragraphs must wrap — especially those containing inline code or URLs */
  overflow-wrap: break-word;
  word-break: break-word;
}

.article-body ul, 
.article-body ol {
  margin-bottom: 24px;
  padding-left: 24px;
}

.article-body li {
  margin-bottom: 8px;
  line-height: 1.7;
  /* List items with long code spans or URLs must wrap */
  overflow-wrap: break-word;
  word-break: break-word;
}

.article-body strong {
  color: #FFFFFF;
  font-weight: 600;
}

.article-body a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(0, 230, 184, 0.4);
  transition: all var(--transition-fast);
  /* Long anchor text / URLs must wrap safely */
  overflow-wrap: break-word;
  word-break: break-word;
}

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

/* Callout Box / Technical Note */
.article-callout {
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-left: 3px solid var(--accent-secondary);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin: 28px 0;
  /* Callout must not escape column */
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.article-callout-title {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  /* Long title text should wrap, not overflow */
  overflow-wrap: break-word;
  word-break: break-word;
  flex-wrap: wrap;
}

.article-callout p {
  overflow-wrap: break-word;
  word-break: break-word;
}

.article-callout p:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   CODE BLOCK & INLINE CODE — OVERFLOW PREVENTION
   
   Philosophy:
   A) Inline <code> — always wraps. Never expands the paragraph.
   B) <pre><code> (explanatory snippets) — wraps with pre-wrap so content
      remains readable without forcing a horizontal scrollbar on the page.
   C) The <pre> container itself gets overflow-x: auto so long exact-whitespace
      code CAN scroll, but only inside its own box — the page never scrolls.
   D) In all cases: max-width: 100%, min-width: 0.
   ========================================================================== */

/* Inline code — wraps safely inside paragraphs, list items, headings */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background-color: rgba(255, 255, 255, 0.08);
  color: #38BDF8;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  /* Wrap at character boundaries — prevents inline code from
     expanding its parent paragraph beyond container width */
  overflow-wrap: anywhere;
  word-break: break-word;
  /* Keeps inline: doesn't force a new line unless necessary */
  display: inline;
}

/* Code block container — scrolls internally only, never the page */
.article-body pre {
  background-color: #05080E;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 20px;
  margin: 28px 0;
  /* Hard boundaries — code blocks stay inside the column */
  max-width: 100%;
  min-width: 0;
  /* If content truly needs scrolling, only THIS box scrolls */
  overflow-x: auto;
  /* Contain the box — don't let it be a source of page overflow */
  overflow-y: visible;
}

/* Code block content — explanatory SEO/JSON snippets wrap naturally */
.article-body pre code {
  background: transparent;
  padding: 0;
  border: none;
  color: #E2E8F0;
  font-size: 0.86rem;
  line-height: 1.6;
  /* pre-wrap preserves line breaks and indentation (essential for
     JSON-LD, canonical examples, config snippets) while ALSO allowing
     wrapping at natural break points. This eliminates horizontal page
     overflow for most explanatory code — keeping it readable. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  /* Reset display to block within pre */
  display: block;
  /* Full width of the pre container */
  max-width: 100%;
}

/* ==========================================================================
   DATA COMPARISON TABLES — RESPONSIVE ISOLATION
   
   Tables are isolated inside a scrollable wrapper so wide tables
   scroll within their own box, never causing page-level overflow.
   ========================================================================== */
.article-table-wrap {
  /* Fill column width exactly */
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* Wide tables scroll inside this wrapper only */
  overflow-x: auto;
  /* Smooth momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
  margin: 32px 0;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  /* Show a subtle scroll indicator shadow on overflow */
  box-shadow: inset -8px 0 8px -8px rgba(0,0,0,0.3);
}

.article-table {
  /* min-content width so narrow tables don't stretch unnecessarily,
     but wide tables can grow and be scrolled within the wrapper */
  width: 100%;
  min-width: 600px; /* table starts scrolling before columns collapse */
  border-collapse: collapse;
  font-size: 0.9rem;
  text-align: left;
}

.article-table th {
  background-color: rgba(255, 255, 255, 0.03);
  color: #FFFFFF;
  font-family: var(--font-heading);
  font-weight: 600;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  /* Prevent long header text from making columns too wide */
  overflow-wrap: break-word;
  word-break: break-word;
  /* Minimum readable width per column */
  min-width: 120px;
  white-space: normal;
}

.article-table td {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  /* Cell content must wrap, not expand the table horizontally */
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}

.article-table tr:last-child td {
  border-bottom: none;
}

.article-table tr:hover td {
  background-color: rgba(255, 255, 255, 0.015);
}

/* FAQ Accordions / Section */
.faq-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border-subtle);
}

.faq-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 600;
  color: #FFFFFF;
  margin-bottom: 22px;
}

.faq-item {
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  overflow: hidden;
}

.faq-question {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 18px 22px;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  color: #FFFFFF;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 14px;
  transition: color var(--transition-fast);
}

.faq-question:hover {
  color: var(--accent-primary);
}

.faq-chevron {
  color: var(--accent-primary);
  transition: transform var(--transition-smooth);
  flex-shrink: 0;
}

.faq-item.active .faq-chevron {
  transform: rotate(180deg);
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  padding: 0 22px;
  font-size: 0.94rem;
  color: var(--text-secondary);
  line-height: 1.68;
}

.faq-item.active .faq-answer {
  max-height: 600px;
  padding-bottom: 20px;
}

/* Author Bio Card */
.author-bio-card {
  display: flex;
  align-items: center;
  gap: 24px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 30px;
  margin-top: 48px;
  /* Author box must not exceed column width */
  min-width: 0;
  max-width: 100%;
}

.author-bio-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(0, 230, 184, 0.2), rgba(59, 130, 246, 0.2));
  border: 2px solid var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.author-bio-content {
  flex-grow: 1;
  /* Prevent content from exceeding available flex space */
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.author-bio-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.author-bio-name {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: #FFFFFF;
  overflow-wrap: break-word;
}

.author-bio-role {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent-primary);
  overflow-wrap: break-word;
}

.author-bio-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 14px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.author-bio-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.84rem;
  font-family: var(--font-mono);
}

.author-bio-links a {
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color var(--transition-fast);
  overflow-wrap: break-word;
  word-break: break-word;
}

.author-bio-links a:hover {
  color: var(--accent-primary);
}

/* Related Articles Section */
.related-articles-section {
  margin-top: 64px;
  padding-top: 48px;
  border-top: 1px solid var(--border-subtle);
  /* Related section must not escape its column */
  min-width: 0;
  max-width: 100%;
}

.related-header {
  margin-bottom: 28px;
}

.related-tag {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  display: block;
}

.related-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
  color: #FFFFFF;
  overflow-wrap: break-word;
}

.related-grid {
  display: grid;
  /* minmax(0, 1fr) instead of minmax(280px, 1fr) on narrow screens
     prevents grid items from escaping on 390px viewports */
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 24px;
  min-width: 0;
}

/* Article CTA Block */
.article-cta-box {
  background: linear-gradient(135deg, rgba(13, 20, 32, 0.95), rgba(7, 11, 18, 0.95));
  border: 1px solid rgba(0, 230, 184, 0.25);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  margin-top: 56px;
  text-align: center;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  position: relative;
  overflow: hidden;
}

.article-cta-box::before {
  content: "";
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 200px;
  background: radial-gradient(circle, rgba(0, 230, 184, 0.12) 0%, transparent 70%);
  pointer-events: none;
}

.cta-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: #FFFFFF;
  margin-bottom: 12px;
}

.cta-desc {
  font-size: 0.98rem;
  color: var(--text-secondary);
  max-width: 580px;
  margin: 0 auto 24px auto;
  line-height: 1.65;
}

.cta-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* ≤ 992px: Collapse to single column, TOC moves above content */
@media (max-width: 992px) {
  .article-layout-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  
  .article-sidebar {
    position: static;
    order: -1;
    margin-bottom: 24px;
    /* Sidebar becomes full-width on mobile */
    max-width: 100%;
    width: 100%;
  }

  .toc-card {
    background-color: var(--bg-card);
  }

  /* On mobile, tables with min-width can still scroll in their wrapper */
  .article-table {
    min-width: 480px;
  }
}

/* ≤ 768px: Tablet adjustments */
@media (max-width: 768px) {
  .article-page {
    padding-top: calc(var(--header-height) + 16px);
  }

  .breadcrumb-current {
    max-width: 200px;
  }

  .article-meta-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .author-bio-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px;
    /* Ensure the stacked author box does not create overflow */
    min-width: 0;
    width: 100%;
  }

  .article-cta-box {
    padding: 30px 20px;
    min-width: 0;
  }

  .article-h1 {
    font-size: 1.75rem;
  }

  .article-body h2 {
    font-size: 1.35rem;
  }

  .key-takeaways-card {
    padding: 20px 18px;
  }

  .article-callout {
    padding: 16px 18px;
  }
}

/* ≤ 430px: Small mobile (iPhone Plus, Pixel) */
@media (max-width: 430px) {
  .article-h1 {
    font-size: 1.55rem;
  }

  /* Reduce padding inside code blocks so they have more room */
  .article-body pre {
    padding: 14px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
  }

  /* Slightly smaller inline code at small breakpoint */
  .article-body code {
    font-size: 0.82em;
  }

  .article-table-wrap {
    margin: 20px 0;
    border-radius: var(--radius-sm);
  }

  .article-table {
    /* At very narrow widths, allow tighter min-width */
    min-width: 400px;
  }

  .author-bio-avatar {
    width: 52px;
    height: 52px;
    font-size: 1.2rem;
  }

  .related-grid {
    /* At very small widths, force single column */
    grid-template-columns: 1fr;
  }

  .article-cta-box {
    padding: 24px 16px;
  }

  .cta-buttons {
    flex-direction: column;
    align-items: center;
  }

  .cta-buttons .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ≤ 390px: Smallest common viewport — ZERO page overflow required */
@media (max-width: 390px) {
  .article-body {
    font-size: 0.97rem;
  }

  /* Tightest padding for list items with code */
  .article-body ul,
  .article-body ol {
    padding-left: 18px;
  }

  .takeaways-list li {
    font-size: 0.88rem;
  }

  .faq-question {
    padding: 14px 16px;
    font-size: 0.94rem;
  }

  .faq-answer {
    padding: 0 16px;
  }

  .faq-item.active .faq-answer {
    padding-bottom: 16px;
  }
}
