/**
 * SEARCH: HOMEPAGE BLOCK
 */

#block-taxa-search-block {

  /* All items wrapper */
  & .taxa-search-fieldset .fieldset-wrapper {
    display: grid;
    grid-template-columns: auto auto 160px;
    grid-template-rows: auto auto auto;
    gap: 0.5rem;
    grid-template-areas:
      "input input categories"
      "search search search";

    > .form-item.form-type-textfield {
      grid-area: input;
      grid-column: 1 / 4;
      #edit-query--description {
        display: none;
      }
      #edit-query {
        margin: 0;
        width: 100%;
        padding-right: 165px;
        &::placeholder {
          width: auto; /* Just show "Search label" */
        } 
      }
    }
    > .form-item.form-type-select {
      grid-area: categories;
      height: fit-content;
    }
    > input[type="submit"].search-btn--icon {
      grid-area: search;
      grid-column: 1 / 4;
    }

    @media (min-width: 758px) {
      grid-template-areas: 
        "input categories search";
      grid-template-columns: auto 160px 140px;

      > .form-item.form-type-textfield {
        #edit-query--description {
          display: block;
        }
        #edit-query {
          width: calc(100% - 160px);
        }
      }

      &.taxa-search-form #edit-query {
        width: calc(100% - 160px);
      }

      > input[type="submit"].search-btn--icon {
        grid-column: 3;
        top: 0;
      }
    }
  }

  /* Make sure inputs/selects align */
  & .taxa-search-fieldset .form-item-query input,
  & .taxa-search-fieldset .form-item-type select {
    box-sizing: border-box;
  }

  /* The 'All categories' select */
  & .taxa-search-fieldset .form-item-type select.taxa-search-type {
    grid-area: categories;
    font-family: 'Open Sans';
    font-size: 1rem;
    font-weight: var(--font-weight-semibold);
    right: 0; /* Search button width + margin */
    height: 30px;
    border: none;
    border-left: 2px solid var(--border-grey);
    background: none;
    /* Custom arrow */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23333' stroke-width='1.5'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.5rem;
    padding-left: 0.5rem;
    padding-right: 2.5rem; 
    margin: 10px 0;

    &:hover {
      outline: none;
    }

    &::-ms-expand {
      /* Custom dropdown arrow in use */
      display: none;
    }
  }

  /* Homepage search has 'Search' and not icon */
  & input[type="submit"].search-btn--icon {
    font-family: inherit;
    font-size: 1rem;
    margin: 0 auto;
    width: 100%;
    height: 50px;
    background: var(--secondary-green);
    color: white;
    font-weight: var(--font-weight-strong);
    top: 0.25rem;
    border-radius: var(--border-radius);
    transition: 0.3s;
    position: relative;

    &:hover {
      background: var(--mid-green);
      cursor: pointer;
    }
  }
}

/**
 * SEARCH: FILTERS
 */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.list-view-header,
.results-toggle {
  display: none;
}

input[type="submit"].search-btn--icon {
  background: none;
  border: none;
  font-family: 'Material Symbols Outlined';
  font-style: normal;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  font-size: 2rem;
  top: 0.5rem;
  right: 0;
  position: absolute;
}

input[type="submit"].clear-btn--icon {
  display: none;
  background: none;
  border: none;
  font-family: 'Material Symbols Outlined';
  font-style: normal;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  font-size: 2rem;
  top: 0.5rem;
  right: 2rem;
  position: absolute;
}

/* Conservation Status Filter Container */
.results-filters {
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  height: fit-content;
  position: relative;

  &.initialized {
    animation: slideDown 0.3s ease-out;
  }

  & > h3 {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 1.85rem;
    position: relative;

    &::after {
      content: '\e316';
      font-family: 'Material Symbols Outlined';
      font-style: normal;
      font-weight: 400;
      -webkit-font-smoothing: antialiased;
      font-size: 2rem;
      right: 0;
      position: absolute;
      transition: transform 0.3s ease;
    }

    &.is-collapsed::after {
      transform: rotate(180deg);
    }
  }

  & .filter-label {
    text-transform: uppercase;
    color: var(--secondary-green);
    font-size: 1.25rem;
    width: 100%;
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Filter Wrapper */
.filter-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;

  & input[type='checkbox'] {
    width: 25px;
    height: 40px;
    cursor: pointer;
    vertical-align: middle;
    margin: 0 0.5rem;

    &:checked {
      accent-color: var(--main-green);
    }
  }

  /* Checkbox label */
  & label {
    font-size: 1.15rem;
    font-weight: 400;
    color: #495057;
    margin-bottom: 0;
    white-space: break-spaces;
    width: 100%;
    display: inline-block;
    padding-bottom: 0.5rem;
  }

  & > div[class$="-checkboxes"] {
    width: 100%;
  }

  & .item-count {
    color: var(--border-grey);
    margin-left: 0.5rem;
  }
}

/* 'Clear filters' */
.clear-filter-btn {
  background: none;
  border: none;
  font-size: 1rem;
  text-decoration: underline;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  margin-bottom: 1rem;

  &:hover {
    transform: translateY(-1px);
  }

  &:active {
    transform: translateY(0);
  }

  &:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
  }
}

