.structured-field-editor {

  // --- Relation field ---
  .sf-relation {
    position: relative;
  }

  .sf-relation-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .sf-relation-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;

    &:empty {
      display: none;
    }
  }

  .sf-relation-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--darkened-bg, #f0f0f0);
    border: 1px solid var(--border-color, #ccc);
    border-radius: 4px;
    font-size: 0.8125rem;
    color: var(--body-fg, #333);
    max-width: 100%;
  }

  .sf-relation-tag-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sf-relation-tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--body-quiet-color, #666);
    cursor: pointer;
    font-size: 0.6875rem;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;

    &:hover {
      color: var(--error-fg, #ba2121);
      background: rgba(186, 33, 33, 0.1);
    }
  }

  // --- Search input ---
  .sf-relation-search {
    position: relative;
  }

  .sf-relation-input {
    padding-left: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 8px center;
    background-size: 14px;
  }

  // --- Dropdown ---
  .sf-relation-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    max-height: 240px;
    overflow-y: auto;
    background: var(--body-bg, #fff);
    border: 1px solid var(--border-color, #ccc);
    border-top: none;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .sf-relation-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.8125rem;
    color: var(--body-fg, #333);
    transition: background 0.1s;
    border-bottom: 1px solid var(--hairline-color, #eee);

    &:last-child {
      border-bottom: none;
    }

    &:hover,
    &.highlighted {
      background: var(--selected-bg, #e4e4e4);
    }
  }

  // --- Optional per-item rich rendering (image + secondary text) ---
  .sf-relation-item-image {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--hairline-color, #eee);
    background: var(--darkened-bg, #f0f0f0);
  }

  .sf-relation-item-content {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0; // allow children to ellipsis instead of overflowing
  }

  .sf-relation-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sf-relation-item-description {
    font-size: 0.6875rem;
    color: var(--body-quiet-color, #999);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sf-relation-tag-image {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    object-fit: cover;
    border-radius: 3px;
  }

  .sf-relation-dropdown-empty {
    padding: 12px;
    text-align: center;
    color: var(--body-quiet-color, #999);
    font-size: 0.8125rem;
    font-style: italic;
  }

  .sf-relation-dropdown-loading {
    padding: 8px 12px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--body-quiet-color, #999);
    font-style: italic;
    border-top: 1px solid var(--hairline-color, #eee);
  }
}
