/**
 * print.css — SkylarkOS institutional PDF/print stylesheet
 * Owns: @media print rules only. Zero screen layout changes.
 * Does NOT own: screen layout, chart logic, data, auth, routing.
 *
 * Usage: <link rel="stylesheet" href="/print.css"> in every dashboard page.
 * Purpose: Clean institutional PDF exports — no floating chrome, no cut charts,
 *          proper page breaks, readable dark theme, header/footer metadata.
 */

/* ══════════════════════════════════════════════════════════════════════════════
 * PAGE SETUP
 * ══════════════════════════════════════════════════════════════════════════════ */
@page {
  size: A4 portrait;
  margin: 16mm 12mm;
}

@page :first {
  margin-top: 12mm;
}

/* ══════════════════════════════════════════════════════════════════════════════
 * PRINT BASELINE
 * ══════════════════════════════════════════════════════════════════════════════ */
@media print {

  /* Override the body=white override in skylark-theme.css — keep dark theme */
  body {
    background: #030914 !important;
    color: #f0f4fc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    font-size: 11px;
  }

  /* Force color printing for all elements */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* ── HIDE: Fixed/floating/sticky UI chrome ─────────────────────────────────── */

  /* Global nav bar (injected by nav.js) */
  #sky-global-nav,
  #sky-nav-menu,
  #sky-nav-backdrop {
    display: none !important;
  }

  /* Body offset class added by nav.js when mounted */
  body.sky-nav-mounted {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }

  /* Live market ticker bar */
  #sky-market-ticker,
  .sky-ticker-wrap,
  .sky-ticker-bar {
    display: none !important;
  }

  /* System status strip */
  #sky-system-status,
  .sky-system-status,
  .system-status-bar,
  .status-strip {
    display: none !important;
  }

  /* Intelligence rail (right-side fixed rail) */
  #sky-intel-rail,
  #sky-intel-rail-toggle,
  #sky-intel-rail-panel {
    display: none !important;
  }

  /* Chatbot / AI console floating widget */
  #sky-chatbot-widget,
  #sky-console-launcher,
  #sky-console-panel,
  #sky-console-badge,
  .sky-chatbot-widget,
  .sky-console-launcher {
    display: none !important;
  }

  /* Search modal overlay */
  #sky-search-overlay,
  .sky-search-modal,
  .sky-search-overlay {
    display: none !important;
  }

  /* Background decorative elements (fixed, full-viewport) */
  .grid-bg,
  .glow-orb,
  .glow-orb-1,
  .glow-orb-2 {
    display: none !important;
  }

  /* Refresh / admin-only controls */
  .refresh-btn,
  .zoom-reset-btn,
  .reset-zoom-btn,
  .toggle-btn,
  .scale-toggle,
  .scale-toggle-row,
  .scale-toggle-group,
  .seg-ctrl,
  .ctrl-group,
  .chart-controls,
  .view-snap-group,
  .overlay-select-wrap,
  .rm-history-toggle {
    display: none !important;
  }

  /* Admin-only status/debug elements */
  #debug-toggle-btn,
  #force-recompute-btn,
  #bmi-admin-status,
  #regime-admin-refresh-btn,
  #scrapeBtn,
  #flpRefreshBtn,
  .admin-badge,
  .debug-toggle-btn,
  .force-recompute-btn,
  .regime-admin-refresh,
  .bmi-admin-status,
  .admin-only {
    display: none !important;
  }

  /* News carousel (interactive scroll component) */
  #sky-news-carousel,
  .snc-outer {
    display: none !important;
  }

  /* Tooltip popups */
  #tput-tooltip-popup,
  .sky-tooltip,
  .sky-ticker-tooltip,
  .sk-tooltip {
    display: none !important;
  }

  /* Hover-only legend items / popovers */
  .sky-ticker-status,
  .overlay-warning,
  .scale-warning,
  .stale-badge,
  .chart-loading {
    display: none !important;
  }

  /* Nav bars within pages (not the global nav) */
  nav {
    display: none !important;
  }

  /* Back links and navigation breadcrumbs */
  .back-link,
  .breadcrumb {
    display: none !important;
  }

  /* Upgrade wall / paywall overlays */
  .upgrade-wall,
  .upgrade-wall-blur,
  .upgrade-wall-body {
    display: none !important;
  }

  /* Any position:fixed element not handled above */
  [style*="position: fixed"],
  [style*="position:fixed"] {
    display: none !important;
  }

  /* ── ADMIN PAGE: Hide interactive-only controls in print ──────────────── */

  /* Admin action buttons (refresh, retry, test) */
  .refresh-btn,
  #retry-ai-btn,
  #test-gemini-btn,
  #retry-ai-status,
  #test-gemini-status {
    display: none !important;
  }

  /* Admin overall card — keep visible, prevent break */
  .overall-card,
  .cat-card,
  .issue-card {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Admin token budget section — prevent break */
  #token-budget-section {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* ── LAYOUT: Remove viewport constraints ───────────────────────────────────── */

  /* Remove Intel Rail body offset */
  body {
    padding-right: 0 !important;
    margin-right: 0 !important;
  }

  /* Expand page content to full width */
  .page,
  #page-content,
  .page-wrap,
  .page-content,
  .dashboard,
  .dashboard-content {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 8px !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  /* Remove scroll containers — expand to full height */
  .scroll-container,
  .overflow-auto,
  .overflow-scroll,
  .overflow-y-auto,
  .overflow-x-auto,
  .matrix-scroll,
  .matrix-outer {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
  }

  /* ── SECTION BREAK PREVENTION ──────────────────────────────────────────────── */

  /* Cards and chart containers: never break in half */
  .chart-card,
  .nowcast-card,
  .crypto-intel-card,
  .intro-card,
  .sidebar-card,
  .sk-card,
  .sk-card-gold,
  .access-card,
  .metric-card,
  .regime-card,
  .regime-section,
  .breadth-card,
  .description-block,
  .methodology,
  .disclaimer,
  .spread-panel,
  .chart-footer,
  .regime-composite-badge,
  .drift-leaders-card,
  .section-divider,
  .legend-list,
  .regime-metric-table,
  .regime-stress-flags,
  .terminology-panel {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Table rows never split */
  tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Table headers repeat on every page */
  thead {
    display: table-header-group !important;
  }

  /* ── TABLE CLEANUP ─────────────────────────────────────────────────────────── */

  table {
    width: 100% !important;
    font-size: 10px !important;
    page-break-inside: auto !important;
    border-collapse: collapse !important;
  }

  .table-container,
  .matrix-grid,
  .regime-metric-table {
    overflow: visible !important;
    max-height: none !important;
    width: 100% !important;
  }

  /* ── CHART HEIGHTS ─────────────────────────────────────────────────────────── */

  /* Standard chart canvas wrappers */
  .chart-canvas-wrap {
    height: 480px !important;
    min-height: 480px !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* Small chart variants */
  .spread-chart-wrap,
  .regime-matrix-canvas-wrap {
    height: 340px !important;
    min-height: 340px !important;
    max-height: none !important;
  }

  /* Matrix / heatmap cells — allow taller */
  .matrix-layout,
  .cell-chart-wrap {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Avoid vh-based heights */
  .chart-card {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* ── FORCED PAGE BREAKS BEFORE MAJOR SECTIONS ──────────────────────────────── */

  /* Utility class — add .print-page-break-before to major section headers */
  .print-page-break-before {
    break-before: page !important;
    page-break-before: always !important;
  }

  /* ── PRINT HEADER (injected by JS on print trigger) ────────────────────────── */

  #sky-print-header {
    display: block !important;
    padding: 0 0 12px 0;
    border-bottom: 1px solid rgba(245, 184, 46, 0.4);
    margin-bottom: 20px;
  }

  #sky-print-header .ph-logo {
    font-family: 'DM Mono', monospace, serif;
    font-size: 13px;
    font-weight: 600;
    color: #f5b82e;
    letter-spacing: 2px;
    text-transform: uppercase;
    display: block;
    margin-bottom: 4px;
  }

  #sky-print-header .ph-title {
    font-size: 18px;
    font-weight: 700;
    color: #f0f4fc;
    display: block;
    margin-bottom: 4px;
  }

  #sky-print-header .ph-meta {
    font-family: 'DM Mono', monospace, serif;
    font-size: 9px;
    color: #8fa4c0;
    letter-spacing: 0.5px;
    display: block;
  }

  #sky-print-header .ph-disclaimer {
    font-size: 9px;
    color: #4e6a88;
    margin-top: 4px;
    display: block;
  }

  /* Hide print header on screen */

  /* ── PRINT FOOTER ───────────────────────────────────────────────────────────── */

  #sky-print-footer {
    display: block !important;
    margin-top: 40px;
    padding-top: 12px;
    border-top: 1px solid rgba(245, 184, 46, 0.2);
    font-size: 8px;
    color: #4e6a88;
    line-height: 1.5;
  }

  /* ── TYPOGRAPHY: Keep dark theme legible ───────────────────────────────────── */

  /* Core text colors — remain on dark background */
  .text-primary, [class*="text-primary"] { color: #f0f4fc !important; }
  .text-secondary, [class*="text-secondary"] { color: #8fa4c0 !important; }
  .text-muted, [class*="text-muted"] { color: #6a8099 !important; }

  /* Gold/accent labels — remain gold */
  .sk-text-gold, .page-eyebrow, .cc-eyebrow, .chart-header-eyebrow,
  .regime-eyebrow, .state-eyebrow, .sk-badge-gold,
  [style*="color: #f5b82e"], [style*="color:#f5b82e"],
  [style*="color: #febc2e"], [style*="color:#febc2e"] {
    color: #f5b82e !important;
  }

  /* Cyan accent labels — remain cyan */
  .sk-text-cyan,
  [style*="color: #22d3ee"], [style*="color:#22d3ee"] {
    color: #22d3ee !important;
  }

  /* Card backgrounds — keep dark, not white */
  .chart-card,
  .nowcast-card,
  .metric-card,
  .regime-card,
  .sk-card,
  .sk-card-gold,
  .crypto-intel-card,
  .intro-card,
  .sidebar-card,
  .access-card {
    background: #091e38 !important;
    border: 1px solid rgba(245, 184, 46, 0.2) !important;
  }

  /* Section dividers — visible */
  .section-divider-line,
  .sk-divider,
  .sk-divider-gold {
    border-color: rgba(245, 184, 46, 0.3) !important;
    opacity: 1 !important;
  }

  /* Chart axis labels and legend text — keep visible */
  .legend-item,
  .legend-dot,
  .chart-footer-item,
  .chart-footer-line,
  .data-timestamps,
  .ts-item,
  .chart-footnote {
    color: #8fa4c0 !important;
  }

  /* Regime pills — keep colored badges readable */
  .regime-pill {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .regime-pill.favorable { background: rgba(34, 197, 94, 0.2) !important; color: #4ade80 !important; }
  .regime-pill.transitional { background: rgba(245, 184, 46, 0.2) !important; color: #f5b82e !important; }
  .regime-pill.defensive { background: rgba(255, 95, 87, 0.2) !important; color: #ff5f57 !important; }

  /* ── MISC CLEANUPS ──────────────────────────────────────────────────────────── */

  /* Remove box shadows (look muddy in print) */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }

  /* Remove animation keyframes */
  * {
    animation: none !important;
    transition: none !important;
  }

  /* Links — no underline in print, keep color */
  a { text-decoration: none !important; }

  /* Ensure canvas elements display correctly */
  canvas {
    max-width: 100% !important;
  }

} /* end @media print */

/* ══════════════════════════════════════════════════════════════════════════════
 * SCREEN: Hide print-only elements
 * ══════════════════════════════════════════════════════════════════════════════ */
@media screen {
  #sky-print-header { display: none; }
  #sky-print-footer { display: none; }
}
