/* ============================================================
   Truely — bespoke PDF report ("UK Postcode Intelligence Report")
   A purpose-built magazine layout, NOT the web page printed.
   Rendered into #pdf-doc by report-pdf.js, shown only in print
   (or in the /_pdfpreview harness). Matches the approved mockup.
   Units: mm for print fidelity. A4 = 210 x 297mm.
   ============================================================ */

:root {
  --pdf-paper:   #F7F4ED;
  --pdf-card:    #FBF9F4;
  --pdf-ink:     #1F1B16;
  --pdf-soft:    #6B6259;
  --pdf-faint:   #9B8E7F;
  --pdf-accent:  #D8492A;
  --pdf-accent2: #C8674A;
  --pdf-rule:    #E4DCCE;
  --pdf-green:   #2E8B57;
  --pdf-amber:   #C4923D;
  --pdf-red:     #B53A2A;
  --pdf-blue:    #3d6db5;
  --pdf-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --pdf-disp: "Fraunces", Georgia, "Times New Roman", serif;
}

/* ---- preview harness: render #pdf-doc on screen as stacked A4 pages ---- */
.pdf-preview body { background: #d8d2c6; margin: 0; }
#pdf-doc { font-family: var(--pdf-sans); color: var(--pdf-ink); display: none; }
.pdf-preview #pdf-doc { display: block; }
.pdf-preview .pdf-page {
  width: 210mm; min-height: 297mm; margin: 0 auto 10mm; background: var(--pdf-paper);
  box-shadow: 0 2mm 8mm rgba(0,0,0,0.18);
}

/* ---- the page box ---- */
.pdf-page {
  position: relative;
  box-sizing: border-box;
  padding: 13mm 13mm 14mm;
  background: var(--pdf-paper);
  overflow: hidden;
}

/* =========================== COVER HEADER =========================== */
.pdf-coverhead { position: relative; }
.pdf-ch-top { display: flex; align-items: center; gap: 8px; margin: 0 0 9mm; }
.pdf-logo { font-family: var(--pdf-disp); font-size: 19pt; font-weight: 600; letter-spacing: -0.01em; }
.pdf-logo em { color: var(--pdf-accent); font-style: normal; }
.pdf-logo-uk {
  font-family: var(--pdf-sans); font-size: 7.5pt; font-weight: 700; letter-spacing: 0.12em;
  color: var(--pdf-accent); border: 1px solid var(--pdf-accent); border-radius: 4px;
  padding: 1px 5px; margin-left: 4px; text-transform: uppercase;
}

/* two-column: title block left, contents box right */
.pdf-ch-grid { display: grid; grid-template-columns: 1fr 62mm; gap: 10mm; align-items: start; }
.pdf-ch-title {
  font-family: var(--pdf-disp); font-weight: 600; font-size: 27pt; line-height: 1.02;
  letter-spacing: -0.015em; margin: 0; color: var(--pdf-ink);
}
.pdf-ch-powered {
  font-family: var(--pdf-sans); font-size: 8pt; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--pdf-soft); margin: 3mm 0 0;
}
.pdf-ch-powered b { color: var(--pdf-ink); }
.pdf-ch-powered b em { color: var(--pdf-accent); font-style: normal; }
.pdf-ch-intro { font-size: 9pt; line-height: 1.5; color: var(--pdf-soft); margin: 3.5mm 0 0; max-width: 105mm; }

.pdf-ch-pin { display: flex; align-items: center; gap: 9px; margin: 4.5mm 0 0; }
.pdf-ch-pin-ic {
  width: 11mm; height: 11mm; border-radius: 9px; background: rgba(216,73,42,0.10);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.pdf-ch-pin-pc { font-family: var(--pdf-disp); font-size: 18pt; font-weight: 600; line-height: 1.05; }
.pdf-ch-pin-place { font-size: 9.5pt; color: var(--pdf-soft); margin-top: 1mm; }

/* Big Ben illustration sits behind / beside the contents column */
.pdf-ch-illo { position: absolute; top: 2mm; right: 57mm; width: 44mm; opacity: 0.9; pointer-events: none; }
.pdf-ch-illo svg { width: 100%; height: auto; display: block; }

/* contents box */
.pdf-contents { border: 1px solid var(--pdf-rule); border-radius: 10px; padding: 6mm 6mm 5mm; background: var(--pdf-card); }
.pdf-contents-h { font-family: var(--pdf-sans); font-size: 8pt; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--pdf-soft); margin: 0 0 4mm; }
.pdf-contents-row { display: flex; justify-content: space-between; align-items: baseline; padding: 1.7mm 0; border-bottom: 1px solid var(--pdf-rule); font-size: 9.5pt; }
.pdf-contents-row:last-child { border-bottom: 0; }
.pdf-contents-row .n { font-family: var(--pdf-sans); font-size: 8.5pt; font-weight: 700; color: var(--pdf-faint); }

