/*
 * Fund pages: fund selector, fund head with facts bar, share-class table
 * (cards on narrow screens).
 * Markup: template-parts/fund-table.php, template-parts/funds/*.
 * Kept out of main.css on purpose (main.css carries local edits that are not
 * in the SCSS sources). Every rule is scoped to .fundTable
 * only, so
 * the legacy view and the rest of the site stay untouched.
 *
 * Colour roles (contrast):
 *   --fund-ink          text, table head, current fund          14.9:1 on white
 *   --fund-muted        labels, category                         6.0:1 on white, 5.5:1 on --fund-ground
 *   --fund-ground       calm area behind the fund head
 *   --fund-rule         hairlines
 *   --fund-orange       brand accent: bars, icons, fill of the factsheet button on hover (ink on it 5.3:1)
 *   --fund-orange-text  orange used as text colour               5.3:1 on white
 *   --fund-orange-soft  highlighted row
 *
 * Type scale (rem): 0.75 · 0.8125 · 0.875 · 1 · 1.125 · 1.25 · 1.5 · 1.75 · 2.125 · 3.5
 * Space scale (rem): 0.25 · 0.5 · 0.75 · 1 · 1.5 · 2 · 3 · 4
 */

.fundTable {
  --fund-ink: #262626;
  --fund-muted: #636363;
  --fund-ground: #F4F4F2;
  --fund-rule: #E3E3E0;
  --fund-rule-control: #C9C9C6;
  --fund-hover: #FAF7F2;
  --fund-orange: #ED7802;
  --fund-orange-text: #A85400;
  --fund-orange-soft: #FFF1E2;
  --fund-orange-flash: #FFD8A8;
}

.fundTable {
  display: none;
}

.input-fonds:checked + section.fundTable,
section.fundTable.is-visible {
  display: block;
}

.fundTable .screen-reader-text,
.fundTable__caption {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fundTable a:focus-visible {
  outline: 2px solid var(--fund-ink);
  outline-offset: 3px;
}

/* Keep the production fund selector untouched; space only the new table. */
.input-fonds + section.fundTable {
  padding-top: 0 !important;
}

/* Fund head ------------------------------------------------------------- */

.fundTable__head {
  position: relative;
  isolation: isolate;
  padding-top: 4rem;
}

.fundTable__category {
  color: var(--fund-muted);
  font-size: 1.125rem;
  line-height: 1.4;
  margin: 0 0 0.75rem;
}

.fundTable__category::before {
  content: "";
  display: block;
  width: 3rem;
  height: 4px;
  margin-bottom: 1.5rem;
  background-color: var(--fund-orange);
}

.fundTable .fundTable__title {
  font-size: 3.5rem;
  line-height: 1.05;
  letter-spacing: -0.015em;
  margin: 0 0 1.5rem;
  text-wrap: balance;
}

.fundTable__intro {
  color: var(--fund-ink);
  font-size: 1.25rem;
  line-height: 1.55;
  max-width: 64rem;
  padding-bottom: 3.5rem;
}

.fundTable__intro p {
  margin: 0;
}

.fundTable__intro a,
.fundTable__intro span,
.fundTable__intro strong {
  color: inherit !important;
  font-size: inherit !important;
  font-weight: inherit !important;
  font-family: inherit !important;
}

/* Facts bar: closes the head. */
.fundTable__facts {
  display: grid;
  /* Four equal columns; one only grows when its value needs the room. */
  grid-auto-flow: column;
  grid-auto-columns: minmax(max-content, 1fr);
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--fund-rule-control);
}

.fundTable__fact {
  padding: 1.5rem 1.5rem 1.75rem;
  border-left: 1px solid var(--fund-rule-control);
  white-space: nowrap;
}

.fundTable__fact:first-child {
  padding-left: 0;
  border-left: 0;
}

.fundTable__fact-label {
  color: var(--fund-muted);
  font-size: 0.8125rem;
  line-height: 1.3;
  margin: 0 0 0.375rem;
}

.fundTable__fact-value {
  color: var(--fund-ink);
  font-size: 1.5rem;
  font-weight: bold;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  margin: 0;
}

/* Table ----------------------------------------------------------------- */

.fundTable__scroll {
  margin-top: 3rem;
  overflow-x: auto;
}

.fundTable__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--fund-ink);
  font-variant-numeric: tabular-nums;
}

.fundTable__th {
  text-align: left;
  font-weight: bold;
  font-size: 0.8125rem;
  line-height: 1.3;
  color: var(--fund-ink);
  background-color: var(--fund-ground);
  padding: 1rem 1.5rem 1rem 0;
  vertical-align: middle;
  white-space: nowrap;
}

.fundTable__row > th,
.fundTable__row > td {
  text-align: left;
  font-weight: normal;
  padding: 0.75rem 1.5rem 0.75rem 0;
  height: 4rem;
  border-bottom: 1px solid var(--fund-rule);
  vertical-align: middle;
  white-space: nowrap;
}