/* Applied filters */
.filter-indicator {
  animation: fadeIn 0.3s ease-out;
  margin-bottom: 1rem;

  & ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;

    & li {
      padding: 0.25rem 0.5rem;
      border: 1px solid var(--secondary-green);
      width: fit-content;
      border-radius: 20px;
      font-size: 0.8rem;
      color: var(--secondary-green);

      &:after {
        content: 'x';
        margin-left: 0.5rem;
      }
    }
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/**
 * SEARCH: RESULTS
 */

.taxa-search-results .results-wrap {
  display: grid;
  grid-template-columns: 1fr;

  @media (min-width: 992px) {
    grid-template-columns: minmax(200px, 30%) 1fr;
    gap: 2rem;
  }
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 1fr);
  background: #ffffff;
  height: fit-content;

  &.list-view {
    .no-export {
      display: none;
    }
  }

  & > h2 {
    margin-bottom: 1rem;
  }

  & .results-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
  }

  & .result-count {
    width: fit-content;
    margin: 0;
    margin-right: auto;
    padding: 0;
  }

  & .results-toggle {
    border: 1px solid var(--border-grey);
    border-radius: var(--border-radius);
    width: fit-content;
    padding: 0.5rem;

    & a.list-display,
    & a.grid-display {
      font-size: 0;
      cursor: pointer;
    }

    & a.grid-display {
      padding-left: 0.25rem;
      margin-left: 0.25rem;
      border-left: 1px solid var(--border-grey);
    }

    & a.list-display::before {
      content: '\f0c9';
      -webkit-font-smoothing: antialiased;
      font-family: 'Font Awesome 7 Free';
      font-weight: 900;
      font-size: 1.35rem;
      color: var(--mid-green);
      display: inline-block;
      width: 1.5rem;
      text-align: center;
      transition: 0.2s;
    }

    & a.grid-display::before {
      content: '\f0ca';
      -webkit-font-smoothing: antialiased;
      font-family: 'Font Awesome 7 Free';
      font-weight: 900;
      font-size: 1.35rem;
      color: var(--mid-green);
      display: inline-block;
      width: 1.5rem;
      text-align: center;
      transition: 0.2s;
    }

    & a.list-display:hover::before,
    & a.grid-display:hover::before {
      color: black;
    }
  }

  &:not(:has(.result-card:not(.filtered-out))) .export-list {
    pointer-events: none;
    cursor: default;
    color: var(--border-grey);
    border: 2px solid var(--border-grey);
    text-decoration: none;

    &::after {
      color: var(--border-grey);
    }
  }

  @media (min-width: 768px) {

    & .results-toggle {
      display: flex;
    }

    &.list-view {
      grid-template-columns: 1fr;

      & .list-view-header {
        display: grid;
        grid-template-columns: 2fr 2fr 1.5fr 1.5fr 2fr;
        gap: 0 1rem;
        padding: 0 1rem 0.5rem 1rem;
        border-bottom: 1px solid var(--border-grey);

        & > div {
          font-size: 0.85rem;
          text-transform: uppercase;
          color: grey;
          margin-bottom: 0;

          &:last-of-type {
            margin-left: auto;
          }
        }
      }

      & .result-cards {
        border: 1px solid var(--border-grey);
        border-radius: var(--border-radius);
        padding: 1rem;
      }

      & .result-card {
        grid-template-columns: 2fr 2fr 1.5fr 1.5fr 2fr;
        grid-template-rows: min-content auto;
        grid-template-areas: 
          "sci-name common-name taxonomic-group date-effective labels"
          "sci-name common-name taxonomic-group date-effective additional-labels";
        align-items: start;
        gap: 0 1rem;
        border: none;
        border-radius: 0;
        border-bottom: 1px solid var(--border-grey);
        padding: 1rem;
        margin-bottom: 0;
        min-height: auto;

        &:last-of-type {
          border-bottom: none;
        }

        &:hover {
          box-shadow: none;
        }

        & .result-card-content {
          display: contents;
        }

        & .result-card-labels {
          display: contents;
          flex-direction: column;
          gap: 0.25rem;
          grid-area: labels;

          & > div[class*="label-"] {
            grid-area: labels;
            margin-left: auto;
            margin-bottom: 0.65rem;
          }

          &:has(> div[class*="label-"]) .additional-labels {
            grid-area: additional-labels;
          }
        }

        & .display-image {
          display: none;
        }

        & .sci-name {
          grid-area: sci-name;
          font-size: 1rem;
        }

        & .common-name {
          grid-area: common-name;
          font-size: 1rem;
        }

        & .taxonomic-group {
          grid-area: taxonomic-group;
          font-size: 0.85rem;
        }

        & .date-effective {
          grid-area: date-effective;
          margin: 0;
          padding: 0;
          text-align: left;
        }

        & .additional-labels {
          grid-area: labels;
          margin: 0;
        }
      }
    }
  }
}

