$primary-color: #cccccc; // rgb(204, 204, 204);
$secondary-color: #fff; //rgb(255, 255, 255)
$background-color: #808080; //rgb(128, 128, 128);
$error-color: #ca2f3f; //rgb(202, 47, 63);
$success-color: #6ea050; //rgb(110, 160, 80);
$warning-color: #f0be00; //rgb(240, 190, 0);

$mobile-max-width: 640px;

@mixin scroll-bar {
  &::-webkit-scrollbar {
    width: 5px;
  }

  &::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba($primary-color, 0.8);
    box-shadow: inset 0 0 5px rgba($primary-color, 0.8);
    border-radius: 10px;
  }

  &::-webkit-scrollbar-thumb {
    -webkit-box-shadow: inset 0 0 5px rgba($primary-color, 1);
    box-shadow: inset 0 0 5px rgba($primary-color, 1);
    border-radius: 10px;
  }
}

.dialog__overlay {
  z-index: 1000;
  background: rgb($background-color, 0.5);

  position: fixed;
  top: 0;
  left: 0;

  width: 100vw;
  height: 100vh;

  display: flex;
  justify-content: center;
  align-items: center;
}

.dialog__container {
  z-index: 1010;
  position: fixed;
  box-sizing: border-box;

  max-height: 100vh;
  min-width: 25vw;
  max-width: 50vw;

  @media (max-width: $mobile-max-width) {
    max-width: 75vw;
  }

  padding: 2rem;
  border-radius: 1rem;
  background-color: $secondary-color;
}

.dialog__container--no-padding {
  padding: 0;
}

.dialog__close-button {
  box-sizing: border-box;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;

  height: 1.5rem;
  width: 1.5rem;

  padding: 0;
  border: none;
  cursor: pointer;
  background: transparent;
  border-radius: 1rem;
  background: rgba($primary-color, 1);

  &:after {
    color: $secondary-color;
    content: "\2715";
  }

  &:hover {
    background: rgba($error-color, 0.8);
  }

  &:focus {
    background: rgba($error-color, 0.8);
  }
}

.dialog__header {
  text-align: center;
}

@mixin dialog__header--contextual($color) {
  padding: 2rem 2rem 0 2rem;
  border-radius: 1rem 1rem 0 0;
  color: $secondary-color;
  background-color: $color;
}

.dialog__header--error {
  @include dialog__header--contextual($error-color);
}

.dialog__header--success {
  @include dialog__header--contextual($success-color);
}

.dialog__header--warning {
  @include dialog__header--contextual($warning-color);
}

.dialog__title {
  font-size: large;
  font-weight: bold;
  line-height: 1.5;
  margin: 0;
}

.dialog__title--xx-large {
  font-size: xx-large;
}

.dialog-content__divider {
  border: 1px solid $background-color;
}

.dialog__body {
  box-sizing: border-box;
  text-align: center;
  padding-top: 1rem;
  min-height: 10vh;
  max-height: calc(100vh - 13rem);
  overflow-y: auto;

  @include scroll-bar;
}

.dialog__body--contextual {
  padding: 0 2rem;
}

.dialog__footer {
  margin-top: 1rem;
  display: flex;
}

.dialog__footer--contextual {
  padding: 0 2rem 2rem 2rem;
}

.dialog__footer--space-evenly {
  justify-content: space-evenly;
}

.dialog__footer--space-between {
  justify-content: space-between;
}

.dialog__footer--mobile-responsive {
  flex-direction: row;

  @media (max-width: $mobile-max-width) {
    flex-direction: column;

    .dialog__button-container {
      display: flex;
      justify-content: space-between;

      .dialog__button {
        flex-grow: 1;
      }
    }
  }
}

.dialog__form {
  &.touched .dialog__input:invalid {
    border: 2px solid rgba($error-color, 0.5);
    outline: 0;

    &:focus,
    &:focus-visible {
      border: 2px solid rgba($error-color, 1);
      outline: 0;
    }
  }
}
.dialog__form-element {
  fieldset {
    box-sizing: border-box;
    margin: 8px 0 0 0;
    width: 100%;
    padding: 1rem;
    background-color: $secondary-color;
    border: 2px solid $primary-color;
    border-radius: 1rem;

    legend {
      display: block;
      width: fit-content;
      text-align: left;
      position: relative;
      padding: 0 5px;
      background: $secondary-color;
    }
  }
}

.dialog__input-label {
  display: block;
  width: fit-content;
  margin-left: 1rem;
  text-align: left;
  position: relative;
  top: 8px;
  padding: 0 5px;
  background: $secondary-color;
}

select.dialog__input[multiple],
textarea.dialog__input {
  overflow-y: auto;
  @include scroll-bar;
  direction: rtl;
  text-align: left;

  &::-webkit-scrollbar-track {
    margin: 5px;
  }

  option {
    direction: ltr;
  }
}

.dialog__input {
  box-sizing: border-box;
  margin: 0;

  &:not([type="checkbox"]):not([type="radio"]) {
    width: 100%;
    padding: 1rem;
    background-color: $secondary-color;
    border: 2px solid $primary-color;
    border-radius: 1rem;
  }

  &[type="checkbox"],
  &[type="radio"] {
    width: auto;
    display: block;
    margin-top: -7px;
    text-align: left;
  }

  &[type="color"] {
    min-height: 3.5rem;
  }

  &[type="range"] {
    padding: 1rem 0;
  }

  &[type="file"]::file-selector-button {
    display: none;
  }

  &:focus:not(:invalid) {
    border: 2px solid #333;
  }
}

.dialog__button {
  box-sizing: border-box;
  display: inline-block;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.5rem;
  margin: 2px;
  min-width: 6rem;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
  user-select: none;
  border: 0.1rem solid transparent;
  border-radius: 0.5rem;

  &:disabled {
    cursor: default;
    opacity: 0.5;
  }

  &:focus {
    border: 0.1rem solid transparent;
  }
}

@mixin button-modifier($color) {
  background-color: rgba($color, 1);

  &:hover {
    background-color: rgba($color, 0.8);
  }

  &:not(:disabled):active {
    background-color: rgba($color, 1);
  }

  &:focus {
    box-shadow: 0 0 0 3px rgba($color, 0.5);
  }
}

.dialog__button--primary {
  @include button-modifier($primary-color);
}

.dialog__button--decline {
  @include button-modifier($error-color);
  color: $secondary-color;
}

.dialog__button--error {
  @include button-modifier($error-color);
  color: $secondary-color;
}

.dialog__button--success {
  @include button-modifier($success-color);
  color: $secondary-color;
}

.dialog__button--warning {
  @include button-modifier($warning-color);
  color: $secondary-color;
}
