@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap");

// Modern Dark Theme Variables
$bg-dark: #121212;
$bg-card: #1e1e1e;
$bg-input: #2d2d2d;
$bg-item: #2a2a2a;
$bg-item-hover: #333333;
$accent-blue: #4f46e5;
$accent-hover: #6366f1;
$text-primary: #f5f5f5;
$text-secondary: #a0a0a0;
$text-tertiary: #777777;
$border-color: rgba(255, 255, 255, 0.1);
$tooltip-bg: rgba(0, 0, 0, 0.85);
$shadow-color: rgba(0, 0, 0, 0.5);
$status-green: #22c55e;
$status-red: #ef4444;
$transition-default: all 0.2s ease;

// Animations
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// Container
.tools-popup-container {
  display: flex;
  flex-direction: column;
  min-height: 500px;
  max-height: 60vh;
  width: 450px; // Set fixed width of 450px
  overflow: hidden;
  border-radius: 8px;
  background-color: #1e1e1e;
  box-shadow: 0 10px 30px $shadow-color;
  color: $text-primary;
  font-family: "Inter", sans-serif;
  border: 1px solid $border-color;
  animation: fadeIn 0.3s ease;
  position: relative;
}

.header {
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-bottom: 0;

  .list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 8px;

    input {
      flex: 1;
      padding: 7px 14px;
      border-radius: 6px;
      background-color: $bg-input;
      color: $text-primary;
      font-size: 13px;
      border: 1px solid $border-color;
      transition: $transition-default;
      outline: none;

      &::placeholder {
        color: $text-tertiary;
      }

      &:focus {
        border-color: $accent-blue;
        box-shadow: 0 0 0 2px rgba($accent-blue, 0.15);
      }
    }

    .filter-button {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 12px;
      background-color: $bg-input;
      color: $text-secondary;
      border-radius: 6px;
      cursor: pointer;
      font-size: 13px;
      font-weight: 500;
      transition: $transition-default;
      border: none;

      i {
        font-size: 14px;
        width: 14px;
        height: 14px;
        margin-bottom: 2px;
      }

      &:hover {
        background-color: lighten($bg-input, 5%);
        color: $text-primary;
      }
    }
  }
}

.menu-header {
  display: flex;
  justify-content: flex-start;
  padding: 0;
  margin-bottom: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);

  button {
    background: transparent;
    border: none;
    color: $text-secondary;
    font-size: 13px;
    padding: 8px 16px;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
    font-weight: 500;

    &::after {
      content: "";
      position: absolute;
      bottom: -1px;
      left: 0;
      width: 100%;
      height: 2px;
      background-color: $accent-blue;
      transform: scaleX(0);
    }

    &:hover {
      color: $text-primary;
    }

    &.active {
      color: $text-primary;

      &::after {
        transform: scaleX(1);
      }
    }
  }
}

// Body Section
.body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

// Loading spinner
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
  width: 100%;
}

.dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: $accent-blue;
  animation: dot-animation 1.5s infinite ease-in-out;
}

.dot:nth-child(1) {
  animation-delay: 0s;
}

.dot:nth-child(2) {
  animation-delay: 0.3s;
}

.dot:nth-child(3) {
  animation-delay: 0.6s;
}

@keyframes dot-animation {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.5);
    opacity: 1;
  }
}

// Empty State
.no-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  color: $text-secondary;

  p {
    margin-bottom: 1rem;
  }

  .create-tool-btn {
    background-color: $accent-blue;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: $transition-default;
    border: none;
    cursor: pointer;

    &:hover {
      background-color: $accent-hover;
      transform: translateY(-1px);
    }

    .plus-icon {
      font-size: 16px;
    }
  }
}

