/* Recipes (the library) and the recipe page (M4 WP-WL, UX pass 2 WP1). Shared components
   (rows, buttons, chips, pills, notices, .more) are in app.css; this sheet lays them out. */

/* ---- Recipes: a filter rail and the results (side by side from 64rem) ---- */

.library-grid {
  display: grid;
  gap: var(--space-4);
}

.library-grid > * {
  min-width: 0;
}

.library-filter {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
}

.library-filter input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

/* Starred and the top tags: one scrolling row on a phone (the results stay in view),
   wrapping in the rail. The padding keeps the chips' focus rings inside the scroller. */
.library-chips {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding: var(--space-1);
  margin: calc(-1 * var(--space-1));
}

.library-chips::-webkit-scrollbar {
  display: none;
}

.library-chips > .chip-input {
  flex: 0 0 auto;
}

.library-chips .chip-input span {
  white-space: nowrap;
}

/* "Filters" (a .more from app.css): the rest of the tags and the status. */
.library-more-filters {
  margin-top: 0;
}

.library-more-filters > .chip-inputs + .chip-inputs {
  margin-top: var(--space-4);
}

.library-legend {
  flex: 1 1 100%;
  padding: 0;
  margin: 0 0 var(--space-1);
  font-weight: 600;
  font-size: var(--text-sm);
}

.library-apply {
  align-self: flex-start;
}

.recipe-count {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
}

/* Result rows: each row is one link (title, size, facts, tags), 56 px at least. */
.recipe-rows {
  border-bottom: 1px solid var(--border);
}

.recipe-row-link {
  min-height: 3.5rem;
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-sm);
}

.recipe-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.recipe-row-title {
  overflow-wrap: anywhere;
  min-width: 0;
}

.recipe-row.is-archived .recipe-row-title {
  color: var(--muted);
}

.recipe-star {
  flex: 0 0 auto;
  color: var(--warn);
}

.recipe-row-size {
  color: var(--text);
}

.recipe-row-tags {
  grid-column: 1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.tag-more {
  background: none;
  border: 1px solid var(--border);
}

.recipe-rows > .recipe-more {
  padding: var(--space-3) 0;
}

.recipe-more-link {
  display: flex;
  width: 100%;
}

@media (min-width: 64rem) {
  .library-grid {
    grid-template-columns: 18rem minmax(0, 1fr);
    align-items: start;
    gap: var(--space-6);
  }

  .library-filter {
    position: sticky;
    top: var(--space-5);
  }

  .library-chips {
    flex-wrap: wrap;
    overflow: visible;
  }

  .library-chips .chip-input span {
    white-space: normal;
  }

  /* The rail has room: app.js opens "Filters", so its summary has nothing to do. */
  .library-more-filters {
    border-top: 0;
  }

  .library-more-filters[open] > summary {
    display: none;
  }

  /* Cards: a grid of bordered rows. */
  .recipe-rows {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
    gap: var(--space-3);
    border-bottom: 0;
  }

  .recipe-rows > .recipe-row {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-1);
  }

  .recipe-row-link {
    height: 100%;
    align-content: start;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
  }

  .recipe-rows > .recipe-more {
    grid-column: 1 / -1;
    border: 0;
  }

  .recipe-more-link {
    display: inline-flex;
    width: auto;
  }
}

/* ---- The recipe page ---- */

.recipe-head {
  margin: var(--space-2) 0 var(--space-3);
}

.recipe-head .recipe-title {
  margin: 0;
}

.recipe-version-banner,
.recipe-archived-notice {
  margin: 0 0 var(--space-4);
}

.recipe-version-banner a {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

.recipe-upcoming {
  margin: 0;
}

.recipe-upcoming-link {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  font-weight: 600;
}

/* "Makes 4 servings · Prep 15 min · Cook 30 min", tags, the source. */
.recipe-summary {
  margin: 0 0 var(--space-4);
}

.recipe-summary p {
  margin: 0 0 var(--space-2);
}

.recipe-size {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-1);
}

.recipe-makes {
  font-size: var(--text-lg);
  font-weight: 600;
}

.recipe-times {
  color: var(--text-subtle);
}

.recipe-times::before {
  content: "· ";
}

.recipe-source {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--tap);
  overflow-wrap: anywhere;
}

.recipe-facts {
  margin-bottom: var(--space-5);
}

/* 44 px tall to the finger, but on the text baseline (negative margin keeps the row height). */
.recipe-history-link {
  display: inline-block;
  padding: var(--space-3) 0;
  margin: calc(-1 * var(--space-3)) 0;
}

