/* Print styles */
@media print {
  /* Hide non-essential elements */
  .site-header,
  .site-footer,
  .recipe-sidebar,
  .related-recipes,
  .print-button,
  .execution-mode-toggle,
  .cooking-mode-footer,
  .language-switcher,
  .recipe-video,
  .serving-controls,
  .scaling-warning,
  .print-exclude,
  .recipe-story {
    display: none !important;
  }

  /* Hide timer-related elements in print */
  .timer-suggestions,
  .create-timer-btn,
  .recipe-timer,
  .timer-completion-notification,
  .execution-step .step-number,
  .execution-step .completion-indicator {
    display: none !important;
  }

  /* Hide Instagram content in print */
  .instagram-media,
  .instagram-embed,
  .instagram-shortcode,
  .instagram-post,
  iframe[src*="instagram.com"],
  blockquote[cite*="instagram.com"],
  [class*="instagram"] {
    display: none !important;
  }

  /* Hide blockquotes that contain Instagram links */
  blockquote {
    position: relative;
  }

  blockquote a[href*="instagram.com"] {
    display: none !important;
  }

  /* Hide blockquotes that likely contain only Instagram content */
  blockquote:empty {
    display: none !important;
  }

  /* Hide common Instagram embed patterns */
  div[data-instgrm-permalink],
  div[data-instgrm-captioned],
  script[src*="instagram.com"] {
    display: none !important;
  }

  /* Hide any element with Instagram in data attributes */
  [data-instagram],
  [data-instgrm-permalink],
  [data-instgrm-captioned] {
    display: none !important;
  }

  /* Reset layout */
  .recipe-container {
    display: block;
    width: 100%;
  }

  .recipe-main {
    width: 100%;
    padding: 0;
  }

  /* Typography adjustments */
  body {
    font-size: 11pt;
    line-height: 1.3;
    color: #000;
    background: #fff;
    margin: 0;
    padding: 0;
  }

  h1 {
    font-size: 16pt;
    margin-bottom: 0.3cm;
    margin-top: 0;
  }

  h2 {
    font-size: 13pt;
    margin-top: 0.3cm;
    margin-bottom: 0.2cm;
  }

  /* Only include short introduction */
  .recipe-content p:not(:first-of-type) {
    display: none;
  }

  /* Optimize recipe information */
  .recipe-details {
    background: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
    margin-bottom: 0.3cm;
    padding: 0.2cm;
  }

  .ingredients,
  .equipment,
  .instructions {
    page-break-inside: auto;
    margin-top: 0.2cm;
    margin-bottom: 0.2cm;
  }

  /* Only avoid page breaks inside for smaller sections */
  .ingredients:not(.long-list),
  .equipment:not(.long-list) {
    page-break-inside: avoid;
  }

  /* Ensure links are readable */
  a {
    color: #000;
    text-decoration: none;
  }

  /* Improve image printing */
  .recipe-featured-image {
    max-width: 30%;
    max-height: 6cm;
    margin: 0.1cm auto 0.2cm auto;
    display: block;
    object-fit: cover;
    page-break-after: avoid;
  }

  /* Make all images smaller in print */
  img {
    max-width: 30% !important;
    max-height: 6cm !important;
    object-fit: cover;
  }

  /* Add URL after links */
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 10pt;
  }

  /* Page breaks */
  h1,
  h2,
  h3 {
    page-break-after: avoid;
  }

  img {
    page-break-inside: avoid;
    page-break-after: avoid;
  }

  /* Prevent large gaps after images */
  .recipe-featured-image + * {
    page-break-before: avoid;
  }

  /* Ensure intro section is styled properly in print */
  .recipe-intro {
    margin-bottom: 0.2cm;
    padding: 0.2cm;
    background: #f9f9f9;
    border: 1px solid #ddd;
    page-break-inside: avoid;
    page-break-after: avoid;
  }

  /* Ensure ordered lists show numbers in print */
  .instructions ol {
    list-style-type: decimal !important;
    list-style-position: outside !important;
    margin-left: 1.2em !important;
    padding-left: 0 !important;
    margin-bottom: 0.2cm;
  }

  .instructions ol li {
    margin-bottom: 0.2cm;
    padding-left: 0.1em;
    display: list-item !important;
    line-height: 1.3;
  }

  /* Ensure list numbers are visible */
  .instructions ol li::marker {
    font-weight: bold;
    color: #000 !important;
  }

  /* Also ensure any nested lists maintain numbering */
  .instructions ul {
    list-style-type: disc !important;
    list-style-position: outside !important;
    margin-left: 1em !important;
    margin-bottom: 0.2cm;
  }

  .instructions ul li {
    display: list-item !important;
    margin-bottom: 0.15cm;
    line-height: 1.3;
  }

  /* Additional print optimizations */
  .recipe-header {
    margin-bottom: 0.2cm;
  }

  .recipe-content section {
    margin-bottom: 0.3cm;
  }

  /* Reduce spacing after featured image */
  .recipe-featured-image {
    margin-bottom: 0.1cm !important;
  }

  /* Ensure content flows better after image */
  .recipe-content > *:first-child {
    margin-top: 0;
  }

  /* Reduce margins on ingredient and equipment lists */
  .ingredients ul,
  .equipment ul,
  .time-planning ul {
    margin-bottom: 0.3cm;
  }

  .ingredients li,
  .equipment li,
  .time-planning li {
    margin-bottom: 0.1cm;
    padding: 0.05cm 0;
    line-height: 1.2;
  }

  /* Compact recipe details grid */
  .recipe-details {
    display: block !important;
    columns: 2;
    column-gap: 0.5cm;
  }

  .recipe-details div {
    break-inside: avoid;
    margin-bottom: 0.2cm;
    display: inline-block;
    width: 100%;
  }

  /* Optimize page margins */
  @page {
    margin: 1.5cm 1cm 1cm 1cm;
    size: A4;
  }

  /* Remove excessive spacing from various elements */
  p {
    margin-bottom: 0.2cm;
  }

  /* Make content more compact */
  .container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }

  /* Ensure related recipe images are also smaller */
  .related-recipe-item img,
  .related-recipe-image img {
    max-width: 25% !important;
    max-height: 4cm !important;
  }

  /* Compact the recipe meta information */
  .recipe-meta {
    margin-bottom: 0.2cm;
    font-size: 10pt;
  }

  /* Reduce spacing in recipe details */
  .recipe-details strong {
    margin-bottom: 0.1cm;
    font-size: 9pt;
  }

  /* Make ingredient and equipment lists more compact */
  .ingredients li::before,
  .equipment li::before,
  .time-planning li::before {
    width: 6px;
    height: 6px;
    margin-right: 0.3cm;
  }

  /* Optimize instruction numbering */
  .instructions ol li::before {
    font-size: 0.9rem;
  }

  /* Remove extra spacing from various sections */
  .recipe-content {
    margin: 0;
  }

  /* Ensure no orphaned headings */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
    orphans: 3;
    widows: 3;
  }

  /* Better paragraph control */
  p {
    orphans: 2;
    widows: 2;
  }

  /* Prevent large gaps and improve content flow */
  .recipe-content {
    page-break-inside: auto;
  }

  /* Force content to stay together when possible */
  .recipe-header + .recipe-featured-image + * {
    page-break-before: avoid;
    margin-top: 0;
  }

  /* Reduce any excessive spacing that might cause page breaks */
  .recipe-intro,
  .recipe-content > section:first-of-type {
    margin-top: 0;
    page-break-before: avoid;
  }

  /* Make sure content after image doesn't get pushed to next page unnecessarily */
  .recipe-featured-image ~ * {
    page-break-before: avoid;
  }

  /* Prevent page breaks after intro/summary sections */
  .recipe-intro + * {
    page-break-before: avoid;
  }

  /* Keep the first few sections together with the intro */
  .recipe-content > section:nth-child(-n + 3) {
    page-break-before: avoid;
  }

  /* Specifically target common section patterns that might cause breaks */
  section[class*="planning"],
  section[class*="ingredients"]:first-of-type,
  .ingredients:first-of-type {
    page-break-before: avoid;
    margin-top: 0;
  }

  /* Prevent breaks between closely related content */
  .recipe-intro + .recipe-details,
  .recipe-details + .ingredients,
  .recipe-details + section {
    page-break-before: avoid;
  }

  /* Force tighter grouping of initial content */
  .recipe-header,
  .recipe-featured-image,
  .recipe-intro,
  .recipe-details {
    page-break-after: avoid;
  }
}