// Tool List
.tools-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeIn 0.3s ease;

  .tool-item-container {
    display: flex;
    flex-direction: column;
    position: relative;

    .tool-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 12px;
      background-color: $bg-item;
      font-size: 13px;
      border-radius: 6px;
      cursor: pointer;
      transition: $transition-default;
      border: 1px solid transparent;

      &:hover {
        background-color: $bg-item-hover;
      }

      .tool-icon {
        font-size: 14px;
        opacity: 0.9;
        flex-shrink: 0;
      }

      .tool-name {
        flex: 1;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis; // Added ellipsis for text overflow
        max-width: 300px;
        margin-right: auto; // Push subsequent items to the right
      }

      .chevron-icon {
        color: $text-secondary;
        transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
        flex-shrink: 0;
        margin-left: auto; // Push to the right if there's no checkbox
      }

      .expanded {
        transform: rotate(180deg);
      }

      input[type="checkbox"] {
        appearance: none;
        -webkit-appearance: none;
        height: 16px;
        width: 16px;
        background-color: $bg-input;
        border: 1px solid $border-color;
        border-radius: 4px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: $transition-default;
        flex-shrink: 0;
        margin-left: 8px; // Add some space between the name and checkbox

        &:checked {
          background-color: $accent-blue;
          border-color: $accent-blue;

          &::after {
            content: "✓";
            color: white;
            font-size: 10px;
          }
        }

        &:hover:not(:checked) {
          background-color: lighten($bg-input, 5%);
        }
      }

      &.selected-item {
        border-color: $accent-blue;
        background-color: rgba($accent-blue, 0.08);
      }
    }

    .tool-configs {
      display: flex;
      flex-direction: column;
      gap: 8px;
      margin: 6px 0 8px 20px;
      overflow: hidden;
      transform-origin: top;
      animation: slideDown 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);

      input[type="checkbox"] {
        appearance: none;
        -webkit-appearance: none;
        height: 16px;
        width: 16px;
        background-color: $bg-input;
        border: 1px solid $border-color;
        border-radius: 4px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: $transition-default;
        flex-shrink: 0;

        &:checked {
          background-color: $accent-blue;
          border-color: $accent-blue;

          &::after {
            content: "✓";
            color: white;
            font-size: 10px;
          }
        }

        &:hover:not(:checked) {
          background-color: lighten($bg-input, 5%);
        }
      }

      .tool-config-item {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 8px;
        background-color: $bg-input;
        border-radius: 5px;
        transition: $transition-default;
        cursor: pointer;
        border-left: 2px solid transparent;

        .config-name {
          flex: 1;
          font-size: 12px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis; // Added ellipsis for config names
          margin-right: auto; // Push status indicator and checkbox to right
        }

        .status-indicator {
          width: 6px;
          height: 6px;
          border-radius: 50%;
          display: inline-block;
          flex-shrink: 0;
          margin-left: 8px; // Add space between name and indicator

          &.green {
            background-color: $status-green;
            box-shadow: 0 0 5px rgba($status-green, 0.5);
          }

          &.red {
            background-color: $status-red;
            box-shadow: 0 0 5px rgba($status-red, 0.5);
          }
        }

        &:hover {
          background-color: lighten($bg-input, 5%);
        }

        &.selected-config {
          border-left: 2px solid $accent-blue;
          background-color: rgba($accent-blue, 0.08);
        }
      }

      .create-config-btn {
        background-color: transparent;
        color: $accent-blue;
        padding: 6px 8px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 12px;
        font-weight: 500;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        transition: $transition-default;
        border: 1px dashed $accent-blue;
        margin-top: 4px;
        width: fit-content;

        &:hover {
          background-color: rgba($accent-blue, 0.1);
        }

        .plus-icon {
          font-size: 12px;
          font-weight: 600;
        }
      }
    }
  }
}

