/* ──────────────────────────────────────────────────────────────────────────
   Nest IQ — Executive Print Report Stylesheet
   Activated by:  body.is-printing  +  @media print
   Goal:          crisp vector PDF (no rasterization), no chart clipping,
                  preserved Tabler pastel tones, page-break safety.
   ──────────────────────────────────────────────────────────────────────── */

/* On-screen, the cover header stays hidden — Bootstrap's d-print-block does
   that for free, this keeps things tidy if someone removes the class. */
#nestiq-print-cover { display: none; }

@media print {

	/* ── Color fidelity for badges, progress bars, sparkline fills ──────── */
	*,
	*::before,
	*::after {
		-webkit-print-color-adjust: exact !important;
		print-color-adjust: exact !important;
	}

	/* ── Paper geometry ─────────────────────────────────────────────────── */
	@page {
		size: A4;
		margin: 12mm 10mm;
	}

	html, body {
		background: #ffffff !important;
		color: #1d2433 !important;
		font-size: 11pt;
	}

	/* ── Strip the application chrome ───────────────────────────────────── */
	aside.navbar-vertical,
	header.navbar,
	.navbar-vertical,
	footer.footer,
	.footer,
	#btn-create-report,
	#btn-create-report-mobile,
	.dropdown,
	.btn-list .btn,
	#horizon-toggle,
	#filter-bar,
	#filter-apply-btn,
	#filter-reset-btn,
	.card-actions .btn-group,
	[data-bs-toggle="dropdown"] {
		display: none !important;
	}

	/* Hide the filter bar's outer card entirely */
	body.is-printing .nestiq-filter-card,
	body.is-printing .nestiq-context-strip {
		display: none !important;
	}

	/* ── Reclaim full width — sidebar gone, no left padding needed ──────── */
	.page,
	.page-wrapper,
	.page-body,
	.container-fluid,
	.container-xl {
		margin-left: 0 !important;
		padding-left: 0 !important;
		padding-right: 0 !important;
		max-width: 100% !important;
		width: 100% !important;
	}

	/* ── Card flattening — paper, not glass ─────────────────────────────── */
	.card {
		box-shadow: none !important;
		border: 1px solid #c9d1d9 !important;
		border-radius: 4px !important;
		background: #ffffff !important;
	}
	.card-header {
		background: #f8f9fa !important;
		border-bottom: 1px solid #c9d1d9 !important;
		padding: 8px 12px !important;
	}
	.card-body {
		padding: 10px 12px !important;
	}

	/* ── Module 3: chart and insights occupy full width in print ────────── */
	body.is-printing .row > [class*="col-"] {
		flex: 0 0 100% !important;
		max-width: 100% !important;
		margin-bottom: 8mm !important;
	}

	/* Telemetry chart card occupies full vector width */
	body.is-printing #chart-revenue-occupancy {
		width: 100% !important;
		max-width: 100% !important;
	}
	body.is-printing .apexcharts-canvas,
	body.is-printing .apexcharts-canvas svg {
		max-width: 100% !important;
		width: 100% !important;
	}

	/* ── Page-break safety ──────────────────────────────────────────────── */
	.card,
	.row > [class*="col-"],
	#nestiq-print-cover,
	#chart-revenue-occupancy {
		break-inside: avoid;
		page-break-inside: avoid;
	}
	thead { display: table-header-group; }
	tfoot { display: table-footer-group; }
	tr, .progress, .card-header { break-inside: avoid; page-break-inside: avoid; }

	/* Push the channel & monthly ledgers cleanly to subsequent pages */
	body.is-printing .nestiq-page-break-before { break-before: page; page-break-before: always; }

	/* ── Cover header (revealed during print) ───────────────────────────── */
	#nestiq-print-cover {
		display: block !important;
		border-bottom: 2px solid #206bc4;
		padding-bottom: 8px;
		margin-bottom: 14px;
	}
	#nestiq-print-cover .cover-title {
		font-size: 18pt;
		font-weight: 700;
		color: #206bc4;
		margin: 0;
		line-height: 1.1;
	}
	#nestiq-print-cover .cover-sub {
		font-size: 10pt;
		color: #4a5568;
		margin: 2px 0 0;
	}
	#nestiq-print-cover .cover-meta {
		margin-top: 6px;
		display: flex;
		flex-wrap: wrap;
		gap: 4px 16px;
		font-size: 9.5pt;
		color: #2b3445;
	}
	#nestiq-print-cover .cover-meta b {
		color: #1d2433;
	}

	/* ── OOO subtitle below chart title in print only ───────────────────── */
	#chart-ooo-print-subtitle {
		display: block !important;
		font-size: 10pt;
		color: #b91c1c;
		font-weight: 600;
		margin-top: 2px;
	}

	/* ── Tables: stripe + bordered look on paper ───────────────────────── */
	body.is-printing .table {
		border: 1px solid #c9d1d9 !important;
		font-size: 9.5pt;
	}
	body.is-printing .table th,
	body.is-printing .table td {
		border: 1px solid #e2e8f0 !important;
		padding: 5px 8px !important;
	}
	body.is-printing .table tbody tr:nth-of-type(odd) {
		background-color: #f8fafc !important;
	}
	body.is-printing .table thead th {
		background-color: #edf2f7 !important;
		color: #1d2433 !important;
		font-weight: 700;
	}

	/* Progress bars print with their tint */
	.progress { background-color: #edf2f7 !important; }
	.progress-bar { print-color-adjust: exact; }

	/* KPI ribbon — flatten avatars/badges */
	.kpi-ribbon .card { padding: 6px; }

	/* Keep small badges legible */
	.badge { border: 1px solid currentColor; padding: 2px 6px !important; }

	/* ───────────────────────────────────────────────────────────────────────
	   Executive Report Template — Section styles
	   ─────────────────────────────────────────────────────────────────── */
	.report-section {
		margin: 0 0 10mm 0;
		break-inside: avoid;
		page-break-inside: avoid;
	}
	.report-section .section-title {
		font-size: 13pt;
		font-weight: 700;
		color: #1d2433;
		margin: 8mm 0 3mm 0;
		padding-bottom: 2px;
		border-bottom: 1px solid #c9d1d9;
	}
	.report-section .section-blurb {
		font-size: 9.5pt;
		color: #4a5568;
		margin: 0 0 4mm 0;
		line-height: 1.4;
	}

	/* Section 3 page break — Volatility ledger anchors a fresh page */
	#report-section-extremes.page-break-before {
		break-before: page;
		page-break-before: always;
	}

	/* Section 6 — Appendix forced to the final page */
	#report-section-appendix {
		break-before: page;
		page-break-before: always;
		margin-top: 0;
	}

	/* Trajectory matrix */
	.trajectory-table,
	.kpi-matrix-table,
	.extremes-table,
	.appendix-table {
		width: 100%;
		border-collapse: collapse;
		font-size: 9.5pt;
		border: 1px solid #c9d1d9;
	}
	.trajectory-table th,
	.kpi-matrix-table th,
	.extremes-table th,
	.appendix-table td:first-child {
		background: #edf2f7;
		font-weight: 700;
		color: #1d2433;
	}
	.trajectory-table th,
	.trajectory-table td,
	.kpi-matrix-table th,
	.kpi-matrix-table td,
	.extremes-table th,
	.extremes-table td,
	.appendix-table td {
		border: 1px solid #e2e8f0;
		padding: 5px 8px;
	}
	.kpi-matrix-table code {
		font-size: 8.5pt;
		color: #2563eb;
		background: transparent;
	}

	/* Trajectory directional pill — colored by sign */
	.trend-pill {
		display: inline-block;
		padding: 1px 6px;
		border-radius: 3px;
		font-weight: 700;
		font-size: 9.5pt;
	}
	.trend-pill.up   { background: #d1fae5; color: #047857; border: 1px solid #10b981; }
	.trend-pill.down { background: #fee2e2; color: #b91c1c; border: 1px solid #ef4444; }
	.trend-pill.flat { background: #fef9c3; color: #92400e; border: 1px solid #facc15; }
	.trend-pill.na   { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

	/* Peak / trough row tints */
	.extremes-table .row-peak td   { background: #ecfdf5 !important; }
	.extremes-table .row-trough td { background: #fef2f2 !important; }
	.extremes-table .row-mean td   { background: #f8fafc !important; font-style: italic; }

	/* Appendix loss highlight */
	.appendix-table .row-loss td {
		background: #fff7ed !important;
		font-weight: 700;
		color: #b91c1c;
		font-size: 11pt;
	}

	/* Cover header polish */
	#nestiq-report-print-template .cover-title {
		font-size: 18pt;
		font-weight: 700;
		color: #206bc4;
		margin: 0;
		line-height: 1.1;
	}
	#nestiq-report-print-template .cover-sub {
		font-size: 10pt;
		color: #4a5568;
		margin: 2px 0 0;
	}
	#nestiq-report-print-template .cover-meta {
		margin: 6px 0 4mm;
		display: flex;
		flex-wrap: wrap;
		gap: 4px 16px;
		font-size: 9.5pt;
		color: #2b3445;
		border-bottom: 2px solid #206bc4;
		padding-bottom: 6px;
	}
}
