@import "../base/variables";

.PageHeader {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
  padding: 0;

  @media (max-width: 768px) {
    margin-bottom: 16px;
  }
}

.Article[data-has-copy-dropdown="true"] {
  .page-heading-container {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-top: 0;
    margin-bottom: 1.5rem;
    line-height: 1.3;

    @media (max-width: 768px) {
      flex-wrap: nowrap;
      gap: 0.5rem;
    }

    h1 {
      flex: 1;
      margin: 0;
      min-width: 0;
      word-wrap: break-word;
      hyphens: auto;
    }

    .page-copy-dropdown--inline {
      flex-shrink: 0;
      margin: 0;
      align-self: flex-start;
    }
  }
}

.page-copy-dropdown {
  position: relative;
  display: inline-flex;
  margin-bottom: 1rem;
  flex-shrink: 0;

  &.page-copy-dropdown--inline {
    margin-bottom: 0;
    order: 1;

    @media (max-width: 768px) {
      // order: -1;
      // margin-bottom: 0.5rem;
      // align-self: flex-start;
    }
  }

  &__button {
    @extend .Button;
    @extend .Button--default;
    @extend .Button--small;

    --icon-color: #{rgba(map-get($color-aliases, "icon"), 0.8)};

    display: flex;
    align-items: center;
    padding-left: 12px;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: $base-0;
    color: map-get($color-aliases, "text-base");
    white-space: nowrap;
    transition: all 0.15s ease;

    &:hover {
      border-color: map-get($color-aliases, "border");
      transform: translateY(-1px);
    }

    &:active {
      transform: translateY(0);
    }

    svg {
      flex-shrink: 0;
    }

    .lucide-copy {
      color: rgba(map-get($color-aliases, "icon"), 0.8);
    }

    .lucide-chevron-down {
      margin-left: 5px;

      @media (max-width: 768px) {
        margin-left: 2px;
      }
    }

    @media (max-width: 768px) {
      padding: 8px 10px;
      gap: 4px;
      min-width: auto;
    }

    @media (max-width: 480px) {
      padding: 6px 5px 6px 8px;
      gap: 2px;
    }
  }

  &__button-text-full {
    @media (max-width: 768px) {
      display: none;
    }
  }

  &__button-text-short {
    display: none;

    @media (max-width: 768px) {
      display: none;
    }
  }

  &__menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    padding: 4px;
    background: $base-0;
    border: 1px solid map-get($color-aliases, "border");
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
      0 4px 6px -2px rgba(0, 0, 0, 0.05);
    min-width: 260px;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.15s ease;

    &--open {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }

    @media (max-width: 768px) {
      max-width: calc(100vw - 16px);
      box-shadow: 0 8px 12px -2px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.05);
    }

    @media (max-width: 480px) {
      max-width: calc(100vw - 32px);
    }
  }

  &__divider {
    height: 1px;
    background: $gray-100;
    margin: 4px 0;
  }

  &__item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 12px;
    border: none;
    border-radius: 4px;
    background: none;
    color: map-get($color-aliases, "text-base");
    font-family: $font-family-base;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;

    &:hover {
      background: map-get($color-aliases, "panel-background");
      color: $navy-900;
    }

    &:first-child {
      border-top-left-radius: 5px;
      border-top-right-radius: 5px;
    }

    &:last-child {
      border-bottom-left-radius: 5px;
      border-bottom-right-radius: 5px;
    }

    svg {
      flex-shrink: 0;
      color: map-get($color-aliases, "icon");
    }

    @media (max-width: 768px) {
      padding: 10px 8px;
      gap: 10px;
      font-size: 13px;
    }

    @media (max-width: 480px) {
      padding: 8px 6px;
      gap: 8px;
    }
  }

  &__item {
    &--loading {
      color: map-get($color-aliases, "icon");
      pointer-events: none;

      .page-copy-dropdown__item-icon svg {
        color: map-get($color-aliases, "icon");
      }
    }

    &--success {
      color: map-get($color-aliases, "state-success");

      .page-copy-dropdown__item-icon svg {
        color: map-get($color-aliases, "state-success");
      }
    }

    &--error {
      color: map-get($color-aliases, "state-fail");

      .page-copy-dropdown__item-icon svg {
        color: map-get($color-aliases, "state-fail");
      }
    }
  }

  &__item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;

    svg {
      color: map-get($color-aliases, "icon");
    }
  }

  &__item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  &__item-title {
    font-weight: 500;
    font-size: 14px;
    line-height: 1.2;
  }

  &__item-subtitle {
    font-size: 12px;
    color: $charcoal-300;
    line-height: 1.2;
  }

  &__item-external {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.6;

    svg {
      color: currentColor;
    }
  }

  // Temporarily hide Cursor MCP connection until hosted server is ready
  &__item[data-action="connect-cursor"] {
    display: none;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}
