/* ============================================================
   cma-print.css — CMA Module Phase 11: Print-Safe PDF Export
   Stanley Martin Atlanta Division Sales Tracker
   ============================================================
   Load with: <link rel="stylesheet" href="css/cma-print.css" media="print">
   This file is MEDIA=PRINT ONLY. It never affects screen rendering.
   Do NOT add any screen rules here.

   Print-safe rule (per Stanley Martin/_shared/style-guides/print-safe-pdf-guidelines.md):
     • @page margin: 0.25in (safe zone on all sides for home/office printers)
     • Design canvas: 8in × 10.5in inside 8.5in × 11in letter sheet
     • Critical content (footer, header, data) must NOT fall within the 0.25in crop zone
     • Decorative color bands may extend to canvas edge (0.25in from physical paper edge)
   ============================================================ */


/* ── PAGE SETUP ─────────────────────────────────────────────── */

@page {
  size: letter;       /* 8.5in × 11in */
  margin: 0.25in;     /* 0.25in safe zone all sides — home printers cannot print closer */
}


/* ── BASE RESET FOR PRINT ───────────────────────────────────── */

/* Force background colors and fills to print — browser default is to strip them */
*,
*::before,
*::after {
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* Remove browser-default body margin — @page margin handles safe zone */
body {
  margin: 0 !important;
  padding: 0 !important;
  background: #ffffff !important;
  color: #0f1b20 !important;  /* --ink-900 */
  font-size: 11pt !important;
  line-height: 1.4 !important;
}


/* ── HIDE APP SHELL (non-CMA chrome) ────────────────────────── */

/* Top navigation bar */
.topnav,
#nav-st-links,
#modules-nav,
#st-mobile-nav,
.topnav-right,
.topnav-avatar-wrap,
#nav-user-email {
  display: none !important;
}

/* Modules dropdown and menu */
.modules-button,
.modules-menu,
#modules-menu {
  display: none !important;
}

/* Toast notification */
#toast {
  display: none !important;
}

/* Module selector / community selector screens */
#module-selector,
#community-selector-screen {
  display: none !important;
}

/* All other top-level module containers */
#module-st-content,
#module-bm-content,
#module-competition-content {
  display: none !important;
}


/* ── HIDE CMA-SPECIFIC UI (not needed in PDF) ───────────────── */

/* CMA subnav (Current / Inputs tabs) */
.cma-subnav,
#cma-subnav {
  display: none !important;
}

/* Approach picker pills (Scoreboard / Position Map / Timeline / Heatmap / Tables) */
.cma-approach-picker,
#cma-approach-picker {
  display: none !important;
}

/* View-mode toggle (Current / Trend) */
.cma-mode-toggle,
#cma-mode-toggle {
  display: none !important;
}

/* All button elements inside the CMA shell — includes "← Modules", refresh, etc.
   Exception: .cma-print-footer buttons are already excluded by the footer rule.
   The Export PDF button itself is never rendered in print context. */
.cma-shell .btn,
.cma-shell button {
  display: none !important;
}

/* Comp toggle chips / filter row */
.cma-comp-chips,
.cma-filter-row {
  display: none !important;
}

/* Window period pills inside trend view */
.cma-window-pills {
  display: none !important;
}

/* Resize handles (position map drag crosshair handles) */
.cma-position-map-crosshair-handle {
  display: none !important;
}

/* Modal overlays and dialogs */
.modal-overlay,
dialog,
.cma-drilldown-overlay,
#bm-modal-root {
  display: none !important;
}

/* Skeleton shimmer loading state — should not appear in print but guard anyway */
.cma-skeleton-table,
.cma-skeleton-row,
.cma-skeleton-line {
  display: none !important;
}

/* Empty-state block — user should not print an empty CMA */
.cma-empty-state {
  display: none !important;
}

/* Mobile compact view — never printed (print is always desktop layout) */
.cma-mobile-compact {
  display: none !important;
}

