@use '../../style/variables.scss';

.aiChatToggle {
  position: fixed;
  left: 50%;
  bottom: 20px; /* Position it at the bottom of the window */
  transform: translateX(-50%); /* Center it horizontally */
  z-index: 9; /* Lower z-index to be below modals */

  button {
    padding: 18px 14px; /* Adjusted padding to keep icon centered */
    border-radius: 10px; /* Rounded corners on all sides since it's centered */
    height: 60px;
    /* When toggle is open, don't expand width and don't show text on hover */
    &.isOpen {
      display: none;
    }
  }
}

.chatContainer {
  position: fixed;
  left: 50%;
  bottom: 20px; /* Position it above the toggle button */
  transform: translateX(-50%); /* Center it horizontally */
  z-index: 8; /* Lower z-index to be below modals */
  min-width: 450px;
  width: 50vw;
  overflow-y: auto;
  background-color: rgba(40, 40, 40, 0.8);
  backdrop-filter: blur(10px);
  border-radius: 8px; /* Rounded corners on all sides */
  border: 1px solid variables.$gray-200;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

  .chat-header {
    display: flex;
    align-items: center;
    padding: 18px 15px;
    border-bottom: 1px solid variables.$gray-700;
    position: relative;

    .chat-title {
      font-weight: 1000;
      color: variables.$white;
      font-size: 24px;
      display: flex;
      align-items: center;
      gap: 12px; /* Add space between text and icon */
      position: absolute;
      left: 0;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      justify-content: center;
      pointer-events: none; /* Allow clicks to pass through to elements below */

      svg {
        pointer-events: none; /* Ensure icon doesn't capture clicks */
      }
    }

    .betaPill {
      background: conic-gradient(
        from 0deg,
        #ff00cc,
        #ff00cc,
        #ff9900,
        #ff9900,
        #9900ff,
        #ff00cc
      );
      color: white;
      font-weight: bold;
      font-size: 12px;
      padding: 4px 10px;
      border-radius: 12px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
      text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
      white-space: nowrap;

      &:hover {
        opacity: 0.8;
      }
    }

    .chat-actions {
      display: flex;
      gap: 8px;
      margin-left: auto; /* Push to the right side */

      .reset-button {
        background: none;
        border: none;
        cursor: pointer;
        color: variables.$gray-400;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 4px;
        border-radius: 4px;

        &:hover {
          color: variables.$white;
          background-color: rgba(255, 255, 255, 0.1);
        }

        &:disabled {
          opacity: 0.5;
          cursor: not-allowed;
        }
      }

      .closeButton {
        background: none;
        border: none;
        cursor: pointer;
        color: variables.$gray-400;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 4px;
        border-radius: 4px;
        transition: all 0.2s ease;

        &:hover {
          color: variables.$white;
          background-color: rgba(255, 255, 255, 0.1);
        }
      }
    }
  }

  .chatMessages {
    max-height: 50vh;
    overflow-y: auto;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .loadingIndicator {
    align-self: center;
    padding: 8px 12px;
    color: variables.$gray-400;
    font-style: italic;
  }

  .ratingContainer {
    display: flex;
    justify-content: flex-end;
    padding: 0 15px 8px;
  }

  .ratingButtons {
    display: flex;
    gap: 10px;
    margin-top: 4px;
  }

  .ratingButton {
    background: none;
    border: 1px solid variables.$gray-600;
    border-radius: 4px;
    color: variables.$gray-400;
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;

    &:hover {
      background-color: variables.$darkgray-600;
      color: variables.$white;
      border-color: variables.$gray-400;
    }
  }

  .ratingFeedback {
    font-size: 12px;
    color: variables.$gray-400;
    font-style: italic;
    padding: 8px 0;
  }

  .chatMessage {
    max-width: 90%;
    padding: 8px 12px;
    border-radius: 12px;
    color: variables.$white;

    &.user {
      align-self: flex-end;
      background-color: variables.$purple-900;
    }

    &.functionCall {
      align-self: flex-start;
      background-color: variables.$darkgray-600;
      width: 100%;
      border-left: 3px solid #ffc107;
      position: relative;

      &.success {
        border-left-color: #28a745;
      }

      &.error {
        border-left-color: #dc3545;
      }

      .functionCallSummary {
        display: flex;
        align-items: center;
        cursor: pointer;
        font-size: 1.2em;

        .statusIndicator {
          display: inline-block;
          width: 10px;
          height: 10px;
          border-radius: 50%;
          margin-right: 8px;
          background-color: #ffc107;

          &.success {
            background-color: #28a745;
          }

          &.error {
            background-color: #dc3545;
          }
        }

        .editLocationButton {
          margin-left: auto;
          background-color: variables.$purple-100;
          color: variables.$white;
          border: none;
          border-radius: 4px;
          padding: 4px 8px;
          font-size: 0.8em;
          cursor: pointer;

          &:hover {
            background-color: variables.$purple-200;
          }

          &:focus {
            outline: none;
            box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
          }

          &:active {
            background-color: variables.$purple-400;
          }
        }
      }

      .functionCallDetails {
        margin-top: 8px;
        padding: 8px;
        background-color: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
        font-family: monospace;
        font-size: 1.2em;
        overflow-x: auto;
      }
    }

    &.assistant {
      align-self: flex-start;
      background-color: variables.$black;
      width: 100%; // Ensure full width for JSON content
      position: relative;

      .assistantAvatar {
        position: absolute;
        top: 3px;
        right: -45px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        overflow: hidden;
        border: 2px solid variables.$purple-900;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        z-index: 0;
        display: flex;
        align-items: center;
        justify-content: center;

        svg {
          width: 24px;
          height: 24px;
          color: variables.$white;
        }
      }
    }
  }

  .chatInput {
    display: flex;
    flex-direction: column;
    padding: 10px 15px;
    border-top: 1px solid variables.$gray-700;
    gap: 8px;
    background-color: rgb(50, 50, 50);

    input,
    .chatTextarea {
      background-color: rgb(50, 50, 50) !important;
      width: 100%;
      font-size: 18px !important;
      padding: 10px 4px;
      color: variables.$white !important; /* Ensure text is white */
      caret-color: variables.$white; /* Make cursor white too */

      &:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        background-color: rgba(255, 255, 255, 0.05);
      }
    }

    .chatTextarea {
      resize: none;
      border: none;
      outline: none;
      min-height: 40px;
      max-height: 320px;
      line-height: 1.4;
      font-family: inherit;
      box-sizing: border-box; /* Ensure padding is included in height calculations */
      transition: height 0.1s ease; /* Smooth height transitions */
    }

    .actionButtons {
      display: flex;
      justify-content: space-between;
      gap: 8px;

      .leftButtons {
        display: flex;
        gap: 8px;
        justify-content: flex-start;
        flex-grow: 1;
      }

      .rightButtons {
        display: flex;
        gap: 8px;
        justify-content: flex-end;
      }

      .actionButton {
        background-color: transparent;
        color: variables.$white;
        border: 1px solid variables.$purple-500;
        border-radius: 4px;
        padding: 8px 16px;
        cursor: pointer;
        transition: all 0.2s ease;

        &:hover {
          background-color: rgba(variables.$purple-500, 0.1);
        }

        &:disabled {
          opacity: 0.6;
          cursor: not-allowed;
          border-color: variables.$gray-600;
          color: variables.$gray-400;
        }
      }

      .sendButton {
        background-color: variables.$purple-100;
        color: variables.$white;
        border: none;
        border-radius: 4px;
        padding: 8px 16px;
        cursor: pointer;
        transition: all 0.2s ease;

        &:hover {
          background-color: variables.$purple-200;
        }

        &:disabled {
          opacity: 0.6;
          cursor: not-allowed;
        }

        &:active {
          background-color: variables.$purple-400;
        }
      }

      .resetButton {
        background: none;
        border: none;
        cursor: pointer;
        color: variables.$gray-400;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px;
        border-radius: 4px;

        &:hover {
          color: variables.$white;
          background-color: rgba(255, 255, 255, 0.1);
        }

        &:disabled {
          opacity: 0.5;
          cursor: not-allowed;
        }
      }

      .greenIcon {
        &:hover {
          color: #44ff44;
        }
      }
    }
  }
}

