/**
 * PROFILE: Sidebar
 */
.back-btn {
  text-decoration: none;
  font-weight: 600;
  color: var(--main-green);
  transition: margin-left 0.3s ease;

  &:hover {
    text-decoration: underline;
  }

  &::before {
    content:"<";
    padding-right: 0.25em;
  }
}

@media (min-width: 768px) {

  .sidebar-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
  }

}

/* PROFILE: Header */

.species-header {
  height: auto;
  padding: 1rem 1rem 2rem 0;
  position: relative;
}

.header-wrap {
  display: grid;
  padding: 0 2rem;
  margin-top: 2rem;
  background: whitesmoke;
  border-radius: 16px;
  grid-template-columns: 150px 1fr;
  gap: 0 2rem;
  grid-template-areas:
    "placeholder status"
    "text text";

  /* KEF, KTP and Critical Habitat profiles */
  &.plain-bg {
    background: none;
    padding: 0;
    .species-header {
      padding-left: 0;
    }
  }

  &.has-image > img:not(.placeholder) {
    margin-top: 2rem;
  }

  &.has-image > figure.placeholder {

    figcaption {
      font-size: 0.9rem;
      color: grey;
      line-height: 1.4;
      font-style: italic;
    }

    img {
      border-radius: 4px;
      margin: 2rem 0;
      margin-bottom: 0.5rem;

      &.conservation-dependent {
        border-right: 6px solid var(--main-blue);
      }

      &.critically-endangered {
        border-right: 6px solid var(--critically-endangered);
      }

      &.endangered {
        border-right: 6px solid var(--endangered);
      }

      &.extinct {
        border-right: 6px solid var(--extinct);
      }

      &.extinct-in-the-wild {
        border-right: 6px solid var(--dark-purple);
      }

      &.vulnerable {
        border-right: 6px solid var(--vulnerable);
      }
    }
  }

  & .species-header {
    grid-area: text;
  }

  & img.status {
    grid-area: status;
    max-width: 100px;
  }

  & figure.placeholder {
    grid-area: placeholder;
    max-width: 150px;
    margin: 0;
  }

  & p.species-sprat-date {
    grid-column: 2 / span 2;
    grid-row: 4;
    font-size: 0.9rem;
  }

  &.has-image .species-header {
    min-width: 200px;
    flex: 1;
  }

  #copy-citation-btn {
    display: flex;
    justify-content: center;
    align-items: center; 
    width: 150px;
    transition: 0.3s;
  }
}

.species-links {
  margin-top: 2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;

  & a {
    border-radius: var(--border-radius);
    padding: 0.5rem 1.25rem;
    text-decoration: none;
    text-transform: uppercase;
    font-weight: var(--font-weight-semibold);

    &.download {
      display: flex;
      align-items: center;
      background: var(--main-green);
      color: white;
      transition: 0.2s;

      &:hover {
        background: var(--mid-green);
        transition: 0.2s;
      }
    }

    &.cite-this,
    &.api-btn {
      display: flex;
      align-items: center;
      border: 1px solid var(--secondary-green);
      color: var(--secondary-green);
      transition: 0.3s;
      font-size: 1rem;

      &:hover {
        background: var(--secondary-green);
        color: white;
        transition: 0.3s;
        &:after {
          color: white;
        }
      }
    }
  }
}

.species-details {

  .species-date {
    color: grey;
    text-transform: uppercase;
  }

  & .species-group {
    text-transform: uppercase;
    color: grey;
    font-size: 1.25rem;
    margin: 0.8rem 0;
  }

  & .species-title {
    margin: 0.5rem 0;
  }

  & .species-common-name {
    font-size: 1.25rem;
    margin: 0.8rem 0;
  }

  & .species-sprat-id p,
  & .species-sprat-date {
    color: grey;
    font-size: 1.25rem;
    font-weight: 400;
    margin: 0;
  }

  & .species-sprat-id {
    display: flex;
    align-items: center;
    gap: 20px;
    width: fit-content;

    & p {
      margin: 0;
    }
  }

  & h2 {
    padding-bottom: 10px;
    border-bottom: 2px solid var(--secondary-green);
  }

  & h3 {
    color: var(--mid-green);
    margin-top: 2.5rem;
    margin-bottom: 0.75rem;
  }

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

  & .species-other-documents div[class*="label-"] {
    padding: 0.1rem 0.45rem;
    border-radius: 12px;
  }
}