/* metadata strip */
.pdf-ch-meta { display: grid; grid-template-columns: auto auto 1fr auto; gap: 9mm; align-items: start;
  margin: 5mm 0 0; padding: 3.5mm 0 0; border-top: 1px solid var(--pdf-rule); }
.pdf-meta-k { font-family: var(--pdf-sans); font-size: 7pt; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--pdf-faint); display: flex; align-items: center; gap: 5px; }
.pdf-meta-v { font-size: 9.5pt; color: var(--pdf-ink); margin-top: 1.5mm; }
.pdf-meta-note { font-size: 8.5pt; color: var(--pdf-soft); line-height: 1.4; }

/* =========================== SECTION CARDS =========================== */
.pdf-body { margin: 6mm 0 0; column-gap: 6mm; }
.pdf-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 5mm; align-items: start; }
/* grid children must be allowed to shrink below content width, else tables
   overflow the column and clip past the page edge */
.pdf-cols > * { min-width: 0; }
.pdf-card {
  border: 1px solid var(--pdf-rule); border-radius: 10px; background: var(--pdf-card);
  padding: 4mm 4.5mm; break-inside: avoid;
}
.pdf-card + .pdf-card { margin-top: 5mm; }
.pdf-card-head { display: flex; align-items: baseline; gap: 7px; margin: 0 0 3mm; flex-wrap: wrap; }
.pdf-card-rn { font-family: var(--pdf-disp); font-size: 10pt; font-weight: 600; color: var(--pdf-faint); }
.pdf-card-title { font-family: var(--pdf-disp); font-size: 13.5pt; font-weight: 600; color: var(--pdf-ink); margin: 0; letter-spacing: -0.01em; }
.pdf-badge { font-family: var(--pdf-sans); font-size: 7pt; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 1.5px 7px; border-radius: 999px; margin-left: auto; }
.pdf-badge-good { background: rgba(46,139,87,0.12); color: var(--pdf-green); }
.pdf-badge-mid  { background: rgba(196,146,61,0.14); color: var(--pdf-amber); }
.pdf-badge-bad  { background: rgba(181,58,42,0.12); color: var(--pdf-red); }
.pdf-card-lead { font-size: 9.5pt; line-height: 1.5; color: var(--pdf-ink); margin: 0 0 3mm; }
.pdf-card-note { font-size: 8pt; line-height: 1.45; color: var(--pdf-soft); margin: 3mm 0 0; }
.pdf-src { font-size: 7.5pt; color: var(--pdf-faint); margin-top: 2mm; }

/* exec-summary stat tiles */
.pdf-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 3mm; }
.pdf-stat { border: 1px solid var(--pdf-rule); border-radius: 8px; padding: 3.5mm 4mm; background: var(--pdf-paper); }
.pdf-stat-k { font-size: 7.5pt; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--pdf-soft); }
.pdf-stat-v { font-family: var(--pdf-disp); font-size: 16pt; font-weight: 600; color: var(--pdf-ink); margin: 1mm 0 0.5mm; line-height: 1.05; }
.pdf-stat-s { font-size: 7.5pt; color: var(--pdf-soft); line-height: 1.3; }

/* key/value rows (transport, healthcare) */
.pdf-kv { width: 100%; border-collapse: collapse; table-layout: fixed; }
.pdf-kv td { font-size: 8.5pt; padding: 1.6mm 0; border-bottom: 1px solid var(--pdf-rule); vertical-align: top; overflow-wrap: break-word; word-break: normal; }
/* the name cell must never collapse to 1 char in a narrow nested column */
.pdf-kv td.b { min-width: 18mm; }
.pdf-kv tr:last-child td { border-bottom: 0; }
.pdf-kv .r { text-align: right; color: var(--pdf-soft); width: 38%; }
.pdf-kv .b { font-weight: 600; }
/* 3-column tables (transport: name/dist/time · health: name/value/rating):
   two value columns at 38% each leave the NAME only ~24% and force long names
   like "Birmingham Moor Street (Rail)" to break mid-word. Narrow the two value
   columns so the name column gets ~62% and word-wraps cleanly. */