.markdownContent {
  position: relative; // This is needed for the absolute positioned footer
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: bold;
  }

  h1 {
    font-size: 1.8em;
  }
  h2 {
    font-size: 1.5em;
  }
  h3 {
    font-size: 1.3em;
  }
  h4 {
    font-size: 1.2em;
  }

  ul,
  ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
  }

  li {
    margin: 0.25em 0;
  }

  p {
    margin: 0.5em 0;
  }

  strong {
    font-weight: bold;
  }

  em {
    font-style: italic;
  }

  code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
  }

  pre {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;

    code {
      background-color: transparent;
      padding: 0;
    }
  }

  blockquote {
    border-left: 4px solid #ccc;
    padding-left: 1em;
    margin: 0.5em 0;
    color: #666;
  }

  table {
    border-collapse: collapse;
    margin: 1em 0;

    th,
    td {
      border: 1px solid #ccc;
      padding: 0.5em;
    }

    th {
      background-color: rgba(0, 0, 0, 0.05);
    }
  }

  .markdownFooter {
    position: absolute;
    bottom: 8px;
    right: 8px;
    opacity: 0;

    .copyButton {
      display: flex;
      align-items: center;
      gap: 4px;
      border: 1px solid variables.$darkgray-600;
      font-size: 12px;
      padding: 4px 8px;
      backdrop-filter: blur(3px);
      border-radius: 4px;
      cursor: pointer;

      &:hover {
        background-color: rgba(0, 0, 0, 0.3);
      }

      &:active {
        background-color: rgba(0, 0, 0, 0.4);
      }

      svg {
        width: 14px;
        height: 14px;
      }
    }
  }

  &:hover {
    .markdownFooter {
      opacity: 1;
    }
  }
}