@media (min-width: 1200px) {

  .header-wrap {
    display: grid;
    grid-template-columns: 1fr 220px;
    grid-template-rows: repeat(4, 1fr);
    margin-top: 0;
    gap: 1rem;
    position: relative;

    &.has-status {
      grid-template-columns: 1fr 120px 220px;
    }

    & figure.placeholder {
      max-width: 220px;
    }

    &.has-image > img:not(.placeholder) {
      margin: auto;
      margin-top: 2rem;
      max-width: 120px;
    }

    & .species-header {
      grid-row: 1 / span 5;
    }

    &.has-status .species-header {
      grid-column: 1;
    }

    & img.status {
      grid-column: 2;
      grid-row: 1 / span 4; 
    }

    & figure.placeholder {
      grid-column: 3;
      grid-row: 1 / span 4; 
    }
  }

  .species-header {
    padding: 30px;
  }

}

/**
 * PROFILE: Taxonomy and naming
 */

.species-naming {

  & .grid {
    gap: 20px;
  }

  @media (min-width: 990px) {
    & .grid {
      grid-template-columns: 1fr 325px;
    }
  }
}

.table-wrapper {

  & table {
    display: flex;
  }

  & tbody tr td {
    padding-bottom: 1rem;

    &:first-of-type {
      padding-right: 2rem;
      padding-left: 0;
    }
  }

  &:not(.simple) table {
    width: 100%;
    border-collapse: collapse;
  }

  &:not(.simple) table tr {
    border-bottom: 1px solid var(--border-grey);
  }

  &:not(.simple) tbody tr td {
    padding: 1rem 0;
    padding-right: 2rem;

    &:last-of-type {
      padding-right: 4rem;
      position: relative;
      clip-path: inset(0);
    }
  }

  &:not(.simple) tbody tr:not(:first-of-type) > td:first-of-type:empty {
    border-top: 3px solid white;
  }
}

ul.kingdom {
  list-style-type: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 0;

  & li {
    --i: 1;
    position: relative;
    padding-left: calc(var(--i) * 8px + 0.75rem);
    text-transform: uppercase;
    color: var(--mid-green);
    font-size: 0.9rem;

    & a {
      text-transform: none;
      color: purple;
      text-decoration: underline;
      font-weight: var(--font-weight-semibold);
      margin-left: 0.5rem;
    }

    & strong {
      color: grey;
      text-transform: none;
      font-weight: var(--font-weight-semibold);
      font-size: 1rem;
      padding-left: 0.15rem;
    }

    &:nth-child(2) { --i: 3; }
    &:nth-child(3) { --i: 5; }
    &:nth-child(4) { --i: 7; }
    &:nth-child(5) { --i: 9; }

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: calc(var(--i) * 8px);
      height: 0.8rem;
      background: rgb(from var(--secondary-green) r g b / 10%);
    }
  }
}

.critical-habitat {

  & p,
  & strong {
    margin-top: 0;
    margin-left: 3rem;
  }

  &::before {
    -webkit-font-smoothing: antialiased;
    font-family: 'Font Awesome 7 Free';
    content: '\e47b';
    font-weight: 900;
    font-size: 2rem;
    color: var(--mid-green);
    margin-top: 0.25rem;
    margin-right: 0.5rem;
    display: inline-block;
    width: 2rem;
    text-align: center;
    position: absolute;
  }

  & a:hover {
    text-decoration: none;
  }
}

.species-comment {
  padding: 0 1rem;
  margin-top: 1rem;
  border: 2px solid var(--secondary-green);
  border-radius: var(--border-radius);
}

/** 
 * SPECIES: EPBC legal status and documents
 */