/* Specific styles for Python tools section */
.python-tools {
  animation: fadeIn 0.3s ease;

  .python-tool-item {
    background-color: $bg-item;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    font-size: 12px;
    color: $text-primary;
    cursor: pointer;
    transition: $transition-default;
    border: 1px solid transparent;
    margin-bottom: 6px;
    position: relative;

    &:hover {
      background-color: $bg-item-hover;
    }

    .tool-icon {
      font-size: 14px;
      opacity: 0.9;
      flex-shrink: 0;
    }

    .tool-name {
      flex: 1;
      font-weight: 500;
      position: relative;
      cursor: pointer;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis; // Added ellipsis for python tool names
      max-width: 300px;
      margin-right: auto; // Push checkbox to the right
    }

    input[type="checkbox"] {
      appearance: none;
      -webkit-appearance: none;
      height: 16px;
      width: 16px;
      background-color: $bg-input;
      border: 1px solid $border-color;
      border-radius: 4px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: $transition-default;
      flex-shrink: 0;
      margin-left: 8px; // Add space between name and checkbox

      &:checked {
        background-color: $accent-blue;
        border-color: $accent-blue;

        &::after {
          content: "✓";
          color: white;
          font-size: 10px;
        }
      }

      &:hover:not(:checked) {
        background-color: lighten($bg-input, 5%);
      }
    }

    &.selected-tool {
      border-color: $accent-blue;
      background-color: rgba($accent-blue, 0.08);
    }
  }
}

// Filter Panel
.filter-panel {
  position: absolute;
  top: 50px;
  right: 12px;
  width: 250px;
  background-color: $bg-dark;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 1px solid $border-color;
  z-index: 10;
  overflow: hidden;

  .filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid $border-color;

    h4 {
      margin: 0;
      font-size: 14px;
      font-weight: 500;
      color: $text-primary;
    }

    .close-btn {
      background: none;
      border: none;
      color: $text-secondary;
      font-size: 18px;
      cursor: pointer;

      &:hover {
        color: $text-primary;
      }
    }
  }

  .filter-content {
    padding: 12px;

    .filter-group {
      margin-bottom: 12px;

      label {
        display: block;
        margin-bottom: 6px;
        color: $text-secondary;
        font-size: 12px;
      }

      .checkbox-group {
        display: flex;
        flex-direction: column;
        gap: 8px;

        .checkbox-label {
          display: flex;
          align-items: center;
          gap: 8px;
          font-size: 13px;
          cursor: pointer;

          input[type="checkbox"] {
            appearance: none;
            -webkit-appearance: none;
            height: 14px;
            width: 14px;
            background-color: $bg-input;
            border: 1px solid $border-color;
            border-radius: 3px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: $transition-default;

            &:checked {
              background-color: $accent-blue;
              border-color: $accent-blue;

              &::after {
                content: "✓";
                color: white;
                font-size: 9px;
              }
            }
          }
        }
      }

      select {
        width: 100%;
        padding: 6px 8px;
        background-color: $bg-input;
        border: 1px solid $border-color;
        border-radius: 4px;
        color: $text-primary;
        font-size: 13px;

        &:focus {
          outline: none;
          border-color: $accent-blue;
        }
      }
    }

    .filter-actions {
      display: flex;
      gap: 8px;
      margin-top: 16px;

      button {
        padding: 6px 12px;
        border-radius: 4px;
        font-size: 13px;
        cursor: pointer;
        transition: $transition-default;
        border: none;
      }

      .apply-btn {
        background-color: $accent-blue;
        color: white;
        flex: 1;

        &:hover {
          background-color: $accent-hover;
        }
      }

      .reset-btn {
        background-color: $bg-input;
        color: $text-secondary;

        &:hover {
          background-color: lighten($bg-input, 5%);
          color: $text-primary;
        }
      }
    }
  }
}

// Footer Section
.footer {
  padding: 1rem;
  border-top: 1px solid $border-color;
  display: flex;
  justify-content: flex-end;

  .save-btn {
    background-color: $accent-blue;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: $transition-default;
    display: flex;
    align-items: center;
    border: none;

    &:hover {
      background-color: $accent-hover;
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba($accent-blue, 0.3);
    }

    &:active {
      transform: translateY(0px);
      box-shadow: none;
    }
  }
}
