/* ==========================================================================
   Phase 8.4: the recipe feed — cards (label, time, difficulty, one link), category chips,
   the «Фильтры» sheet, «Для вас», site promo cards, «Показать ещё», empty result and
   search suggestions. Loaded only on the feed (templates/recipes/feed.html).
   Tokens from site.css; logical properties only (RTL).
   ========================================================================== */

/* ---------- Card links: the title is the only link, its ::after covers the card ---------- */
.card-linked {
  position: relative;
}

.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}

.card-link:focus-visible {
  outline: none;
}

.card-link:focus-visible::after {
  outline: var(--focus-ring);
  outline-offset: -3px;
}

/* Controls inside a linked card (like button) stay clickable above the overlay. */
.card-above-link {
  position: relative;
  z-index: 2;
}

.card-title {
  margin: 0;
  font-size: inherit;
  line-height: inherit;
}

@media (hover: hover) {
  .card-linked:hover .card-link {
    color: var(--accent);
  }
}

.mobile-post--recipe .mobile-post-body--recipe {
  gap: var(--space-2);
}

/* One column that never grows past the screen (a long reader name is cut with «…»). */
.mobile-scroll,
.mobile-post-body--recipe,
.desktop-tile-body--recipe {
  grid-template-columns: minmax(0, 1fr);
}

/* ---------- Time and difficulty ---------- */
.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
}

.card-meta__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.card-meta__icon {
  width: 16px;
  height: 16px;
}

.difficulty-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.difficulty-bars i {
  display: block;
  width: 4px;
  border-radius: 1px;
  background: var(--line);
}

.difficulty-bars i:nth-child(1) { height: 6px; }
.difficulty-bars i:nth-child(2) { height: 10px; }
.difficulty-bars i:nth-child(3) { height: 14px; }

.difficulty-bars--1 i:nth-child(-n + 1),
.difficulty-bars--2 i:nth-child(-n + 2),
.difficulty-bars--3 i:nth-child(-n + 3) {
  background: currentColor;
}

/* ---------- «Рецепт Любы» / «От читателя» ---------- */
.card-byline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.card-label {
  flex: none;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  line-height: 1.5;
  white-space: nowrap;
}

.card-label--lyuba {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.card-label--reader {
  background: var(--surface-2);
  color: var(--muted);
}

.card-byline__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}

/* ---------- «Фильтры» + category chips (horizontal scroll) in one row ---------- */
.feed-filterbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-block: 0 var(--space-3);
}

.feed-filterbar__filters {
  flex: none;
  gap: var(--space-2);
  padding-inline: var(--space-3) var(--space-4);
  white-space: nowrap;
}

.feed-filterbar__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding-inline: 6px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--fs-xs);
}

.feed-cats {
  flex: 1 1 auto;
  min-width: 0;
}

.feed-cats__list {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: 3px 3px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

.feed-cats__list::-webkit-scrollbar {
  display: none;
}

.feed-chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  text-decoration: none;
}

.feed-chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

@media (hover: hover) {
  .feed-chip:not(.is-active):hover {
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    color: var(--accent-deep);
  }
}

/* ---------- Found count and removable chips of the filters that are on ---------- */
.feed-found {
  margin: 0 0 var(--space-2);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

.feed-active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

.feed-active__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: var(--target-min);
  padding-inline: 14px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-decoration: none;
}

.feed-active__chip .icon {
  width: 18px;
  height: 18px;
}

.feed-active__reset {
  display: inline-flex;
  align-items: center;
  min-height: var(--target-min);
  padding-inline: 8px;
  color: var(--accent-deep);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
}

/* ---------- The «Фильтры» sheet: bottom sheet on phones, a centred dialog on wide screens ---------- */
.feed-sheet {
  width: 100%;
  max-width: 560px;
  max-height: min(92dvh, 820px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

/* Without JavaScript (?filters=1) the dialog is open in the page flow. */
.feed-sheet[open]:not(:modal) {
  position: static;
  margin: 0 0 var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.feed-sheet[open]:not(:modal) .feed-sheet__actions {
  position: static;
}

.feed-sheet::backdrop {
  background: var(--scrim);
}

html:has(.feed-sheet:modal) {
  overflow: hidden;
}

.feed-sheet__inner {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) calc(var(--space-4) + var(--safe-bottom));
}

.feed-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.feed-sheet__head h2 {
  margin: 0;
  font-size: var(--fs-xl);
  line-height: 1.2;
}

.feed-sheet__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--target);
  height: var(--target);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink);
}

.feed-sheet__group {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.feed-sheet__group legend {
  padding: 0;
  margin-block-end: var(--space-2);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
}

.feed-sheet__options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.feed-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 6px 16px;
  border: 1.5px solid var(--field);
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  cursor: pointer;
}

