/* Recipe / post page layout (templates/blog_detail.html).
   Loaded after pages/blog_detail.css and wins over it; the older file still
   provides colours, the step cards and other details.

   Computers and tablets
     .recipe-top   photo on the left, title + facts + intro + share on the right
     .recipe-card  ingredients column (stays in view while scrolling) | steps
   Phones
     everything stacked, photo edge to edge; ingredients and steps are two
     tabs ("Ingredienser" / "Gör så här") whose bar stays under the menu.
     The tabs only take effect once static/js/pages/blog_detail.js has run
     (.tabs-ready), so without JavaScript both parts are simply shown.

   Images written into the post in the editor go through the |content_images
   filter (templatetags/images.py): scaled-down copies, lazy loading, and two
   or more images in a row wrapped in .content-gallery. Here they get a
   maximum height so a tall photo never fills more than about half a screen,
   and tapping one opens it full screen (.image-viewer). */

.blog-post {
  --content-img-max: 460px;   /* single image in the text */
  --gallery-h: 380px;         /* max height of images side by side */
}

/* ------------------------------------------------------------------ */
/* Top: photo + title, facts, intro, share                             */
/* ------------------------------------------------------------------ */
.blog-post .recipe-top__text .post-header {
  margin: 0 0 0.75rem !important;
  padding: 0 !important;
  text-align: left !important;
}

.blog-post .recipe-top__text .post-title {
  text-align: left !important;
  margin: 0 !important;
}

.blog-post .recipe-top__text .post-title::after {
  left: 0 !important;
  right: auto !important;
  transform: none !important;
  margin-left: 0 !important;
}

.blog-post .recipe-top__text .post-meta {
  justify-content: flex-start !important;
  margin: 0.6rem 0 0 !important;
}