/* Star-rating input widgets (inputs view) */
.cma-star-rating {
  display: none !important;
}

/* Any alert/info banners that are transient UI state */
.alert.alert-info,
.alert.alert-danger {
  display: none !important;
}


/* ── CMA PAGE HEADER: retain community name, strip action buttons ── */

.cma-page-header {
  display: flex !important;
  align-items: flex-start !important;
  padding: 0 0 8pt 0 !important;
  border-bottom: 1.5pt solid #1e4d60 !important; /* --sm-dark-blue */
  margin-bottom: 8pt !important;
}

.cma-page-header .page-header-title {
  font-size: 14pt !important;
  font-weight: 700 !important;
  color: #1e4d60 !important;
}

.cma-page-header .page-header-subtitle {
  font-size: 9pt !important;
  color: #6a7c83 !important; /* --ink-500 */
  margin-top: 1pt !important;
}

/* The right-side button group (← Modules, etc.) — hidden via .btn rule above */
.cma-page-header > div:last-child {
  display: none !important;
}


/* ── CMA PRINT CANVAS ───────────────────────────────────────── */
/* The active CMA approach content area.
   With @page margin: 0.25in, the printable area is already 8in × 10.5in.
   We constrain the canvas to 8in max-width and let it flow naturally.
   No transform-scale: content is structured (tables/SVGs) and scales poorly;
   instead we let the content flow to multiple pages if needed, with page-break
   discipline on rows and SVG blocks.
   Decision: natural flow (no scaling) — keeps text sharp and readable.
             If a chart SVG overflows 8in width, the @page clip handles it cleanly.
             Complex multi-approach charts that exceed one page are expected to paginate. */

.cma-shell {
  width: 8in !important;
  max-width: 8in !important;
  margin: 0 !important;
  padding: 0 !important;
  background: #ffffff !important;
  box-shadow: none !important;
}

#cma-content-area {
  overflow: visible !important;
  height: auto !important;
  max-height: none !important;
  padding-bottom: 0.65in !important; /* I6: prevent last-page content bleeding under fixed 0.5in footer */
}


/* ── INK SAVINGS: SHADOWS, ELEVATIONS, BORDERS ─────────────── */

/* Remove all box-shadows — they don't translate well and waste ink */
* {
  box-shadow: none !important;
}

/* Reduce border-radius extremes — rounded cards with no shadow look odd in print */
.card,
.cma-scoreboard-card,
.cma-position-map-wrap,
.cma-timeline-wrap,
.cma-heatmap-wrap {
  border-radius: 0 !important;
  border: 1pt solid #c3cfd4 !important; /* --ink-300 — subtle structure only */
}

/* Freshness pills: flatten for print */
.cma-fresh-pill,
.cma-fresh-dot {
  border-radius: 0 !important;
  font-size: 8pt !important;
}

/* Source badges */
.cma-source-badge {
  border-radius: 0 !important;
  font-size: 8pt !important;
}

/* Market pills */
.cma-market-pill {
  border-radius: 0 !important;
  font-size: 8pt !important;
}


/* ── TABLES ─────────────────────────────────────────────────── */

/* Prevent rows from splitting across page boundaries */
tr {
  page-break-inside: avoid !important;
}

/* Prevent thead from orphaning */
thead {
  display: table-header-group !important;
}

/* Table styling for print — collapse borders, use ink-friendly colors */
.data-table,
.cma-table,
.cma-scoreboard-table,
.cma-current-table {
  border-collapse: collapse !important;
  width: 100% !important;
  font-size: 9pt !important;
}

.data-table th,
.cma-table th,
.cma-scoreboard-table th,
.cma-current-table th {
  background: #e4ecf0 !important;  /* --sm-light-blue-soft — prints as light tint */
  color: #1e4d60 !important;
  font-size: 8pt !important;
  font-weight: 700 !important;
  padding: 4pt 6pt !important;
  border: 0.5pt solid #c3cfd4 !important;
}