.proFeaturesWrapper {
  position: relative;

  .proOverlay {
    position: absolute;
    top: 57px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    border-radius: 0 0 12px 12px; /* Only round the bottom corners */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    cursor: pointer;
    transition: background-color 0.2s ease;

    &:hover {
      background: rgba(0, 0, 0, 0.4);
    }

    &:active {
      background: rgba(0, 0, 0, 0.3);
    }

    .proOverlayContent {
      display: flex;
      align-items: center;
      gap: 8px;
      background: rgba(119, 77, 238, 0.9);
      transition: all 0.2s ease;
      padding: 8px 16px;
      border-radius: 8px;
      color: white;
      font-weight: 500;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

      &:hover {
        background: rgba(119, 77, 238, 1);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
      }

      &:active {
        background: rgba(107, 69, 214, 1);
        transform: translateY(0);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
      }

      span[role='img'] {
        font-size: 16px;
      }
    }
  }
}

/* Snapshot component styles */
.snapshotContainer {
  margin: 10px 0;
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.snapshotCaption {
  font-weight: 500;
  margin-bottom: 8px;
  color: #cccccc;
  text-align: center;
}

.snapshotImageWrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 4px;
  position: relative;
}

.snapshotImage {
  max-width: 100%;
  max-height: 400px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.snapshotActions {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
  opacity: 0;
}

.resetButton {
  margin-left: 8px;
  padding: 4px;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease;

  &:hover {
    opacity: 1;

    svg path {
      stroke: #44ff44;
    }
  }

  &:disabled {
    opacity: 0.3;
    cursor: not-allowed;

    &:hover svg path {
      stroke: inherit;
    }
  }
}

.snapshotButton {
  background: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 4px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
  padding: 0;

  svg {
    width: 20px;
    height: 20px;
  }

  &:hover {
    background: rgba(0, 0, 0, 0.7);
  }
}

.snapshotImageWrapper:hover .snapshotActions {
  opacity: 1;
}

.resetConfirmModal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.resetConfirmContent {
  background-color: variables.$darkgray-800;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);

  p {
    margin: 10px 0 30px 0;
    color: variables.$white;
    text-align: center;
    font-size: 18px !important;
  }

  .resetConfirmButtons {
    display: flex;
    justify-content: center;
    gap: 12px;

    button {
      padding: 8px 16px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-weight: 500;
      font-size: 18px !important;

      &:first-child {
        background-color: #dc3545;
        color: variables.$white;

        &:hover {
          background-color: #bd2130;
        }
      }

      &:last-child {
        background-color: variables.$darkgray-600;
        color: variables.$white;

        &:hover {
          background-color: variables.$darkgray-500;
        }
      }
    }
  }
}