/* Readable steps: a little more air between them. */
.recipe .step {
  padding: var(--space-2) 0 var(--space-3);
  line-height: 1.5;
}

.recipe-steps .step-list {
  padding-left: var(--space-5);
}

/* From 64rem the page grows to 60rem: ingredients in a sticky column beside the steps. */
@media (min-width: 64rem) {
  body.has-tabbar > main.page:has(> .recipe) {
    max-width: calc(60rem + 2 * var(--space-6));
  }

  body.has-tabbar:has(> main > .recipe) > .action-bar {
    padding-inline: max(var(--space-6), calc((100% - 60rem) / 2));
  }

  .recipe-body {
    display: grid;
    grid-template-columns: minmax(16rem, 20rem) minmax(0, 1fr);
    align-items: start;
    gap: var(--space-6);
  }

  .recipe-body > .section + .section {
    margin-top: 0;
  }

  /* The archived and earlier-version notices keep a reading line length. */
  .recipe > .notice {
    max-width: var(--content-reading);
  }

  .recipe-ingredients {
    position: sticky;
    top: var(--space-5);
    max-height: calc(100dvh - var(--space-5) - var(--actionbar-h) - var(--space-6));
    overflow-y: auto;
  }
}

/* The sticky bar: Cook now · Plan this · the star (Restore to plan when archived). */
.recipe-actions form {
  margin: 0;
  display: flex;
}

.recipe-actions form > button,
.recipe-actions > a {
  width: 100%;
}

/* M9a: "Cook instructions" is a second secondary in the recipe bar. On a phone it takes
   its own row under Cook now · Plan this · star, so no label is squeezed; from 40rem the
   bar lays out in one row (app.css). */
@media (max-width: 39.99rem) {
  .recipe-actions {
    flex-wrap: wrap;
  }

  .recipe-actions > .cook-instructions {
    flex: 1 0 100%;
    order: 10;
  }
}

/* M9a: the owner's Instructions check (the step check's warnings). */
.recipe-check h2 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-base);
}

.recipe-check-list {
  margin: 0 0 var(--space-2);
  padding-left: var(--space-5);
}

.recipe-check-hint {
  margin: 0;
  font-weight: 600;
}

/* M9a: the read-only Cook instructions page. It borrows cook.css's pieces (amounts,
   hints, "You need", phase pills) outside cooking mode, at a fixed reading size. */
.instructions {
  --cook-text: 1.05rem;
}

.instructions-title {
  margin-bottom: 0;
}

.instructions-recipe {
  margin: 0 0 var(--space-3);
  color: var(--muted);
}

.instructions-portions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
}

.instructions-portions input {
  width: 6rem;
}

.instructions-ings,
.instructions-plan-prep,
.instructions-plan-early {
  padding-left: var(--space-5);
}

.instructions-ings li,
.instructions-plan-prep li,
.instructions-plan-early li {
  padding: var(--space-1) 0;
  font-size: var(--cook-text);
  line-height: 1.4;
}

.instructions-step-list {
  list-style: none;
  padding: 0;
}

.instructions-step {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border);
  scroll-margin-top: var(--space-6);
}

.instructions-step-title {
  margin: 0;
  font-size: var(--text-base);
}

.instructions-timer {
  margin-left: var(--space-2);
  color: var(--muted);
  font-weight: 400;
}

.star-button.is-starred {
  border-color: var(--warn);
}

.star-button.is-starred .star-icon {
  color: var(--warn);
}

/* Archive at the page bottom (the owner's), or inside a member's "More". */
.recipe-manage {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.recipe-history + .recipe-manage {
  margin-top: var(--space-4);
}

.recipe-more .recipe-manage {
  margin-top: var(--space-4);
  padding-top: 0;
  border-top: 0;
}

.recipe-manage form {
  margin: 0;
}

.recipe-manage-hint {
  margin-top: var(--space-2);
}

/* Version history: the owner's <details class="more" id="versions">, a member's flat list in More. */
.recipe-history .recipe-versions {
  margin-top: 0;
}

.recipe-versions-h {
  font-size: var(--text-base);
  margin: 0 0 var(--space-1);
}

.version-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

.version-row.is-viewed {
  background: var(--surface-selected);
  margin-inline: calc(-1 * var(--space-2));
  padding-inline: var(--space-2);
  border-radius: var(--radius-sm);
}

.version-meta {
  margin: 0;
  flex: 1 1 14rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.version-note {
  color: var(--muted);
}

.version-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.version-actions form {
  margin: 0;
}

.version-view,
.version-viewing {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-2);
}

.version-actions button {
  width: auto;
}

/* ---- Photos (M7): every photo style lives here (base.html links this sheet on every page,
   cook pages included); Home's Today thumb is in home.css. Images always carry width and
   height, so the box is reserved before the bytes arrive; object-fit crops, never stretches. */

/* Recipe rows: the cover thumb (or a neutral block) leads the row on phones. */
.recipe-row-link {
  grid-template-columns: 4.5rem minmax(0, 1fr);
  column-gap: var(--space-3);
}

.recipe-row-link > :not(.photo-thumb, .photo-thumb-empty) {
  grid-column: 2;
}

.recipe-row-link > :is(.photo-thumb, .photo-thumb-empty) {
  grid-column: 1;
  grid-row: 1 / span 4;
  align-self: start;
  width: 4.5rem;
  height: auto;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-hover);
}