.export-list {
  font-size: 0.9rem;
  width: fit-content;
  border: 2px solid var(--mid-green);
  border-radius: var(--border-radius);
  padding: 0.5rem;
  text-transform: uppercase;
  font-weight: var(--font-weight-semibold);
  transition: 0.1s;
  cursor: pointer;
  min-width: 125px;

  &::after {
    content: '\f1c6';
    -webkit-font-smoothing: antialiased;
    font-family: 'Font Awesome 7 Free';
    font-weight: normal;
    font-size: 1.15rem;
    color: var(--mid-green);
    display: inline-block;
    width: 1.5rem;
    text-align: center;
    margin-left: 0.25rem;
    transition: 0.1s;
  }

  &:hover,
  &:hover::after {
    color: black;
    border-color: black;
  }
}

.api-btn {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  width: fit-content;
  border: 2px solid var(--mid-green);
  border-radius: var(--border-radius);
  padding: 0.45rem;
  text-transform: uppercase;
  text-decoration: none;
  font-weight: var(--font-weight-semibold);
  transition: 0.1s;
  cursor: pointer;
  min-width: 125px;

  &::after {
    font-family: 'Material Symbols Outlined';
    content: '\f1b7';
    font-style: normal;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    font-size: 1.15rem;
    margin-left: 0.25rem;
    transition: 0.1s;
  }

  &:hover,
  &:hover::after {
    color: black;
    border-color: black;
  }
}

.result-card {
  border: 1px solid var(--border-grey);
  border-radius: var(--border-radius);
  position: relative;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: 1fr;
  -webkit-transition: box-shadow 0.3s;
  -khtml-transition: box-shadow 0.3s;
  -moz-transition: box-shadow 0.3s;
  -ms-transition: box-shadow 0.3s;
  -o-transition: box-shadow 0.3s;
  transition: box-shadow 0.3s;

  &:hover {
    -webkit-box-shadow: 5px 5px 5px 0 rgba(0, 112, 150, 0.2);
    -khtml-box-shadow: 5px 5px 5px 0 rgba(0,112,150,0.2);
    -moz-box-shadow: 5px 5px 5px 0 rgba(0,112,150,0.2);
    -ms-box-shadow: 5px 5px 5px 0 rgba(0,112,150,0.2);
    -o-box-shadow: 5px 5px 5px 0 rgba(0,112,150,0.2);
    box-shadow: 5px 5px 5px 0 rgba(0, 112, 150, 0.2);
  }

  & .result-card-content {
    padding: 1rem;
    align-content: center;
  }

  & img.display-image {
    display: none;
  }

  & .result-card-labels {

    & div[class*="label-"] {
      padding: 0.2rem 0.35rem;
      margin-left: 1rem;
      border-radius: 6px;
      font-size: var(--label-font-size);
      width: fit-content;
    }

    & .additional-labels {
      display: flex;
      margin-bottom: 1rem;
    }

    & .date-effective {
      margin: 0.5rem 1rem;
      padding: 0.25rem 0;
      font-size: var(--label-font-size);
      color: grey;
      text-transform: uppercase;
    }
  }

  & .result-field:nth-child(2) {
    grid-area: 1 / 1;
  }

  & .result-field:nth-child(3) {
    grid-area: 2 / 1;
  }

  & .result-field:nth-child(4) {
    grid-area: 1 / 2;
  }

  & .result-field:nth-child(5) {
    grid-area: 2 / 2;
  }

  & .result-field:nth-child(6) {
    grid-area: 3 / 2;
  }

  @media (min-width: 768px) {
    grid-template-columns: 180px 1fr 220px;
    min-height: 180px;

    & img.display-image {
      display: block;
      border-radius: var(--border-radius) 0 0 var(--border-radius);
      width: 180px;
      height: 100%;
      object-fit: cover;
      object-position: center;
    }

    & .result-card-labels {
      margin: 1.5rem auto 0;
      width: calc(100% - 2.5rem);

      & .additional-labels {
        display: flex;
        flex-direction: column;
        gap: 10px;

        & > div[class*="label-"] {
          margin-left: auto;
        }
      }

      & .date-effective {
        text-align: center;
        margin: 0.25rem auto;
        padding-bottom: 1rem;
      }

      & div[class*="label-"] {
        margin-left: auto;
      }
    }
  }
}