.species-epbc-status {

  & .epbc-current-status {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    margin-top: 1rem;

    & img {
      max-width: 100px;
    }
  }

  & table tbody tr td:nth-of-type(2) {
    color: grey;
  }

  @media (min-width: 990px) {
    & .grid:first-of-type {
      grid-template-columns: 200px 1fr;
    }

    & .epbc-current-status img {
      max-width: 120px;
    }
  }
}

/**
 * PROFILE: SECTIONS
 */
section[class^="species"] {
  position: relative;
  padding: 1rem 0;

  & a[name^="toc"] {
    position: absolute;
    top: 0;
  }
}

table {
  & p.label {
    color: var(--mid-green);
    text-transform: uppercase;
  }

  &:not(.table-wrapper.simple table) {
    & tr {
      position: relative;
      clip-path: inset(0);

      &::before {
        content: "";
        position: absolute;
        inset: 0;
        margin-bottom: -0.05rem;
        background-color: transparent;
        transition: background-color 0.3s;
        z-index: -1;       /* sits behind all row content */
        pointer-events: none;
      }

      &:hover::before {
        border: none;
        background-color: var(--background-grey);
      }

      &:has(a.row-link[target="_blank"]) {
        & td:last-child::after {
          content: "\fffb5";
          color: var(--mid-green);
          font-family: 'Material Symbols Outlined';
          font-style: normal;
          font-weight: 400;
          -webkit-font-smoothing: antialiased;
          font-size: 1.65rem;
          margin-left: 0.25rem;
          display: flex;
          align-items: center;
          position: absolute;
          z-index: 1;
          right: 0;
          top: 0;
          bottom: 0;
        }
      }
    }
  }

  & span.text-only {
    color: grey;
    text-decoration: none;   
  }

  & a.row-link {
    color: grey;
    text-decoration: none;

    /* Overlay to make row clickable */
    &::before {
      content: "";
      display: block;
      position: absolute;
      z-index: 1;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
    }

    &[href$=".doc"]::after,
    &[href$=".docx"]::after,
    &[href$=".csv"]::after,
    &[href$=".xls"]::after,
    &[href$=".xlsx"]::after {
      content: "\f090";
      color: var(--mid-green);
      font-family: 'Material Symbols Outlined';
      font-style: normal;
      font-weight: 400;
      -webkit-font-smoothing: antialiased;
      font-size: 1.65rem;
      margin-left: 0.25rem;
      display: flex;
      align-items: center;
      position: absolute;
      z-index: 1;
      right: 0;
      top: 0;
      bottom: 0;
    }
  }
}

.species-maps-images {
  .map-info {
    display: grid;
    grid-template-columns: auto 1fr auto;
    column-gap: 1rem;
    align-items: center;
    & p {
      margin: 0.25rem 0;
    }
    & a.external-link {
      > * {
        color: black;
        text-decoration: none;
      }
      &:after {
        display: none;
      }
      &:hover {
        text-decoration: underline;
      }
    }
    & a:after {
      display: none;
    }
    &:before {
      content: '\f279';
      -webkit-font-smoothing: antialiased;
      font-family: 'Font Awesome 7 Free';
      font-weight: 400;
      font-size: 1.75rem;
      color: white;
      background: var(--mid-green);
      border-radius: 50%;
      margin-right: 0.5rem;
      padding: 0.5rem;
      display: inline-block;
      width: 2rem;
      text-align: center;
    }
    &:after {
      content: "\fffb5";
      color: var(--mid-green);
      font-family: 'Material Symbols Outlined';
      font-style: normal;
      font-weight: 400;
      -webkit-font-smoothing: antialiased;
      font-size: 1.65rem;
      margin-left: 0.25rem;
      display: flex;
      align-items: center;
      z-index: 1;
      right: 0;
      top: 0;
      bottom: 0;   
    }
  }
}

.species-other-documents {

  & table tbody tr td:nth-of-type(2) {
    color: grey;
  }

  & .labels-col {
    width: 130px;
  }

  @media (min-width: 990px) {
    & .labels-col {
      width: 180px;
    }
  }
}

