/*
 * Kobol article content overrides.
 *
 * Scoped to `body.article-page` (see apps/templates/home/article.html) so it
 * only affects the article detail page and never touches other pages.
 */

/*
 * Header: Material Kit's `.page-header` is a fixed-height (min-vh-25),
 * overflow-hidden flex box that vertically centres its content, while the
 * navbar is absolutely positioned over its top and the content card
 * (`mt-n6`) overlaps its bottom. A title that wraps to two+ lines was
 * clipped under the nav. Pad the header so it grows with the title and
 * always clears both the nav and the overlapping card.
 */
body.article-page .page-header {
  padding-top: 9rem;
  padding-bottom: 6rem;
}

body.article-page .page-header h1 {
  font-size: clamp(1.75rem, 1.2rem + 2.2vw, 3rem);
  line-height: 1.2;
  overflow-wrap: break-word;
}

/*
 * Hero image: `.img-fluid` only caps width, so a portrait photo in the
 * col-lg-8 column rendered ~1000px tall. Crop it to a banner instead.
 */
body.article-page .article-hero {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(60vh, 480px);
  object-fit: cover;
}

/*
 * Markdown-authored bodies (apps/cms/rendering.py) contain raw <img> tags
 * with no sizing attributes (bleach strips width/height). Cap both width
 * and height so large or portrait images stay proportionate to the text.
 */
body.article-page .markdown-content img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
  margin: 1.5rem auto;
  border-radius: 0.5rem;
}

/*
 * Body copy: Material Kit's default (#7b809a at weight 300) is below WCAG AA
 * contrast on white and hard to read in long articles. Darken and thicken it.
 */
body.article-page .markdown-content {
  color: #3a4556;
  overflow-wrap: break-word; /* never let long URLs widen the page */
}

body.article-page .markdown-content p,
body.article-page .markdown-content li {
  color: inherit;
  font-weight: 400;
}

body.article-page .markdown-content strong,
body.article-page .markdown-content b {
  color: #1f2a3d;
}

body.article-page .markdown-content pre {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

/*
 * Tables: Markdown emits bare <table> markup with no Bootstrap classes, so
 * cells had no padding, borders or row separation. Give them a clean,
 * full-width data-table look.
 */
body.article-page .markdown-content table {
  width: 100%;
  margin: 2rem 0;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #dde1e8;
  border-radius: 0.75rem;
  overflow: hidden;
  font-size: 0.95rem;
  line-height: 1.55;
}

body.article-page .markdown-content th,
body.article-page .markdown-content td {
  padding: 0.9rem 1.1rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #e8ebf0;
}

body.article-page .markdown-content th + th,
body.article-page .markdown-content td + td {
  border-left: 1px solid #eef0f4;
}

body.article-page .markdown-content thead th {
  background: #f1f3f7;
  color: #1f2a3d;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-bottom: 2px solid #dde1e8;
}

body.article-page .markdown-content tbody tr:nth-child(even) td {
  background: #f9fafc;
}

body.article-page .markdown-content tbody tr:last-child td {
  border-bottom: 0;
}

/* First column is usually the row label ("Core idea", "Model", ...). */
body.article-page .markdown-content tbody td:first-child {
  min-width: 9rem;
  font-weight: 600;
  color: #1f2a3d;
}

@media (max-width: 767.98px) {
  /* Scroll wide tables sideways instead of crushing the columns. */
  body.article-page .markdown-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }

  body.article-page .markdown-content th,
  body.article-page .markdown-content td {
    min-width: 12rem;
  }

  body.article-page .page-header {
    padding-top: 7rem;
    padding-bottom: 5rem;
  }

  body.article-page .markdown-content {
    font-size: 1.125rem;
    line-height: 1.7;
  }
}
