// Toggle Variables
$toggle-background-color: white;
$toggle-size: 4rem;
$toggle-padding: 1rem;
$toggle-margin: 1rem;
$toggle-height: $toggle-size - ($toggle-padding * 2);
$toggle-width: $toggle-size - ($toggle-padding * 2);
$toggle-online-indicator-size: 10px;

// Widget Variables
$widget-font-family: helvetica, arial, sans-serif;
$widget-font-size: 15px;
$widget-header-background-color: rgb(9 94 84);
$widget-header-color: white;
$widget-header-online-indicator-size: 7px;
$widget-content-background-color: #d1ecd4;

$whatsapp-green: #4fce5d;

$box-shadow: 0 0 10px 5px rgb(0 0 0 / 10%);

$transition-all: all 0.25s linear;

.wa-widget-content {
  margin: $toggle-margin;
  overflow: hidden;
  font-family: $widget-font-family;
  font-size: $widget-font-size;
  border-radius: 0.75rem;
  box-shadow: $box-shadow;

  *,
  ::after,
  ::before {
    box-sizing: border-box;
  }
}

.wa-widget {
  position: fixed;
  right: 0;
  bottom: 0;
  margin: 0;

  &:last-child {
    margin-right: 0;
  }

  &.expanded {
    border-radius: 1rem;
  }

  .wa-widget-content {
    position: absolute;
    right: 0;
    bottom: $toggle-size + ($toggle-margin * 2);
    z-index: -1;
    width: 360px;
    visibility: hidden;
    opacity: 0;
    transition: $transition-all;

    &.expanded {
      z-index: 99;
      visibility: visible;
      opacity: 1;
    }
  }
}

.wa-widget-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: $toggle-width;
  height: $toggle-height;
  padding: 1rem;
  margin: $toggle-margin;
  text-align: center;
  background-color: $toggle-background-color;
  border-radius: 9rem;
  box-shadow: $box-shadow;

  &::before {
    position: absolute;
    top: calc($toggle-online-indicator-size / 2);
    right: calc($toggle-online-indicator-size / 2);
    width: $toggle-online-indicator-size;
    height: $toggle-online-indicator-size;
    content: '';
    background-color: red;
    border-radius: $toggle-online-indicator-size;
  }
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 1rem;
  color: $widget-header-color;
  background-color: $widget-header-background-color;

  .chat-admin-picture {
    position: relative;
    width: 3rem;
    height: 3rem;
    margin-right: 1rem;

    img {
      width: 100%;
      height: 100%;
    }

    &::before {
      position: absolute;
      right: calc($widget-header-online-indicator-size / 3);
      bottom: calc($widget-header-online-indicator-size / 3);
      width: $widget-header-online-indicator-size;
      height: $widget-header-online-indicator-size;
      content: '';
      background-color: $whatsapp-green;
      border: 2px solid $widget-header-background-color;
      border-radius: $widget-header-online-indicator-size;
    }
  }

  h4,
  p {
    margin: 0.2rem;
  }
}

.chat-content {
  padding: 1rem;
  background-color: $widget-content-background-color;

  .chat-admin-picture {
    width: 2rem;
    height: 2rem;
    margin-right: 0.5rem;
  }
}

.chat-item {
  display: inline-flex;
  align-items: flex-end;

  p {
    padding: 1rem;
    margin: 0 2rem 0.5rem 0;
    background-color: white;
    border-radius: 1rem;

    &:first-child {
      border-top-left-radius: 0;
    }
  }
}

.chat-form {
  padding: 0.25rem;
  background-color: white;

  textarea,
  input {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    font-family: inherit;
    resize: none;
    background-color: inherit;
    transition: $transition-all;
  }

  textarea,
  input,
  input:focus {
    border: 1px solid transparent;
    border-radius: 0.5rem;
    outline: 0;
  }

  .chat-send {
    width: 100%;
    padding: 0.75rem;
    font-size: 1.1rem;
    font-weight: bold;
    color: white;
    cursor: pointer;
    background-color: $whatsapp-green;
    border: 0;
    border-radius: 0.5rem;
    outline: 0;
  }

  .invalid {
    background-color: rgba($color: red, $alpha: 10%);
    border: 1px solid rgba($color: red, $alpha: 25%);
  }
}

@media (width <= 460px) {
  .wa-widget {
    width: 100%;
  }

  .wa-widget-toggle {
    float: right;
  }

  .wa-widget-content {
    right: $toggle-margin;
    left: $toggle-margin;
    width: auto;
  }
}