/* Facts as small labels */
.blog-post .recipe-top .recipe-info {
  display: flex !important;
  flex-wrap: wrap;
  gap: 0.5rem !important;
  margin: 0.9rem 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

.blog-post .recipe-top .info-item {
  gap: 0.45rem !important;
  padding: 0.35rem 0.8rem;
  font-size: 0.92rem !important;
  color: #5a4a3c !important;
  background: #f6efe6;
  border: 1px solid #e6d9c8;
  border-radius: 999px;
}

.blog-post .recipe-top .info-item i {
  font-size: 0.95rem !important;
}

.blog-post .recipe-top .post-intro {
  margin: 0.9rem 0 !important;
  padding: 0 0 0 1rem !important;
  font-size: 1.02rem;
  line-height: 1.6;
  text-align: left !important;
  background: none !important;
  border: 0 !important;
  border-left: 3px solid #b85c3c !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.blog-post .recipe-top .post-intro::before,
.blog-post .recipe-top .post-intro::after {
  display: none !important;
}

.blog-post .recipe-top .recipe-share {
  margin: 0.75rem 0 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: none !important;
}

.blog-post .recipe-top .print-btn {
  margin-left: 0 !important;
}

.blog-post .featured-image {
  margin: 0 !important;
  text-align: center;
}

.blog-post .featured-image-wrapper {
  display: block !important;
  max-width: 100% !important;
  width: auto !important;
  margin: 0 auto !important;
  border-width: 8px !important;
}

/* The photo keeps its own shape (no cropping); a tall photo is limited in
   height and the frame shrinks around it */
.blog-post .featured-image-wrapper {
  display: inline-block !important;
  vertical-align: top;
}

.blog-post .featured-image img.post-thumbnail {
  display: block;
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: 620px !important;
  margin: 0 !important;          /* pages/blog_detail.css gives every image a 1rem margin */
  aspect-ratio: auto;
  object-fit: contain;
}

@media screen and (min-width: 769px) {
  .blog-post {
    max-width: 1100px !important;
  }

  .recipe-top:has(.featured-image) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 2.25rem;
    align-items: center;
  }

  .blog-post .recipe-top .post-title {
    font-size: clamp(1.8rem, 2.6vw, 2.3rem) !important;
    line-height: 1.2 !important;
  }
}

/* ------------------------------------------------------------------ */
/* Ingredients and steps                                               */
/* ------------------------------------------------------------------ */
.blog-post .recipe-card {
  position: relative;
  left: auto !important;
  transform: none !important;
  width: auto !important;
  max-width: none !important;
  margin: 1.5rem 0 !important;
  padding: 1.75rem !important;
  box-sizing: border-box;
}

.recipe-tabs {
  display: none;
}

.blog-post .ingredients-section {
  margin: 0 !important;
  padding: 0 !important;
}

.blog-post .ingredients-section h3,
.blog-post .cooking-steps > h3 {
  font-size: 1.3rem !important;
  margin: 0 0 0.8rem !important;
}

.blog-post .wake-lock-toggle {
  margin: 0 0 1rem !important;
}

/* One row per ingredient: amount | name, with any note under the name */
.blog-post .ingredients-list {
  gap: 0 !important;
  padding: 0.6rem 1rem !important;
}

.blog-post .ingredient-item {
  display: grid !important;
  grid-template-columns: 4rem minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: baseline;
  padding: 0.45rem 0 0.45rem 1rem !important;
  gap: 0 0.6rem !important;
}

.blog-post .ingredient-item::before {
  position: absolute !important;
  left: 0 !important;
  top: 0.45rem !important;
  margin: 0 !important;
}

.blog-post .ingredient-amount,
.blog-post .ingredient-name {
  min-width: 0 !important;
  width: auto !important;
  margin: 0 !important;
  font-size: 1rem !important;
  line-height: 1.4 !important;
  text-align: left !important;
}

.blog-post .ingredient-amount {
  font-weight: 700;
}

.blog-post .ingredient-name {
  grid-column: 2;
}

.blog-post .ingredient-notes {
  grid-column: 2;
  position: static !important;
  max-width: none !important;
  margin: 0 !important;
  font-size: 0.85rem !important;
  text-align: left !important;
}

/* Steps: same cards as before, just less padding */
.blog-post .cooking-steps {
  margin-top: 0 !important;
  padding-top: 0 !important;
  border-top: 0 !important;
}

.blog-post .steps-content {
  font-size: 1.03rem !important;
  line-height: 1.6 !important;
}

.blog-post .steps-content h2,
.blog-post .steps-content h3,
.blog-post .steps-content h4 {
  font-size: 1.12rem !important;
  margin: 1.25rem 0 0.5rem !important;
  color: #784527;
}

.blog-post .steps-content ol {
  margin: 0.5rem 0 1rem !important;
}

.blog-post .steps-content ol li {
  padding: 0.7rem 1rem 0.7rem 3.3rem !important;
  margin-bottom: 0.5rem !important;
}

.blog-post .steps-content ol li::before {
  top: 0.65rem !important;
  left: 0.75rem !important;
  width: 1.9rem !important;
  height: 1.9rem !important;
  transform: none !important;
  font-size: 0.95rem;
}

.blog-post .steps-content p {
  margin: 0.75rem 0;
}

@media screen and (min-width: 769px) {
  .blog-post .recipe-card {
    display: grid !important;
    grid-template-columns: minmax(250px, 32%) minmax(0, 1fr);
    gap: 2.5rem;
    align-items: start;
  }

  /* The ingredients stay in view below the menu bar while the steps scroll;
     a list longer than the screen scrolls inside its column */
  .blog-post .ingredients-section {
    position: sticky !important;
    top: calc(65px + 1rem);
    max-height: calc(100vh - 65px - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* ------------------------------------------------------------------ */
/* Images from the editor                                              */
/* ------------------------------------------------------------------ */
.blog-post .steps-content figure,
.blog-post .post-content figure {
  display: block !important;     /* pages/blog_detail.css makes them 90% wide flex boxes */
  max-width: 100% !important;
  margin: 1.25rem 0 !important;
  text-align: center;
}

.blog-post .steps-content img,
.blog-post .post-content img {
  position: static !important;
  left: auto !important;
  display: block;
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: var(--content-img-max) !important;
  margin: 0 auto !important;
  transform: none !important;
  object-fit: contain;
  border: 4px solid #fff !important;
  border-radius: 8px !important;
  outline: 1px solid #e0d9cf;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.blog-post img.zoomable {
  cursor: zoom-in;
}

.blog-post img.zoomable:focus-visible {
  outline: 3px solid var(--accent-warm, #ae5c40);
  outline-offset: 2px;
}

/* Two or more images in a row: side by side, each in its own shape */
.content-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 0.6rem;
  margin: 1.25rem 0;
}

.content-gallery--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.blog-post .content-gallery figure {
  margin: 0 !important;
}

.blog-post .content-gallery img {
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: var(--gallery-h) !important;
  object-fit: contain;
}

/* Full-screen view of a tapped image */
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(20, 15, 10, 0.92);
  cursor: zoom-out;
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.image-viewer__close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
}

html.image-viewer-open {
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Phones                                                              */
/* ------------------------------------------------------------------ */
@media screen and (max-width: 768px) {
  .blog-post {
    --content-img-max: 62vh;
    --gallery-h: 75vw;
    padding-top: 0 !important;
  }

  /* Photo edge to edge, no frame */
  .blog-post .featured-image {
    width: auto !important;
    max-width: none !important;
    margin: 0 -0.5rem 1rem !important;
  }

  .blog-post .featured-image-wrapper {
    width: 100% !important;
    border: 0 !important;
    outline: 0 !important;
    box-shadow: none !important;
  }

  .blog-post .featured-image-wrapper::before,
  .blog-post .featured-image-wrapper::after {
    display: none !important;
  }

  /* landscape photos fill the width; a tall one takes at most 3/4 of the
     screen height, centred */
  .blog-post .featured-image img.post-thumbnail {
    max-height: 75vh !important;
    margin: 0 auto !important;
  }

  .blog-post .recipe-top .post-title {
    font-size: 1.7rem !important;
    line-height: 1.2 !important;
  }

  /* Share: one row of small round buttons, print as an icon */
  .blog-post .recipe-top .recipe-share__label {
    display: none !important;
  }

  .blog-post .recipe-top .recipe-share {
    gap: 0.45rem !important;
  }

  .blog-post .recipe-top .share-btn {
    min-width: 40px !important;
    height: 40px !important;
  }

  .blog-post .recipe-top .print-btn {
    height: 40px !important;
    padding: 0 0.9rem !important;
  }

  .blog-post .recipe-top .print-btn span {
    display: none;
  }

  .blog-post .recipe-card {
    margin: 1rem -0.25rem !important;
    padding: 1rem !important;
  }

  /* Tabs, under the menu bar (52px high on phones) */
  .recipe-tabs {
    position: sticky;
    top: 52px;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: -1rem -1rem 1rem;
    background: #fff;
    border-bottom: 2px solid #e6d9c8;
    border-radius: 10px 10px 0 0;
  }

  .recipe-tab {
    appearance: none;
    margin: 0 0 -2px;
    padding: 0.85rem 0.25rem;
    font: 700 1rem Georgia, serif;
    color: #7a6a5a;
    text-align: center;
    background: none;
    border: 0;
    border-bottom: 3px solid transparent;
    cursor: pointer;
  }

  .recipe-tab.is-active {
    color: #b85c3c;
    border-bottom-color: #b85c3c;
  }

  .recipe-tab:focus-visible {
    outline: 2px solid #b85c3c;
    outline-offset: -4px;
  }

  .recipe-tab__count {
    display: inline-block;
    min-width: 1.4em;
    margin-left: 0.2em;
    padding: 0 0.35em;
    font-size: 0.8rem;
    background: #f1e4d6;
    border-radius: 999px;
  }

  /* With the tabs working: one part at a time, and the tab names replace
     the section headings */
  .recipe-card.tabs-ready .recipe-panel:not(.is-active) {
    display: none !important;
  }

  .recipe-card.tabs-ready .ingredients-section > h3,
  .recipe-card.tabs-ready .cooking-steps > h3 {
    display: none !important;
  }

  .recipe-card:not(.tabs-ready) .recipe-tabs {
    display: none;
  }

  .recipe-card:not(.tabs-ready) .ingredients-section {
    margin-bottom: 1.5rem !important;
  }

  .blog-post .steps-content ol li {
    padding: 0.65rem 0.75rem 0.65rem 2.9rem !important;
  }

  .blog-post .steps-content ol li::before {
    left: 0.55rem !important;
    width: 1.75rem !important;
    height: 1.75rem !important;
  }

  .content-gallery {
    gap: 0.4rem;
  }

  .content-gallery--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-gallery--3 figure:first-child {
    grid-column: 1 / -1;
  }

  /* Related recipes: two per row instead of one big card each */
  .related-posts-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.6rem !important;
  }

  .related-post-card {
    margin: 0 !important;
  }

  .related-post-image,
  .related-post-image img {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    object-fit: cover;
  }

  .related-post-content {
    padding: 0.5rem 0.6rem !important;
  }

  .related-post-content h4 {
    font-size: 0.95rem !important;
    margin: 0 !important;
  }
}

/* ------------------------------------------------------------------ */
/* Tags and the bottom of the page                                     */
/* ------------------------------------------------------------------ */
/* Tags are a small side note: one quiet line under the recipe, not a
   centred block of their own. They aren't links, so they don't need the
   44px tap height pages/blog_detail.css gives them on touch screens. */
.blog-post .post-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin: 1.25rem 0 0 !important;
  padding: 0.75rem 0 0 !important;
  text-align: left !important;
  border-top: 1px solid #ece3d7;
}

.blog-post .post-tags h4 {
  margin: 0 !important;
  font-size: 0.85rem !important;
  font-weight: normal;
  color: #8a7b6c !important;
}

.blog-post .post-tags .tags-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start !important;
  gap: 0.35rem;
  margin: 0 !important;
}

.blog-post .post-tags .tag {
  display: inline-block !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0.15rem 0.55rem !important;
  font-size: 0.78rem !important;
  line-height: 1.5;
  color: #8a6a55 !important;
  background: #f6efe6 !important;
  border-radius: 999px !important;
  transform: none !important;
}

.post-navigation .back-link {
  align-self: flex-start;
}

.post-navigation .related-posts {
  margin-top: 1.5rem !important;
}

@media screen and (max-width: 768px) {
  .blog-post .recipe-card {
    margin-bottom: 0 !important;
  }

  .blog-post .post-tags {
    margin-top: 1rem !important;
  }

  .blog-post {
    margin-bottom: 1.25rem !important;
  }

  .post-navigation .back-link {
    margin-left: 0.5rem;
  }
}