.fundTable__th:first-child,
.fundTable__row > :first-child {
  padding-left: 1.25rem;
}

.fundTable__th:last-child,
.fundTable__row > :last-child {
  padding-right: 1rem;
}

.fundTable__th--documents,
.fundTable__row > .fundTable__documents {
  text-align: center;
  width: 1%;
}

.fundTable__th--factsheet,
.fundTable__row > .fundTable__factsheet {
  width: 1%;
}

.fundTable__row > .fundTable__class {
  font-size: 1.0625rem;
  font-weight: bold;
}

.fundTable__row > .fundTable__distribution {
  color: var(--fund-muted);
}

.fundTable__row > .fundTable__minimum {
  white-space: normal;
}

.fundTable__isin {
  letter-spacing: 0.03em;
}

.fundTable__chip {
  display: inline-block;
  min-width: 2.75rem;
  padding: 0.25rem 0.5rem;
  background-color: #fff;
  border: 1px solid var(--fund-rule-control);
  border-radius: 2px;
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  line-height: 1.2;
  text-align: center;
}

.fundTable__row {
  transition: background-color 0.15s ease;
}

.fundTable__row:hover {
  background-color: var(--fund-hover);
}

/* Row a legacy link (#fond_<share class>) points at. */
.fundTable__row.is-highlighted,
.fundTable__row.is-highlighted:hover {
  background-color: var(--fund-orange-soft);
  animation: fundTableArrive 1.6s ease-out 0.6s backwards;
}

.fundTable__row.is-highlighted > :first-child {
  box-shadow: inset 5px 0 0 var(--fund-orange);
}

@keyframes fundTableArrive {
  from { background-color: var(--fund-orange-flash); }
  to { background-color: var(--fund-orange-soft); }
}

/* Factsheet download and fund documents link ----------------------------- */

.fundTable__icon {
  display: block;
  flex: none;
  width: 1rem;
  height: 1rem;
  background-color: currentColor;
  -webkit-mask: center / contain no-repeat;
  mask: center / contain no-repeat;
}

.fundTable__icon--download {
  -webkit-mask-image: url("svg/download-icon.svg");
  mask-image: url("svg/download-icon.svg");
  color: var(--fund-orange);
}

/* Hover/focus remains a plain link, without a button frame or fill. */
.fundTable__pdf:hover .fundTable__icon--download,
.fundTable__pdf:focus-visible .fundTable__icon--download {
  color: var(--fund-ink);
}

.fundTable__icon--external {
  -webkit-mask-image: url("svg/external-link.svg");
  mask-image: url("svg/external-link.svg");
  width: 1.125rem;
  height: 1.125rem;
}

.fundTable__pdf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.25rem 0;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  color: var(--fund-ink);
  font-size: 0.875rem;
  font-weight: bold;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.fundTable__pdf:hover,
