/*
 * «Избранное» (phase 8.4): chips «Все» + lists, the list page, the «Сохранить в…» sheet and the
 * inline note after a save (templates/saved/*, static/js/saved_lists.js). Linked by the saved
 * pages and by templates/saved/_save_sheet.html. Site tokens only (site.css); logical
 * properties for RTL; every control is at least 48 px (chips 44 px, the minimum).
 */
.saved [hidden],
.save-sheet [hidden],
.save-note [hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ chips */
.saved-chips {
  min-width: 0;
  margin-inline: calc(-1 * var(--space-1));
}

.saved-chips__list {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  /* Swiped on phones; from 861 px the chips wrap (below), so no scrollbar is needed. */
  scrollbar-width: none;
}

.saved-chips__list::-webkit-scrollbar {
  display: none;
}

.saved-chips__list > li {
  flex: none;
}

.saved-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  /* Long list names end with «…» here (the full name: title, the list page, the sheet). */
  max-width: min(18rem, 80vw);
  min-height: var(--target-min);
  padding-inline: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.saved-chip__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-chip__count {
  flex: none;
  color: var(--muted);
  font-weight: var(--fw-regular);
}

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

.saved-chip.is-current .saved-chip__count {
  color: inherit;
  opacity: 0.8;
}

.saved-chip--new {
  border-style: dashed;
  border-color: var(--field);
  color: var(--accent-deep);
}

.saved-chip--new .icon {
  width: 18px;
  height: 18px;
}

@media (hover: hover) {
  .saved-chip:not(.is-current):hover {
    border-color: var(--ink);
  }
}

.saved-chip:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* Wide screens: the chips wrap instead of scrolling. */
@media (min-width: 861px) {
  .saved-chips__list {
    flex-wrap: wrap;
    overflow: visible;
  }
}

/* ------------------------------------------------------------------ cards */
.saved-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.saved-card__lists {
  padding: 6px 12px;
  font-size: var(--fs-sm);
}

/* ------------------------------------------------------------------ list page */
.saved-list-head {
  display: grid;
  gap: var(--space-2);
}

.page-shell .saved-list-head__count {
  margin: 0;
  font-size: var(--fs-sm);
}

.saved-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.saved-tool[open] {
  flex-basis: 100%;
}

.saved-tool__summary {
  list-style: none;
  padding: 6px 14px;
  font-size: var(--fs-sm);
}

.saved-tool__summary::-webkit-details-marker {
  display: none;
}

.saved-tool[open] > .saved-tool__summary {
  border-color: var(--ink);
}

.saved-tool .saved-form {
  margin-block-start: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

/* ------------------------------------------------------------------ forms (new list, rename, no-JS sheet) */
.saved--narrow {
  max-width: 34rem;
}

.saved-form {
  display: grid;
  gap: var(--space-2);
  justify-items: start;
  margin: 0;
}

.saved-form__label {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
}

.saved-form__input,
.save-sheet__input {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--target);
  padding: 10px 14px;
  border: 1.5px solid var(--field);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-md);
}

.saved-form__input:focus-visible,
.save-sheet__input:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 1px;
}

.saved-form__input[aria-invalid="true"] {
  border-color: var(--accent-deep);
}

.page-shell .saved-form__note,
.page-shell .saved-form__error {
  margin: 0;
  font-size: var(--fs-sm);
}

.saved-form__error {
  color: var(--accent-deep);
  font-weight: var(--fw-semibold);
}

.saved-form__danger {
  border-color: var(--accent-deep);
  color: var(--accent-deep);
}

/* ------------------------------------------------------------------ the «Сохранить в…» sheet */
.save-sheet {
  box-sizing: border-box;
  width: 100%;
  max-width: 480px;
  max-height: min(88dvh, 720px);
  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);
}

/* The dialog box itself may take focus (a click on its text); only its controls show the ring. */
.save-sheet:focus,
.save-sheet:focus-visible {
  outline: none;
}

.save-sheet::backdrop {
  background: rgb(20 10 15 / 0.45);
}

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

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

.save-sheet__title {
  margin: 0;
  font-size: var(--fs-xl);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.save-sheet__close {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: var(--target);
  height: var(--target);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}

.save-sheet__close .icon {
  width: 22px;
  height: 22px;
}

.save-sheet__muted {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.save-sheet__lists {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.save-sheet__rows {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: min(42dvh, 22rem);
  overflow-y: auto;
}

.save-sheet__row + .save-sheet__row {
  border-block-start: 1px solid var(--line);
}

.save-sheet__option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--target);
  padding-block: var(--space-1);
  cursor: pointer;
}

.save-sheet__check {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.save-sheet__check:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.save-sheet__name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: var(--fw-semibold);
}

.save-sheet__count {
  flex: none;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.save-sheet__new {
  display: grid;
  gap: var(--space-2);
  margin: 0;
}

.save-sheet__label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

.save-sheet__new-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.save-sheet__new-row .save-sheet__input {
  flex: 1 1 10rem;
  width: auto;
  min-width: 0;
}

.save-sheet__create {
  flex: none;
}

.save-sheet__status {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.save-sheet__status:empty {
  display: none;
}

.save-sheet__done {
  width: 100%;
}

.save-sheet__close:focus-visible,
.save-sheet__done:focus-visible,
.save-sheet__create:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

html:has(.save-sheet[open]) {
  overflow: hidden;
}

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

/* ------------------------------------------------------------------ the note after a save */
.save-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-block: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.4;
  animation: save-note-in 160ms ease-out;
}

.save-note__text {
  flex: 1 1 12rem;
  margin: 0;
  min-width: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.save-note__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.save-note__btn {
  min-height: var(--target-min);
  padding: 6px 14px;
  font-size: var(--fs-sm);
}

.save-note__btn--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.save-note__btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* In a slot (the recipe header, a card body) the note takes a whole row of the grid or flex box. */
[data-save-slot] > .save-note {
  grid-column: 1 / -1;
  flex-basis: 100%;
}

@keyframes save-note-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .save-note {
    animation: none;
  }
}
