/*
 * Battlecard layout styles.
 *
 * Premium editorial style — generous whitespace, strong typographic
 * hierarchy, restrained palette, subtle accents. All values come from
 * semantic CSS variables defined in src/themes/*.css so theme swaps work
 * without touching this file.
 *
 * Emoji icons in `.bc-cap` cards: rendered as Twemoji SVG `<img>` tags
 * via the `twemoji_url(emoji)` Jinja global, NOT as font glyphs. We
 * tried `@font-face` for Twemoji Mozilla (COLR/CPAL TTF) here, but
 * WeasyPrint's emoji rendering on macOS picks Apple Color Emoji
 * regardless and the same is unreliable on Linux container builds.
 * SVG `<img>` is the only approach that gives consistent flat-emoji
 * output across platforms and between editor preview / PDF.
 */

/*
 * Pagination model: explicit per-page layout (ADR 0002 addendum).
 *
 * The document is composed of N independent `.bc-page` containers,
 * each exactly the size of one A4 page. WeasyPrint only ever inserts
 * page breaks BETWEEN containers (via `page-break-after: always`),
 * never INSIDE one. Sections are allocated to pages in `_preview.html`
 * by the template author — there is no auto-pagination, no `break-
 * inside: avoid` heuristics, no continuation-page padding tricks.
 *
 * The trade-off is that each page has a fixed height (297mm) and a
 * fixed inset (18mm), and content that would overflow is *clipped*
 * (`overflow: hidden`). We treat overflow as a content-too-long
 * authoring bug, not a layout bug — schema cardinality and char-length
 * limits in `app/schema.py` keep content within bounds.
 */

@page {
  size: A4;
  /* The page box itself contributes nothing — the `.bc-page` element
     IS the page in this model. Margin: 0 means no engine-applied
     inset; the inset is `padding: 18mm` on `.bc-page` and applies
     identically on every page because each page is its own box. */
  margin: 0;
}

.bc-document {
  background: var(--color-surface-page);
  color: var(--color-text-primary);
  font-family: var(--font-family-body);
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  orphans: 2;
  widows: 2;
}

.bc-document * {
  box-sizing: border-box;
}

.bc-page {
  width: 210mm;
  height: 297mm;
  padding: 18mm;
  background: var(--color-surface-page);
  /* Stack sections vertically with consistent gaps. Using flex (not
     block + margin) because consistent gap behavior between sections
     is easier to reason about. */
  display: flex;
  flex-direction: column;
  gap: 6mm;
  box-sizing: border-box;
  position: relative;
  /* Hard cap on content: anything that exceeds the page height is
     clipped here. This is intentional — silent text-running-past-edge
     is a worse failure mode than a visible cut, and it forces us to
     keep schema limits honest. */
  overflow: hidden;
  /* Force a page break after every page except the last. */
  page-break-after: always;
  break-after: page;
}

.bc-page:last-child {
  page-break-after: auto;
  break-after: auto;
}

/* Flex-grow spacer rendered immediately before `.bc-cta` in
   `_preview.html`. Absorbs all remaining vertical space on the page so
   the CTA anchors to the bottom edge regardless of how many other
   sections share the page. This works in single-child cases too,
   unlike `justify-content: space-between` (which is a no-op for a
   single flex item). */
.bc-spacer {
  flex: 1 1 auto;
  min-height: 0;
}

/* Editor preview (screen media): show each page as a card-like rectangle
   with a soft border and a small gap between pages. Print media gets
   none of this — `@page` is in charge. */
@media screen {
  .bc-document {
    display: flex;
    flex-direction: column;
    gap: 8mm;
  }

  .bc-page {
    border: 1px solid var(--color-border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  }
}

/* ── HERO ───────────────────────────────────────────────────────────────── */

.bc-hero {
  position: relative;
  padding: 0 0 5mm 0;
  border-bottom: 1px solid var(--color-border);
}

/* Klypup brand mark — replaces the previous accent stripe (`.bc-hero::before`,
   removed). Scales by height; width follows the SVG's ~2.83:1 aspect ratio.
   The hero template (`sections/hero.html`) picks the right variant per
   theme via `brand_logo_src(theme)`: original white SVG on dark themes,
   dark-fill variant on light themes. See `app/theme_meta.py`. */
.bc-hero__brandmark {
  display: block;
  height: 7mm;
  width: auto;
  margin: 0 0 4mm 0;
}

.bc-hero__product {
  font-size: var(--font-size-small);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin: 0 0 4mm 0;
  font-weight: 600;
}

.bc-hero__tagline {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: var(--font-size-hero);
  color: var(--color-brand-primary);
  margin: 0;
  line-height: 1.05;
  letter-spacing: -0.015em;
}

.bc-hero__subline {
  margin: 4mm 0 0 0;
  color: var(--color-text-muted);
  font-size: 11pt;
  max-width: 90%;
  line-height: 1.4;
}

/* ── STAT TILES ─────────────────────────────────────────────────────────── */

.bc-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3mm;
}

