/* ============================================================
   post.css – Static article reader (A4 sheet layout)
   Loaded on /post/{slug} pages by generate-static.js
   Depends on css/style.css for tokens, header, footer.

   Behaviour:
   - Desktop/tablet: article sits on a centered A4-proportioned
     "paper" sheet (210mm wide) over a soft grey backdrop.
   - Mobile (<= 820px): sheet becomes full-width, no shadow,
     fluid padding — nothing overflows horizontally.
   - Print: exact A4, 20mm margins, no chrome, clean page breaks.

   Accessibility: text/background combinations meet WCAG AA.
   ============================================================ */

/* ============================================================
   PAGE BACKDROP + A4 SHEET
   ============================================================ */
.post-page {
  background: #eef1f5;
}

.post-container {
  /* A4 width = 210mm; capped by viewport on small screens */
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;               /* A4 height as minimum */
  margin: 28px auto 60px;
  padding: 20mm 18mm 24mm;
  box-sizing: border-box;
  background: #fff;
  border-radius: 4px;
  box-shadow:
    0 1px 2px rgba(16, 24, 40, .06),
    0 12px 32px -8px rgba(16, 24, 40, .16);
}

/* ============================================================
   BREADCRUMB
   ============================================================ */
.post-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted, #667085);
  margin-bottom: 24px;
  flex-wrap: wrap;
  line-height: 1.4;
}

