/**
 * Print Stylesheet for After the Third Cup
 *
 * Optimized for offline reading and printing of safety-critical content
 *
 * Design Principles:
 * - Safety content must be readable without internet
 * - Emergency numbers must be prominent and easily accessible
 * - Typography optimized for paper (serif fonts, high contrast)
 * - Unnecessary UI elements hidden
 * - Proper page breaks for multi-section documents
 * - URLs printed for reference
 */

@media print {
  /* Page Setup */
  @page {
    size: letter;
    margin: 0.75in 0.75in;
    widows: 3;
    orphans: 3;
  }

  @page :first {
    margin-top: 1in;
  }

  /* Base Styles */
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  html,
  body {
    width: 100%;
    margin: 0;
    padding: 0;
    background: white;
    color: black;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 12pt;
    line-height: 1.6;
  }

  /* Typography for Print */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
    margin-bottom: 12pt;
    margin-top: 18pt;
    line-height: 1.3;
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: bold;
    color: black;
  }

  h1 {
    font-size: 24pt;
    margin-top: 0;
    margin-bottom: 18pt;
    border-bottom: 2pt solid black;
    padding-bottom: 12pt;
  }

  h2 {
    font-size: 18pt;
    margin-top: 24pt;
    border-bottom: 1pt solid black;
    padding-bottom: 8pt;
    page-break-before: avoid;
  }

  h3 {
    font-size: 14pt;
    margin-top: 12pt;
  }

  h4,
  h5,
  h6 {
    font-size: 12pt;
    font-weight: bold;
  }

  /* Paragraphs */
  p {
    margin-bottom: 12pt;
    orphans: 3;
    widows: 3;
    page-break-inside: avoid;
  }

  /* Links - Print URL after link text */
  a[href]::after {
    content: " (" attr(href) ")";
    word-break: break-all;
    font-size: 10pt;
    color: black;
  }

  /* Special handling for specific link types */
  a[href^="tel:"]::after,
  a[href^="mailto:"]::after,
  a[href^="#"]::after {
    content: "";
  }

  a {
    color: black;
    text-decoration: underline;
  }

  /* Hide Interactive Elements */
  nav,
  .navigation,
  nav ul,
  nav li,
  nav a,
  #navigation {
    display: none !important;
  }

  .skip-link {
    display: none !important;
  }

  .emergency-exit {
    display: none !important;
  }

  .reading-progress {
    display: none !important;
  }

  .feedback-form,
  .feedback-section,
  #feedback-form-placeholder {
    display: none !important;
  }

  .content-warning,
  [role="alert"] {
    display: none !important;
  }

  .table-of-contents {
    page-break-after: always;
    margin-bottom: 24pt;
    padding: 12pt;
    border: 1pt solid black;
  }

  .table-of-contents h2 {
    margin-top: 0;
  }

  .table-of-contents ul {
    margin: 12pt 0;
  }

  .table-of-contents li {
    margin-bottom: 6pt;
  }

  .table-of-contents a {
    color: black;
  }

  /* Crisis Resources - Special Treatment */
  .crisis-resource {
    border: 2pt solid black;
    padding: 12pt;
    margin: 18pt 0;
    page-break-inside: avoid;
    background: white;
  }

  .crisis-resource.emergency {
    border-width: 3pt;
    font-weight: bold;
  }

  .crisis-resource h4 {
    margin: 0 0 8pt 0;
    font-size: 13pt;
  }

  .crisis-resource h3 {
    margin: 0 0 8pt 0;
    font-size: 13pt;
  }

  /* Phone Numbers - Make them stand out */
  .crisis-resource {
    font-size: 11pt;
  }

  /* Make phone numbers bold and larger */
  :is(.crisis-resource, .safety-reminder) strong {
    font-size: 13pt;
    display: block;
    margin: 8pt 0;
  }

  /* Safety Warning and Experience Boxes */
  .safety-warning,
  .experience-box,
  .opinion-box,
  .integration-callout,
  .safety-reminder {
    border-left: 3pt solid black;
    border-top: 1pt solid black;
    border-bottom: 1pt solid black;
    padding: 12pt;
    margin: 18pt 0;
    page-break-inside: avoid;
    background: white;
    font-size: 11pt;
  }

  .safety-warning h3,
  .experience-box strong,
  .opinion-box strong,
  .integration-callout h3,
  .safety-reminder strong {
    display: block;
    margin-bottom: 8pt;
    font-size: 12pt;
  }

  .safety-reminder {
    border: 2pt solid black;
    margin: 24pt 0;
  }

  /* Content Meta Information */
  .content-header {
    page-break-after: avoid;
    margin-bottom: 24pt;
  }

  .content-description {
    font-size: 13pt;
    font-style: italic;
    margin-bottom: 12pt;
  }

  .content-meta {
    font-size: 10pt;
    color: #333;
    margin-bottom: 12pt;
    page-break-after: avoid;
  }

  .content-meta span {
    display: block;
    margin-bottom: 4pt;
  }

  /* Disclaimer Boxes */
  .opinion-box {
    font-style: italic;
  }

  /* Lists */
  ul,
  ol {
    margin: 12pt 0;
    padding-left: 30pt;
  }

  li {
    margin-bottom: 6pt;
    page-break-inside: avoid;
  }

  /* Code and Preformatted Text */
  pre,
  code {
    font-family: 'Courier New', monospace;
    font-size: 10pt;
    background: #f5f5f5;
    border: 1pt solid #ddd;
    padding: 8pt;
    margin: 12pt 0;
    page-break-inside: avoid;
    color: black;
  }

  pre {
    overflow-x: auto;
    white-space: pre-wrap;
  }

  /* Blockquotes */
  blockquote {
    border-left: 3pt solid black;
    margin: 12pt 0;
    padding-left: 12pt;
    font-style: italic;
    page-break-inside: avoid;
  }

  /* Tables */
  table {
    border-collapse: collapse;
    margin: 12pt 0;
    page-break-inside: avoid;
    width: 100%;
  }

  table,
  th,
  td {
    border: 1pt solid black;
  }

  th {
    background: #f5f5f5;
    font-weight: bold;
    padding: 8pt;
  }

  td {
    padding: 8pt;
  }

  /* Images and Media */
  img {
    max-width: 100%;
    page-break-inside: avoid;
    margin: 12pt 0;
  }

  img[alt]::after {
    content: " (" attr(alt) ")";
    font-size: 9pt;
    color: #666;
  }

  figure {
    page-break-inside: avoid;
    margin: 18pt 0;
  }

  figcaption {
    font-size: 10pt;
    font-style: italic;
    margin-top: 6pt;
  }

  /* Footer */
  footer {
    margin-top: 36pt;
    padding-top: 12pt;
    border-top: 1pt solid black;
    font-size: 10pt;
  }

  footer p {
    margin-bottom: 8pt;
  }

  /* Content Body */
  .content-body {
    margin: 18pt 0;
  }

  .content-body p {
    page-break-inside: avoid;
  }

  /* Related Content */
  .related-content {
    page-break-before: avoid;
    margin: 18pt 0;
    padding: 12pt;
    border: 1pt solid black;
  }

  .related-content h2 {
    margin-top: 0;
  }

  /* Footer Information */
  .content-footer {
    margin-top: 36pt;
    padding-top: 12pt;
    border-top: 1pt solid black;
    page-break-inside: avoid;
  }

  .author-info {
    font-size: 11pt;
  }

  /* Breadcrumbs - Hide in print */
  .breadcrumbs {
    display: none;
  }

  /* Print-specific header with emergency info */
  main::before {
    content: "IMPORTANT: Print this page and keep it for offline reference. In a mental health crisis, call 988 (US Suicide & Crisis Lifeline) or Fireside Project at 623-473-7433.";
    display: block;
    font-weight: bold;
    border: 3pt solid black;
    padding: 12pt;
    margin-bottom: 18pt;
    font-size: 11pt;
    page-break-after: avoid;
  }

  /* Print Header/Footer */
  @page {
    @bottom-center {
      content: "Page " counter(page);
      font-size: 10pt;
    }

    @bottom-left {
      content: "After the Third Cup - Ayahuasca Safety Resources";
      font-size: 10pt;
    }

    @bottom-right {
      content: "Printed " string(printed-date);
      font-size: 10pt;
    }
  }

  /* Crisis Resources Page Specific */
  .crisis-resource strong {
    color: black;
    font-weight: bold;
  }

  /* Ensure proper spacing for readability */
  .container {
    max-width: 100%;
  }

  /* Remove max-width constraints for better paper usage */
  p,
  article,
  .content {
    max-width: 100%;
  }

  /* Explicit page breaks for multi-section content */
  h2 {
    page-break-before: always;
  }

  h2:first-child {
    page-break-before: avoid;
  }

  /* Section breaks */
  hr {
    border: none;
    border-top: 2pt solid black;
    margin: 24pt 0;
    page-break-after: avoid;
  }

  /* Article container adjustments */
  article {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .content-page {
    width: 100%;
  }

  /* Make sure content is not cut off */
  div {
    page-break-inside: avoid;
  }

  /* But allow some divs to break if necessary */
  .content-body div {
    page-break-inside: auto;
  }

  /* Empty elements shouldn't create spacing */
  p:empty,
  div:empty {
    display: none;
  }

  /* Print-specific typography for emphasis */
  strong {
    font-weight: bold;
  }

  em {
    font-style: italic;
  }

  /* Ensure good contrast */
  :is(h1, h2, h3, h4, h5, h6, p, li, strong) {
    color: black;
  }

  /* Print Date Marker */
  body::before {
    content: "Printed on " attr(data-print-date);
    display: none;
  }

  /* Accessibility: Remove visual-only decorations */
  .skip-link,
  .sr-only,
  [aria-hidden="true"],
  .no-print {
    display: none !important;
  }

  /* Ensure form elements are hidden */
  form,
  input,
  textarea,
  button,
  select {
    display: none !important;
  }

  /* But preserve button text for clarity if needed */
  button {
    display: none;
  }

  /* Print version note */
  body::after {
    content: "\A\AThis is a printed version of After the Third Cup. Some interactive features are not available offline. Emergency numbers and resources are included. Please keep this for reference.";
    white-space: pre-wrap;
    display: block;
    margin-top: 36pt;
    padding: 12pt;
    border-top: 1pt solid black;
    font-size: 10pt;
    color: #333;
  }

  /* Ensure we don't lose important text */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* Improve readability of spacing */
  section {
    margin-bottom: 24pt;
    page-break-inside: auto;
  }

  section > h2 {
    page-break-before: always;
  }

  section > h2:first-of-type {
    page-break-before: auto;
  }

  /* Special handling for nested lists in crisis resources */
  .crisis-resource ul,
  .crisis-resource ol {
    margin: 8pt 0;
  }

  .crisis-resource li {
    margin-bottom: 4pt;
  }

  /* Print margins for nested content */
  .crisis-resource .crisis-resource {
    margin: 12pt 0;
    border: 1pt solid black;
  }

  /* Ensure borders print properly */
  * {
    border-color: black !important;
  }

  /* Print optimal font sizes for readability */
  small {
    font-size: 10pt;
  }

  /* Prevent widow/orphan problems */
  p {
    widows: 3;
    orphans: 3;
  }

  /* Explicit control for when content can break */
  article {
    page-break-inside: auto;
  }

  .crisis-resource,
  .safety-warning {
    page-break-inside: avoid;
  }

  /* Last element spacing */
  main > :last-child {
    margin-bottom: 24pt;
  }
}

/* Print-specific styles for screen to indicate printability */
@media screen {
  .print-only {
    display: none;
  }

  body[data-print-mode] {
    background: #f9f9f9;
  }
}

/* Additional support for print-specific content visibility */
@media print {
  .screen-only {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  /* Ensure content doesn't have display: none in print */
  .crisis-resource {
    display: block !important;
  }

  .safety-reminder {
    display: block !important;
  }

  .opinion-box,
  .experience-box,
  .safety-warning {
    display: block !important;
  }
}