.pdf-kv-3 .r { width: 19%; }
.pdf-kv-3 .b { min-width: 30mm; }

/* category bars (crime) */
.pdf-bars { margin: 1mm 0 0; }
.pdf-bar-row { display: grid; grid-template-columns: 32mm 1fr auto; gap: 4px; align-items: center; padding: 1.1mm 0; font-size: 8.5pt; }
.pdf-bar-track { height: 4mm; background: var(--pdf-rule); border-radius: 3px; overflow: hidden; }
.pdf-bar-fill { height: 100%; background: var(--pdf-accent); border-radius: 3px; }
.pdf-bar-n { font-weight: 600; font-size: 8.5pt; min-width: 8mm; text-align: right; }

/* mini stat strip (transport/healthcare summary) */
.pdf-mini { display: grid; grid-template-columns: 1fr auto; gap: 2px; font-size: 9pt; padding: 1.6mm 0; border-bottom: 1px solid var(--pdf-rule); }
.pdf-mini:last-child { border-bottom: 0; }
.pdf-mini b { font-weight: 600; }

/* data table (air quality, connectivity) */
.pdf-table { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
.pdf-table th { text-align: left; font-size: 7pt; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--pdf-faint); padding: 1.5mm 2mm 1.5mm 0; border-bottom: 1px solid var(--pdf-rule); }
.pdf-table th.r, .pdf-table td.r { text-align: right; }
.pdf-table td { padding: 1.8mm 2mm 1.8mm 0; border-bottom: 1px solid var(--pdf-rule); }
.pdf-table tr:last-child td { border-bottom: 0; }
.pdf-table .pos { color: var(--pdf-green); font-weight: 600; }

/* split rows (flood) */
.pdf-split { display: grid; grid-template-columns: 1fr 1fr; gap: 5mm; }
.pdf-split h4 { font-size: 8.5pt; font-weight: 700; margin: 0 0 1mm; color: var(--pdf-soft); }
.pdf-split .v { font-family: var(--pdf-disp); font-size: 12pt; color: var(--pdf-green); }
.pdf-split .vlow { color: var(--pdf-green); }

/* charts */
.pdf-chart { margin: 2mm 0; }
.pdf-chart svg { width: 100%; height: auto; display: block; }
.pdf-chart-cap { font-size: 8pt; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--pdf-soft); margin: 0 0 1.5mm; }

/* page footer */
.pdf-foot { position: absolute; left: 13mm; right: 13mm; bottom: 6mm; display: flex; justify-content: space-between; align-items: center;
  font-size: 8pt; color: var(--pdf-faint); border-top: 1px solid var(--pdf-rule); padding-top: 3mm; }
.pdf-foot .logo { font-family: var(--pdf-disp); font-weight: 600; color: var(--pdf-ink); }

/* =========================== PRINT =========================== */
/* CRITICAL: these rules are GATED on body.pdf-magazine, NOT body.printing.
   postcode.js's existing Build-PDF handler adds body.printing for the
   default web-page-printed PDF. Only the new magazine-engine opt-in
   handler in postcode-inline.js adds body.pdf-magazine. Without this
   class separation, this stylesheet hides the entire report on EVERY
   print (because #pdf-doc is empty by default) and produces a blank
   PDF — exactly the regression hit on 2026-05-28. Never key these on
   body.printing. */
