/* Patternbook custom styles */

/* Improve readability for non-technical audience */
/* Override mdbook's :root { font-size: 62.5% } which sets 1rem = 10px.
   We set the content area directly in px to avoid the rem trap.
   Width comes from --content-max-width (theme-template/css/variables.css)
   so a single token controls the measure across all books. */

.content main {
  max-width: var(--content-max-width);
  font-size: 18px;
  line-height: 1.6;
}

/* Override mdbook's .content p { line-height: 1.45em } which is more specific
   than our .content main rule and wins the cascade. */
.content main p {
  line-height: 1.6;
}

/* Softer code block styling */
pre > code {
  font-size: 0.9em;
}

/* Admonition tweaks */
.admonition {
  border-radius: 6px;
}

/* Highlight table rows that use bold (e.g., "this is us" in comparison tables) */
.content table tbody tr:has(strong) {
  background: rgba(50, 150, 220, 0.25);
}

/* Ad placement — single, tasteful, non-intrusive */
.patternbook-ad {
  margin: 1.5em 0;
  padding: 0.75em 1em;
  border: 1px solid var(--sidebar-bg);
  border-radius: 6px;
  background: var(--sidebar-bg);
  font-size: 0.85rem;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.patternbook-ad.loaded {
  opacity: 1;
}

/* EthicalAds overrides — keep their styling minimal */
.patternbook-ad [data-ea-publisher] {
  margin: 0 auto;
}

/* Carbon Ads overrides */
.patternbook-ad #carbonads {
  max-width: 330px;
  margin: 0 auto;
  font-family: inherit;
}

.patternbook-ad #carbonads a {
  color: var(--links);
  text-decoration: none;
}

.patternbook-ad #carbonads .carbon-poweredby {
  font-size: 0.75rem;
  opacity: 0.6;
}

/* Hide ad container entirely when empty (no ad served) */
.patternbook-ad:empty {
  display: none;
}

/* Mobile: ad takes full width */
@media (max-width: 768px) {
  .patternbook-ad {
    margin: 1em -0.5em;
    border-radius: 0;
  }
}

/* Cover page wrapper — design tokens for the in-book cover image embed.
   Used by every book's src/cover.md via `<div class="bartley-cover">`. */
:root {
  --bartley-cover-top-padding: 10px;
}
.bartley-cover {
  text-align: center;
  padding-top: var(--bartley-cover-top-padding);
}
.bartley-cover img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
}

/* Cover page brag cards — deploy-refreshed article counts.
   Row 1: total Articles card (wide). Row 2: Patterns / Antipatterns / Concepts.
   Responsive: three breakdown cards stack 1-per-line on narrow viewports. */
.brag-cards {
  margin: 1.5em 0 2em;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brag-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.brag-row-breakdown {
  flex-wrap: wrap;
}

.brag-card {
  flex: 1 1 0;
  min-width: 0;
  padding: 16px 12px;
  border: 1px solid var(--table-border-color);
  border-radius: 8px;
  background: var(--quote-bg);
  text-align: center;
  color: var(--fg);
}

.brag-card-total {
  flex: 0 1 100%;
  max-width: 560px;
  padding: 20px 16px;
}

.brag-number {
  font-size: 38px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--fg);
}

.brag-card-total .brag-number {
  font-size: 52px;
}

.brag-label {
  margin-top: 4px;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg);
  opacity: 0.85;
}

/* Narrow viewports: keep breakdown row in one line, shrunk to fit. The
   previous one-per-line stack consumed an entire phone viewport with stat
   cards before any actual content appeared. */
@media (max-width: 560px) {
  .brag-row {
    gap: 8px;
  }
  .brag-row-breakdown {
    flex-wrap: nowrap;
  }
  .brag-row-breakdown .brag-card {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 6px;
  }
  .brag-card-total {
    padding: 14px 12px;
  }
  .brag-number {
    font-size: 24px;
  }
  .brag-card-total .brag-number {
    font-size: 36px;
  }
  .brag-label {
    font-size: 10px;
    letter-spacing: 0.03em;
  }
}

/* Related Patterns — sortable table */
.content table.related-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5em 0 1.5em;
}

.content table.related-table th,
.content table.related-table td {
  text-align: left;
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 1px solid var(--table-border-color);
}

.content table.related-table th {
  background: var(--table-header-bg);
  font-weight: 600;
}

.content table.related-table td:nth-child(1) {
  white-space: nowrap;
}

.related-table button.related-sort {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.related-table button.related-sort:hover {
  text-decoration: underline;
}

.related-table button.related-sort:focus-visible {
  outline: 2px solid var(--links);
  outline-offset: 2px;
}

.related-table button.related-sort .related-sort-indicator {
  font-size: 0.85em;
  min-width: 1ch;
}

.related-table button.related-sort[data-active="false"] .related-sort-indicator {
  opacity: 0.45;
}

/* ===========================================================================
 * Article-image figures (bin/mdbook-image preprocessor output)
 *
 * The preprocessor stamps the natural width/height of the shipping derivative
 * onto the <img> element so the browser can reserve layout space and avoid
 * cumulative layout shift (CLS). Without `height: auto` the HTML height
 * attribute is treated as a fixed pixel size, and `max-width: 100%` then
 * compresses the width below the natural ratio when the column is narrow —
 * producing a horizontally squished image. Setting `height: auto` lets the
 * browser scale the height proportionally and keep the aspect ratio.
 *
 * `display: block` removes the inline-baseline gap under the <img>; centering
 * via auto margins keeps the figure on the article column.
 * ========================================================================= */

figure.bartley-figure {
  margin: 1.6em auto;
  max-width: 100%;
  text-align: center;
}

figure.bartley-figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  margin: 0 auto;
}

figure.bartley-figure figcaption {
  margin-top: 0.6em;
  font-size: 0.92em;
  font-style: italic;
  color: var(--fg, inherit);
  opacity: 0.78;
  line-height: 1.45;
}

/* The hero placement gets a touch more breathing room above and below; no
 * sizing change yet — readers still see the image at the column's full
 * width. Future CSS may bleed it slightly past the column edge. */
figure.bartley-figure[data-placement="hero"] {
  margin-top: 2em;
  margin-bottom: 2em;
}