.bc-stat {
  position: relative;
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-tile);
  padding: 5mm 4mm 4mm 4mm;
  overflow: hidden;
}

.bc-stat::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-brand-primary);
}

.bc-stat__value {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: 24pt;
  line-height: 1;
  color: var(--color-brand-primary);
  letter-spacing: -0.02em;
}

.bc-stat__label {
  margin-top: 3mm;
  font-size: var(--font-size-small);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  line-height: 1.3;
}

/* ── SECTIONS (shared) ──────────────────────────────────────────────────── */

/* Page-break hints (`break-inside: avoid`, `break-after: avoid`) are
   intentionally absent everywhere below. With explicit `.bc-page`
   containers, WeasyPrint never breaks inside a section anyway. */
.bc-section {
  /* No-op selector kept for HTML-template clarity. */
}

.bc-section__heading {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: var(--font-size-h2);
  color: var(--color-text-primary);
  margin: 0 0 4mm 0;
  letter-spacing: -0.01em;
  /* Inline-block layout (not flex) so the badge sits inline with the heading
     and doesn't force the title to wrap onto a second line in WeasyPrint. */
  line-height: 1.2;
}

.bc-section__heading::before {
  content: attr(data-num);
  font-size: 10pt;
  color: var(--color-brand-accent);
  font-weight: 600;
  letter-spacing: 0.08em;
  font-family: var(--font-family-body);
  margin-right: 3mm;
  vertical-align: 1mm;
}

/* ── PROBLEM ────────────────────────────────────────────────────────────── */

.bc-problem__headline {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: 13pt;
  margin: 0 0 3mm 0;
  color: var(--color-text-primary);
  line-height: 1.3;
}

.bc-problem__body {
  margin: 0;
  color: var(--color-text-muted);
  line-height: 1.55;
  max-width: 95%;
}

/* ── CAPABILITIES ───────────────────────────────────────────────────────── */

.bc-caps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3mm;
}

.bc-cap {
  position: relative;
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: 4mm;
  display: flex;
  flex-direction: column;
  gap: 2mm;
}

.bc-cap__num {
  position: absolute;
  top: 3mm;
  right: 4mm;
  font-size: 9pt;
  color: var(--color-text-muted);
  font-weight: 500;
  letter-spacing: 0.06em;
  font-family: var(--font-family-body);
}

.bc-cap__icon {
  width: 10mm;
  height: 10mm;
  /* SVG-img-based icons (see capabilities.html). Flex-centring the
     `<img>` child works perfectly in WeasyPrint — none of the
     font-baseline gymnastics the previous emoji-as-glyph approach
     required. */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-muted);
  border-radius: 50%;
  margin-bottom: 1mm;
  box-sizing: border-box;
}

.bc-cap__icon img {
  width: 6mm;
  height: 6mm;
  display: block;
}

.bc-cap__title {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: 11.5pt;
  margin: 0;
  color: var(--color-text-primary);
  line-height: 1.25;
}

