/* Browse / search results page (results/): search row, filters card, plant grid,
   pagination and the no-results state. Sizes follow the 1440px design. */

.browse {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 56px var(--page-gutter);
}

/* ---------- Arrow icon ----------
   One arrow file serves every colour and direction: it is used as a mask and
   takes the text colour. The file points down; the default here points to the
   inline end (left in this right-to-left page). */
.browse-arrow {
  display: block;
  flex: none;
  width: 9.58px;
  height: 14.58px;
  background: currentColor;
  -webkit-mask: url('../img/ui/i-arrow-right-02.svg') center / 100% 100% no-repeat;
  mask: url('../img/ui/i-arrow-right-02.svg') center / 100% 100% no-repeat;
  transform: rotate(90deg);
}

.browse-arrow--24 {
  width: 11.5px;
  height: 17.5px;
}

.browse-arrow--forward {
  transform: rotate(-90deg);
}

/* ---------- Search row ---------- */
.browse-search {
  display: flex;
  align-items: center;
  gap: 12px;
}

.browse-search__field {
  position: relative;
  display: flex;
  flex: 1 0 0;
  align-items: center;
  gap: 12px;
  min-width: 0;
  height: 48px;
  padding: 0 16px;
  border: 2px solid var(--accent-focus);
  border-radius: var(--radius-md);
  background: var(--bg-white);
}

.browse-search__field:focus-within {
  outline: 2px solid var(--text-default);
  outline-offset: 2px;
}

.browse-search__field .petal {
  inline-size: 20px;
  block-size: 20px;
}

.browse-search__input {
  flex: 1 0 0;
  min-width: 0;
  height: 44px;
  padding: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--text-default);
  font-size: 16px;
  line-height: 24px;
  -webkit-appearance: none;
  appearance: none;
}

.browse-search__input::placeholder {
  color: var(--text-secondary);
  opacity: 1;
}

.browse-search__input::-webkit-search-cancel-button,
.browse-search__input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

/* The design draws the arrow on the search button only in the no-results state. */
.browse-search__arrow {
  display: none;
}

.browse[data-view='empty'] .browse-search__arrow {
  display: inline-flex;
}

/* Suggestions list added by Site.autocomplete(). */
.browse-search .suggestions {
  position: absolute;
  inset-inline: -2px;
  top: calc(100% + 6px);
  z-index: 10;
  max-height: 296px;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-white);
  box-shadow: 0 12px 24px rgba(16, 24, 40, 0.12);
  list-style: none;
}

.browse-search .suggestions li {
  padding: 8px 16px;
  cursor: pointer;
}

.browse-search .suggestions li:hover,
.browse-search .suggestions li[aria-selected='true'] {
  background: var(--accent-surface-soft);
  color: var(--green-700);
}

/* ---------- Body: filters card beside the results ---------- */
.browse-body {
  display: flex;
  /* The filters come first in the document and sit at the inline end in the design. */
  flex-direction: row-reverse;
  align-items: flex-start;
  gap: 32px;
}

.browse[data-view='empty'] .browse-body {
  display: none;
}

.browse-filters {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 24px;
  width: 300px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-white);
}

.browse-filters__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

.browse-filters__title {
  font-size: 18px;
  font-weight: 700;
  line-height: 28px;
}

.browse-filters__clear {
  /* The ink sits 1px lower in the design. */
  position: relative;
  top: 1px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--green-600);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
}

.browse-filters__clear:hover {
  color: var(--green-700);
  text-decoration: underline;
  text-underline-position: from-font;
}

.browse-filters__groups {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.browse-filters__groups:empty {
  display: none;
}

.browse-filters__note {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 20px;
}

.browse-filters__title:focus-visible {
  outline-offset: 4px;
}

/* Below 700px the long letter list folds away (see results.js). */
.filter-group--details {
  display: block;
}

.filter-group--details > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  list-style: none;
  cursor: pointer;
}

.filter-group--details > summary::-webkit-details-marker {
  display: none;
}

.filter-group--details > summary::after {
  content: '';
  flex: none;
  width: 9px;
  height: 5px;
  margin-inline-end: 4px;
  background: currentColor;
  -webkit-mask: url('../img/ui/i-arrow-down-01.svg') center / 100% 100% no-repeat;
  mask: url('../img/ui/i-arrow-down-01.svg') center / 100% 100% no-repeat;
}

.filter-group--details[open] > summary::after {
  transform: rotate(180deg);
}

