/**
 * Print-Friendly Stylesheet for Fleeing to Allah
 * Optimizes duas for printing with proper formatting
 */

@media print {
  /* Reset and Base Styles */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    background: white !important;
    font-size: 12pt;
    line-height: 1.6;
    color: black;
    margin: 0;
    padding: 0;
  }

  /* Hide UI Elements */
  header,
  nav,
  aside,
  button,
  .no-print,
  [role="navigation"],
  [role="banner"],
  .sidebar,
  .mobile-menu,
  .settings-button,
  .bookmark-button,
  .search-bar,
  .filter-buttons,
  .scroll-to-top,
  .welcome-screen,
  .dialog,
  .modal {
    display: none !important;
  }

  /* Page Setup */
  @page {
    size: A4;
    margin: 2cm 1.5cm;
    
    @top-center {
      content: "Fleeing to Allah - الفرار إلى الله";
      font-size: 10pt;
      color: #666;
      font-family: "Noto Naskh Arabic", "Amiri", serif;
    }
    
    @bottom-right {
      content: "Page " counter(page) " of " counter(pages);
      font-size: 9pt;
      color: #666;
    }
  }

  /* Main Content */
  main {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Section Headers */
  .section-title,
  h2 {
    font-size: 18pt;
    font-weight: bold;
    color: #1a1a1a;
    margin-top: 24pt;
    margin-bottom: 12pt;
    page-break-after: avoid;
    border-bottom: 2pt solid #d4af37;
    padding-bottom: 6pt;
  }

  .section-description {
    font-size: 11pt;
    color: #444;
    margin-bottom: 16pt;
    font-style: italic;
  }

  /* Dua Cards */
  .dua-card,
  [class*="dua"] {
    page-break-inside: avoid;
    margin-bottom: 20pt;
    padding: 12pt;
    border: 1pt solid #ddd;
    border-radius: 4pt;
    background: #fafafa !important;
  }

  /* Dua Title */
  .dua-title,
  h3 {
    font-size: 14pt;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 10pt;
    page-break-after: avoid;
  }

  /* Arabic Text */
  .arabic-text,
  [class*="arabic"],
  [dir="rtl"] {
    font-family: "Noto Naskh Arabic", "Amiri", "Traditional Arabic", serif !important;
    font-size: 16pt !important;
    line-height: 2.2 !important;
    text-align: right;
    direction: rtl;
    color: #000;
    margin: 12pt 0;
    padding: 8pt;
    background: white !important;
    border-right: 3pt solid #d4af37;
    page-break-inside: avoid;
  }

  /* Line-by-Line Arabic (for enhanced memorization) */
  .line-by-line .arabic-line {
    display: block;
    margin-bottom: 8pt;
    padding: 6pt 8pt;
    background: #f9f9f9 !important;
    border-radius: 2pt;
  }

  /* Transliteration */
  .transliteration,
  [class*="transliteration"] {
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 11pt;
    font-style: italic;
    color: #555;
    line-height: 1.8;
    margin: 8pt 0;
    padding-left: 12pt;
    border-left: 2pt solid #ccc;
  }

  /* Translation */
  .translation,
  [class*="translation"] {
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 11pt;
    color: #333;
    line-height: 1.7;
    margin: 8pt 0;
    padding: 6pt 0;
  }

  /* Reference/Hadith Citation */
  .reference,
  .citation,
  [class*="reference"] {
    font-size: 9pt;
    color: #666;
    font-style: italic;
    margin-top: 8pt;
    padding-top: 6pt;
    border-top: 1pt dashed #ddd;
    page-break-inside: avoid;
  }

  /* Repeat Count Indicator */
  .repeat-count {
    font-size: 10pt;
    color: #d4af37;
    font-weight: 600;
    margin-left: 8pt;
  }

  /* Page Breaks */
  .section {
    page-break-before: always;
  }

  .section:first-child {
    page-break-before: avoid;
  }

  /* Prevent Orphans and Widows */
  p, .dua-card {
    orphans: 3;
    widows: 3;
  }

  /* Links */
  a {
    color: inherit;
    text-decoration: none;
  }

  a[href]:after {
    content: none !important;
  }

  /* Table of Contents (if present) */
  .toc {
    page-break-after: always;
    margin-bottom: 20pt;
  }

  .toc-item {
    margin: 6pt 0;
    font-size: 11pt;
  }

  /* Special Sections */
  .ruqya-section,
  .morning-evening-section {
    border: 2pt solid #d4af37;
    padding: 12pt;
    margin: 16pt 0;
    background: #fffef8 !important;
  }

  /* Bookmarked Duas Indicator */
  .bookmarked::before {
    content: "★ ";
    color: #d4af37;
    font-size: 12pt;
  }

  /* Ensure proper spacing between duas */
  .dua-card + .dua-card {
    margin-top: 16pt;
  }

  /* Print-specific utility classes */
  .print-only {
    display: block !important;
  }

  .screen-only {
    display: none !important;
  }

  /* Cover Page (if implemented) */
  .cover-page {
    page-break-after: always;
    text-align: center;
    padding-top: 30%;
  }

  .cover-title {
    font-size: 28pt;
    font-weight: bold;
    margin-bottom: 12pt;
  }

  .cover-subtitle {
    font-size: 20pt;
    font-family: "Noto Naskh Arabic", "Amiri", serif;
    color: #d4af37;
  }

  /* Optimize for black and white printing */
  @media print and (monochrome) {
    .arabic-text,
    [dir="rtl"] {
      border-right-color: #000 !important;
    }

    .section-title,
    h2 {
      border-bottom-color: #000 !important;
    }

    .repeat-count,
    .cover-subtitle {
      color: #000 !important;
    }
  }
}