.photo-thumb-empty {
  display: block;
  border: 1px solid var(--border);
}

/* The recipe page's header photo: full column width, a fixed box, cropped to fit. */
.photo-hero {
  margin: var(--space-2) 0 var(--space-3);
}

.photo-hero[hidden] {
  display: none;
}

.photo-hero-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface-hover);
}

/* "Your photos": a grid of thumbnails, who and when underneath, the owner's menu on top. */
/* "Your photos" straight after the steps (no "How it went" yet) still gets a section gap. */
.recipe-body + .recipe-photos {
  margin-top: 2rem;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.photo-card {
  position: relative;
  margin: 0;
}

.photo-card-link {
  display: block;
  border-radius: var(--radius-sm);
}

.photo-card-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
}

.photo-card.is-cover .photo-card-img {
  outline: 3px solid var(--brand);
  outline-offset: -3px;
}

.photo-card-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-subtle);
  overflow-wrap: anywhere;
}

.photo-menu {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
}

.photo-menu > summary {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.photo-menu .menu-panel {
  min-width: 9.5rem;
}

.photo-menu form {
  margin: 0;
}

.photo-show {
  margin: var(--space-1) 0 0;
}

.photo-show button {
  width: 100%;
}

.photo-hidden {
  margin-top: var(--space-4);
}

.photo-hidden .photo-card-img {
  opacity: 0.6;
}

.photo-empty {
  margin: 0;
}

/* Mise en place: a small banner above "Get ready". */
.cook-cover {
  display: block;
  width: 100%;
  height: auto;
  max-height: 9rem;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  margin: var(--space-2) 0 0;
  border-radius: var(--radius);
  background: var(--surface-hover);
}

/* The done screen's "Add a photo": the label is the button; the file input stays in the
   form (focusable, required, auto-submitting) but out of sight, its focus ring on the label. */
/* The feedback card above already ends in a divider: no second rule here. */
.photo-add {
  margin: var(--space-4) 0;
}

.photo-add-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
}

.photo-add > .alert,
.photo-add > .notice,
.photo-add-hint {
  margin: 0 0 var(--space-3);
}

.photo-add-form {
  position: relative;
  margin: 0;
}

.photo-add-form .photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  opacity: 0;
}

.photo-input:focus-visible + label {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.photo-add-form.htmx-request label {
  opacity: 0.6;
  pointer-events: none;
}

.photo-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

.photo-strip-link {
  display: block;
  border-radius: var(--radius-sm);
}

.photo-strip-img {
  display: block;
  width: 6rem;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
}

@media (min-width: 40rem) {
  /* Wide: a banner, not a wall (the reading column is wider than a phone's photo). */
  .photo-hero-img {
    aspect-ratio: 16 / 9;
    max-height: min(24rem, 50vh);
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  }
}

/* Cards from 64rem: the photo runs edge to edge across the top. A card without one stays
   text-only (no empty block: a grid of blank tiles reads heavier than the photos). */
@media (min-width: 64rem) {
  .recipe-row-link {
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
  }

  .recipe-row-link > :not(.photo-thumb, .photo-thumb-empty) {
    grid-column: 1;
  }

  .recipe-row-link > :is(.photo-thumb, .photo-thumb-empty) {
    grid-row: auto;
    width: calc(100% + 2 * var(--space-4));
    max-width: none;
    aspect-ratio: 16 / 9;
    margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-4)) var(--space-2);
    border: 0;
    border-radius: 0;
  }

  .recipe-row-link > .photo-thumb-empty {
    display: none;
  }
}