/**
 * Labels
 */

div[class^="label-"] {
  background: var(--border-grey);
}

div.label-conservation-dependent {
  background: var(--conservation-dependent);
  color: white;
}

div.label-critically-endangered {
  background: var(--critically-endangered);
  color: white;
}

div.label-extinct-in-the-wild {
  background: var(--extinct-in-wild);
  color: white;
}

div.label-least-concern {
  background: var(--least-concern);
}

div.label-near-threatened {
  background: var(--near-threatened);
}

div.label-vulnerable {
  background: var(--vulnerable);
} 

div.label-endangered {
  background: var(--endangered);
}

div.label-extinct {
  background: var(--extinct);
  color: white;
} 

.result-field {
  margin-bottom: 0.75em;
  word-wrap: break-word;

  &.sci-name {
    font-size: 1.5em;
    z-index: 1;

    & a {
      color: black;
      text-decoration: none;
      z-index: 1;

      &::before {
        content: "";
        position: absolute;
        display: block;
        z-index: 1;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
      }
    }
  }

  &.common-name {
    font-size: 1.15rem;
    z-index: 1;
    .matched {
      font-size: 1rem;
      color: grey;
    }
  }

  &.taxonomic-group {
    font-size: 1.15rem;
    text-transform: uppercase;
    color: grey;
    margin-bottom: 0;
    z-index: 1;
  }

  & strong {
    color: #495057;
  }
}

.results-error {
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  color: #721c24;
  padding: 1em;
  border-radius: 4px;

  & h3 {
    margin: 0 0 0.5em 0;
    color: #721c24;
  }
}

.form-item-query input {
  font-size: 1em;
  padding: 0.5em;
}

.button--secondary {
  background-color: #6c757d;
  border-color: #6c757d;

  &:hover {
    background-color: #5a6268;
    border-color: #545b62;
  }
}

/** 
 * v2
 */
/* Taxa Search Form Styles */
.taxa-search-fieldset {
  position: relative;
  border: none;
  padding: 0.25rem;
  margin-bottom: 20px;
}

.taxa-search-form {

  & #edit-query {
    font-size: 1.25rem;
    padding: 0.75rem 1.25rem;
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    transition: border-color 0.3s;
    width: calc(100% - 65px); /* Acomodate the search and clear button */
    padding-right: 80px;
    margin: 0 -1.5rem;

    &::placeholder {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      font-size: 1.25rem;
      color: var(--border-grey);
    }

    &:focus {
      border-color: var(--main-blue);
      outline: none;
    }
  }

  & #edit-query--description {
    font-size: 1rem;
    font-style: italic;
    padding: 0.5rem;
    padding-left: 0;
  }

  & .form-actions {
    margin-top: 15px;
  }
}

/**
 * "RAW DATA"
 */
.raw-data-toggle {
  margin-top: 1em;
  margin-bottom: 2em;
  border: 1px solid #ddd;
  border-radius: 4px;

  & span.micro {
    font-size: 0.8rem;
    color: grey;
  }

  & summary {
    background: #f8f9fa;
    padding: 0.5em 1em;
    cursor: pointer;
    border-radius: 4px 4px 0 0;

    &:hover {
      background: #e9ecef;
    }
  }
}

.raw-data {
  background: #f8f9fa;
  padding: 1em;
  margin: 0;
  border-radius: 0 0 4px 4px;
  overflow-x: auto;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  border-top: 1px solid #ddd;
  white-space: pre-wrap;
  word-break: break-word;
}