/* What the DSFR does not cover, in DSFR colour tokens so the dark theme follows.
   Every rule is scoped under .fico, the class each element puts on itself. */

.fico {
  .line {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
  }

  /* Each component grows in proportion to its share of the line; below a
     minimum in the same proportion (10rem for a quarter, 20rem for a half) it
     wraps to the next line. */
  .line > * {
    display: block;
    flex: var(--width, 1) 1 0;
    min-width: min(calc(var(--width, 1) * 40rem), 100%);
  }

  /* Panels side by side keep the height of the tallest. */
  .fr-callout {
    height: 100%;
  }

  .muted {
    color: var(--text-mention-grey);
  }

  .definitions {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.2rem 1.2rem;
    margin: 0;

    dt {
      color: var(--text-mention-grey);
    }

    dd {
      margin: 0;
      font-weight: 500;
    }
  }

  /* Financements */

  .figures {
    height: 100%;
    text-align: right;
  }

  .histogram {
    position: relative;
    height: 9rem;
    margin: 0.5rem 0 1.5rem 3.5rem;
  }

  .histogram-tick {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(var(--share) * 100%);
    border-top: 1px solid var(--border-default-grey);

    span {
      position: absolute;
      right: calc(100% + 0.4rem);
      transform: translateY(-50%);
      font-size: 0.7rem;
      color: var(--text-mention-grey);
      white-space: nowrap;
    }
  }

  .histogram-bars {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
  }

  .histogram-bar {
    position: relative;
    flex: 1;
    height: calc(var(--share) * 100%);
    background: var(--background-action-high-blue-france);

    span {
      position: absolute;
      top: 100%;
      left: 50%;
      transform: translateX(-50%);
      font-size: 0.7rem;
      color: var(--text-mention-grey);
    }
  }

  .ranking {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 12rem;
    margin: 3.5rem 0 1.5rem;
  }

  .ranking-bar {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: 1px;
    height: calc(var(--share) * 100%);
    background: var(--blue-france-850-200);

    .ranking:not([data-few]) > &:not([data-accent=""]) {
      flex: 0 0 2.75rem;
    }

    .ranking[data-few] > &[data-accent="focus"] {
      flex-grow: 1.5;
    }

    &[data-accent="focus"],
    &[data-accent="neighbour"] {
      background: var(--blue-france-main-525);
    }

    &[data-accent="top"] {
      background: var(--blue-france-sun-113-625);
    }

    &[data-accent="bottom"] {
      background: var(--pink-macaron-main-689);
    }

    span {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      font-size: 0.75rem;
      white-space: nowrap;
    }
  }

  .ranking-value {
    bottom: calc(100% + 0.25rem);
    font-weight: 700;
  }

  .ranking-name {
    bottom: calc(100% + 1.75rem);
    padding: 0 0.5rem;
    background: var(--background-default-grey);
    box-shadow: var(--raised-shadow);

    /* Pointe désignant la barre. */
    &::after {
      content: "";
      position: absolute;
      top: 100%;
      left: 50%;
      transform: translateX(-50%);
      border: 0.375rem solid transparent;
      border-top-color: var(--background-default-grey);
      border-bottom-width: 0;
    }
  }

  .ranking-rank {
    top: calc(100% + 0.25rem);
    color: var(--text-mention-grey);
  }

  /* Carto */

  .map {
    display: block;
    width: 100%;
    height: 18rem;

    path {
      vector-effect: non-scaling-stroke;
      stroke-width: 0.6px;
    }

    path.focus {
      stroke-width: 2px;
    }

    path:hover {
      opacity: 0.75;
    }
  }

  .legend {
    color: var(--text-mention-grey);
  }

  .legend-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.2rem;
  }

  .swatch {
    display: inline-block;
    width: 1rem;
    height: 0.5rem;
  }

  /* Downloads */

  &:is(fico-component) {
    position: relative;
  }

  .downloads {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 1;

    summary {
      list-style: none;
    }

    ul {
      position: absolute;
      top: 100%;
      right: 0;
      margin: 0;
      padding: 0.25rem 0;
      list-style: none;
      background: var(--background-default-grey);
      box-shadow: var(--overlap-shadow);
    }

    li {
      padding: 0;
    }

    a {
      display: block;
      padding: 0.25rem 1.5rem;
    }
  }

  /* Figures read from the right: the menu takes the corner they leave free. */
  &:is(fico-component):has(> .figures) .downloads {
    right: auto;
    left: 0.5rem;

    ul {
      right: auto;
      left: 0;
    }
  }
}