.post-breadcrumb a {
  color: var(--primary-dark, #005fa3);
  text-decoration: none;
  font-weight: 500;
}
.post-breadcrumb a:hover {
  text-decoration: underline;
}

.post-breadcrumb span[aria-hidden] {
  color: var(--muted, #667085);
  font-size: 16px;
  line-height: 1;
}

.post-breadcrumb [aria-current="page"] {
  color: var(--muted, #667085);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 340px;
}

/* ============================================================
   ARTICLE HEADER
   ============================================================ */
.post-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.post-category {
  display: inline-block;
  padding: 4px 12px;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--primary-dark, #005fa3);
  background: rgba(0, 120, 212, .1);
  border: 1px solid rgba(0, 120, 212, .22);
  border-radius: 999px;
}

.post-title {
  font-size: clamp(1.6rem, 3.6vw, 2.25rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.02em;
  color: var(--text, #1a1a1a);
  margin: 0 0 18px;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--muted, #667085);
}

.post-author {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-2, #344054);
}

.post-author-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0078d4, #00b4d8);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}

.post-meta-sep {
  color: var(--muted, #667085);
}

.post-lede {
  margin: 20px 0 0;
  padding: 14px 18px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-2, #344054);
  background: #f8fbff;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
}

/* ============================================================
   ARTICLE BODY
   ============================================================ */
.post-content {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text, #1a1a1a);
}

.post-content > *:first-child { margin-top: 0; }
.post-content > *:last-child  { margin-bottom: 0; }

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4 {
  color: var(--text, #1a1a1a);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -.01em;
  scroll-margin-top: 90px;
}
.post-content h1 { font-size: 1.7rem;  margin: 1.8em 0 .6em; }
.post-content h2 { font-size: 1.45rem; margin: 1.8em 0 .7em; }
.post-content h3 { font-size: 1.2rem;  margin: 1.5em 0 .5em; }
.post-content h4 { font-size: 1.05rem; margin: 1.3em 0 .4em; }

.post-content p { margin: 1.1em 0; }

.post-content a {
  color: var(--primary-dark, #005fa3);
  text-decoration: none;
  border-bottom: 1px solid rgba(0, 95, 163, .4);
  transition: border-color .15s ease;
  font-weight: 500;
}
.post-content a:hover {
  border-bottom-color: var(--primary-dark, #005fa3);
}

.post-content ul,
.post-content ol {
  margin: 1em 0;
  padding-left: 1.5em;
}
.post-content li {
  margin: .4em 0;
}

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.4em auto;
  display: block;
}

.post-content blockquote {
  border-left: 4px solid var(--primary);
  padding: 4px 0 4px 20px;
  margin: 1.5em 0;
  color: var(--text-2, #344054);
  font-style: italic;
  background: #fafbff;
  border-radius: 0 8px 8px 0;
}

/* Inline code: !important + :not(pre) so no other stylesheet can make it
   dark-on-dark. Covers code inside <em>, <a>, <li>, <blockquote>, etc. */
.post-content :not(pre) > code,
.post-content code {
  background: #eef1f5 !important;
  color: #1a1a1a !important;
  -webkit-text-fill-color: #1a1a1a;
  border: 1px solid #d8dee6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .9em;
  font-style: normal;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  text-shadow: none;
  opacity: 1;
}

.post-content pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px 18px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.5em 0;
  font-size: 13.5px;
  line-height: 1.55;
}
.post-content pre code {
  background: transparent !important;
  border: 0;
  padding: 0;
  color: #e2e8f0 !important;
  -webkit-text-fill-color: #e2e8f0;
  font-size: inherit;
}

.post-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.2em 0;
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: .95rem;
}
.post-content th,
.post-content td {
  padding: 10px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.post-content th {
  background: #f8fafc;
  color: var(--text, #1a1a1a);
  font-weight: 600;
}

/* ============================================================
   ARTICLE FOOTER
   ============================================================ */
.post-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.post-share {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.post-share-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted, #667085);
  margin-right: 4px;
}

.post-share-btn {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-dark, #005fa3);
  background: #fff;
  border: 1px solid var(--border-2, #cbd5e1);
  border-radius: 999px;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.post-share-btn:hover {
  background: rgba(0, 120, 212, .08);
  border-color: var(--primary-dark, #005fa3);
  color: var(--primary-dark, #005fa3);
}

.post-back {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-dark, #005fa3);
  text-decoration: none;
}
.post-back:hover {
  text-decoration: underline;
}

/* ============================================================
   RELATED ARTICLES (below the sheet, same width)
   ============================================================ */
.related {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto 60px;
  padding: 0 18mm;
  box-sizing: border-box;
}

.related-heading {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--text, #1a1a1a);
  margin: 0 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.related-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.related-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: 0 12px 24px -12px rgba(0, 120, 212, .22);
}

.related-card-link {
  display: flex;
  flex-direction: column;
  padding: 18px 18px 16px;
  text-decoration: none;
  color: inherit;
  height: 100%;
}
.related-card-link:hover {
  text-decoration: none;
}

.related-card-cat {
  display: inline-block;
  align-self: flex-start;
  padding: 3px 10px;
  margin-bottom: 10px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--primary-dark, #005fa3);
  background: rgba(0, 120, 212, .1);
  border: 1px solid rgba(0, 120, 212, .22);
  border-radius: 999px;
}

.related-card-title {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text, #1a1a1a);
  letter-spacing: -.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.related-card-excerpt {
  margin: 0 0 14px;
  font-size: .875rem;
  line-height: 1.55;
  color: var(--text-2, #344054);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.related-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted, #667085);
  flex-wrap: wrap;
}

.related-card-avatar {
  width: 20px;
  height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #0078d4, #00b4d8);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

/* ============================================================
   OVERFLOW SAFETY NET (all screen sizes)
   ============================================================ */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}

.post-container,
.post-article,
.post-content,
.related {
  box-sizing: border-box;
}

.post-content,
.post-content p,
.post-content li,
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6,
.post-content blockquote,
.post-content a,
.post-lede,
.post-title {
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.post-content img,
.post-content video,
.post-content iframe,
.post-content svg,
.post-content embed,
.post-content object {
  max-width: 100%;
  height: auto;
  display: block;
}

.post-content pre,
.post-content pre code {
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.post-content code:not(pre code) {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Tables scroll inside themselves instead of widening the page */
.post-content table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.post-content table th,
.post-content table td {
  white-space: nowrap;
}

/* ============================================================
   TABLET / MOBILE – sheet becomes a fluid column
   ============================================================ */
@media (max-width: 820px) {
  .post-page {
    background: #fff;
  }

  .post-container {
    width: 100%;
    min-height: 0;
    margin: 0 auto;
    padding: 24px 20px 56px;
    border-radius: 0;
    box-shadow: none;
  }

  .related {
    width: 100%;
    margin: 40px auto 48px;
    padding: 0 20px;
  }
}

@media (max-width: 640px) {
  .post-container {
    padding: 20px 16px 48px;
  }

  .post-breadcrumb {
    font-size: 12.5px;
    margin-bottom: 18px;
  }
  .post-breadcrumb [aria-current="page"] {
    max-width: 180px;
  }

  .post-title {
    font-size: 1.55rem;
    margin-bottom: 14px;
  }

  .post-meta {
    font-size: 13px;
    gap: 8px;
  }

  .post-lede {
    font-size: .95rem;
    padding: 12px 14px;
    margin-top: 16px;
  }

  .post-content {
    font-size: 1rem;
    line-height: 1.7;
  }
  .post-content h2 { font-size: 1.3rem; }
  .post-content h3 { font-size: 1.1rem; }

  .post-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .related {
    margin-top: 36px;
    padding: 0 16px;
  }
  .related-grid {
    grid-template-columns: 1fr;
  }
  .related-heading {
    font-size: 1.15rem;
  }
}

@media (max-width: 380px) {
  .post-container {
    padding-left: 12px;
    padding-right: 12px;
  }
  .post-title {
    font-size: 1.4rem;
    line-height: 1.25;
  }
  .post-content {
    font-size: .96rem;
  }
  .post-breadcrumb [aria-current="page"] {
    max-width: 120px;
  }
  .related {
    padding: 0 12px;
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: .001ms !important;
  }
  .related-card:hover {
    transform: none;
  }
}

/* ============================================================
   PRINT – exact A4, clean pages
   ============================================================ */
@page {
  size: A4 portrait;
  margin: 20mm 18mm;
}

@media print {
  html, body {
    background: #fff !important;
    overflow: visible !important;
    width: 210mm;
    max-width: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Hide site chrome and interactive bits */
  header,
  footer,
  nav,
  .site-header,
  .site-footer,
  .post-breadcrumb,
  .post-share,
  .post-back,
  .related {
    display: none !important;
  }

  .post-page {
    background: #fff !important;
  }

  /* The page margins now come from @page, so the sheet is flat */
  .post-container {
    width: 100%;
    max-width: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
  }

  .post-footer {
    display: none !important;
  }

  .post-title {
    font-size: 22pt;
    color: #000;
  }

  .post-content {
    font-size: 11pt;
    line-height: 1.6;
    color: #000;
  }
  .post-content h1 { font-size: 20pt; }
  .post-content h2 { font-size: 16pt; }
  .post-content h3 { font-size: 13pt; }
  .post-content h4 { font-size: 11.5pt; }

  /* Show link targets for readers of the paper copy */
  .post-content a {
    color: #000;
    border-bottom: 0;
    text-decoration: underline;
  }
  .post-content a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #444;
    word-break: break-all;
  }

  /* Page-break control */
  .post-header,
  .post-content h1,
  .post-content h2,
  .post-content h3,
  .post-content h4 {
    break-after: avoid;
    page-break-after: avoid;
  }
  .post-content img,
  .post-content pre,
  .post-content blockquote,
  .post-content table,
  .post-content tr,
  .post-lede {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .post-content p {
    orphans: 3;
    widows: 3;
  }

  /* Code and tables wrap instead of scrolling on paper */
  .post-content pre {
    background: #f5f6f8;
    color: #111;
    border: 1px solid #d0d5dd;
    white-space: pre-wrap;
    overflow: visible;
    font-size: 9.5pt;
  }
  .post-content pre code {
    color: #111 !important;
    -webkit-text-fill-color: #111;
  }
  .post-content table {
    display: table;
    overflow: visible;
    font-size: 10pt;
  }
  .post-content table th,
  .post-content table td {
    white-space: normal;
  }
  .post-content img {
    max-height: 230mm;
    object-fit: contain;
  }
}