@import 'colors';
@import 'constants';
@import 'placeholders';

.button {
  @extend %outline;

  display: inline-block;
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid $border-grey;
  font-size: 14px;
  line-height: 20px;
  background-color: #ffffff;
  color: $black;
  text-align: center;
  -webkit-appearance: none;
  background-image: none; // Remove DSFR underline

  &:hover:not(:disabled) {
    cursor: pointer;
    background: $light-grey;
    text-decoration: none;
  }

  &:disabled {
    opacity: 0.5;
    filter: saturate(50%);
  }

  &.primary {
    color: #ffffff;
    border-color: $blue-france-700;
    background-color: $blue-france-700;

    &:hover:not(:disabled) {
      background: $blue-france-500;
    }
  }

  &.secondary {
    color: $blue-france-700;
    border-color: $blue-france-700;
    background-color: #ffffff;

    &:hover:not(:disabled) {
      color: #ffffff;
      background: $blue-france-700;
    }
  }

  &.danger {
    color: $black;
    border-color: $border-grey;
    background-color: #ffffff;

    &:hover:not(:disabled) {
      color: #ffffff;
      border-color: $medium-red;
      background-color: $medium-red;

      > .icon {
        filter: contrast(0) brightness(100);
      }
    }
  }

  &.accepted {
    color: #ffffff;
    border-color: $green;
    background-color: $green;

    &:hover:not(:disabled) {
      color: $green;
      background-color: #ffffff;
    }
  }

  &.without-continuation {
    color: #ffffff;
    border-color: $black;
    background-color: $black;

    &:hover:not(:disabled) {
      color: $black;
      background-color: #ffffff;
    }
  }

  &.refused {
    color: #ffffff;
    border-color: $dark-red;
    background-color: $dark-red;

    &:hover:not(:disabled) {
      color: $dark-red;
      background-color: #ffffff;
    }
  }

  &.small {
    line-height: 14px;
    padding: 5px 10px 6px 10px;
  }

  &.large {
    font-size: 18px;
    line-height: 26px;
    padding: 15px 32px;
  }

  &.expand {
    width: 100%;
  }

  > .icon {
    width: 18px;
    height: 18px;
    background-size: 18px 18px;
    vertical-align: text-bottom;
    margin-right: $default-spacer;
  }

  &.icon-only {
    padding: 9px 16px;

    .icon {
      margin-right: 0;
    }
  }
}

.icon-size {
  width: 18px;
  height: 18px;
}

.icon-size-big {
  width: 25px;
  height: 25px;
}

.instruction-button {
  display: inline-block;
}

.dropdown {
  display: inline-block;
  position: relative;

  .dropdown-button {
    white-space: nowrap;

    [aria-hidden='true'].fr-ml-2v::after {
      content: '▾';
    }

    &.icon-only {
      &::after {
        margin-left: 2px;
        color: $blue-france-500;
      }
    }
  }

  .dropdown-content {
    display: none;
  }

  &.open .dropdown-content {
    display: block;
  }
}

[data-fr-theme='dark'] .dropdown-content {
  border: none;
  background: var(--background-action-low-blue-france);
}

[data-fr-theme='dark'] .dropdown-items {
  li {
    &:not(.inactive) {
      &:hover,
      &.selected {
        background: var(--background-action-low-blue-france-hover);
      }
    }

    &.form-inside {
      background-color: var(--background-action-low-blue-france);
    }
  }
}

.dropdown-content {
  border: 1px solid $border-grey;
  background: #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  position: absolute;
  right: 0;
  text-align: left;
  top: 5 * $default-spacer;
  cursor: default;
  z-index: 11;
  list-style: none;

  a {
    background-image: none; // remove DSFR underline
  }

  &.left-aligned {
    left: 0;
    right: unset;
  }

  &.terminated {
    width: 600px;
    color: $black;
    padding: $default-padding;

    .title {
      font-size: 24px;
    }

    .dossier-motivation {
      margin: $default-padding 0;
    }

    .attestation {
      margin: $default-padding 0;
      color: $dark-grey;
    }
  }
  @media (max-width: 48em) {
    left: 0;
  }
}