.feed-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.feed-option:has(input:checked) {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.feed-option:has(input:focus-visible) {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.feed-sheet__note {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.45;
}

/* The buttons stay in view while the options scroll. */
.feed-sheet__actions {
  position: sticky;
  inset-block-end: 0;
  z-index: 1;
  display: flex;
  gap: var(--space-2);
  margin-inline: calc(-1 * var(--space-4));
  padding: var(--space-3) var(--space-4) calc(var(--space-4) + var(--safe-bottom));
  margin-block-end: calc(-1 * (var(--space-4) + var(--safe-bottom)));
  border-block-start: 1px solid var(--line);
  background: var(--surface);
}

.feed-sheet__actions .btn {
  flex: none;
  padding-inline: 14px;
  white-space: nowrap;
}

.feed-sheet__actions .btn-primary {
  flex: 1 1 0;
  min-width: 0;
  white-space: normal;
  overflow-wrap: normal;
}

@media (min-width: 700px) {
  .feed-sheet {
    margin: auto;
    border-radius: var(--radius-xl);
  }
}

/* ---------- «Для вас» ---------- */
.for-you {
  margin-block: var(--space-2) var(--space-4);
}

.for-you__title {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-lg);
  line-height: 1.25;
}

.for-you__list {
  display: flex;
  gap: var(--space-3);
  margin: 0 -4px;
  padding: 2px 4px 8px;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.for-you__list::-webkit-scrollbar {
  display: none;
}

.for-you__item {
  flex: 0 0 132px;
  display: grid;
  align-content: start;
  gap: 6px;
  scroll-snap-align: start;
  border-radius: var(--radius-md);
}

.for-you__media {
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.for-you__media picture,
.for-you__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.for-you__placeholder {
  display: block;
  width: 100%;
  height: 100%;
}

.for-you__name {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: 1.3;
}

.for-you__name .card-link {
  /* The whole card is the target (::after); the title itself is still at least 44 px tall. */
  min-height: var(--target-min);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  color: var(--ink);
  text-decoration: none;
}

.for-you .card-meta {
  font-size: var(--fs-xs);
}

@media (min-width: 861px) {
  .for-you__item {
    flex-basis: 180px;
  }
}

/* ---------- The site's own cards in the feed ---------- */
.site-promo {
  position: relative;
  display: grid;
  gap: var(--space-3);
  align-content: start;
  justify-items: start;
  padding: var(--space-4);
  border: 1.5px dashed var(--field);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.site-promo--mobile {
  margin: var(--space-3) 0;
}

.site-promo__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  padding-inline-end: calc(var(--target) - var(--space-2));
}

.site-promo__icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.site-promo__title {
  margin: 0;
  min-width: 0;
  font-size: var(--fs-lg);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.site-promo__text {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.45;
}

.site-promo__cta {
  max-width: 100%;
}

.site-promo__hide {
  position: absolute;
  inset-block-start: var(--space-1);
  inset-inline-end: var(--space-1);
  margin: 0;
}

.site-promo__hide-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--target);
  height: var(--target);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

@media (hover: hover) {
  .site-promo__hide-btn:hover {
    background: var(--surface);
    color: var(--ink);
  }
}

/* ---------- «Показать ещё» ---------- */
.feed-more {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  margin-block: var(--space-4) var(--space-2);
}

.feed-more__btn {
  width: 100%;
  max-width: 360px;
}

.feed-more__btn[aria-busy="true"] {
  opacity: 0.7;
  cursor: progress;
}

.feed-more__status {
  min-height: 1.4em;
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-align: center;
}

.feed-more__status:empty {
  min-height: 0;
}

/* ---------- Empty result ---------- */
.feed-empty {
  display: grid;
  gap: var(--space-3);
  margin-block: var(--space-2) var(--space-4);
}

.feed-empty h2,
.feed-empty p {
  margin: 0;
  overflow-wrap: anywhere;
}

.feed-empty h2 {
  font-size: var(--fs-xl);
  line-height: 1.25;
}

.feed-empty__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.feed-empty__actions:empty {
  display: none;
}

.feed-empty__subtitle {
  margin: var(--space-2) 0 0;
  font-size: var(--fs-md);
}

.feed-empty__cats {
  flex-wrap: wrap;
  overflow: visible;
  padding: 0;
}

/* ---------- Search suggestions (ARIA combobox, static/js/feed_search.js) ---------- */
.feed-search {
  position: relative;
}

.feed-suggest {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline: -1.5px;
  z-index: 40;
  display: grid;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  max-height: min(60dvh, 420px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.feed-suggest[hidden] {
  display: none;
}

.feed-suggest__option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.3;
  cursor: pointer;
}

.feed-suggest__option .icon {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.feed-suggest__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.feed-suggest__kind {
  flex: none;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}

.feed-suggest__option[aria-selected="true"] {
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--accent);
}

html[dir="rtl"] .feed-suggest__option[aria-selected="true"] {
  box-shadow: inset -3px 0 0 var(--accent);
}

@media (hover: hover) {
  .feed-suggest__option:hover {
    background: var(--surface-2);
  }
}

.feed-suggest__option mark {
  background: none;
  color: inherit;
  font-weight: var(--fw-bold);
}

/* Phones: the list takes the whole width of the header bar, not only the narrow field. */
@media (max-width: 860px) {
  .feed-search {
    position: static;
  }

  .feed-suggest {
    inset-inline: 0;
  }
}

/* Narrow phones: with text in the field the magnifier gives way to the field (the keyboard's
   search key submits), so the typed query stays readable next to the clear button. */
@media (max-width: 360px) {
  .feed-search:has(.feed-search__input:not(:placeholder-shown)) .feed-search__btn--submit {
    display: none;
  }
}