@media print {
  body.pdf-magazine { background: #fff; }
  body.pdf-magazine > *:not(#pdf-doc) { display: none !important; }
  body.pdf-magazine #pdf-doc { display: block !important; }
  body.pdf-magazine .pdf-page { margin: 0; box-shadow: none; page-break-after: always; }
  body.pdf-magazine .pdf-page:last-child { page-break-after: auto; }
}

/* =================================================================
   7-PAGE INTELLIGENCE REPORT TEMPLATE (institutional)
   Dark page-header bars + dense panel grids. Compresses 26-32
   sections into 7 high-signal pages.
   ================================================================= */
.pdf-page { display: flex; flex-direction: column; }
/* dark full-bleed page header bar */
.pdf-phead {
  background: #26231E; color: #FBF9F4; margin: -13mm -13mm 6mm; padding: 4mm 13mm;
  display: flex; align-items: baseline; gap: 6mm;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.pdf-phead-n { font-family: var(--pdf-sans); font-size: 7.5pt; font-weight: 700; letter-spacing: 0.14em; color: #C8B9A6; text-transform: uppercase; }
.pdf-phead-t { font-family: var(--pdf-disp); font-size: 14pt; font-weight: 600; letter-spacing: 0.01em; text-transform: uppercase; }
/* page footer */
.pdf-pfoot { margin-top: auto; padding-top: 5mm; border-top: 1px solid var(--pdf-rule); display: flex; justify-content: space-between; align-items: center; font-size: 7.5pt; color: var(--pdf-faint); }
.pdf-pfoot .logo { font-family: var(--pdf-disp); font-weight: 600; color: var(--pdf-soft); }
.pdf-pfoot .logo em { color: var(--pdf-accent); font-style: normal; }
.pdf-purpose { margin-top: 4mm; font-size: 7.5pt; font-style: italic; color: var(--pdf-faint); }
.pdf-section-rule { font-family: var(--pdf-sans); font-size: 8pt; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--pdf-soft); border-top: 1px solid var(--pdf-rule); padding-top: 3mm; margin: 6mm 0 3mm; }

/* tone helpers */
.pdf-tone-good { color: var(--pdf-green); }
.pdf-tone-bad  { color: var(--pdf-red); }
.pdf-tone-mid  { color: var(--pdf-amber); }

/* generic column grids */
/* auto-fit so skipped/empty tiles never leave gaps — populated tiles fill the row */
.pdf-cols-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(50mm, 1fr)); gap: 5mm; }
.pdf-cols-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(40mm, 1fr)); gap: 5mm; }

/* PAGE 1 — executive */
.pdf-p1-top { display: flex; justify-content: space-between; align-items: flex-start; }
.pdf-p1-id .pdf-ch-top { margin: 0 0 3mm; }
.pdf-p1-pc { font-family: var(--pdf-disp); font-weight: 600; font-size: 30pt; line-height: 1; margin: 0; letter-spacing: -0.01em; }
.pdf-p1-place { font-family: var(--pdf-disp); font-size: 12pt; color: var(--pdf-soft); margin-top: 1.5mm; }
.pdf-p1-date { font-size: 8pt; color: var(--pdf-faint); margin-top: 1.5mm; }
.pdf-p1-actions { font-size: 8pt; color: var(--pdf-soft); border: 1px solid var(--pdf-rule); border-radius: 6px; padding: 2mm 4mm; white-space: nowrap; }
.pdf-p1-grade { display: flex; gap: 6mm; align-items: center; margin-top: 6mm; padding: 5mm; background: var(--pdf-card); border: 1px solid var(--pdf-rule); border-radius: 3mm; }
.pdf-grade-circle { flex: 0 0 26mm; width: 26mm; height: 26mm; border: 2px solid currentColor; border-radius: 2.5mm; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pdf-grade-l { font-family: var(--pdf-disp); font-weight: 700; font-size: 30pt; line-height: 1; }
.pdf-grade-s { font-size: 7.5pt; color: var(--pdf-soft); margin-top: 1mm; }
.pdf-grade-cap { font-size: 8pt; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--pdf-faint); margin-bottom: 1.5mm; }
.pdf-p1-summary { font-size: 9.5pt; line-height: 1.5; color: var(--pdf-ink); margin: 0; }
/* at a glance row */
.pdf-gl-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4mm; }
.pdf-gl { border: 1px solid var(--pdf-rule); border-radius: 2.5mm; padding: 3mm; background: var(--pdf-card); }
.pdf-gl-ic { width: 5mm; height: 5mm; color: var(--pdf-accent); margin-bottom: 1.5mm; }
.pdf-gl-ic svg { width: 100%; height: 100%; }
.pdf-gl-k { font-size: 7pt; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--pdf-faint); }
.pdf-gl-v { font-family: var(--pdf-disp); font-size: 13pt; font-weight: 600; margin: 0.5mm 0; }
.pdf-gl-s { font-size: 7pt; color: var(--pdf-soft); line-height: 1.25; }
/* page-1 three columns: strengths / concerns / value */
.pdf-p1-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5mm; margin-top: 5mm; }
.pdf-list { border: 1px solid var(--pdf-rule); border-radius: 2.5mm; padding: 4mm; background: var(--pdf-card); }
.pdf-list-h { font-size: 8pt; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--pdf-soft); margin-bottom: 2.5mm; }
.pdf-list-row { display: flex; align-items: flex-start; gap: 2mm; font-size: 8.5pt; line-height: 1.4; margin-bottom: 1.5mm; }
.pdf-list-mk { flex: 0 0 4px; width: 4px; height: 4px; border-radius: 50%; margin-top: 4px; background: var(--pdf-soft); }
.pdf-list-good .pdf-list-mk, .pdf-list-mk.good { background: var(--pdf-green); }
.pdf-list-bad .pdf-list-mk { background: var(--pdf-red); }
.pdf-val-big { font-family: var(--pdf-disp); font-weight: 600; font-size: 17pt; }
.pdf-val-range { font-family: var(--pdf-disp); font-size: 11pt; margin-top: 2mm; }
.pdf-val-sub { font-size: 7.5pt; color: var(--pdf-soft); margin-bottom: 1mm; }