.data-table td,
.cma-table td,
.cma-scoreboard-table td,
.cma-current-table td {
  padding: 3pt 6pt !important;
  border: 0.5pt solid #c3cfd4 !important;
  font-size: 9pt !important;
  color: #0f1b20 !important;
}

/* Light-gray alternating rows → slightly darker tint for ink contrast on white */
.data-table tr:nth-child(even) td,
.cma-table tr:nth-child(even) td {
  background: #f4f6f7 !important; /* --canvas */
}

/* Delta pills in scoreboard: keep color intent but flatten */
.cma-scoreboard-delta-up   { color: #16a34a !important; background: transparent !important; }
.cma-scoreboard-delta-down { color: #b42318 !important; background: transparent !important; }
.cma-scoreboard-delta-flat { color: #6a7c83 !important; background: transparent !important; }


/* ── CHART SVGs ─────────────────────────────────────────────── */

/* Prevent SVG chart blocks from splitting mid-chart across pages */
.cma-trend-cell,
.cma-timeline-sparkline-cell,
.cma-heatmap-svg-wrap,
.cma-position-map-svg-wrap,
svg {
  page-break-inside: avoid !important;
}

/* Cap SVG width to canvas — prevent overflow beyond 8in */
svg {
  max-width: 100% !important;
  height: auto !important;
}

/* Position Map: the bespoke SVG canvas — constrain for print */
.cma-position-map-chart {
  max-width: 7in !important;
}


/* ── APPROACH-SPECIFIC TWEAKS ───────────────────────────────── */

/* Scoreboard: ensure focus-mode panel doesn't show in print */
.cma-scoreboard-focus-panel {
  display: none !important;
}

/* Position Map: hide ghost-trail toggle + controls */
.cma-position-map-controls,
.cma-position-map-legend-wrap .btn {
  display: none !important;
}

/* Timeline: hide event-marker click overlays */
.cma-timeline-event-click-zone {
  display: none !important;
}

/* Heatmap: the calendar grid prints as-is — color intensity is preserved
   because print-color-adjust: exact is set globally above */


/* ── CMA PRINT FOOTER ───────────────────────────────────────── */
/*
   Decision: fixed-position bottom inside the canvas, not @page @bottom-center.
   Rationale: @page margin-box content is limited to counter()/string() — it can't
   access DOM values (community name, comp list, generated-by). Fixed-position
   achieves the same visual result: footer locks to bottom of every page, does not
   reflow into the main content column, and can contain dynamic text injected by
   pdfExport.js.
   The .cma-print-footer block is injected by pdfExport.js immediately before
   window.print() and removed in the afterprint handler.
*/

.cma-print-footer {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 0.5in !important;         /* lives in the bottom 0.5in of the printable area */
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 4pt 0 !important;
  border-top: 1pt solid #1e4d60 !important;
  background: #ffffff !important;   /* white — sits on top of content, not a bleed band */
  font-size: 7.5pt !important;
  color: #6a7c83 !important;        /* --ink-500 */
  font-family: 'Lato', Arial, sans-serif !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.cma-print-footer-left {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 1pt !important;
  overflow: hidden !important;
}

.cma-print-footer-center {
  flex: 1 !important;
  text-align: center !important;
}

.cma-print-footer-right {
  flex: 1 !important;
  text-align: right !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  gap: 1pt !important;
}

.cma-print-footer-community {
  font-weight: 700 !important;
  color: #1e4d60 !important;    /* --sm-dark-blue */
  font-size: 8pt !important;
}

.cma-print-footer-comps {
  font-size: 7pt !important;
  color: #6a7c83 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 2.5in !important;
}

.cma-print-footer-freshness {
  font-style: italic !important;
  font-size: 7pt !important;
}

/* Page-break utility: use on elements that should start on a new page */
.cma-print-page-break {
  page-break-before: always !important;
}


/* ── DEFEAT VIEWPORT-DEGRADATION ON PRINT ───────────────────── */
/* Letter paper at 96dpi = ~816px CSS pixels, which trips the screen-side
   `@media (max-width: 1024px)` and `@media (max-width: 899px)` blocks in
   cma.css that hide Position Map / Timeline / Heatmap charts and substitute
   a "Best on desktop" ::before notice. Restore them for print. */

/* Position Map — restore chart, hide notice */
.cma-position-map-chart-wrap {
  display: block !important;
}
.cma-position-map-svg {
  display: block !important;
}
.cma-position-map-legend {
  display: flex !important; /* I7: controls intentionally dropped — hidden by rule at line 345; legend is print-useful */
}
.cma-position-map-equation {
  display: block !important;
}
.cma-position-map-shell::before {
  content: none !important;
  display: none !important;
}

/* Timeline — restore grid, hide notice */
.cma-timeline-grid,
.cma-timeline-window-pills {
  display: flex !important;
}
.cma-timeline-shell::before {
  content: none !important;
  display: none !important;
}

/* Heatmap — restore svg + controls, hide notice */
.cma-heatmap-svg-wrap {
  display: block !important;
}
.cma-heatmap-controls {
  display: flex !important;
}
.cma-heatmap-shell::before {
  content: none !important;
  display: none !important;
}


/* =================================================================
   === CMA PRINT — PHASE 15 (landing redesign) ===
   Concept B landing layout: rail collapses below map at print.
   Append-only.
   Added: 2026-05-11.
   ================================================================= */

@media print {

  /* 1. Landing frame becomes single column */
  .cma-landing-frame {
    display: block !important;
    grid-template-columns: none !important;
    gap: 0 !important;
  }

  /* 2. Insight Rail stacks vertically below the map (2x2 ish, page-width permitting) */
  .cma-insight-rail {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: var(--sp-3) !important;
    margin-top: var(--sp-4) !important;
    overflow: visible !important;
  }

  .cma-rail-tile {
    flex: 1 1 calc(50% - var(--sp-3)) !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    min-width: 0 !important;
  }

  /* 3. Hide interactive-only chrome from print */
  .cma-rail-drilldowns {
    display: none !important;
  }

  .cma-approach-picker-row {
    display: none !important;
  }

  .cma-slide-over {
    display: none !important;
  }

  /* 4. Module-level freshness chip stays visible */
  .cma-module-freshness {
    display: inline-flex !important;
    color: var(--ink-700) !important;
  }

  /* 5. Headline sentence stays — but cap at 1 line */
  .cma-headline {
    font-size: var(--fs-sm) !important;
    margin-bottom: var(--sp-2) !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* 6. Page-break discipline */
  .cma-landing-main {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* =================================================================
     === CMA PRINT — PHASE 15.1 (polish pass) ===
     Hide rail controls row in print; chip block stays visible
     in monochrome-safe form.
     Append-only.
     Added: 2026-05-11.
     ================================================================= */

  .cma-rail-controls-row { display: none !important; }
  .cma-view-dropdown { display: none !important; }
  .cma-mode-toggle { display: none !important; }

  .cma-rail-comps {
    margin-top: var(--sp-4) !important;
    padding-top: var(--sp-3) !important;
    border-top: 1px solid var(--ink-300) !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  .cma-rail-comps__bulk-row { display: none !important; }
  .cma-rail-comps__grid {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: var(--sp-1) var(--sp-2) !important;
  }
  .cma-rail-chip {
    background: transparent !important;
    border: 1px solid var(--ink-700) !important;
    color: var(--ink-900) !important;
    font-size: var(--fs-xs) !important;
    font-weight: 600 !important;
    cursor: default !important;
  }
  .cma-rail-chip.is-visible {
    background: var(--ink-900) !important;
    border-color: var(--ink-900) !important;
    color: var(--surface) !important;
  }
  .cma-rail-chip__dot {
    background: var(--ink-500) !important;
  }
  .cma-rail-chip.is-visible .cma-rail-chip__dot { display: none !important; }

}