.bc-cap__body {
  margin: 0;
  font-size: 9pt;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ── WITH / WITHOUT ─────────────────────────────────────────────────────── */

.bc-ww {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 9.5pt;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  /* Tables never split across pages now (the table lives entirely on
     page 2), so we can clip the rounded corners on screen safely. */
  overflow: hidden;
}

.bc-ww th,
.bc-ww td {
  text-align: left;
  padding: 2.5mm 4mm;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.bc-ww tr:last-child th,
.bc-ww tr:last-child td {
  border-bottom: 0;
}

.bc-ww th {
  background: var(--color-surface-muted);
  font-family: var(--font-family-heading);
  font-weight: 600;
  font-size: 9pt;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

.bc-ww__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4mm;
  height: 4mm;
  margin-right: 2mm;
  vertical-align: -0.5mm;
  border-radius: 50%;
  font-size: 7pt;
  font-weight: 700;
}

.bc-ww__icon--no {
  background: rgba(244, 63, 94, 0.12);
  color: var(--color-negative);
}

.bc-ww__icon--yes {
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-positive);
}

.bc-ww__without {
  color: var(--color-text-primary);
}

.bc-ww__with {
  color: var(--color-text-primary);
  font-weight: 500;
}

/* ── FAQ (PULL QUOTES) ──────────────────────────────────────────────────── */

.bc-faq {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3mm;
}

.bc-faq__item {
  position: relative;
  padding: 4mm;
  border-left: 3px solid var(--color-brand-accent);
  background: var(--color-surface-card);
}

.bc-faq__objection {
  font-family: var(--font-family-heading);
  font-weight: 600;
  font-size: 10pt;
  margin: 0 0 2mm 0;
  color: var(--color-text-primary);
  line-height: 1.35;
}

.bc-faq__response {
  margin: 0;
  font-size: 9pt;
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ── ROADMAP (TIMELINE) ─────────────────────────────────────────────────── */

.bc-roadmap {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3mm;
  position: relative;
}

.bc-phase {
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: 4mm;
  display: flex;
  flex-direction: column;
  gap: 2mm;
  position: relative;
}

.bc-phase__week {
  display: inline-flex;
  align-items: center;
  gap: 2mm;
  font-size: var(--font-size-small);
  color: var(--color-brand-primary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.bc-phase__week::before {
  content: "";
  display: inline-block;
  width: 2mm;
  height: 2mm;
  border-radius: 50%;
  background: var(--color-brand-primary);
  flex-shrink: 0;
}

.bc-phase__title {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: 11.5pt;
  margin: 0;
  color: var(--color-text-primary);
  line-height: 1.25;
}

.bc-phase__deliverables {
  margin: 1mm 0 0 0;
  padding: 0;
  list-style: none;
  font-size: 9pt;
  color: var(--color-text-muted);
}

.bc-phase__deliverables li {
  position: relative;
  padding-left: 4mm;
  margin-bottom: 1mm;
  line-height: 1.45;
}

.bc-phase__deliverables li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.6mm;
  width: 2mm;
  height: 0.5mm;
  background: var(--color-brand-accent);
  opacity: 0.7;
}

/* ── CTA ────────────────────────────────────────────────────────────────── */

.bc-cta {
  padding: 6mm 7mm;
  background: var(--color-brand-primary);
  color: var(--color-text-on-brand);
  border-radius: var(--radius-card);
  /* Flex layout with EXPLICIT flex factors. Earlier iterations used
     `justify-content: space-between` (children stacked when WeasyPrint
     misjudged child widths), `display: grid` (`::before` overlay
     misplaced grid tracks so columns reversed), and `display: table`
     with `width: 1%` on the buttons cell (table didn't fill 100% width
     so the right button got clipped). The reliable pattern is:
     `flex: 1 1 0` on the heading container so it absorbs all remaining
     space, and `flex: 0 0 auto` on the buttons so they take exactly
     their content width. */
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5mm;
  /* Explicit `width: 100%` because WeasyPrint's flex implementation
     doesn't always treat a block-level flex container as filling its
     containing block — without this, the CTA box shrinks to fit content
     and clips the secondary button on the right. */
  width: 100%;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

.bc-cta > div:first-child {
  flex: 1 1 0;
  min-width: 0;
}

.bc-cta::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 90% 50%, rgba(255, 255, 255, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 10% 100%, rgba(255, 255, 255, 0.06) 0%, transparent 60%);
  pointer-events: none;
}

.bc-cta__heading {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-heading);
  font-size: 14pt;
  letter-spacing: -0.01em;
  margin: 0;
  position: relative;
  line-height: 1.15;
}

.bc-cta__sub {
  margin: 1.5mm 0 0 0;
  font-size: var(--font-size-small);
  opacity: 0.8;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
}

.bc-cta__buttons {
  flex: 0 0 auto;
  white-space: nowrap;
  text-align: right;
  position: relative;
}

.bc-cta__buttons > .bc-cta__btn + .bc-cta__btn {
  margin-left: 2mm;
}

.bc-cta__btn {
  padding: 2.2mm 4mm;
  border-radius: var(--radius-tile);
  font-family: var(--font-family-heading);
  font-weight: 600;
  font-size: 9.5pt;
  text-decoration: none;
  /* `inline-block` (not `inline-flex`) is more predictable in
     WeasyPrint inline contexts and avoids any flex-line-box behavior
     that could push the button beyond its computed inline width. */
  display: inline-block;
  transition: opacity 120ms;
}

.bc-cta__btn--primary {
  background: var(--color-text-on-brand);
  color: var(--color-brand-primary);
}

.bc-cta__btn--secondary {
  background: transparent;
  color: var(--color-text-on-brand);
  border: 1px solid var(--color-text-on-brand);
  opacity: 0.85;
}
