/* 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,
.screen-only,
.recipe-story,
.recipe-action-buttons,
.breadcrumb,
.recipe-meta {
  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 — exclude ingredients/equipment/time-planning sections */
.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;
}

/* Allow page breaks inside ingredients/equipment since they can contain rich markdown content */
.ingredients,
.equipment {
  page-break-inside: auto;
}

/* 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;
}

/* Image and details side by side */
.recipe-header-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5cm;
  margin-bottom: 0.3cm;
  page-break-inside: avoid;
}

.recipe-header-row .recipe-featured-image {
  flex: 0 0 auto;
  max-width: 35%;
  max-height: 7cm;
  margin: 0;
  object-fit: cover;
}

.recipe-header-row .recipe-details {
  flex: 1;
  display: block !important;
  columns: 1;
}

/* Use native list numbering only — no CSS counter ::before */
.instructions ol {
  list-style-type: decimal !important;
  list-style-position: outside !important;
  padding-left: 2.5em !important;
  margin-left: 0 !important;
  margin-bottom: 0.2cm;
}

.instructions ol li {
  margin-bottom: 0.2cm;
  padding-left: 0.2em;
  display: list-item !important;
  line-height: 1.3;
}

.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 */
.recipe-details {
  display: flex !important;
  flex-direction: column;
  columns: unset;
}

.recipe-details div {
  break-inside: avoid;
  margin-bottom: 0.2cm;
  display: inline-block;
  width: 100%;
}

/* QR code in print header */
.print-qr-code {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  gap: 0.15cm;
}

.print-qr-code svg {
  width: 2.2cm;
  height: 2.2cm;
}

.print-qr-label {
  font-size: 7pt;
  color: #555;
  text-align: center;
  max-width: 2.5cm;
  line-height: 1.2;
}

/* Show print-only content */
.print-only {
  display: block !important;
}
span.print-only {
  display: inline !important;
}

/* Hide screen-only content in print */
.screen-only {
  display: none !important;
}

/* In post-content, hide everything except print-only blocks */
.post-content > *:not(.print-only) {
  display: none !important;
}
.post-content > .print-only {
  display: block !important;
}

/* 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;
}

/* No CSS counter ::before for instructions — native ol numbering only */
.instructions ol li::before {
  content: none !important;
}

/* Cooking mode execution steps: use counter-based numbering matching non-cooking layout */
.instructions ol li.execution-step {
  list-style-type: none !important;
  position: relative !important;
  padding-left: 2.5em !important;
  counter-increment: exec-step !important;
}

.instructions ol li.execution-step:first-of-type {
  counter-reset: exec-step !important;
}

.instructions ol li.execution-step::before {
  content: counter(exec-step) "." !important;
  font-weight: bold !important;
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  display: block !important;
}

.instructions ol li.execution-step .step-content {
  display: block !important;
}

/* 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;
}