.filter-group--details > .chip-list {
  margin-top: 12px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-group__label {
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.chip-list > li,
.browse-active > li,
.browse-empty__chips > li {
  max-width: 100%;
  min-width: 0;
}

/* ---------- Chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  /* Half the one-line height, so a long name that wraps keeps the same corners. */
  border-radius: 17px;
  background: var(--bg-white);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  /* Names come from the lexicon: a long one wraps inside its container. */
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chip:hover {
  border-color: var(--green-300);
  background: var(--accent-surface-subtle);
}

.chip .petal {
  inline-size: 10px;
  block-size: 10px;
}

.chip[aria-pressed='true'],
.chip--active {
  border-color: var(--green-300);
  background: var(--accent-surface-soft);
  color: var(--green-700);
  font-weight: 600;
}

.chip[aria-pressed='true']:hover,
.chip--active:hover {
  background: var(--green-200);
}

/* The design's «✕»: 10px wide, 3px after the label. */
.chip__remove {
  display: block;
  flex: none;
  width: 10px;
  height: 10px;
  margin-inline-start: -3px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M.6 .6l8.8 8.8M9.4 .6L.6 9.4' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E")
    center / 100% 100% no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M.6 .6l8.8 8.8M9.4 .6L.6 9.4' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E")
    center / 100% 100% no-repeat;
}

/* ---------- Results column ---------- */
.browse-results {
  display: flex;
  flex: 1 0 0;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.browse-results:focus {
  outline: none;
}

/* Search summary and active-filter chips share the row above the grid. */
.browse-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 34px;
}

.browse-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  overflow-wrap: anywhere;
}

.browse-summary__count {
  color: var(--text-secondary);
  font-weight: 400;
}

.browse-active {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

ul.browse-grid {
  display: grid;
  /* Four cards a row on desktop, whatever the screen width. */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
}

.browse-grid:empty {
  display: none;
}

/* The previous cards stay, dimmed, while the next set loads. */
ul.browse-grid[aria-busy='true'] {
  opacity: 0.5;
  pointer-events: none;
}

.browse-grid > li {
  min-width: 0;
}

.browse .plant-card__title {
  overflow-wrap: anywhere;
}

.browse .plant-card__title a:hover {
  text-decoration: underline;
  text-underline-position: from-font;
}

.browse .plant-card__scientific {
  /* Latin-only lines sit 1px lower in the design than the Latin font file sets them. */
  position: relative;
  top: 1px;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: right;
}

.browse .plant-card__description {
  display: -webkit-box;
  align-self: stretch;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* Takes the spare height, so the actions of a row of cards line up. */
.plant-card__spacer {
  flex: 1 0 8px;
}

/* The spacer above replaces the shared 16px margin. */
.browse .plant-card__action {
  margin-top: 0;
}

/* The label's ink sits 1px lower in the design. */
.browse .plant-card__action > span:first-child {
  position: relative;
  top: 1px;
}

/* Cards are listed before their entries arrive; these bars hold the lines. */
.browse-skel {
  display: block;
  height: 12px;
  margin-block: 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-neutral);
}

.browse-skel--meta {
  width: 120px;
}

.browse-skel--scientific {
  width: 150px;
}

/* Two description lines: 48px, like the loaded card. */
.browse-skel-lines {
  display: block;
  align-self: stretch;
  height: 48px;
}

.browse-skel--text {
  width: 100%;
  margin-block: 6px 12px;
}

.plant-card[aria-busy='true'] .plant-card__media,
.plant-card[aria-busy='true'] .browse-skel {
  animation: browse-pulse 1.2s ease-in-out infinite alternate;
}

@keyframes browse-pulse {
  from {
    opacity: 1;
  }

  to {
    opacity: 0.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  .plant-card[aria-busy='true'] .plant-card__media,
  .plant-card[aria-busy='true'] .browse-skel {
    animation: none;
  }
}

/* Loading, error and "nothing matches these filters" messages. */
.browse-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 240px;
  padding: 40px 24px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-lg);
  background: var(--accent-surface-subtle);
  color: var(--text-paragraph);
  text-align: center;
}

.browse-status__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.browse-status--error {
  border-color: #fecdca;
  background: #fef3f2;
  color: #b42318;
}

.browse-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--green-200);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: browse-spin 0.8s linear infinite;
}

@keyframes browse-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .browse-spinner {
    animation-duration: 2.4s;
  }
}

/* ---------- Pagination ----------
   Runs right to left with the page: previous, 1 2 3 … last, next. */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pagination__item {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  /* 1px lower than centred, as the design draws the digits. */
  padding: 5px 4px 3px;
  border-radius: var(--radius-sm);
  color: var(--text-default);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
}

a.pagination__item:hover {
  background: var(--bg-neutral);
}

.pagination__item[aria-current='page']::after {
  content: '';
  position: absolute;
  top: 22px;
  left: 50%;
  width: 16px;
  /* The design's 3px bar is cut off by the 24px row. */
  height: 2px;
  border-radius: var(--radius-full) var(--radius-full) 0 0;
  background: var(--green-700);
  transform: translateX(-50%);
}

.pagination__item--gap {
  padding: 4px 3px 2px;
  border: 1px solid var(--text-default);
}

.pagination__item--arrow {
  width: 24px;
  padding: 0;
}

/* "Previous" sits on the right and points right, "next" points left. */
.pagination__item--prev img {
  transform: scaleX(-1);
}

.pagination__item--next img {
  transform: rotate(90deg);
}

.pagination__item[aria-disabled='true'] {
  cursor: default;
}

/* ---------- No results ---------- */
.browse-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 64px 40px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-lg);
  background: var(--accent-surface-subtle);
  text-align: center;
}

.browse-empty__mark {
  display: block;
  flex: none;
  width: 120px;
  height: 120px;
  background: var(--green-300);
  -webkit-mask: url('../img/ui/petal-mark.svg') center / 100% 100% no-repeat;
  mask: url('../img/ui/petal-mark.svg') center / 100% 100% no-repeat;
}

.browse-empty__title {
  max-width: 100%;
  font-size: 28px;
  font-weight: 700;
  line-height: 40px;
  overflow-wrap: anywhere;
}

.browse-empty__text {
  width: 560px;
  max-width: 100%;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 28px;
}

.browse-empty__suggestions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.browse-empty__label {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

.browse-empty__chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
  gap: 8px;
  margin: 0;
}

.browse-empty__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding-top: 8px;
}

/* ---------- Narrow screens ---------- */
@media (max-width: 1279px) {
  ul.browse-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  ul.browse-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  ul.browse-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 1100px) {
  .browse-body {
    flex-direction: column;
    align-items: stretch;
  }

  .browse-filters {
    width: auto;
  }

  .browse-results {
    flex: none;
  }
}

@media (max-width: 700px) {
  .browse {
    gap: 24px;
    padding-block: 32px;
  }

  .browse-filters {
    padding: 16px;
  }

  .browse-empty {
    padding: 40px 16px;
  }

  .browse-empty__title {
    font-size: 24px;
    line-height: 34px;
  }
}