/* On KEF profile */
.species-profile-descriptions {
  .table-wrapper {
    &:not(.simple) tbody tr td:first-of-type {
      vertical-align: top;
    }
    tr {
      &:hover::before {
        background: none;
      }
      td {
        a.external-link span {
          &:hover {
            text-decoration: underline;
          }
        }
      }
    }
  }
}

.species-superceded-documents {

  & table tbody tr td:nth-of-type(2) {
    color: grey;
  }

  @media (min-width: 990px) {
    & .grid {
      grid-template-columns: 200px 1fr;
      gap: 1rem;
    }
  }
}

.species-other-lists {

  & table tbody tr td:nth-of-type(3) {
    color: grey;
  }

  & h4 {
    font-size: 1.25rem;
    margin: 1rem 0;
  }

  & .grid {
    gap: 1rem;
  }

  @media (min-width: 990px) {
    & .grid {
      grid-template-columns: 1fr 1fr;
    }
  }
}

/**
 * PROFILE: LABELS
 */
.species-labels {
  display: flex;
  gap: 10px;
  margin: 0 0.25rem;
}

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

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

div.label-migratory,
div.label-migratory-name-change {
  background: var(--migratory);
}

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

div.label-threatened,
div.label-threatened-name-change {
  background: var(--threatened);
}

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

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

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

div.label-wildlife-conservation-plan {
  background: var(--wildlife-conservation-plan);
} 

div.label-threat-abatement-plan {
  background: var(--threat-abatement-plan);
}

.resource-card {
  background: var(--background-grey);
  padding: 0 1rem;
  border-radius: var(--border-radius);
}

.resource-card .relevant-docs {
  border-top: 1px solid var(--border-grey);
}

.resource-card .relevant-docs .table-wrapper {
  display: none;
}

.resource-card table {
  margin-top: 1rem;
}

.resource-card .show-documents {
  display: flex;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: grey;
  padding-top: 1rem;
  pointer: cursor;

  &:hover {
    color: black;
    cursor: pointer;
  }

  &.is-active {
    border-top: 1px solid var(--border-grey);
  }

  & hr {
    color: grey;
  }

  & p {
    margin-top: 0;
  }
}

.relevant-docs {
  table a {
    &:hover {
      color: black;
      cursor: pointer;
    }
  }
}

/**
 * PROFILE: TABLE OF CONTENTS (TOC)
 */ 

body.toolbar-fixed .toc-doc-wrapper {
  top: calc(38.9757px + 1rem);
}

body.toolbar-fixed.toolbar-tray-open .toc-doc-wrapper {
  top: calc(79.0625px + 1rem); 
}

.toc-doc-wrapper {
  top: 0;
  height: fit-content;
  padding: 1rem 1.5rem 1rem 0;
  //border-radius: var(--border-radius);
  //-webkit-box-shadow: 2px 2px 2px 0 var(--border-grey);
  //-khtml-box-shadow: 2px 2px 2px 0 var(--border-grey);
  //-moz-box-shadow: 2px 2px 2px 0 var(--border-grey);
  //-ms-box-shadow: 2px 2px 2px 0 var(--border-grey);
  //-o-box-shadow: 2px 2px 2px 0 var(--border-grey);
  //box-shadow: 2px 2px 2px 0 var(--border-grey);

  @media (min-width: 768px) {
    position: sticky;
  }
}

#toc {
  margin-top: 0.5rem;

  & strong {
    color: black;
    font-size: 1.5em;
  }

  & ul {
    margin-top: 10px;
    margin-bottom: 0;
    padding: 0 0.15rem;
  }

  & ul li {
    list-style: none;
    padding: 0.15rem 0;
    border-left: 4px solid lightgrey;
    padding-left: 1rem;
    margin-bottom: 0.5rem;

    &:hover {
      border-color: var(--secondary-green);
    }

    & a {
      padding: 0.15rem 0;

      &:hover,
      &.current {
        color: var(--main-green);
      }
    }

    @media (min-width: 990px) {
      margin-bottom: 1.15rem;
    }
  }

  & a {
    color: var(--secondary-green);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;

    &:hover {
      font-weight: var(--font-weight-semibold);
    }
  }
}