ul.dropdown-items {
  padding-inline-start: 0;
  list-style: none;
  margin-top: 0;
  margin-bottom: 0;
}

// Apply custom styles to DSFR fr-translate component
.fr-translate__btn.fr-btn.help-btn::before {
  content: none;
}

.help-content.fr-menu .fr-menu__list {
  --text-decoration: underline;
  text-align: left;
  font-size: 1rem;

  @media (min-width: 62em) {
    font-size: 0.875rem;
    padding: 0;
    width: 450px;
  }
}

.help-content.fr-menu ul.fr-menu__list > li {
  padding: 0.75rem 1rem;

  @media (min-width: 62em) {
    padding-right: 1rem;
    padding-left: 1rem;
  }
}

.help-content.fr-menu .fr-menu__list > div:last-child,
.help-content.fr-menu .fr-menu__list > li:last-child {
  @media (min-width: 62em) {
    border-top: 1px solid $border-grey;
  }
}

.help-content.fr-menu .fr-menu__list {
  h1,
  p {
    font-size: inherit;
    line-height: inherit;
  }

  dd {
    word-break: break-word;
  }
}

.help-content a[href]:hover,
.help-content a[href]:active {
  @media (hover: hover) and (pointer: fine) {
    --text-decoration: none;
  }
}

.dropdown-items {
  li {
    display: flex;
    padding: $default-padding;
    border-bottom: 1px solid $border-grey;
    font-size: 12px;
    min-width: 300px;

    &.selected {
      cursor: default;

      h4 {
        color: $blue-france-500;
      }
    }

    &:not(.inactive) {
      cursor: pointer;

      &:hover,
      &.selected {
        background: $light-grey;
      }
    }

    &.form-inside {
      background-color: $white;
      margin-top: -2px;
    }

    &.danger {
      &:hover {
        background-color: $medium-red;

        &,
        a {
          color: $white;
        }

        .icon {
          filter: contrast(0) brightness(100);
        }
      }
    }

    &:last-child {
      border-bottom: none;
    }

    // Make child links fill the whole clickable area
    > a,
    .dropdown-items-link {
      display: flex;
      flex-grow: 1;
      margin: -$default-padding;
      padding: $default-padding;
      text-align: left;
      align-items: baseline;
    }

    .icon {
      flex-shrink: 0;
    }

    .dropdown-description {
      padding-left: $default-spacer;
    }
  }

  h4 {
    font-size: 14px;
    margin-bottom: $default-spacer;
  }

  p + h4,
  p + p {
    margin-top: $default-spacer;
  }
}

.dropdown-form {
  padding: 2 * $default-spacer;

  &.large {
    width: 90vw;

    @media (min-width: 62em) {
      width: 40vw;
    }
  }

  ul {
    list-style: none;
  }
}

.link {
  color: $blue-france-500;
}

.account-btn {
  flex-wrap: wrap;
  hyphens: auto;
  text-align: left;

  &::before {
    content: none !important;
  }
}

.back-btn {
  line-height: 1.75rem;
}

.copy-zone {
  cursor: pointer;

  .copy-btn {
    background-color: var(--background-action-low-blue-france);
    color: var(--text-active-blue-france);
    font-weight: normal;
    text-transform: none;

    &.fr-icon-check-line {
      color: var(--text-default-success);
    }

    border: 0 !important;
    clip: rect(1px, 1px, 1px, 1px) !important;
    -webkit-clip-path: inset(50%) !important;
    clip-path: inset(50%) !important;
    height: 1px !important;
    overflow: hidden !important;
    position: absolute !important;
    width: 1px !important;
    white-space: nowrap !important;
  }

  &:hover .copy-btn,
  .copy-btn:focus-visible {
    background-color: var(--background-action-low-blue-france);
    color: var(--text-active-blue-france);

    &.fr-icon-check-line {
      color: var(--text-default-success);
    }

    border: none !important;
    clip: auto !important;
    -webkit-clip-path: none !important;
    clip-path: none !important;
    height: auto !important;
    overflow: visible !important;
    position: static !important;
    width: auto !important;
    white-space: normal !important;
  }
}