.fundTable__pdf:focus-visible {
  color: var(--fund-orange-text);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.fundTable__pdf-type {
  color: inherit;
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  transition: color 0.15s ease;
}

.fundTable__pdf:hover .fundTable__pdf-type,
.fundTable__pdf:focus-visible .fundTable__pdf-type {
  color: var(--fund-ink);
}

.fundTable__docs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  border: 1px solid var(--fund-rule-control);
  border-radius: 50%;
  background-color: #fff;
  color: var(--fund-ink);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.fundTable__docs:hover,
.fundTable__docs:focus-visible {
  background-color: var(--fund-ink);
  border-color: var(--fund-ink);
  color: #fff;
}

.fundTable__docs-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.fundTable__none {
  color: var(--fund-muted);
}

/* Narrow desktop: tighter columns before the table turns into cards. */
@media (min-width: 1101px) and (max-width: 1360px) {
  .fundTable__th,
  .fundTable__row > th,
  .fundTable__row > td {
    padding-right: 1rem;
  }

  .fundTable .fundTable__title {
    font-size: 3rem;
  }
}

/* Cards on narrow screens ------------------------------------------------ */

@media (max-width: 1100px) {
  .fundTable__head {
    padding-top: 2.5rem;
  }

  .fundTable__category {
    font-size: 1rem;
  }

  .fundTable__category::before {
    margin-bottom: 1.25rem;
  }

  .fundTable .fundTable__title {
    font-size: 2.125rem;
    line-height: 1.1;
    margin-bottom: 1rem;
  }

  .fundTable__intro {
    font-size: 1.0625rem;
    padding-bottom: 2rem;
  }

  .fundTable__facts {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .fundTable__fact,
  .fundTable__fact:first-child {
    padding: 1rem 0.75rem 1.125rem 0;
    border-left: 0;
    border-bottom: 1px solid var(--fund-rule-control);
    white-space: normal;
  }

  .fundTable__fact:nth-child(even) {
    padding-left: 1rem;
    border-left: 1px solid var(--fund-rule-control);
  }

  .fundTable__fact:nth-last-child(-n + 2):nth-child(odd),
  .fundTable__fact:nth-last-child(-n + 2):nth-child(odd) ~ .fundTable__fact {
    border-bottom: 0;
  }

  .fundTable__fact-value {
    font-size: 1.125rem;
    text-wrap: balance;
  }

  .fundTable__scroll {
    margin-top: 2rem;
    overflow: visible;
  }

  .fundTable__table {
    display: block;
  }

  .fundTable__table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .fundTable__table tbody {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr));
    gap: 1rem;
  }

  /*
   * One card per share class:
   *   [ class  distribution      currency ]   head strip
   *     minimum
   *     ISIN
   *     [ factsheet ]        fund documents
   */
  .fundTable__row {
    --fund-strip: var(--fund-ground);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 0 0.25rem;
    background: #fff linear-gradient(var(--fund-strip), var(--fund-strip)) top / 100% 3.25rem no-repeat;
    border: 1px solid var(--fund-rule-control);
    border-radius: 3px;
    overflow: hidden;
  }

  .fundTable__row:hover {
    background-color: #fff;
  }

  .fundTable__row > th,
  .fundTable__row > td,
  .fundTable__row > :first-child,
  .fundTable__row > :last-child {
    display: block;
    width: auto;
    height: auto;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
  }

  .fundTable__row > .fundTable__class {
    order: 1;
    font-size: 1.125rem;
    line-height: 3.25rem;
    padding-left: 1rem;
    margin-right: 0.625rem;
    white-space: nowrap;
  }

  .fundTable__row > .fundTable__distribution {
    order: 2;
    font-size: 0.9375rem;
    line-height: 3.25rem;
    white-space: nowrap;
  }

  .fundTable__row > .fundTable__currency {
    order: 3;
    margin-left: 0;
    padding: 0 1rem 0 0.5rem;
  }

  .fundTable__row > .fundTable__minimum { order: 4; }
  .fundTable__row > .fundTable__isin { order: 6; }

  .fundTable__row > .fundTable__minimum {
    flex: 0 0 100%;
    padding: 1rem 1rem 0;
  }


  .fundTable__row > .fundTable__isin {
    flex: 0 0 100%;
    margin-top: 0.75rem;
    padding: 0 1rem;
  }

  .fundTable__row > .fundTable__minimum::before,
  .fundTable__row > .fundTable__isin::before {
    content: attr(data-label);
    display: block;
    color: var(--fund-muted);
    font-size: 0.75rem;
    letter-spacing: 0;
    line-height: 1.3;
    margin-bottom: 0.125rem;
  }

  .fundTable__row > .fundTable__factsheet {
    order: 7;
    flex: 0 0 100%;
    width: auto;
    margin-top: 1.125rem;
    padding: 0 1rem;
  }

  .fundTable__row > .fundTable__documents {
    order: 8;
    flex: 0 0 100%;
    width: auto;
    margin-top: 0.25rem;
    padding: 0 1rem;
    text-align: left;
  }

  .fundTable__row > .fundTable__factsheet:has(.fundTable__none)::before {
    content: attr(data-label) " ";
    color: var(--fund-muted);
    font-size: 0.875rem;
  }

  .fundTable__row > .fundTable__documents:has(.fundTable__none) {
    display: none;
  }

  /* Touch targets of at least 44px. */
  .fundTable__pdf {
    display: flex;
    justify-content: flex-start;
    min-height: 2.75rem;
  }

  .fundTable__docs {
    justify-content: flex-start;
    min-height: 2.75rem;
    border: 0;
    border-radius: 0;
    background-color: transparent;
    font-size: 0.875rem;
    text-decoration: underline;
    text-decoration-color: var(--fund-rule-control);
    text-underline-offset: 0.25em;
  }

  .fundTable__docs:hover,
  .fundTable__docs:focus-visible {
    background-color: transparent;
    color: var(--fund-orange-text);
  }

  .fundTable__docs .fundTable__icon {
    width: 0.875rem;
    height: 0.875rem;
  }

  .fundTable__docs-text {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .fundTable__row.is-highlighted,
  .fundTable__row.is-highlighted:hover {
    --fund-strip: var(--fund-orange-flash);
    background-color: var(--fund-orange-soft);
    border-color: var(--fund-orange);
    box-shadow: 0 0 0 2px var(--fund-orange);
    animation: none;
  }

  .fundTable__row.is-highlighted > :first-child {
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fundTable__row.is-highlighted,
  .fundTable__row.is-highlighted:hover {
    animation: none;
  }

  .fundTable__row,
  .fundTable__pdf,
  .fundTable__pdf-type,
  .fundTable__docs {
    transition: none;
  }
}

/* Jumps below the fixed header (#nav) ------------------------------------ */
/* --plenum-header-offset is set by js/fund-table.js from the header height. */

section.fundTable,
.fundTable__head,
.fundTable__row {
  scroll-margin-top: var(--plenum-header-offset, 12rem);
}