/* KPI block + /10 score block */
.pdf-kpi, .pdf-s10, .pdf-panel { border: 1px solid var(--pdf-rule); border-radius: 2.5mm; padding: 3.5mm; background: var(--pdf-card); }
.pdf-kpi-k, .pdf-s10-k, .pdf-panel-h { font-size: 7.5pt; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--pdf-faint); }
.pdf-kpi-v { font-family: var(--pdf-disp); font-weight: 600; font-size: 18pt; line-height: 1.1; margin: 1mm 0; }
.pdf-kpi-v.sm { font-size: 12pt; }
.pdf-kpi-v span { font-size: 10pt; color: var(--pdf-faint); }
.pdf-kpi-s { font-size: 7.5pt; color: var(--pdf-soft); line-height: 1.3; }
.pdf-s10-v { font-family: var(--pdf-disp); font-weight: 600; font-size: 20pt; line-height: 1.1; margin: 1mm 0; }
.pdf-s10-v span { font-size: 10pt; color: var(--pdf-faint); }
.pdf-s10-s { font-size: 7.5pt; color: var(--pdf-soft); }
.pdf-panel-h { margin-bottom: 2mm; }

.pdf-minikv { border-left: 2px solid var(--pdf-rule); padding-left: 2.5mm; }
.pdf-minikv-k { font-size: 7pt; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--pdf-faint); }
.pdf-minikv-v { font-family: var(--pdf-disp); font-size: 11pt; margin-top: 0.5mm; }

.pdf-note-strip { font-size: 8pt; color: var(--pdf-soft); background: var(--pdf-card); border: 1px solid var(--pdf-rule); border-radius: 2mm; padding: 3mm; margin: 4mm 0; font-style: italic; }
.pdf-empty { font-size: 8pt; color: var(--pdf-faint); font-style: italic; padding: 3mm 0; }
.pdf-chart-empty { border: 1px dashed var(--pdf-rule); border-radius: 2mm; padding: 3mm; }

/* ALL SECTIONS grid */
.pdf-allsec { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm 6mm; }
.pdf-allsec-h { font-size: 8pt; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--pdf-accent); margin-bottom: 1.5mm; }
.pdf-allsec-row { font-size: 8pt; color: var(--pdf-soft); padding: 0.8mm 0; border-bottom: 1px solid var(--pdf-rule); }

/* full-bleed pages + FORCE backgrounds to print (the report's own @media print
   strips non-important backgrounds; without these the dark header bars + cream
   cards render white). print-color-adjust:exact + !important fills win. */
@page { size: A4; margin: 0; }
#pdf-doc, #pdf-doc * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
#pdf-doc .pdf-phead { background: #26231E !important; }
#pdf-doc .pdf-card, #pdf-doc .pdf-kpi, #pdf-doc .pdf-s10, #pdf-doc .pdf-panel, #pdf-doc .pdf-list, #pdf-doc .pdf-gl, #pdf-doc .pdf-p1-grade, #pdf-doc .pdf-note-strip { background: #FBF9F4 !important; }
#pdf-doc .pdf-page { background: #F7F4ED !important; }
/* nearest-stations: single-line list (name left, dist·time right) — never a
   cramped 3-col table that breaks per-character in a narrow panel */
.pdf-stn { display: flex; justify-content: space-between; align-items: baseline; gap: 3mm; padding: 1.5mm 0; border-bottom: 1px solid var(--pdf-rule); font-size: 8pt; }
.pdf-stn:last-child { border-bottom: 0; }
.pdf-stn-n { min-width: 0; overflow-wrap: break-word; }
.pdf-stn-m { flex: 0 0 auto; white-space: nowrap; color: var(--pdf-soft); font-size: 7.5pt; }
