/**
 * Astrovedha Jeevan Samhita — Professional Print & PDF Stylesheet
 * Traditional Vedic Manuscript Layout with Decorative Borders
 * A4 Portrait · Precise Page Breaks · Premium Typography
 */

/* Print furniture is injected with live report data but stays invisible on screen. */
.report-page-header,
.report-page-footer {
  display: none;
}

@media print {

  /* ============================================================
   * 0. CRITICAL: HIDE ALL WEB UI — COMPLETELY
   * ============================================================ */
  #mobile-bottom-dock,
  #mobile-header-bar,
  #desktop-top-header,
  #app-sidebar,
  aside,
  header,
  footer,
  nav,
  .sticky,
  .dock-tab,
  .print\:hidden,
  [data-print-hidden="true"],
  #broadcast-banner-container,
  #astro-broadcast-banner,
  #pwa-install-banner,
  #cart-drawer,
  #astro-screenshot-shield,
  #astro-capture-shield,
  #report-watermark,
  .astro-forensic-watermark,
  .astro-capture-shield,
  #report-inter-chapter-callout,
  #report-blur-overlay,
  #rep-download-icon,
  button,
  select,
  .backdrop-blur-md,
  [onclick],
  .sunrise-gradient,
  #report-chapter-jump,
  .report-toolbar,
  [class*="bottom-dock"],
  [class*="mobile-header"],
  [class*="sidebar"],
  [id*="sidebar"],
  [id*="drawer"],
  [id*="modal"],
  [id*="topup"],
  [id*="paywall"],
  [class*="lock-banner"],
  [class*="upgrade"],
  [class*="callout"],
  .astro-teaser-fade,
  .astro-feature-lock,
  .astro-fade-overlay {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    width: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    position: absolute !important;
    left: -9999px !important;
  }

  /* ============================================================
   * 1. PAGE SETUP — A4 WITH GENEROUS MARGINS
   * ============================================================ */
  @page {
    size: A4 portrait;
    margin: 18mm 16mm 20mm 16mm;
  }

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

  /* ============================================================
   * 2. BASE RESET
   * ============================================================ */
  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    box-sizing: border-box !important;
  }

  html, body {
    background: #ffffff !important;
    color: #1a1209 !important;
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: 'Crimson Text', 'Georgia', 'Times New Roman', serif !important;
    font-size: 10pt !important;
    line-height: 1.6 !important;
  }

  #app-main-content,
  #app-viewport,
  main,
  #root,
  #app-root {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: unset !important;
    background: transparent !important;
    overflow: visible !important;
  }

  /* While exporting the dossier, suppress every sibling in the dynamic viewport.
     This prevents unrelated routed content or transient UI from entering the PDF. */
  html.report-print-mode #app-viewport > *:not(#report-dossier-root):not(:has(#report-dossier-root)),
  body.report-print-mode #app-viewport > *:not(#report-dossier-root):not(:has(#report-dossier-root)) {
    display: none !important;
  }

  /* ============================================================
   * 3. UNBLUR & UNLOCK ENTITLED PREMIUM CONTENT
   * ============================================================ */
  #report-deep-chapters-wrapper,
  #report-deep-chapters-content,
  .report-page,
  [data-premium-feature],
  [data-premium-chapter] {
    filter: none !important;
    -webkit-filter: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    user-select: auto !important;
    display: block !important;
    position: relative !important;
    left: auto !important;
    top: auto !important;
  }

  #report-dossier-root {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  /* ============================================================
   * 4. PROFESSIONAL CHAPTER PAGE TEMPLATE
   *    Each .report-page becomes a self-contained A4 page
   * ============================================================ */
  .report-page {
    /* Page geometry */
    display: flow-root !important;
    width: 100% !important;
    min-height: 0 !important;
    padding: 28pt 28pt 32pt 28pt !important;
    margin: 0 !important;
    background:
      linear-gradient(rgba(255, 253, 248, 0.97), rgba(255, 253, 248, 0.97)),
      repeating-linear-gradient(0deg, transparent 0 13pt, rgba(139, 94, 26, 0.025) 13pt 13.5pt) !important;
    box-shadow: none !important;
    border-radius: 0 !important;

    /* Page breaks */
    page-break-before: always !important;
    break-before: page !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: auto !important;
    break-inside: auto !important;

    /* Traditional Vedic Border — double-line with amber tones */
    border: none !important;
    position: relative !important;
    overflow: visible !important;
  }

  /* First chapter — no leading page break */
  .report-page:first-of-type,
  #ch-1 {
    page-break-before: avoid !important;
    break-before: avoid !important;
  }

  /* ============================================================
   * 5. DECORATIVE TRADITIONAL VEDIC BORDER SYSTEM
   *    A fixed frame is repeated by Chromium on every physical PDF page.
   * ============================================================ */
  html.report-print-mode #report-dossier-root::before,
  body.report-print-mode #report-dossier-root::before {
    content: '' !important;
    display: block !important;
    position: fixed !important;
    inset: 6mm !important;
    border: 1.1mm double #8B5E1A !important;
    outline: 0.25mm solid #c49a3c !important;
    outline-offset: -2.2mm !important;
    pointer-events: none !important;
    z-index: 9999 !important;
  }

  .report-page::before,
  .report-page::after {
    content: none !important;
    display: none !important;
  }

  /* Keep wrapper spacing utilities from creating blank strips before pages. */
  #report-dossier-root > *,
  #report-deep-chapters-content > *,
  .report-page + .report-page {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }

  /* ============================================================
   * 7. RUNNING PAGE HEADER & FOOTER (via @page — supported in Chrome/Edge print)
   * ============================================================ */
  .report-page-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 12pt !important;
    padding: 0 0 6pt 0 !important;
    margin-bottom: 10pt !important;
    border-bottom: 1pt solid #c49a3c !important;
    font-size: 7.5pt !important;
    color: #8B5E1A !important;
    font-family: 'Crimson Text', Georgia, serif !important;
    font-style: italic !important;
    letter-spacing: 0.04em !important;
    break-after: avoid !important;
  }

  .report-page-header span:last-child,
  .report-page-footer span:last-child {
    text-align: right !important;
  }

  .report-page-footer {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 12pt !important;
    padding: 6pt 0 0 0 !important;
    margin-top: 10pt !important;
    border-top: 1pt solid #c49a3c !important;
    font-size: 7pt !important;
    color: #9a7040 !important;
    font-family: 'Crimson Text', Georgia, serif !important;
    break-before: avoid !important;
  }

  #ch-1 > .report-page-header {
    visibility: hidden !important;
    margin-bottom: 2pt !important;
  }

  /* ============================================================
   * 8. CHAPTER TITLE TYPOGRAPHY
   * ============================================================ */
  .report-page h2 {
    font-family: 'Crimson Text', Georgia, 'Times New Roman', serif !important;
    font-size: 18pt !important;
    font-weight: 700 !important;
    color: #2c1d0e !important;
    margin-top: 4pt !important;
    margin-bottom: 6pt !important;
    line-height: 1.3 !important;
    letter-spacing: -0.01em !important;
    border-bottom: 1.5pt solid #c49a3c !important;
    padding-bottom: 6pt !important;
  }

  .report-page h3 {
    font-family: 'Crimson Text', Georgia, serif !important;
    font-size: 13pt !important;
    font-weight: 700 !important;
    color: #3d2106 !important;
    margin-top: 12pt !important;
    margin-bottom: 5pt !important;
    line-height: 1.35 !important;
  }

  .report-page h4 {
    font-family: 'Crimson Text', Georgia, serif !important;
    font-size: 11pt !important;
    font-weight: 700 !important;
    color: #4a2c08 !important;
    margin-top: 8pt !important;
    margin-bottom: 4pt !important;
  }

  .report-page p,
  .report-page li,
  .report-page td,
  .report-page th,
  .report-page dd,
  .report-page dt,
  .report-page span {
    font-family: 'Crimson Text', Georgia, 'Times New Roman', serif !important;
    font-size: 9.5pt !important;
    line-height: 1.55 !important;
    color: #1a1209 !important;
  }

  .report-page dt {
    font-weight: 700 !important;
    color: #3d2106 !important;
    font-size: 9.5pt !important;
  }

  .report-page dd {
    margin-left: 12pt !important;
    color: #2c1d0e !important;
    margin-bottom: 4pt !important;
  }

  /* Chapter label badge */
  .report-page > div > span:first-child,
  .report-page .text-amber-800.text-\\[11px\\] {
    font-size: 7pt !important;
    font-weight: 800 !important;
    letter-spacing: 0.12em !important;
    text-transform: uppercase !important;
    color: #8B5E1A !important;
    display: block !important;
    margin-bottom: 2pt !important;
    font-family: 'Inter', Arial, sans-serif !important;
  }

  /* ============================================================
   * 9. TABLE FORMATTING — Compact & Readable
   * ============================================================ */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 8pt !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    margin-bottom: 10pt !important;
    table-layout: fixed !important;
  }

  thead {
    display: table-header-group !important;
  }

  thead tr {
    background: #f5ede0 !important;
    border-bottom: 1.5pt solid #c49a3c !important;
  }

  th {
    font-size: 7.5pt !important;
    font-weight: 700 !important;
    color: #3d2106 !important;
    padding: 4pt 5pt !important;
    text-align: left !important;
    font-family: 'Inter', Arial, sans-serif !important;
    letter-spacing: 0.02em !important;
    border-bottom: 1pt solid #d4aa70 !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  td {
    font-size: 8pt !important;
    padding: 3.5pt 5pt !important;
    color: #1a1209 !important;
    border-bottom: 0.5pt solid #e8ddd0 !important;
    vertical-align: top !important;
    word-break: break-word !important;
    white-space: normal !important;
    overflow: visible !important;
  }

  tr:nth-child(even) td {
    background: #fdf8f0 !important;
  }

  tr:hover td {
    background: inherit !important;
  }

  /* Remove horizontal scroll wrappers for print */
  .overflow-x-auto,
  .custom-scrollbar,
  .table-scroll-wrap {
    overflow: visible !important;
    width: 100% !important;
    display: block !important;
  }

  /* ============================================================
   * 10. GRID & CARD LAYOUTS — Convert to Print-Safe Layouts
   * ============================================================ */
  .grid {
    display: grid !important;
    gap: 8pt !important;
  }

  /* 2-col grids stay 2-col in print */
  .grid-cols-1.sm\:grid-cols-2,
  .md\:grid-cols-2 {
    grid-template-columns: 1fr 1fr !important;
  }

  /* 3-col grids compress to 2-col */
  .sm\:grid-cols-3,
  .md\:grid-cols-3,
  .grid-cols-2.sm\:grid-cols-4,
  .lg\:grid-cols-4 {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Card styling */
  .rounded-xl,
  .rounded-2xl,
  .rounded-3xl {
    border-radius: 3pt !important;
  }

  [class*="bg-[#fbf9f6]"],
  [class*="bg-amber-50"],
  [class*="bg-white"] {
    background: #fdfaf4 !important;
  }

  [class*="border-amber"] {
    border-color: #d4aa70 !important;
  }

  /* Inner content cards */
  .p-4, .p-5, .p-6, .p-8 {
    padding: 8pt !important;
  }

  /* ============================================================
   * 11. COVER PAGE (Chapter 1) — Full-page premium layout
   * ============================================================ */
  #ch-1 {
    page-break-before: avoid !important;
    break-before: avoid !important;
    min-height: auto !important;
    text-align: center !important;
    padding: 36pt 40pt !important;
  }

  #ch-1 h1 {
    font-family: 'Crimson Text', Georgia, serif !important;
    font-size: 30pt !important;
    font-weight: 900 !important;
    color: #2c1d0e !important;
    letter-spacing: -0.02em !important;
    line-height: 1.15 !important;
    margin-bottom: 10pt !important;
  }

  #ch-1 .text-center p {
    font-size: 10pt !important;
    color: #5a3e1b !important;
    max-width: 100% !important;
  }

  /* Cover Om symbol */
  #ch-1 .text-2xl,
  #ch-1 .text-3xl {
    font-size: 32pt !important;
    color: #8B5E1A !important;
  }

  /* Decorative Sanskrit verse */
  #ch-1 .font-serif.tracking-widest {
    font-size: 8.5pt !important;
    letter-spacing: 0.15em !important;
    color: #7a5018 !important;
    margin: 8pt 0 !important;
  }

  /* Cover top gold bar */
  #ch-1 .absolute.top-0 {
    display: block !important;
    position: absolute !important;
    top: 6pt !important;
    left: 6pt !important;
    right: 6pt !important;
    height: 6pt !important;
    background: linear-gradient(90deg, #8B5E1A 0%, #c49a3c 50%, #8B5E1A 100%) !important;
    border-radius: 0 !important;
  }

  /* Hide logo image in cover (avoid broken images in PDF) */
  #ch-1 img {
    max-width: 80pt !important;
    max-height: 80pt !important;
    object-fit: contain !important;
  }

  /* Birth certificate cards */
  #ch-1 .grid [class*="p-3"] {
    border: 0.75pt solid #d4aa70 !important;
    padding: 5pt 7pt !important;
    background: #fffdf8 !important;
    break-inside: avoid !important;
  }

  /* ============================================================
   * 12. AVAKHADA CHAKRA — 2-col grid in print
   * ============================================================ */
  #ch-1 .grid-cols-2.sm\:grid-cols-4 {
    grid-template-columns: 1fr 1fr 1fr 1fr !important;
  }

  /* ============================================================
   * 13. CHAPTER HEADER DIVIDER BAR
   * ============================================================ */
  .border-b.border-amber-900\/15 {
    border-bottom: 1.5pt solid #c49a3c !important;
    padding-bottom: 7pt !important;
    margin-bottom: 10pt !important;
  }

  /* ============================================================
   * 14. CALLOUT BOXES — Professional Shaded Panels
   * ============================================================ */
  .bg-amber-50\/60,
  [class*="bg-amber-50"] {
    background: #fdf6e8 !important;
    border: 0.75pt solid #d4aa70 !important;
    border-radius: 3pt !important;
    padding: 8pt !important;
  }

  /* Gradient info banners */
  [class*="from-amber"] {
    background: #f5ede0 !important;
    border: 0.75pt solid #c49a3c !important;
    border-radius: 3pt !important;
  }

  /* ============================================================
   * 15. PREVENT AWKWARD PAGE SPLITS
   * ============================================================ */
  h2, h3, h4 {
    page-break-after: avoid !important;
    break-after: avoid !important;
    orphans: 3 !important;
    widows: 3 !important;
  }

  p {
    orphans: 2 !important;
    widows: 2 !important;
  }

  /* Tables can split across pages (by row) */
  tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Cards/panels stay together */
  [class*="rounded"],
  .space-y-2,
  .space-y-3 {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* ============================================================
   * 16. SVG CHART CONTAINERS
   * ============================================================ */
  svg, canvas {
    max-width: 100% !important;
    height: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  #rep-chart-d1-container,
  #rep-chart-d9-container {
    width: 200pt !important;
    height: 200pt !important;
    margin: 0 auto !important;
  }

  /* Varga chart grid — 4 per row in print */
  #rep-vargas-grid {
    grid-template-columns: 1fr 1fr 1fr 1fr !important;
    gap: 6pt !important;
  }

  #rep-vargas-grid > div {
    padding: 5pt !important;
    border: 0.5pt solid #d4aa70 !important;
    break-inside: avoid !important;
    background: #fffdf8 !important;
  }

  /* ============================================================
   * 17. PROFESSIONAL ORNAMENTAL DIVIDERS
   *    Between major sections within a chapter
   * ============================================================ */
  .border-t.border-amber-900\/15,
  .border-b.border-amber-900\/15 {
    border-color: #c49a3c !important;
  }

  /* Shanti mantra seals */
  .font-serif.font-bold.text-amber-900 {
    font-family: 'Crimson Text', Georgia, serif !important;
    font-size: 11pt !important;
    color: #7a5018 !important;
    letter-spacing: 0.05em !important;
  }

  /* ============================================================
   * 18. STATUS BADGES & PILLS — Simplified for Print
   * ============================================================ */
  [class*="rounded-full"] {
    border-radius: 2pt !important;
    padding: 1pt 4pt !important;
    font-size: 7pt !important;
    font-weight: 700 !important;
  }

  [class*="bg-emerald"] {
    background: #d4edda !important;
    color: #155724 !important;
    border: 0.5pt solid #28a745 !important;
  }

  [class*="bg-amber-100"],
  [class*="bg-amber-50"] {
    background: #fef3cd !important;
    color: #7a5018 !important;
    border: 0.5pt solid #c49a3c !important;
  }

  [class*="bg-rose"],
  [class*="bg-red"] {
    background: #f8d7da !important;
    color: #721c24 !important;
    border: 0.5pt solid #dc3545 !important;
  }

  /* ============================================================
   * 19. GLOSSARY CHAPTER — 2-col balanced layout
   * ============================================================ */
  #ch-17 .grid-cols-1.sm\:grid-cols-2 {
    grid-template-columns: 1fr 1fr !important;
    column-gap: 16pt !important;
  }

  #ch-17 dl {
    break-inside: avoid !important;
    margin-bottom: 6pt !important;
  }

  /* ============================================================
   * 20. MATERIAL SYMBOLS ICONS — Hide in print
   * ============================================================ */
  .material-symbols-outlined {
    display: none !important;
  }

  /* ============================================================
   * 21. FINAL SEAL SECTION
   * ============================================================ */
  #ch-17 .text-center.space-y-3 {
    margin-top: 20pt !important;
    padding-top: 12pt !important;
    border-top: 1.5pt solid #c49a3c !important;
  }

  code {
    font-family: 'Courier New', monospace !important;
    font-size: 8pt !important;
    color: #7a5018 !important;
    background: none !important;
    padding: 0 !important;
  }

  /* ============================================================
   * 22. LIST STYLES
   * ============================================================ */
  ul, ol {
    padding-left: 14pt !important;
    margin: 4pt 0 !important;
  }

  li {
    margin-bottom: 2pt !important;
    font-size: 9pt !important;
    line-height: 1.5 !important;
  }

  /* ============================================================
   * 23. SPACE UTILITIES — Compress for print
   * ============================================================ */
  .space-y-6 > * + *,
  .space-y-8 > * + * {
    margin-top: 12pt !important;
  }

  .space-y-4 > * + *,
  .space-y-3 > * + * {
    margin-top: 7pt !important;
  }

  .space-y-2 > * + * {
    margin-top: 4pt !important;
  }

  .gap-4, .gap-6, .gap-8 {
    gap: 8pt !important;
  }

  .mt-8, .my-8 {
    margin-top: 14pt !important;
  }

  .mb-8 {
    margin-bottom: 14pt !important;
  }

  .pt-4, .pt-6, .pt-8 {
    padding-top: 8pt !important;
  }

  .pb-4, .pb-6, .pb-8 {
    padding-bottom: 8pt !important;
  }

} /* END @media print */
