/*
 * core/search
 *  - Content search (e.g. homepage): the large design version. Label as a
 *    heading, full-width field, magnifier icon inside. Tokens: --wp--custom--search--*
 *    (border, icon) + radius.extraLarge + shadow.drop.
 *  - Live search results panel (assets/js/live-search.js), for every search
 *    field. The header search gets a compact panel (see the bottom).
 */

/* ---------- Large content search ---------- */

.wp-block-search:not(.site-header__search) {
  & .wp-block-search__label {
    display: block;
    width: auto;
    margin-block-end: 1.25rem;
    color: var(--wp--preset--color--text);
    font-size: var(--wp--preset--font-size--large);
    font-weight: 400;
    line-height: 1.2;
  }

  & .wp-block-search__inside-wrapper {
    position: relative;
    padding: 0;
    border: var(--wp--custom--search--border);
    border-radius: var(--wp--custom--radius--extra-large);
    background: var(--wp--preset--color--white);
    box-shadow: var(--wp--preset--shadow--drop);
    transition: box-shadow 0.2s ease;
  }
  & .wp-block-search__inside-wrapper:focus-within {
    outline: 3px solid color-mix(in srgb, var(--wp--custom--search--icon) 35%, transparent);
    outline-offset: 2px;
  }

  & .wp-block-search__input {
    min-height: 3.25rem;
    margin: 0;
    padding: 0.9rem 3.75rem 0.9rem 1.5rem;
    border: 0;
    border-radius: inherit;
    background: transparent;
    color: var(--wp--preset--color--text);
    font-size: var(--wp--preset--font-size--normal);
  }
  & .wp-block-search__input:focus {
    outline: none;
  }
  & .wp-block-search__input::placeholder {
    color: color-mix(in srgb, var(--wp--preset--color--text) 60%, transparent);
  }

  /* The button becomes just the magnifier icon inside the field. */
  & .wp-block-search__button {
    position: absolute;
    top: 50%;
    right: 0.6rem;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--wp--custom--search--icon);
    font-size: 0; /* hide the text, keep it for screen readers */
    transform: translateY(-50%);
    cursor: pointer;

    & svg {
      display: none;
    }
    &::before {
      content: '';
      width: 1.6rem;
      height: 1.6rem;
      background: currentColor;
      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='10' cy='10' r='6.5'/%3E%3Cpath d='m15 15 6 6'/%3E%3C/svg%3E") center / contain no-repeat;
    }
    &:hover {
      background: color-mix(in srgb, var(--wp--custom--search--icon) 10%, transparent);
    }
  }
}

/* ---------- Live search results ---------- */

.wp-block-search.has-live-search {
  position: relative;
}

.arbo-live-search {
  position: absolute;
  z-index: 60;
  top: calc(100% + 0.5rem);
  inset-inline: 0;
  overflow: hidden;
  border-radius: var(--wp--custom--radius--medium);
  background: var(--wp--preset--color--white);
  color: var(--wp--preset--color--text);
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.16);
  font-size: var(--wp--preset--font-size--normal);
  text-align: start;
  animation: arbo-live-search-in 0.16s ease-out;

  &[hidden] {
    display: none;
  }
  &.is-loading .arbo-live-search__list {
    opacity: 0.55;
  }
}
@keyframes arbo-live-search-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .arbo-live-search {
    animation: none;
  }
}

.arbo-live-search__list {
  max-height: min(26rem, 60vh);
  margin: 0;
  padding: 0.4rem 0;
  overflow-y: auto;
  list-style: none;
  transition: opacity 0.15s ease;

  &:empty {
    display: none;
  }

  & a {
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    column-gap: 1rem;
    row-gap: 0.1rem;
    padding: 0.6rem 1.25rem;
    color: inherit;
    text-decoration: none;
  }
  & [aria-selected='true'] a,
  & a:hover {
    background: var(--wp--preset--color--background-medium);
  }
}

/* Type label: a small tag in the left column, so the level is clear at a glance. */
.arbo-live-search__label {
  grid-row: span 3;
  align-self: start;
  justify-self: start;
  margin-top: 0.1rem;
  padding: 0.15em 0.55em;
  border-radius: var(--wp--custom--radius--small);
  background: color-mix(in srgb, var(--wp--preset--color--text) 10%, transparent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  max-width: 100%;
}
[data-type='thema'] .arbo-live-search__label {
  background: var(--wp--preset--color--primary);
  color: var(--wp--preset--color--white);
}
[data-type='werkzaamheid'] .arbo-live-search__label {
  background: var(--wp--preset--color--accent);
  color: var(--wp--preset--color--white);
}

.arbo-live-search__title {
  font-weight: 600;
  line-height: 1.3;

  & mark {
    background: none;
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--wp--custom--search--results-accent, var(--wp--preset--color--accent));
    text-decoration-thickness: 2px;
    text-underline-offset: 0.15em;
  }
}

.arbo-live-search__context,
.arbo-live-search__snippet {
  font-size: var(--wp--preset--font-size--small);
  line-height: 1.4;
  opacity: 0.8;
}
.arbo-live-search__snippet {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.arbo-live-search__snippet mark {
  background: color-mix(in srgb, var(--wp--preset--color--accent) 18%, transparent);
  color: inherit;
}

.arbo-live-search__status {
  margin: 0;
  padding: 0 1.25rem;
  font-size: var(--wp--preset--font-size--small);
  opacity: 0.75;

  /* Count is for screen readers only; "no results" is shown. */
  &:not(.is-empty) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  &.is-empty {
    padding-block: 1rem 0.25rem;
  }
}

.arbo-live-search__all {
  display: block;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--wp--preset--color--background-medium);
  color: inherit;
  font-size: var(--wp--preset--font-size--small);
  font-weight: 600;
  text-decoration: none;

  &::after {
    content: ' →';
  }
  &:hover,
  &:focus-visible {
    background: var(--wp--preset--color--background-medium);
  }
}

/* ---------- Search results page (blocks/search-results): same list, static ---------- */

.arbo-search-results__count {
  margin: 2rem 0 0.75rem;
  font-size: var(--wp--preset--font-size--small);
  opacity: 0.8;
}

.arbo-live-search--static {
  position: static;
  animation: none;
  box-shadow: var(--wp--preset--shadow--drop), 0 0 0 1px color-mix(in srgb, var(--wp--preset--color--text) 10%, transparent);

  & .arbo-live-search__list {
    max-height: none;
    overflow: visible;
    padding-block: 0.5rem;
  }
  & .arbo-live-search__list a {
    padding-block: 0.85rem;
  }
  & .arbo-live-search__list li + li {
    border-top: 1px solid color-mix(in srgb, var(--wp--preset--color--text) 8%, transparent);
  }
  & .arbo-live-search__title {
    font-size: var(--wp--preset--font-size--normal-medium);
  }
  & .arbo-live-search__snippet {
    -webkit-line-clamp: 3;
    line-clamp: 3;
  }
}

/* ---------- Header search: compact panel, aligned right ---------- */

.site-header__search .arbo-live-search {
  inset-inline: auto 0;
  width: min(30rem, 100vw - 2rem);
  font-size: var(--wp--preset--font-size--small);
}
.site-header__search .arbo-live-search__list a {
  grid-template-columns: 6.5rem 1fr;
  padding-block: 0.5rem;
}

@media (max-width: 600px) {
  .arbo-live-search__list a {
    grid-template-columns: 1fr;
  }
  .arbo-live-search__label {
    grid-row: auto;
  }
}
